Skip to content

Fix noise formulas that refer to model expressions - #3379

Closed
dweindl wants to merge 3 commits into
AMICI-dev:mainfrom
dweindl:fix_sigma_expressions
Closed

dweindl wants to merge 3 commits into
AMICI-dev:mainfrom
dweindl:fix_sigma_expressions

Conversation

@dweindl

@dweindl dweindl commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Fix the compilation of models with noise formulas that refer to model expressions (e.g., targets of assignment rules).

sigmay and sigmaz are evaluated without the expressions w, so the generated code referred to undeclared variables. The expressions are now substituted in DEModel._compute_equation (only for noise formulas that contain any), before the existing check for state-dependent noise formulas. That check replaces states by the matching observable; the expressions are now also substituted in the observable formula before solving for the state. Otherwise, expressions that depend on the states (e.g., readout := A in #3384) were rejected at import.

Adds test_noise_formula_with_expression, which checks sigmay, ssigmay and sigmaz for time-resolved and event noise formulas that refer to an expression, including a state-dependent one for sigmay. On main, the model does not compile.

Still not supported: noise formulas that depend on piecewise functions or events (sigmay/sigmaz have no Heaviside argument) or on splines, and state-dependent event noise formulas (also without expressions, e.g., sigma="x * p", since sigmaz has no z argument).

ssigmaz is not checked, since it is never filled in ReturnData (#3380).

Fixes #3377.
Fixes #3384.

🤖 Generated with Claude Code

`sigmay` and `sigmaz` are evaluated without the expressions `w`. If a
noise formula referred to an expression, the generated code referred to
an undeclared variable and did not compile.

Fixes AMICI-dev#3377.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dweindl dweindl self-assigned this Oct 14, 2026
@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.89%. Comparing base (8181384) to head (4924189).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3379      +/-   ##
==========================================
+ Coverage   79.54%   79.89%   +0.34%     
==========================================
  Files         320      320              
  Lines       22466    22593     +127     
  Branches     1507     1516       +9     
==========================================
+ Hits        17870    18050     +180     
+ Misses       4588     4535      -53     
  Partials        8        8              
Flag Coverage Δ
cpp 73.97% <100.00%> (+0.39%) ⬆️
cpp_python 35.15% <50.00%> (-0.03%) ⬇️
petab 48.70% <100.00%> (-0.19%) ⬇️
petab_sciml 16.98% <100.00%> (-0.05%) ⬇️
petab_sciml_benchmarks 15.55% <100.00%> (-0.04%) ⬇️
python 72.14% <100.00%> (+0.34%) ⬆️
sbmlsuite 50.98% <ø> (+0.37%) ⬆️

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

Files with missing lines Coverage Δ
python/sdist/amici/_symbolic/de_model.py 93.54% <100.00%> (+0.88%) ⬆️

... and 17 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…ulas

States in noise formulas are replaced by the matching observable. This
failed if the observable formula refers to expressions, since they were
not expanded before solving for the state.

Fixes AMICI-dev#3384.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Noise formulas that depend on piecewise functions or splines, and
state-dependent event noise formulas, are still not supported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dweindl

dweindl commented Oct 15, 2026

Copy link
Copy Markdown
Member Author

Superseded by #3388.

@dweindl dweindl closed this Oct 15, 2026
@dweindl
dweindl deleted the fix_sigma_expressions branch October 15, 2026 11:53
FFroehlich added a commit that referenced this pull request Oct 15, 2026
sigmaz is evaluated without the event observables, so replacing states
in event noise formulas by the event output generated uncompilable code.
States are now only replaced in sigmay. State-dependent event noise
formulas and event noise formulas that refer to the event observable
itself are rejected at import (#3389, point 3).

Adds `test_noise_formula_with_expression`, adapted from #3379, which
checks sigmay, ssigmay and sigmaz for time-resolved and event noise
formulas that refer to expressions (#3377), and
`test_unsupported_sigmas_rejected` for the cases of #3389 (piecewise
functions, splines, state- and event-observable-dependent event noise
formulas).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dweindl dweindl added the code generation Related to model code generation label Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code generation Related to model code generation

Projects

None yet

1 participant