Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split expressions into static and dynamic #2303

Merged
merged 9 commits into from
Feb 27, 2024

Conversation

dweindl
Copy link
Member

@dweindl dweindl commented Feb 22, 2024

Split expressions in w and its derivatives into dynamic (explicitly or implicitly time-dependent) and static ones.
Evaluate static ones only when needed, i.e. after (re)initializing x_rdata or parameters.

See #1269

Copy link

codecov bot commented Feb 22, 2024

Codecov Report

Attention: Patch coverage is 38.07339% with 270 lines in your changes are missing coverage. Please review.

Project coverage is 77.83%. Comparing base (6a1cc3c) to head (0022111).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2303      +/-   ##
===========================================
+ Coverage    77.72%   77.83%   +0.10%     
===========================================
  Files          321      321              
  Lines        20601    20678      +77     
  Branches      1436     1440       +4     
===========================================
+ Hits         16013    16095      +82     
+ Misses        4585     4580       -5     
  Partials         3        3              
Flag Coverage Δ
cpp 73.62% <38.07%> (+0.12%) ⬆️
cpp_python 34.35% <25.00%> (+0.23%) ⬆️
petab 36.90% <94.73%> (+0.33%) ⬆️
python 72.43% <38.07%> (+0.13%) ⬆️
sbmlsuite ∅ <ø> (∅)

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

Files Coverage Δ
include/amici/abstract_model.h 100.00% <ø> (ø)
include/amici/model.h 73.68% <ø> (ø)
models/model_calvetti/dwdx.cpp 100.00% <100.00%> (ø)
models/model_calvetti/w.cpp 100.00% <100.00%> (ø)
models/model_jakstat_adjoint/dwdp.cpp 100.00% <100.00%> (ø)
models/model_jakstat_adjoint/dwdx.cpp 100.00% <100.00%> (ø)
models/model_jakstat_adjoint/w.cpp 100.00% <100.00%> (ø)
models/model_jakstat_adjoint_o2/dwdp.cpp 100.00% <100.00%> (ø)
models/model_jakstat_adjoint_o2/dwdx.cpp 100.00% <100.00%> (ø)
models/model_jakstat_adjoint_o2/w.cpp 100.00% <100.00%> (ø)
... and 35 more

dweindl added a commit to dweindl/AMICI that referenced this pull request Feb 22, 2024
Currently, parameters that are targets of initial assignments don't show up as parameters or expressions in the amici model. This is rather not what most users would expect.

Therefore, treat all SBML parameters that are initial assignment targets and whose initial assignment does not evaluate to a number (for those that do, see AMICI-dev#2304) as amici expressions.
Those static expressions will be handled more efficiently after AMICI-dev#2303.

Related to AMICI-dev#2150.
@dweindl dweindl self-assigned this Feb 22, 2024
@dweindl dweindl marked this pull request as ready for review February 22, 2024 20:08
@dweindl dweindl requested a review from a team as a code owner February 22, 2024 20:08
dweindl added a commit to dweindl/AMICI that referenced this pull request Feb 23, 2024
Currently, parameters that are targets of initial assignments don't show up as parameters or expressions in the amici model. This is rather not what most users would expect.

Therefore, treat all SBML parameters that are initial assignment targets and whose initial assignment does not evaluate to a number (for those that do, see AMICI-dev#2304) as amici expressions.
Those static expressions will be handled more efficiently after AMICI-dev#2303.

Related to AMICI-dev#2150.
@dweindl dweindl removed the request for review from a team February 24, 2024 07:41
@dweindl
Copy link
Member Author

dweindl commented Feb 24, 2024

On second thought, I'll directly include dwd* here as well.

Copy link
Member

@FFroehlich FFroehlich left a comment

Choose a reason for hiding this comment

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

👍 neat!

include/amici/abstract_model.h Show resolved Hide resolved
python/sdist/amici/de_export.py Outdated Show resolved Hide resolved
python/sdist/amici/de_export.py Outdated Show resolved Hide resolved
return self._static_indices[name]

if name in ("dwdw", "dwdx", "dwdp"):
static_indices_w = set(self.static_indices("w"))
Copy link
Member

Choose a reason for hiding this comment

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

how computationally intensive are those computations? Is caching worthwhile?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently they are cached, but I didn't profile it yet.

python/sdist/amici/de_export.py Show resolved Hide resolved
python/sdist/amici/de_export.py Outdated Show resolved Hide resolved

# dynamic expressions
if len(dynamic_idxs := self.model.dynamic_indices(function)):
tmp_symbols = sp.Matrix(
Copy link
Member

Choose a reason for hiding this comment

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

partial duplication of code above

Copy link
Member Author

Choose a reason for hiding this comment

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

True. But currently I don't think that moving those lines to some separate function will make it clearer or more maintainable, rather the opposite.

src/model.cpp Outdated Show resolved Hide resolved
src/model.cpp Show resolved Hide resolved
src/model.cpp Show resolved Hide resolved
@dweindl
Copy link
Member Author

dweindl commented Feb 26, 2024

Still something wrong here. The number of nonlinear convergence failures is significantly higher than before this change. :/

Resolved. Was related to other changes.

@dweindl dweindl marked this pull request as draft February 26, 2024 19:13
Split expressions in `w` into dynamic (explicitly or implicitly time-dependent) and static ones.
Evaluate static ones only when needed, i.e. after (re)initializing x_rdata or parameters.

See AMICI-dev#1269
@dweindl
Copy link
Member Author

dweindl commented Feb 26, 2024

For a model with nw: 227, nx: 67, ndwdx: 759, ndwdw: 471:

  • determining static expressions add 10 seconds to the previous 5 seconds for full code generation :(
  • no observable difference in simulations times

Looks like some further profiling/optimization is required...

@dweindl
Copy link
Member Author

dweindl commented Feb 26, 2024

For a model with nw: 227, nx: 67, ndwdx: 759, ndwdw: 471:

* determining static expressions add 10 seconds to the previous 5 seconds for full code generation :(

* no observable difference in simulations times

Looks like some further profiling/optimization is required...

Okay, for that model, I am now down to no noticeable overhead and would merge those changes. 2.5 seconds overhead.

EDIT: I removed the derivative-based check for dwd* elements. With just checking for whether the expressions contain dynamic symbols, we have minimal overhead (<1s) and probably don't lose much.

@dweindl dweindl marked this pull request as ready for review February 26, 2024 22:10
@dweindl dweindl requested review from FFroehlich and removed request for FFroehlich February 26, 2024 22:10
dweindl added a commit that referenced this pull request Feb 27, 2024
…2305)

Currently, parameters that are targets of initial assignments don't show up as parameters or expressions in the amici model. This is rather not what most users would expect.

Therefore, treat all SBML parameters that are initial assignment targets and whose initial assignment does not evaluate to a number (for those that do, see #2304) as amici expressions.
Those static expressions will be handled more efficiently after #2303.

Related to #2150.

See also #2304.
Copy link
Member

@FFroehlich FFroehlich left a comment

Choose a reason for hiding this comment

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

👍

@dweindl dweindl merged commit eb3fd4a into AMICI-dev:develop Feb 27, 2024
25 of 26 checks passed
@dweindl dweindl deleted the feature_1269_split_exprs branch February 27, 2024 12:40
@dweindl dweindl restored the feature_1269_split_exprs branch February 27, 2024 12:40
@dweindl dweindl deleted the feature_1269_split_exprs branch February 27, 2024 12:40
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.

2 participants