Skip to content

Support {state}_init symbols for initial values in equations#32

Merged
JR-1991 merged 4 commits into
masterfrom
equation-inits
Jun 18, 2026
Merged

Support {state}_init symbols for initial values in equations#32
JR-1991 merged 4 commits into
masterfrom
equation-inits

Conversation

@JR-1991

@JR-1991 JR-1991 commented Jun 18, 2026

Copy link
Copy Markdown
Owner

This pull request introduces a robust mechanism for referencing the initial value of any state in model equations using the {state}_init symbol. It ensures that initial values are resolved dynamically from simulation initial conditions, both during standard simulations and when using surrogate models or MCMC with sampled initial conditions. Additionally, the documentation and tests have been updated to reflect and validate this new feature.

Support for referencing initial values in equations:

  • Equations can now reference the initial value of any state using the {state}_init suffix. These symbols are resolved from the simulation's initial conditions, not registered as parameters, and are validated to ensure the referenced state exists in the model. [1] [2] [3] [4]

Simulation and surrogate model integration:

  • The simulation stack and surrogate simulation paths have been updated so that {state}_init symbols are always resolved from the current initial conditions (y0) passed to the simulation, ensuring correct behavior when initial conditions are sampled or transformed (e.g., in MCMC or surrogate rate evaluation). [1] [2] [3] [4] [5] [6] [7]

Testing and validation:

  • New integration tests verify that equations referencing {state}_init behave correctly, both in surrogate and full simulation paths, including when initial conditions are sampled (e.g., via estimate_initials). This ensures the new mechanism works end-to-end and guards against regressions.

Minor improvements and cleanup:

  • Typing improvements and minor code cleanups to support the above changes. [1] [2] [3] [4]

JR-1991 added 4 commits June 11, 2026 19:59
Track and expose initial-value symbols so equations can reference a state's initial value via "{state}_init". Equation: add an inits set and collect/validate "*_init" symbols during parsing (ensure referenced state exists and do not register them as parameters). Simulation: forward y0 as an extra arg to the integrator so initial values are available at runtime. Stack: expose an "inits" symbol list (positionally matching state order), accept an optional inits array when evaluating modules, and propagate it through ODE/Reaction stacks. Tests: add an integration test verifying that "{state}_init" reuses the measurement initial value (not a parameter) and that rates behave accordingly.
Ensure initial-value symbols of the form "{state}_init" are resolved from live y0s and not treated as regular constants. Changes include: add target_accept_prob to MCMCConfig and pass it into HMC/NUTS; allow add_assignment to accept kwargs; exclude init symbols from get_constants_order via a new _is_init_symbol helper; rework surrogate-backed sim function to treat flattened y0s as per-measurement points, derive per-measurement inits from each measurement's t=0 state, and vmapped/jit the rate evaluation accordingly. Minor formatting tweak to a sigma prior call. Added integration tests covering surrogate init resolution, estimated-initials MCMC path, and init symbols declared as constants to prevent KeyError when building the constants matrix.
Remove an unused `import jax` from tests/integration/test_mcmc.py. This is a small cleanup to eliminate a leftover import and avoid linter/unused-import warnings; there are no behavioral changes.
Document the new `{state}_init` suffix for referencing a state's initial value inside ODE equations. Adds a brief example showing `S` vs `S_init`, explains use cases (e.g. normalization or driving terms by initial concentration), and notes that the referenced state must exist (raises ValueError if not), `_init` symbols are not registered as parameters, and current and initial values may be mixed in the same expression.
@JR-1991 JR-1991 self-assigned this Jun 18, 2026
@JR-1991 JR-1991 added the enhancement New feature or request label Jun 18, 2026
@JR-1991 JR-1991 merged commit abf2531 into master Jun 18, 2026
@mintlify

mintlify Bot commented Jun 18, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
catalax 🟢 Ready View Preview Jun 18, 2026, 10:09 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant