odes icon indicating copy to clipboard operation
odes copied to clipboard

Add `print_stats` method to `ode` and implement for `CVODE` integrator

Open dmitry-kabanov opened this issue 1 year ago • 3 comments

The CVODE solver has a function called CVodePrintAllStats that prints statistics about the integration process, such as number of right-hand-side function evaluations and number of nonlinear solves.

This PR adds a method print_stats to the ode and CVode classes, such that user could print the above statistics in case, when they specify CVode as the integrator argument at the instantiation of the ode class.

CVodePrintAllStats allows to print the statistics and two different formats (as a formatted table or as a CSV file), to a given file stream (FILE * object). Right now I have narrowed it to always printing statistics to stdout as a formatted table.

dmitry-kabanov avatar Mar 12 '24 13:03 dmitry-kabanov

@dmitry-kabanov If you're still interested in working on this, would you be able to rebase this on the latest master?

aragilar avatar Jul 11 '24 10:07 aragilar

@aragilar Sure, I would be happy to do it. I have actually already rebased on the latest master, but have difficulties compiling the code via pip install -e . (from packages/scikit_sundials subdirectory).

I've created a separate issue about this #178.

dmitry-kabanov avatar Jul 12 '24 09:07 dmitry-kabanov

@aragilar I have rebased the PR on the latest master right now and have tested that it works with the following script:

import numpy as np
from scikits_odes import ode

def rhs(t, y, ydot):
    ydot[:] = -y

t0 = 0.0
y0 = [1.0]

s = ode("cvode", rhs, old_api=False)
sol = s.solve(np.linspace(t0, t0 + 1, 11), y0)

print(sol.values.y[:, 0])
s.print_stats()

dmitry-kabanov avatar Jul 19 '24 14:07 dmitry-kabanov