Search code examples
juliadifferential-equationssuppress-warningsdifferentialequations.jl

Julia Differential Equations suppress warning of detected instabilities


I have a program that simulates the paths of particles using the Differential Equations package of Julia. The simulation allows for particles to hit devices - to prevent the continued simulation of such particles, I use the unstable_check of the solver (specifically of the EulerHeun solver). However, this leads to warnings like the following:

┌ Warning: Instability detected. Aborting
└ @ SciMLBase <path>\.julia\packages\SciMLBase\0s9uL\src\integrator_interface.jl:351

As I simulate thousands of particles, this can be quite annoying (and slow).

Can I suppress this warning? And if not, is there another (better) way to abort the simulation of some particles?

I don't think a code sample makes sense / is necessary here; let me know though if you think otherwise.


Solution

  • https://diffeq.sciml.ai/stable/basics/common_solver_opts/#Miscellaneous

    verbose: Toggles whether warnings are thrown when the solver exits early. Defaults to true.

    Thus to turn off the warnings, you simply do solve(prob,alg;verbose=false).

    The simulation allows for particles to hit devices - to prevent the continued simulation of such particles, I use the unstable_check of the solver

    Using a DiscreteCallback or ContinuousCallback with affect!(integrator) = terminate!(integrator) is a much better way to do this.