Skip to content

Fix incorrect initialization for non-constant initial assignments#2939

Merged
dweindl merged 8 commits intoAMICI-dev:mainfrom
dweindl:fix_2936_nonconst_ia
Aug 26, 2025
Merged

Fix incorrect initialization for non-constant initial assignments#2939
dweindl merged 8 commits intoAMICI-dev:mainfrom
dweindl:fix_2936_nonconst_ia

Conversation

@dweindl
Copy link
Member

@dweindl dweindl commented Aug 18, 2025

Fixes a bug where targets of initial assignments are not initialized correctly if the initial assignment expression is implicitly time-dependent. Fixes #2936.

  • eliminate state variables from x0 after replacing rate-of expressions
  • implement supposed-to-be static expressions that have non-constant entities in their initial condition as state variables instead of expressions.

Fixes a bug where targets of initial assignments are not initialized correctly if the initial assignment expression is implicitly time-dependent.
Fixes AMICI-dev#2936.
@dweindl dweindl self-assigned this Aug 18, 2025
@codecov
Copy link

codecov bot commented Aug 18, 2025

Codecov Report

❌ Patch coverage is 95.83333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.02%. Comparing base (032c21a) to head (6996b7e).
⚠️ Report is 110 commits behind head on main.

Files with missing lines Patch % Lines
python/sdist/amici/sbml_import.py 92.30% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2939      +/-   ##
==========================================
- Coverage   79.60%   79.02%   -0.59%     
==========================================
  Files         362      362              
  Lines       23157    23175      +18     
  Branches     1588     1588              
==========================================
- Hits        18435    18314     -121     
- Misses       4710     4849     +139     
  Partials       12       12              
Flag Coverage Δ
cpp 74.96% <95.83%> (-0.02%) ⬇️
cpp_python 33.15% <66.66%> (+0.02%) ⬆️
petab 38.80% <58.33%> (+0.01%) ⬆️
python 73.82% <95.83%> (-0.02%) ⬇️
sbmlsuite-jax ?

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

Files with missing lines Coverage Δ
python/sdist/amici/de_model.py 92.51% <100.00%> (-0.36%) ⬇️
python/sdist/amici/sbml_import.py 80.16% <92.30%> (-11.88%) ⬇️

... and 6 files with indirect coverage changes

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

@dweindl dweindl marked this pull request as ready for review August 19, 2025 15:03
@dweindl dweindl requested a review from a team as a code owner August 19, 2025 15:03
if replacement:
self._eqs["x0"][i_state] = new
made_substitutions = True
if made_substitutions:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only apply this to new above?

subs = toposort_symbols(
dict(zip(self.sym("x_rdata"), self.eq("x0"), strict=True))
)
subs = dict(zip(self._syms["w"], self.eq("w"), strict=True)) | subs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this has to be done in a loop as dict(zip(self._syms["w"], self.eq("w"), strict=True)) subs may introduce new self.sym("x_rdata") variables.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

w should not depend on x_rdata:

"w": _FunctionInfo(
"realtype *w, const realtype t, const realtype *x, "
"const realtype *p, const realtype *k, "
"const realtype *h, const realtype *tcl, const realtype *spl, "
"bool include_static",
assume_pow_positivity=True,
),

Unless the respective substitutions in w are only made later, but I don't think that is the case - the rateOf processing should happen last.

@dweindl dweindl merged commit b12c68a into AMICI-dev:main Aug 26, 2025
24 of 25 checks passed
@dweindl dweindl deleted the fix_2936_nonconst_ia branch August 26, 2025 09:16
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.

Constant parameter with initial assignment is compiled as a dynamic expression

2 participants