Repository navigation
Make PEtab v2 ExperimentManager lookups constant-time - #3520
Open
FFroehlich wants to merge 2 commits into
Open
FFroehlich wants to merge 2 commits into
FFroehlich wants to merge 2 commits into
Conversation
`ExperimentManager` looked up experiments, conditions, measurements, and estimated parameters through `petab.v2.Problem`, which scans its tables on every lookup and rebuilds `x_ids`/`x_free_ids` on every access. Creating the `ExpData` objects was therefore quadratic in the number of experiments and in the number of parameters. Build lookup tables once in `ExperimentManager.__init__` (the problem must not change afterwards) and use them in `create_edata`, `apply_parameters`, and `PetabSimulator`'s sensitivity aggregation. Also replace the list `.index()` calls for plist entries, observables, and timepoints, and compute the nominal parameters once per `create_edatas` call. Fixes #3519. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3520 +/- ##
==========================================
+ Coverage 80.26% 80.30% +0.04%
==========================================
Files 331 331
Lines 23420 23431 +11
Branches 1631 1631
==========================================
+ Hits 18797 18816 +19
+ Misses 4617 4609 -8
Partials 6 6
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
FFroehlich
marked this pull request as ready for review
November 7, 2026 18:59
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 tasks done
2 tasks done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this pull request do, and why?
Makes
ExperimentManager.create_edatas(andPetabSimulator's sensitivity aggregation) for PEtab v2 problems scale linearly instead of quadratically in the number of experiments and parameters.ExperimentManagerlooked up experiments, conditions, measurements, and estimated parameters throughpetab.v2.Problem, which scans its tables on every lookup (Problem.__getitem__walks the condition table before the experiment table,get_measurements_for_experimentwalks the whole measurement table) and rebuildsx_ids/x_free_idson every access. Withapply_parameterschecking each free model parameter for membership in thex_free_idslist,create_edataswas quadratic both in the number of experiments and in the number of parameters.Since the problem must not be modified after the
ExperimentManageris created, lookup tables are now built once in__init__:x_free_ids;x_free_idsindex for estimated parameters (this is also the experiment-independent part ofplist), and the (problem parameter, model parameter index) pairs for free and fixed model parameters;They are used in
create_edata,_set_constants,_set_timepoints_and_measurements,apply_parameters,_get_placeholder_mapping, andPetabSimulator._aggregate_sllh/_get_plist_to_problem_par_ix. The latter also calledplist.index()per estimated parameter, i.e. was quadratic in the number of parameters for each experiment; it now uses a dict. Smaller things in the same spirit:_get_measurements_and_sigmasusesbisectfor the timepoint index instead oflist.index(quadratic in the number of timepoints of an experiment);create_edatascomputes the scaled nominal parameters once, not per experiment;_aggregate_s2llhfinds non-unique indices with a mask instead ofinon a NumPy array.Testing:
test_simulate_does_not_scan_petab_problem: makesProblem.__getitem__,get_changes_for_period, andget_measurements_for_experimentraise, then simulates with forward sensitivities (sosllh,s2llh, andsresare aggregated). Fails onmain, passes here.python/tests/petab_/test_petab_v2.py: all 24 tests pass locally (libpetabmain, including the JAX tests).tests/petab_test_suite/test_petab_v2_suite.py, SUNDIALS cases (-k False): 41 passed, 6 skipped (the existing PySB "parameters as condition targets" / "compartment size changes" limitations).mainwith this one on a synthetic problem (preequilibration, replicates, observable/noise placeholders with numeric and parameter overrides, experiments without measurements, log/log10 scales, estimated and non-estimated parameters). AllExpDatafields (timepoints, measurements, sigmas, fixed parameters incl. preequilibration,t_start,plist, parameters,pscale) aftercreate_edatasand afterapply_parameterswith random parameters, and the_get_plist_to_problem_par_ixmaps, are identical. Timings for 1000 experiments, 1504 free and 1501 fixed model parameters, 1508 estimated problem parameters, 4545 measurements:maincreate_edatas()apply_parametersfor all experiments_get_plist_to_problem_par_ixfor all experimentsWhat remains is linear per experiment (filling each
ExpData's parameter and scale vectors). Not run on the Froehlich_CellSystems2018 problem from the issue itself.Related issues
Fixes #3519
Use of AI tools
Claude Code (Claude Opus 5.5) wrote the implementation, the test, the changelog entry, and this description, and ran the equivalence check and benchmark described above.
Checklist
changelog.d/(or it is not needed)🤖 Generated with Claude Code