Skip to content

Evaluate the reaction rates once per output row of the selections - #1408

Closed
matthiaskoenig wants to merge 1 commit into
sys-bio:developfrom
matthiaskoenig:reaction-rate-selections
Closed

matthiaskoenig wants to merge 1 commit into
sys-bio:developfrom
matthiaskoenig:reaction-rate-selections

Conversation

@matthiaskoenig

Copy link
Copy Markdown
Collaborator

Selecting reaction rates in a timecourse made every output row quadratic in the number of reactions: getValue of a reaction rate calls getReactionRates(1, &index, ...), and LLVMExecutableModel::getReactionRates evaluates all reaction rates of the model (evalReactionRatesPtr) for that one value. A row with all R reactions selected therefore evaluated R x R rate laws.

For models with many reactions this is most of the time of a simulation. In the PBPK model glimepiride_body (255 reactions, 165 species, from pkdb_models), CVODE takes 8.5 ms and the output of the reaction rates 50 ms more. Tools which select all entities of a model by default, such as sbmlsim, pay this on every simulation.

Change

getSelectedValues (all three overloads) evaluates the reaction rates once per output row when a reaction rate is selected (getSelectedReactionRates, a buffer in RoadRunnerImpl) and reads the selected rates from it (getNthSelectedOutput takes the rates). The rates are the ones getValue evaluates, from the same state, so the output does not change. getValue and the other selection types are unchanged.

Timings

A variable step simulation over 1440 min (rtol = atol = 1e-10), C++ API, Release build on Linux, best of 5:

model reactions rows time only all species all reaction rates (develop) all reaction rates (this PR)
glimepiride_body 255 451 8.5 ms 9.3 ms 60.2 ms 9.4 ms
hctz_body_flat 31 929 2.8 ms 3.0 ms 10.9 ms 3.1 ms

The results with the rates and species selected are identical to develop in every digit (%.17g) for both models.

Tests

  • New getSelectedReactionRates in RoadRunnerAPITests (LLJit and MCJit): the reaction rates selected twice and between species equal the rate laws of the state of every output row, and getSelectedValues() after the simulation equals getValue of each rate.
  • test_cxx_api_RoadRunnerAPITestsLLJit and ...MCJit: 161 tests pass each.
  • ctest without the python tests (Release, Linux): all 3483 tests pass, the semantic SBML test suite included. 110 of them (ModelEditingTests, StateSavingTests) failed under ctest -j20 and pass with -j1; they pass on their own as well, so I take it they share files between parallel runs.

Possible follow-up, not in this PR: the rate selections of species (S1', FLOATING_AMOUNT_RATE) evaluate the model per value in the same way.

Selecting a reaction rate evaluated all reaction rates of the model for
that one value, so an output row with the reaction rates selected was
quadratic in the number of reactions. getSelectedValues evaluates them
once per row and reads the selected rates from them.
@luciansmith

Copy link
Copy Markdown

Superseded by #1421. But it looks good; I just wanted to add to it.

@luciansmith luciansmith closed this Nov 4, 2026
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