It's like scientific community using numerical tools is split in two category : the one that have all the nice toys (and do some data-science and stuff), and the other. I'm in the other category, but I like funny toys. That's why I will present you an overview of modern (and nice) tools that you can use in order to solve non-data-science related problems.

Someone ask me about using Bokeh to have a real-time plotting when solving coupled ordinary differential equation. He asks me about the Lokta-Volterra problem. Long story short, this is about modeling the relation between the prey and predator populations. These can be complex problems, but we will stick to the simple case. The hypothesis are:

The prey population finds ample food at all times. The food supply of the predator population depends entirely on the size of the prey population. The rate of change of population is proportional to its size. During the process, the environment does not change in favour of one species and genetic adaptation is inconsequential. Predators have limitless appetite.

(Thank you, Wikipedia)

This can be modeled with two couples ODE :

\begin{equation} \begin{cases} \frac{\partial x}{\partial t} = \alpha\,x - \beta\,x\,y\\ \frac{\partial y}{\partial t} = \gamma\,x\,y - \sigma\,y \end{cases} \end{equation}

Where $x$ and $y$ are the prey and the predator population. The other parameters have to be chosen wisely. I'm more lazy than wise, so I will just use some data from the Wikipedia article. ¯\(ツ)/¯

What I want to show you

how to solve an coupled ODE with the new scipy api solve_ivp how to use xarray , holoviews and streamz to plot and save the results during the resolution.

These libs are modern (yet not always stable?) and nice tools : xarray provide a data structure which is a kind of pandas Dataframe for gridded data, Holoviews a high level plotting abstraction, rely on matplotlib (static) or bokeh (interactive) backend and provide streaming abilities, and finally streamz give tools to process data via a pipeline of functions.

I will not describe these tools, just demonstrate how we can use them to have an effective computation + vizu + storage pipeline when solving an ODE.

Let's start ! First, the imports.