Skip to content

Fix ExpData(model) not reinitializing states at the start of presimulation - #3468

Open
dweindl wants to merge 1 commit into
AMICI-dev:mainfrom
dweindl:fix-expdata-presim-reinit
Open

dweindl wants to merge 1 commit into
AMICI-dev:mainfrom
dweindl:fix-expdata-presim-reinit

Conversation

@dweindl

@dweindl dweindl commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Model.set_reinitialize_fixed_parameter_initial_states(True) applies to the start of presimulation and of the main simulation, but ExpData(model) only translated it into reinitialization_state_idxs_sim, leaving reinitialization_state_idxs_presim empty. With pre-equilibration and presimulation, states were therefore not reinitialized at the start of presimulation.

Furthermore, ConditionContext applied reinitialization_state_idxs_presim only if fixed_parameters_presimulation was set. Without it, presimulation uses the main fixed parameters, and states still weren't reinitialized at its start, whereas ExpData.reinitialize_fixed_parameter_initial_states = True does reinitialize them. The index lists are now applied independently of whether the respective fixed parameters are provided; for consistency, this also applies to reinitialization_state_idxs_sim and fixed_parameters. Nothing changes for ExpData objects with empty index lists (the default, except for ExpData(model) with reinitialization enabled in the model).

Behavior changes for users:

  • Results change for simulations with pre-equilibration, presimulation, and state reinitialization enabled via ExpData(model), and for ExpData objects with reinitialization_state_idxs_presim/reinitialization_state_idxs_sim set but fixed_parameters_presimulation/fixed_parameters empty (previously, these index lists were silently ignored).
  • Adjoint sensitivity analysis with presimulation now raises an error if reinitialization_state_idxs_presim is set without fixed_parameters_presimulation and these states are reinitialized, as reinitialization at the start of presimulation is not yet supported for adjoints (Enable adjoint preequilibration for models with solver state reinitialization #1156). Previously, this ran without reinitialization.

PEtab-based workflows are not affected (no presimulation, and fixed parameters are always set if there are any).

Fixes #3458.
Relates to #3453.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.71%. Comparing base (7fb8c57) to head (5a98b02).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3468   +/-   ##
=======================================
  Coverage   80.71%   80.71%           
=======================================
  Files         331      331           
  Lines       23688    23689    +1     
  Branches     1674     1674           
=======================================
+ Hits        19120    19121    +1     
  Misses       4562     4562           
  Partials        6        6           
Flag Coverage Δ
cpp 75.31% <100.00%> (+<0.01%) ⬆️
cpp_python 34.88% <71.42%> (+0.01%) ⬆️
petab 47.15% <42.85%> (+<0.01%) ⬆️
petab_sciml 16.50% <0.00%> (-0.01%) ⬇️
petab_sciml_benchmarks 15.11% <0.00%> (-0.01%) ⬇️
python 72.97% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
include/amici/simulation_parameters.h 100.00% <ø> (ø)
src/edata.cpp 89.13% <100.00%> (+0.03%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dweindl dweindl self-assigned this Oct 25, 2026
@dweindl
dweindl force-pushed the fix-expdata-presim-reinit branch 2 times, most recently from a7e5a6b to e0642f7 Compare October 28, 2026 14:52
@dweindl
dweindl force-pushed the fix-expdata-presim-reinit branch from e0642f7 to ba366d9 Compare November 14, 2026 19:03
`ExpData(Model)` translated the model's reinitialization setting only
into `reinitialization_state_idxs_sim`, not into
`reinitialization_state_idxs_presim`, although it applies to the start
of both periods.

Furthermore, `ConditionContext` applied these index lists only if the
respective fixed parameters were provided in the `ExpData`. Without
`fixed_parameters_presimulation`, presimulation uses the main fixed
parameters, but no states were reinitialized at its start, unlike with
`ExpData.reinitialize_fixed_parameter_initial_states`. Apply the index
lists independently of whether fixed parameters are provided, for
presimulation and, for consistency, the main simulation.

Fixes AMICI-dev#3458.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dweindl
dweindl force-pushed the fix-expdata-presim-reinit branch from ba366d9 to 5a98b02 Compare November 16, 2026 09:58
@dweindl
dweindl marked this pull request as ready for review November 16, 2026 11:00
@dweindl
dweindl requested a review from a team as a code owner November 16, 2026 11:00

This branch has not been deployed

No deployments
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.

ExpData(model) drops the model's state reinitialization at the start of presimulation

1 participant