Skip to content

Fix runtime errors in test scripts and utility functions#1

Open
chrishwiggins wants to merge 1 commit intoFrancoisSimon:mainfrom
chrishwiggins:fix/runtime-errors
Open

Fix runtime errors in test scripts and utility functions#1
chrishwiggins wants to merge 1 commit intoFrancoisSimon:mainfrom
chrishwiggins:fix/runtime-errors

Conversation

@chrishwiggins
Copy link
Collaborator

Summary

Hi Francois - congratulations on the ExaTrack paper and release! Really nice work combining the ExTrack and aTrack approaches into a unified framework.

While reading through the code to understand the implementation, I noticed a handful of issues that would cause crashes at runtime. These look like they accumulated naturally as the API in exatrack.py evolved (adding the model type column, renaming keyword arguments, changing return signatures) - the kind of thing that's easy to miss when the main fitting scripts are working fine and the test scripts haven't been run in a while.

I've tried to keep each fix as small and obvious as possible, changing only what's needed to make the calls match the current signatures.

Changes

exatrack.py (core library)

  1. generate_movie / emit_photons argument mismatch - emit_photons expects a pixel_dims parameter, but the call site in generate_movie wasn't passing it. Added the missing argument.

  2. model_to_DataFrame - invalid tf.math.sigmoid call - Two lines computed Tr_shape and Tr_rate but were never used, and the Tr_rate line called tf.math.sigmoid(..., axis=1) which isn't a valid signature. Since the transition rates and shapes are already processed in the params dict above (softmax and exp already applied), these lines appear to be leftover from an earlier version. Removed them.

  3. get_number_of_states - hardcoded model_results[6] reference - Line model_results[6]['model'].summary() was placed before the results dict is populated and uses a hardcoded key that assumes exactly 6 states. This looks like a leftover debug line. Removed it.

  4. get_number_of_states - double log-likelihood scaling - The log-likelihood is already multiplied by nb_tracks when first computed. A later loop (for k in range(1,7)) multiplied it again, which would corrupt the AIC/BIC values used for model selection. The loop also assumed exactly 6 models via the hardcoded range. Removed the redundant multiplication.

  5. Model_finder - get_model_params() returns a dict, not a tuple - The code tried to unpack 5 variables from get_model_params(model), but that function returns a single dictionary. Changed to use model.get_weights(), which matches the pattern used successfully earlier in the same function.

test_model.py

  1. Missing 5th column (model type indicator) in params - The constraint_function reads params[4] to determine confined vs. directed motion, but params only had 4 columns. Added the model type column.

  2. Missing initial_fractions argument - build_model requires initial_fractions as a positional argument, but it wasn't being passed. Added it with sensible defaults (equal fractions, low mislinking probability).

  3. Wrong keyword nb_dimensions - build_model accepts nb_dims, not nb_dimensions. Fixed the keyword name.

test_loading_data.py

  1. Unpacking 3 values from read_table which returns 4 - read_table returns (tracks, frames, track_IDs, opt_metrics) but the script only unpacked 3 values. Added track_ID_list to the unpacking.

  2. Undefined variables nb_independent_vars and nb_dimensions - Added nb_dims = 2 and used it consistently.

  3. Same initial_fractions and model type column fixes as test_model.py.

Test plan

  • Verify python -m py_compile passes for all three files (confirmed locally)
  • Run test_model.py end-to-end with simulated data
  • Run test_loading_data.py with sample CSV data
  • Verify Model_finder and get_number_of_states don't crash on their first call

Generated with Claude Code

…data.py

- Pass missing pixel_dims arg to emit_photons in generate_movie
- Unpack all 4 return values from read_table in test_loading_data.py
- Use correct keyword nb_dims (not nb_dimensions) in build_model calls
- Add missing initial_fractions argument to build_model calls
- Add missing nb_dims and model type column in test scripts
- Remove broken tf.math.sigmoid(axis=1) call in model_to_DataFrame
- Remove hardcoded model_results[6] debug line in get_number_of_states
- Fix double-multiplication of log_likelihood by nb_tracks
- Use model.get_weights() instead of get_model_params() in Model_finder

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@FrancoisSimon
Copy link
Owner

Thank you for the comments. I fixed the issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants