Skip to content

Expose the counters of the integrators for profiling - #1425

Merged
luciansmith merged 2 commits into
sys-bio:developfrom
matthiaskoenig:cvode-statistics
Nov 10, 2026
Merged

luciansmith merged 2 commits into
sys-bio:developfrom
matthiaskoenig:cvode-statistics

Conversation

@matthiaskoenig

Copy link
Copy Markdown
Collaborator

Integrator::getStatistics returns the counters of the work of the
integrator since the last resetStatistics, which RoadRunner calls when a
simulation starts (simulate, and oneStep when it resets the
integrator). In Python, r.integrator.getStatistics() returns them as a
dict.

CVODE returns the counters of CVODE (steps, RHS evaluations, error test
failures, linear solver setups, nonlinear solver iterations and
convergence failures, Jacobian evaluations, root function evaluations,
...) plus the number of events and of reinitializations, and the step
sizes and orders of the last step. CVODE sets its counters to zero when
roadrunner reinitializes it after an event, so the integrator sums them
over the reinitializations. The counters of the linear solver interface
are set to zero at the first step after a reinitialization, which the
sum takes into account. With the new setting collect_timing it also
measures the time of the integration, of the RHS and root function
evaluations, and of the setups and solves of the linear solver, which
it wraps for that.

rk4, rk45, euler and gillespie return the counters that apply to them
under the same keys.

The SWIG typemap for a map of settings did not compile for a map
returned by value, and leaked the keys and values of the dict. Both
typemaps use the new settingsMap_to_py.

Fixes #1411.

Example with Chen_MSB2009 (500 species):

r.integrator.collect_timing = True
r.simulate(0, 100, 1001)
r.integrator.getStatistics()
# {'num_steps': 88, 'num_rhs_evals': 117, 'num_lin_solv_setups': 31, 'num_err_test_fails': 3,
#  'num_nonlin_solv_iters': 116, 'num_jac_evals': 2, 'num_lin_rhs_evals': 1000, 'num_g_evals': 1088,
#  'num_events': 0, 'num_reinits': 0, ..., 'time_total': 0.0258, 'time_rhs_evals': 0.0043,
#  'time_lin_solv_setups': 0.0089, 'time_lin_solv_solves': 0.0056, 'time_g_evals': 0.0001}

Integrator::getStatistics returns the counters of the work of the
integrator since the last resetStatistics, which RoadRunner calls when a
simulation starts (simulate, and oneStep when it resets the
integrator). In Python, r.integrator.getStatistics() returns them as a
dict.

CVODE returns the counters of CVODE (steps, RHS evaluations, error test
failures, linear solver setups, nonlinear solver iterations and
convergence failures, Jacobian evaluations, root function evaluations,
...) plus the number of events and of reinitializations, and the step
sizes and orders of the last step. CVODE sets its counters to zero when
roadrunner reinitializes it after an event, so the integrator sums them
over the reinitializations. The counters of the linear solver interface
are set to zero at the first step after a reinitialization, which the
sum takes into account. With the new setting collect_timing it also
measures the time of the integration, of the RHS and root function
evaluations, and of the setups and solves of the linear solver, which
it wraps for that.

rk4, rk45, euler and gillespie return the counters that apply to them
under the same keys.

The SWIG typemap for a map of settings did not compile for a map
returned by value, and leaked the keys and values of the dict. Both
typemaps use the new settingsMap_to_py.

Fixes sys-bio#1411.
CVODE is reinitialized at every root of its root functions, which
includes a piecewise condition that switches without an event, and
after a delayed event. The documentation of getStatistics said only
after events.
@luciansmith
luciansmith merged commit c4ed476 into sys-bio:develop Nov 10, 2026
223 of 244 checks passed
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.

Expose the CVODE counters of a simulation in Python for profiling

2 participants