Package: ode-explorer
This is the ode-explorer Python package,
a small library designed for solving, fast prototyping and visualization
of systems of ordinary differential equations (ODEs).InstallationThis project is listed on PyPI, the Python Package Index. To obtain it via PyPI, runpip install ode-explorerIt is very much advised to do this inside of a virtual environment to avoid bloating your
system's own Python installation. A popular option for working with virtual environments isvirtualenvwrapper.Quickstart with ExamplesFor a very quick introduction to the main functionalities of this package, check out theode_explorer.examplesfolder. More examples will be gradually added - if you have a suggestion, or you want to contribute your own, feel free to send me a message!Some of the examples require a Jupyter installation. To install Jupyter Notebook or Jupyter Lab, run the following inside your created virtual environment:pip install notebook    ## <---- for Jupyter Notebook
pip install jupyterlab  ## <---- for Jupyter LabIt may also be required to install matplotlib for visualization, which can be done by runningpip install matplotlib.Introduction and main functionalitiesModelsMany processes in nature like radioactive decay, chemical reactions or classical mechanics can be characterized byordinary differential equations (ODEs).Solving these equations for a process then directly gives a prediction of its evolution.The number of equations that actually have closed form solutions available is actually a small minority; hence, numerical methods need to be developed to simulate more complex processes with correspondingly complex equations.An ordinary differential equation is usually written in literature asy' = f(t, y),wheref(t,y)is called themodel. Based on that intuition, ode-explorer exposes theODEModelclass, which is a small wrapper around a standard Python callable with signaturef(t: float, y: float or np.ndarray, **kwargs)where you can add special parameters for your model like reaction constants, decay rates etc. via Python's kwargs paradigm.Integrators and step functionsSolving ordinary differential equations in the computer happens by numerical integration. A popular method of solving ODEs are thesingle-step methods, which also encompass Runge-Kutta methods among others.ode-explorer handles numerical integration by exposing anIntegratorobject. It has some internal state that facilitates logging among other things, and exposes two main integration APIs,integrate_constandintegrate_adaptively. The former can be used to integrate an ODE using a fixed step size h, while the latter can be equipped with a step size controlling mechanism, which chooses a step size based on local error estimates. For more information, check out thetextbook by Hairer, Wanner and Nørsett.Step functionsare used to advance models in time during numerical integration. These methods usually differ in computational complexity and order of consistency; as a rule of thumb, a more accurate solution requires more computational work (as one might expect).ode-explorer provides aStepFunctionInterface that is built exactly for this purpose. Adding your own step functions is very simple - it requires only one of the following:Subclass theStepFunctionbase class and override itsforwardmethod to calculate the estimate.Initialize one of the template classes inode_explorer.stepfunctions.templateswith your chosen arguments.Since most step functions originate from families of methods (e.g. explicit/implicit RK methods, linear multi-step methods), they can be templated rather well - templates for some of the most common step function families are given inode_explorer.stepfunctions.templates.Callbacks and metricsThe main design emphasis of this library is that you can heavily customize your experiments to your liking. Two of the main instruments for this are callbacks and metrics.Callbacksare designed to hook into the control flow of the numerical integration; ode-explorer exposes aCallbackinterface which is basically a callable with state. This concept may be familiar to users of ML libraries of scikit-learn and Tensorflow, which were the main inspiration behind this. You can do many things with callbacks, like logging, broadcasting your solver's intermittent results via websocket, check for NaN values - this is where your creativity comes in!The same applies tometrics(with the correspondingMetricinterface), which are also callables that can be used to compute quantities of interest after each step. Possible use cases include distance to a known ODE solution for sanity checking a step function, logging accepted and rejected steps in a step size control setting, or tracking of a first integral in a Hamiltonian system - again, the possibilities are really vast, so try it out!Step size controlStep size control is something like an art form - you can use the built-inStepSizeControllerinterface to build your own.TestingTesting is still a work in progress, but will be added gradually.Planned features for upcoming releasesSome more feature plans that are in the mix for this library:Visualizations, DashboardGPU support using JAX / XLAMore builtin callbacks / metricsBoundary value problems (BVPs)Differential-Algebraic Equations (DAEs)Run caching / re-use, warm starting