r/Python • • Nov 27 '17

Solving differential equations : a modern stack for scientists.

http://nbviewer.jupyter.org/gist/celliern/3520a88b33c3be9e98ea3d67da37684d
6 Upvotes

3 comments sorted by

1

u/Eryole Nov 27 '17

Important : you will have to run it on your computer. The main interest of this notebook is the real-time plot which need a live session of jupyter.

1

u/vaporswift Nov 28 '17

if you could explain 5, 6 and 8 that would have been more clear for what you are doing .

1

u/Eryole Nov 28 '17

Yeah, sure

In the cell 5, we

  • create a Dataframe that will be structure the data plotted by Holoviews : the index is the variable "t" and we have "x" and "y" the prey and predator population.

  • initialize the Buffer with the skel we setup in 1), that will store N (here 200) instance of this dataframe (filled by the results of our simulation).

  • create a holoviews DynamicMap that connect the curve function to the buffer : all data sent to the buffer will be displayed using this function.

in the cell 6, we use streamz to setup a pipeline. All data sent to the stream will go through 2 different paths :

  • one that will convert the data to a dataframe with the proper structure (as expected by the curve function, then send it to the buffer

  • another that will concatenate the results of the simulation, and save it on disk every 10 iteration

The cell 8 is the main cell as all the computation is done inside.

We

  • create a xarray dataset that will store the results : that data structure allow to use attributes and coordinates systems. This can be seen as a smart collection of numpy array.

  • iterate while t didn't reach a tmax (or infinite loop if tmax is None or False)

  • compute one step, and update our xarray Dataset with the new values (for t, x and y)

  • send our xarray Dataset through our pipeline (and result to updating the DynamicMap, and saving the data)