Repository navigation
Reuse ExpDatas across PEtab v2 PetabSimulator.simulate calls - #3522
Open
FFroehlich wants to merge 1 commit into
Open
FFroehlich wants to merge 1 commit into
FFroehlich wants to merge 1 commit into
Conversation
`PetabSimulator.simulate` recreated the `ExpData` objects for all experiments on every call and then applied the parameters on top of the nominal ones, so `apply_parameters` ran twice per experiment and call. Apart from what `apply_parameters` sets, the `ExpData`s only depend on the PEtab problem, which must not change, and the model. Create the `ExpData`s on the first call to `simulate`, with the given parameters, and afterwards only apply the parameters to them. `ExperimentManager.create_edatas` now takes the problem parameters to apply, like `create_edata`. Fixes #3521. 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 @@
## claude/github-issue-3519-c591fc #3522 +/- ##
================================================================
Coverage 80.30% 80.30%
================================================================
Files 331 331
Lines 23431 23434 +3
Branches 1631 1631
================================================================
+ Hits 18816 18819 +3
Misses 4609 4609
Partials 6 6
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This was referenced Nov 7, 2026
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
PetabSimulator.simulate(PEtab v2) create theExpDataobjects only once, on its first call, and reuse them afterwards. Before, every call recreated allExpDatas (constants, timepoints, measurements, sigmas, and the nominal parameters) and then applied the actual parameters on top, i.e.apply_parametersran twice per experiment and call. None of that apart fromapply_parametersdepends on the problem parameters.PetabSimulatorkeeps theExpDatas from the firstsimulatecall. Later calls only runExperimentManager.apply_parameterson them.apply_parametersalready sets all parameter-dependent values from scratch on each call (plist, free parameters,pscale, and the fixed parameters mapped to problem parameters), and the PEtab problem must not change after theExperimentManageris created, so the reusedExpDatas stay valid.ExperimentManager.create_edatastakes an optionalproblem_parametersargument, likecreate_edataalready does. The firstsimulatecall uses it, so parameters are applied once per experiment and call.PetabSimulationResult.edatasholds the reused objects (in a new list). Thesimulatedocstring already said they "may be changed by subsequent calls". It now says they are reused and must not be modified.Behaviour changes to be aware of:
ExpData(model)copies the model's reinitialization settings (reinitialize_fixed_parameter_initial_states,reinitialization_state_idxs), and, for experiments without periods, its fixed parameters. These are now read on the firstsimulatecall only, so later changes to the model's settings don't reach the reusedExpDatas. Solver settings and all other model settings still apply to every call.simulateon the samePetabSimulatorfrom several Python threads at once now shares theExpDataobjects between them. Copy the simulator per thread instead.ExpDatadeep copies and pickles keep all fields (checked separately), andtest_petab_simulator_deepcopy_and_picklepickles a simulator after it has simulated.This is stacked on #3520 (constant-time lookups in
ExperimentManager, #3519), which makes the remainingapply_parameterscalls cheap.Testing:
New
test_simulate_reuses_edatas: countscreate_edataandapply_parameterscalls over twosimulatecalls (one creation and one application per experiment on the first call, one application per experiment on the second), checks that the sameExpDataobjects are returned, and that after switching parameters (including the nominal ones) the reusedExpDatas,llh, andsllhequal those of a new simulator and of freshly createdExpDatas. The problem has a non-estimated parameter mapped to a fixed model parameter and placeholders overridden by parameters in one experiment and by numbers in the other, on non-linear parameter scales. Fails on Make PEtab v2 ExperimentManager lookups constant-time #3520's head, passes here.python/tests/petab_/test_petab_v2.py: all tests pass locally (25 including the JAX tests before rebasing onto Make PEtab v2 ExperimentManager lookups constant-time #3520's latest commit, which only adds a test; 18 SUNDIALS tests after the rebase).A scratch script timed five
simulatecalls on a synthetic problem with 1000 experiments (1 state, 3 measurements each, an estimated observable placeholder override), single-threaded. The log-likelihoods are identical on both branches.simulatecall after the firstNot run on the Froehlich_CellSystems2018 problem from the issue.
Related issues
Fixes #3521
Use of AI tools
Claude Code (Claude Opus 5.5) wrote the implementation, the test, the changelog entry, and this description, and ran the tests and timings described above.
Checklist
changelog.d/(or it is not needed)🤖 Generated with Claude Code