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

Doc: Illustrate options for potentially speeding up model import/simulation #1965

Merged
merged 7 commits into from
Jan 30, 2023

Conversation

dweindl
Copy link
Member

@dweindl dweindl commented Jan 29, 2023

No description provided.

@dweindl dweindl requested a review from a team as a code owner January 29, 2023 19:07
@codecov
Copy link

codecov bot commented Jan 29, 2023

Codecov Report

Merging #1965 (5c84b1e) into develop (12718e6) will increase coverage by 0.03%.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1965      +/-   ##
===========================================
+ Coverage    75.98%   76.02%   +0.03%     
===========================================
  Files           76       76              
  Lines        12984    12984              
===========================================
+ Hits          9866     9871       +5     
+ Misses        3118     3113       -5     
Flag Coverage Δ
cpp 73.21% <ø> (+0.05%) ⬆️
petab 59.71% <ø> (ø)
python 68.97% <ø> (ø)
sbmlsuite ?

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

Impacted Files Coverage Δ
src/solver_cvodes.cpp 70.23% <0.00%> (+0.16%) ⬆️
src/sundials_matrix_wrapper.cpp 80.61% <0.00%> (+0.40%) ⬆️
src/exception.cpp 80.00% <0.00%> (+5.71%) ⬆️

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.

👍 nice!

"\n",
"#### Parameters as constants\n",
"\n",
"By default, AMICI will generate sensitivity equations with respect to all model parameters. If it is clear upfront, that sensitivities with respect to certain parameters will not be required, their IDs can be passed to [amici.sbml_import.SbmlImporter.sbml2amici](https://amici.readthedocs.io/en/latest/generated/amici.sbml_import.SbmlImporter.html#amici.sbml_import.SbmlImporter.sbml2amici) or [amici.pysb_import.pysb2amici](https://amici.readthedocs.io/en/latest/generated/amici.pysb_import.html?highlight=pysb2amici#amici.pysb_import.pysb2amici) via the `constant_parameters` to not generate the respective equations. This will reduce CPU time and RAM requirements during import and simulation.\n",
Copy link
Member

Choose a reason for hiding this comment

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

constant_parameters argument

"#### Parameters as constants\n",
"\n",
"By default, AMICI will generate sensitivity equations with respect to all model parameters. If it is clear upfront, that sensitivities with respect to certain parameters will not be required, their IDs can be passed to [amici.sbml_import.SbmlImporter.sbml2amici](https://amici.readthedocs.io/en/latest/generated/amici.sbml_import.SbmlImporter.html#amici.sbml_import.SbmlImporter.sbml2amici) or [amici.pysb_import.pysb2amici](https://amici.readthedocs.io/en/latest/generated/amici.pysb_import.html?highlight=pysb2amici#amici.pysb_import.pysb2amici) via the `constant_parameters` to not generate the respective equations. This will reduce CPU time and RAM requirements during import and simulation.\n",
"The PEtab import will take care of that automatically.\n",
Copy link
Member

Choose a reason for hiding this comment

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

will automatically pass all parameters with petab.ESTIMATE==False as constant_parameters arguments.

"#### Extracting common subexpressions\n",
"\n",
"For some models, the size of the generated model code can be significantly reduced by extracting common subexpressions. This can yield substantial reductions of compile times and RAM-requirements. Very large models might not compile without this option. Extracting common subexpressions can be enabled by setting an environment variable `AMICI_EXTRACT_CSE=1` before model import.\n",
"The downside is, that the generated model code becomes rather unreadable. The increase in import time when enabling this feature is usually <15%, the effect on code size and compile time is highly model dependent. Mostly models with tightly coupled ODEs, as obtained from complex rate laws or spatial discretizations of ODEs, seem to benefit. For models with mass action kinetics, this option seems to not be helpful and rather increases compile time (e.g., for FröhlichGer2022, the compile time doubles).\n",
Copy link
Member

Choose a reason for hiding this comment

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

FröhlichGer2022 is a pysb model, which internally uses expressions/rate laws to avoid reuse of common expressions. Technically also not mass action kinetics due to the thermodynamic model formulation, although the resulting equations are effectively the same.

"source": [
"#### Parallelization\n",
"\n",
"For large models or complex model expressions, symbolic computation of the derivatives can be quite time consuming. This can be parallelized by setting the environment variable `AMICI_IMPORT_NPROCS` to the number of parallel processes that should be used. The impact strongly depends on the model. Note that setting this value too may have a negative performance impact (benchmark!).\n",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"For large models or complex model expressions, symbolic computation of the derivatives can be quite time consuming. This can be parallelized by setting the environment variable `AMICI_IMPORT_NPROCS` to the number of parallel processes that should be used. The impact strongly depends on the model. Note that setting this value too may have a negative performance impact (benchmark!).\n",
"For large models or complex model expressions, symbolic computation of the derivatives can be quite time consuming. This can be parallelized by setting the environment variable `AMICI_IMPORT_NPROCS` to the number of parallel processes that should be used. The impact strongly depends on the model. Note that setting this value for smaller model may have a negative performance impact (benchmark!).\n",

"\n",
"If only the objective function gradient is required, adjoint sensitivity analysis are often preferable over forward sensitivity analysis. As a rule of thumb, adjoint sensitivity analysis seem to outperform forward sensitivity analysis for models with more than 20 parameters:\n",
"\n",
"![](https://journals.plos.org/ploscompbiol/article/figure/image?size=medium&id=10.1371/journal.pcbi.1005331.g002)\n",
Copy link
Member

Choose a reason for hiding this comment

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

looks like we're missing a \n here, not sure why though.

@dweindl dweindl merged commit b61abb6 into develop Jan 30, 2023
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@dweindl dweindl deleted the nb_largemodels branch January 30, 2023 11:00
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