Skip to content
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 option to specify maximum number of consecutively rejected steps #2229

Closed
efaulhaber opened this issue May 28, 2024 · 3 comments
Closed

Comments

@efaulhaber
Copy link

Without default dtmin (#2098), automatic time stepping methods reduce the time step below eps() at instabilities and reject all steps infinitely.
MWE:

f(u, p, t) = (print("x"); t > 0.1 ? 1e30 : 0.1);
ode = ODEProblem(f, 0.0, (0.0, 2.0));
cb = DiscreteCallback((u, t, integrator) -> true, integrator -> println("\n$(integrator.iter)"), save_positions=(false, false));
julia> solve(ode, Tsit5(), save_everystep=false, maxiters=1000, callback=cb);
xxxxxxxxx
1
xxxxxxxxxxxxx
2
xxxxxxxxxxxxx
3
xxxxxxxxxxxxxxxxxxx
5
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
19
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
28
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
78
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx┌ Warning: Interrupted. Larger maxiters is needed. If you are using an integrator for non-stiff ODEs or an automatic switching algorithm (the default), you may want to consider using a method for stiff equations. See the solver pages for more details (e.g. https://docs.sciml.ai/DiffEqDocs/stable/solvers/ode_solve/#Stiff-Problems).
└ @ SciMLBase ~/.julia/packages/SciMLBase/NjslX/src/integrator_interface.jl:600

As shown by the many x at the end, f is still called, but there are no more accepted steps to trigger the callback until we reach maxiters.
In simulation frameworks, this will cause apparent freezing of the simulation, as suddenly no more output is generated when an instability is reached, but the simulation doesn't terminate.

I suggest adding an option to limit the maximum number of consecutively rejected steps to terminate time integration in these cases where it gets stuck in an infinite loop until maxiters is reached (which might take a very long time for large simulations and default maxiters).

Note that setting dtmin is not an option, as perfectly stable simulations are terminated when different callbacks happen to add tstops that are very close together (#1616):

julia> solve(ode, Tsit5(), tstops=[0.05, 0.05 + eps()], dtmin=eps())
┌ Warning: dt(2.220446049250313e-16) <= dtmin(2.220446049250313e-16) at t=0.05, and step error estimate = 1.6870185803874452e-14. Aborting. There is either an error in your model specification or the true solution is unstable.
└ @ SciMLBase ~/.julia/packages/SciMLBase/NjslX/src/integrator_interface.jl:619
retcode: DtLessThanMin
Interpolation: specialized 4th order "free" interpolation
t: 5-element Vector{Float64}:
 0.0
 9.999999999999999e-5
 0.0010999999999999998
 0.011099999999999997
 0.05
u: 5-element Vector{Float64}:
 0.0
 9.999999999999997e-6
 0.00010999999999999995
 0.0011099999999999994
 0.004999999999999999

CC @ranocha

@efaulhaber
Copy link
Author

A different, but probably more complicated solution could be to add a different kind of dtmin parameter, which is only used to terminate when automatic time integration chooses too small steps, but which doesn't terminate due to manually added tstops.

@oscardssmith
Copy link
Contributor

oscardssmith commented May 28, 2024

I believe this was fixed (via different means) in SciML/SciMLBase.jl#693. Specifically, on new SciMLBase, this gives

julia> solve(ode, Tsit5(), save_everystep=false, maxiters=1000, callback=cb).stats
xxxxxxxxx
1
xxxxxxx
2
xxxxxxx
3
xxxxxxxxxxxxx
5
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
19
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
28
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
78
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
272
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
281
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
290
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
298
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx┌ Warning: dt(1.3877787807814457e-17) <= eps(t)(0.1) , and step error estimate = 12.775142822640118. Aborting. There is either an error in your model specification or the true solution is unstable (or the true solution can not be represented in the precision of Float64).
└ @ SciMLBase ~/.julia/packages/SciMLBase/JUp1I/src/integrator_interface.jl:632

@efaulhaber
Copy link
Author

Amazing, thanks!

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

No branches or pull requests

2 participants