# How to use sol.retcode to catch ODE instability?

**URL:** <https://discourse.julialang.org/t/how-to-use-sol-retcode-to-catch-ode-instability/124274>\
**Category:** Modelling & Simulations\
**Created:** [December 30, 2024, 11:19am UTC](https://discourse.julialang.org/t/how-to-use-sol-retcode-to-catch-ode-instability/124274 "2024-12-30T11:19:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [December 30, 2024, 11:19am UTC](https://discourse.julialang.org/t/how-to-use-sol-retcode-to-catch-ode-instability/124274/1 "2024-12-30T11:19:29Z")

</div>

I would like to make an interactive plot with GLMakie. There are some instances when the ODEs generate instability. I would like to plot a label “INSTABILITY DETECTED” in the plot itself when instability occurs.  
I understand this can be achieved with `sol.retcode` but what would be the implementation?  
I should set an observable for retcode, then some text that can be written and deleted on the plot when needed.  
I could not find an example of an instable ODE and the instability comes out only some times, so it is difficult to provide a working example.  
Thank you

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [December 30, 2024, 12:18pm UTC](https://discourse.julialang.org/t/how-to-use-sol-retcode-to-catch-ode-instability/124274/2 "2024-12-30T12:18:58Z")

</div>

You would just check SciMLBase.successful\_retcode(sol) or sol.retcode and throw a message based on the returned enum

---

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [January 2, 2025, 8:54am UTC](https://discourse.julialang.org/t/how-to-use-sol-retcode-to-catch-ode-instability/124274/3 "2025-01-02T08:54:10Z")

</div>

Thank you, I wrote something along this line:

```julia
data = lift(p_mod) do p_new
    prob = ODEProblem(odeSolver!, u0, tspan, parms)
    return solve(prob, Rosenbrock23(), p = p_new, saveat = R)
    test_instability = sol.retcode
    if test_instability 
        text!(fig, position = Point2f( 20, 0), "Instability detected", fontsize = 30)
    end
end

```

Would that be enough? The code works without error but I am unsure if I am hitting an instability given that I got

```julia
Warning: At t=0.0, dt was forced below floating point epsilon 5.0e-324, and step error estimate = NaN. 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).

```

on REPL

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 2, 2025, 10:08am UTC](https://discourse.julialang.org/t/how-to-use-sol-retcode-to-catch-ode-instability/124274/4 "2025-01-02T10:08:07Z")

</div>

No, if sol.retcode doesn’t mean anything because the return is not a Boolean. Read my previous post
