-
Notifications
You must be signed in to change notification settings - Fork 44
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
Add print_stats
method to ode
and implement for CVODE
integrator
#165
base: master
Are you sure you want to change the base?
Add print_stats
method to ode
and implement for CVODE
integrator
#165
Conversation
03b60d0
to
dffe1a7
Compare
@dmitry-kabanov If you're still interested in working on this, would you be able to rebase this on the latest master? |
dffe1a7
to
be54ff6
Compare
`CVODE` solver has function `CVodePrintAllStats` that prints statistics about integrator such as number of right-hand-side function evaluations and number of nonlinear solves.
be54ff6
to
651ef5c
Compare
@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() |
def print_stats(self): | ||
if hasattr(self._integrator, "print_stats"): | ||
self._integrator.print_stats() | ||
else: | ||
print(f"Method `print_stats` is not implemented for integrator {self._integrator}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably throw an exception or use logging.error
, rather than printing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIR, I have modeled this method based on the method directly above it:
def get_info(self):
...
if hasattr(self._integrator, 'get_info'):
return self._integrator.get_info()
else:
return {}
Will this work?
def print_stats(self):
if hasattr(self._integrator, "print_stats"):
self._integrator.print_stats()
else:
raise AttributeError(
f"Method `print_stats` is not implemented for integrator "
f"'{self._integrator}'")
claude.ai
says that "[this] approach is idiomatic and well-suited to the adapter pattern you're implementing" 😀
The
CVODE
solver has a function calledCVodePrintAllStats
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 theode
andCVode
classes, such that user could print the above statistics in case, when they specifyCVode
as the integrator argument at the instantiation of theode
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 tostdout
as a formatted table.