Are there any ODE solver packages that use coroutines and yield their results instead of functions and returning?
Briefly, a subroutine in a programming language does some computations, returns a result to whoever called it, and then it's done. A coroutine does some computations, yields a result to whoever called it, and can then be resumed where it last yielded a value. In Python, coroutines are used to implement generators.
For some scientific applications that involve solving systems of ODE, the logic about how long to integrate for can be very complex. For example, if you're writing some code to create a stream plot of a vector field, you'll continue creating an integral curve if (1) it isn't long enough yet and (2) it isn't too close to all of the other integral curves you've already calculated. The second stopping condition is much more complicated and involves some kind of spatial data structure like a KD-tree. Most ODE solving routines – for example SciPy’s solve_ivp
function – present you with a very limited number of options for when to stop integrating and you have to decide what your criterion is at the outset.
By contrast, it's easy to write an adaptive integration scheme that yields the next point on the integral curve, the value of the vector field at that point, and the timestep it used. The ODE integration routine doesn't care about how long the caller wants it to go for. It could be part of a screensaver and it'll keep going until the user wiggles the mouse.