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

Extract common subexpressions #1852

Merged
merged 11 commits into from
Aug 22, 2022
Merged

Extract common subexpressions #1852

merged 11 commits into from
Aug 22, 2022

Conversation

dweindl
Copy link
Member

@dweindl dweindl commented Aug 21, 2022

Add option to extract common subexpressions during code generation (at the model function level, not added to w).

Disabled by default, can be enabled via environment variable AMICI_EXTRACT_CSE=1.

For large models, this may significantly reduce file size and speed up compilation.
Downside: The resulting files are hard to read / debug.

With my test model (SBML import, 2 processes, sequential compilation with clang14, -O2):

before after
import time 160 min (100%) 164 min (103%)
code size 89 MB (100%) 27 MB (30%)
compile time 169 min (100%) 90 min (53%)
compile RAM 7.49 GB (100%) 1.18 GB (16%)
simulation time (*) 100% 97%

(*) lowest out of 20 identical simulations using ASA

Add option to extract common subexpressions during code generation (at the model function level, not added to `w`).

Disabled by default, can be enabled via environment variable `AMICI_EXTRACT_CSE=1`.

For large models, this may significantly reduce file size and speed up compilation.
Downside: The resulting files are hard to read / debug.

With my test model (SBML import, 2 processes, sequential compilation with clang14, -O2):

|                 | before         | after          |
|-----------------|----------------|----------------|
| import time     | 160 min (100%) | 164 min (103%) |
| code size       | 89 MB (100%)   | 27 MB (30%)    |
| compile time    | 169 min (100%) | 90 min (53%)   |
| compile RAM     | 7.49 GB (100%) | 1.18 GB (16%)  |
@codecov
Copy link

codecov bot commented Aug 21, 2022

Codecov Report

Merging #1852 (5087446) into develop (0a15d3e) will increase coverage by 0.41%.
The diff coverage is 53.33%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1852      +/-   ##
===========================================
+ Coverage    76.27%   76.68%   +0.41%     
===========================================
  Files           74       74              
  Lines        12851    13551     +700     
===========================================
+ Hits          9802    10392     +590     
- Misses        3049     3159     +110     
Flag Coverage Δ
cpp 72.91% <ø> (+0.11%) ⬆️
petab 59.24% <53.33%> (-0.05%) ⬇️
python 68.95% <40.00%> (-0.08%) ⬇️

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

Impacted Files Coverage Δ
python/amici/cxxcodeprinter.py 79.74% <46.15%> (-6.83%) ⬇️
python/amici/petab_objective.py 93.50% <100.00%> (ø)
python/amici/sbml_import.py 88.40% <0.00%> (-5.42%) ⬇️
python/amici/ode_export.py 91.16% <0.00%> (-0.62%) ⬇️
src/exception.cpp 75.67% <0.00%> (ø)
src/solver_cvodes.cpp 70.06% <0.00%> (ø)
src/sundials_matrix_wrapper.cpp 80.98% <0.00%> (+0.81%) ⬆️
src/amici.cpp 72.53% <0.00%> (+4.22%) ⬆️

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.

👍 Please document usage of environment variable. Maybe it makes sense to introduce a dedicated doc page that lists and explains all available environment variables?

@FFroehlich
Copy link
Member

👍 Please document usage of environment variable. Maybe it makes sense to introduce a dedicated doc page that lists and explains all available environment variables?

Oh, and maybe add a test that runs cse on a nontrivial testcase?

@sonarcloud
Copy link

sonarcloud bot commented Aug 22, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

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

33.3% 33.3% Coverage
0.0% 0.0% Duplication

@dweindl dweindl merged commit 84ca56d into develop Aug 22, 2022
@dweindl dweindl deleted the cse branch August 22, 2022 11:21
dweindl added a commit that referenced this pull request Aug 23, 2022
Benchmarking in #1852 was done with `cse(..., ignore=None)`.
Turns out, passing symbols to ignore makes things 1000x slower.

Here we toposort the original and extracted expressions together, instead
of ignoring any dependent-symbols.
dweindl added a commit that referenced this pull request Aug 23, 2022
Benchmarking in #1852 was done with `cse(..., ignore=None)`.
Turns out, passing symbols to ignore makes things 1000x slower.

Here we toposort the original and extracted expressions together, instead
of ignoring any dependent symbols.
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