Integrator.sol.retcode does not update after reinit!(integrator)

Hi all,

In my code I need to check the status of my integrator, and if it got terminated (because of my own callback) I want to know about that.
But I have some difficulty with the MWE down below. It seems like the retcode does not change after reinit!.

In this code I check for u if it is positive, and then terminate. But then I change the initial condition and the retcode is still :Terminated (although the solution is perfectly good).

This may be an issue?

using DifferentialEquations
f(u,p,t) = 2*u 
# the solution is positive or negative depends on the initial condition
u_positive(u,t,integrator) = u > 0
terminate_if_u_pos = DiscreteCallback(u_positive, terminate!)

prob = ODEProblem(f, 1.0, (0.0, 1.0)) # positive initial condition > positive u > :Terminated
integrator = init(prob, Tsit5(), callback=terminate_if_u_pos)
sol1 = solve!(integrator)
@show sol1.retcode # should be :Terminated
# julia> sol1.retcode = :Terminated

reinit!(integrator, -1.0) # negative initial condition > negative u > :Success!
sol2 = solve!(integrator)
@show sol2.retcode
# julia> sol2.retcode = :Terminated
# but should be :Success like as to following code:

prob = ODEProblem(f, -1.0,(0.0, 1.0)) # negative initial condition > negative u > :Success!
integrator = init(prob, Tsit5(), callback=terminate_if_u_pos)
sol3 = solve!(integrator)
@show sol3.retcode
# julia> sol3.retcode = :Success

Thanks a lot for the great community!

yeah that’s an issue. Open an issue on DifferentialEquations.jl

Ok, thanks!
Here is the issue.

Any workaround for the meantime? Since it is immutable I couldn’t change the retcode manually.

SetField.jl to swap it out is a fine solution. There’s also an old function specifically for swapping retcodes in SciMLBase or DiffEqBase, but SetField.jl is the modern way to do it.

That’s nice! I’ll check it out.

I’ll just mention here that I was not able to make Setfield.jl package work with ODESolution. To my understanding, the Setfield.jl package does not find the right constructor for the object.

For now just use SciMLBase.jl/ode_solutions.jl at master · SciML/SciMLBase.jl · GitHub then.

Thanks

The issue is closed, thanks.