Log every evaluation of ODE solver

So, Im getting a lot of warnings (and consequently errors) about NaN and Instability problems while trying to solve my ODE system, like:

Warning: NaN dt detected. Likely a NaN value in the state, parameters, or derivative value caused this outcome.

or

Warning: Instability detected. Aborting

All of them are happening in the first step, so conventional log flags like save_everystep doesnt work. I even tried with FunctionCallingCallback or changing the unstable_check function but without any success.

So, i just saw that the solution.destats informs:

DiffEqBase.DEStats
Number of function 1 evaluations:                  3
Number of function 2 evaluations:                  0
Number of W matrix evaluations:                    0
Number of linear solves:                           0
Number of Jacobians created:                       0
Number of nonlinear solver iterations:             0
Number of nonlinear solver convergence failures:   0
Number of rootfind condition calls:                0
Number of accepted steps:                          0
Number of rejected steps:                          0

My question is: is there any way to get the result of each function evaluation (all the 3 in this case) ?

1 Like

You have to share your example. This error is telling you that the third call to your function f has NaNs. Why? There’s likely something really wrong with the way you defined the ODE function and it is impossible to debug your code without seeing it. Just get rid of everything like FunctionCallingCallback etc. because that has nothing to do with what the messages are saying what the issue is.

It’s a Julia function. You can just @show, use a global, Debugger.jl, use the integrator interface and then manually step!, etc.

I just discovered that the NaNs were from divisions by zero :sweat_smile:

It’s a Julia function. You can just @show , use a global, Debugger.jl, use the integrator interface and then manually step! , etc.

Can you describe or indicate any place to search more about this part ? I searched for general debug tutorials in julia but they appear to be very technical at first glance (like using gdb).

Not sure, but that would be a good video to make. Maybe the “Doing Scientific Machine Learning” workshop at JuliaCon 2020 has something for you in there, since it was all live coded so debugged live.

Hi, I just watched it and It was a very nice talk !

Unfortunately (for me) you didnt need to do a lot of debug to make everything working lol.

So, while I was trying to solve the same problem with python I noticed that the scipy’s odeint has the flag “full_output” which describes better what I exactly want. Is it possible to do something similar in Julia ? or can it be implemented in DifferentialEquations too ?

Using the iterator interface will give you more information:

https://diffeq.sciml.ai/stable/basics/integrator/

Then you can step! by step!

1 Like