hgrecco / numbakit-ode

Leveraging numba to speed up ODE integration
Other
68 stars 3 forks source link

Relative and absolute tolerances for integrators? #22

Closed chr218 closed 3 years ago

chr218 commented 3 years ago

It would be nice to have the option to set relative and absolute tolerances for the integrators, like in "scipy.integrate.solve_ivp".

Thanks!

maurosilber commented 3 years ago

It is already possible to do that on variable step methods, but it's not yet documented. For example:

import nbkode

def func(t, y):
    return -y

>>> nbkode.RungeKutta45(func, 0, 1).run(1)
(array([1]), array([[0.37535081]]))

>>> nbkode.RungeKutta45(func, 0, 1, rtol=1e-12, atol=1e-12).run(1)
(array([1]), array([[0.36789539]]))
chr218 commented 3 years ago

Which version is this? I have attempted to reproduce your code, but got the following error below:

import nbkodedef func(t, y): return -y nbkode.RungeKutta45(func, 0, 1).run(1)C:\Users\chr218\Anaconda3\lib\site-packages\nbkode\core.py:532: NumbaExperimentalFeatureWarning: First-class function type feature is experimental if not step(t_bound, rhs, cache, args):C:\Users\chr218\Anaconda3\lib\site-packages\nbkode\core.py:532: NumbaExperimentalFeatureWarning: First-class function type feature is experimental if not step(t_bound, rhs, cache, args):Out[10]: (array([1]), array([[0.37535081]]))nbkode.RungeKutta45(func, 0, 1, rtol=1e-12, atol=1e-12).run(1)Traceback (most recent call last): File "", line 1, in nbkode.RungeKutta45(func, 0, 1, rtol=1e-12, atol=1e-12).run(1) File "C:\Users\chr218\Anaconda3\lib\site-packages\nbkode\core.py", line 577, in init super().init(args, *kwargs) File "C:\Users\chr218\Anaconda3\lib\site-packages\nbkode\runge_kutta\core.py", line 26, in init super().init(args, *kwargs)TypeError: init() got an unexpected keyword argument 'rtol'

On Mon, Jun 7, 2021 at 2:12 PM Mauro Silberberg @.***> wrote:

It is already possible to do that on variable step methods, but it's not yet documented. For example:

import nbkode def func(t, y): return -y

nbkode.RungeKutta45(func, 0, 1).run(1) (array([1]), array([[0.37535081]])) nbkode.RungeKutta45(func, 0, 1, rtol=1e-12, atol=1e-12).run(1) (array([1]), array([[0.36789539]]))

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/hgrecco/numbakit-ode/issues/22#issuecomment-856152982, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJYF5HFDLA25GUNBP3VW4ATTRUDXPANCNFSM46IFCMIA .

maurosilber commented 3 years ago

It was fixed in 1ab77ab8fff1616b606b5ff19b55ccd924cc332a, but there hasn't been a release to PyPI since then. Sorry. You would have to install from GitHub: pip install git+https://github.com/hgrecco/numbakit-ode