SciML / SciMLBase.jl

The Base interface of the SciML ecosystem
https://docs.sciml.ai/SciMLBase/stable
MIT License
118 stars 91 forks source link

`check_error!` returns `Success` but doesn't set it in `sol.retcode` #669

Closed visr closed 2 months ago

visr commented 2 months ago

Describe the bug 🐞

If I run an integrator to the end with step! and call check_error I get ReturnCode.Success (sol.retcode is ReturnCode.Default). The docstring for check_error! states:

Same as check_error but also set solution's return code

However it doesn't set the solution's return code, but leaves it on ReturnCode.Default. I see solve! handles this case specifically and therefore doesn't see this issue.

Not sure what the best fix is. The return code is not set due to this if condition being false:

https://github.com/SciML/SciMLBase.jl/blob/d947bed3aa31cdf54791930cd8272306d6bd0f20/src/integrator_interface.jl#L646

Should that condition perhaps be removed? Or are integration interface users expected to convert Default to Success themselves?

Minimal Reproducible Example πŸ‘‡


using OrdinaryDiffEq, SciMLBase

f(u, p, t) = 1.01 * u
u0 = 1 / 2
tspan = (0.0, 1.0)
prob = ODEProblem(f, u0, tspan)
integrator = init(prob, Tsit5(); reltol = 1e-8, abstol = 1e-8)
step!(integrator, tspan[end])

integrator.sol.retcode  # Default
check_error(integrator)  # Success
SciMLBase.check_error!(integrator) # Success
integrator.sol.retcode  # still Default