Python/Cython lib for solving Stochastic Ordinary Differential Equations

pip install sode==0.0.3




SODE is a python/cython library for generating numerical solutions to Stochastic Ordinary Differential Equations (SODEs)

Setting up the sode-module

1. Compile C and Cython code:

To compile the C and Cython code, you need to type in the terminal:

$ cd /path/to/sode
$ python build_ext --inplace --force

2. Run the sode module

Run the following commands (every time), type in the terminal:

$ cd /path/to/sode
$ . ./   # note: this line begins with a "." followed by a space " "

3. Run the examples

Type in the terminal:

$ sode solve -p

4. Summary (regular use of the module)

Type in the terminal:

$ cd sode
$ . ./
$ sode-time
$ sode solve -p

5. Help and specific simulations

Type in the terminal, for a specific simulation of the tanmult-system:

$ sode -h
$ sode-pyexamples solve -s tanmult -p


Check which version of Python is running:

Method 1:

$ which python

Method 2:

$ python
>>> import sys
>>> sys.version_info
>>> sys.executable

In case these methods provide refer to different versions, ensure that a correct version of Python is running by typing in the terminal (before you run the set-up):

$ export PATH="/Library/Frameworks/Python.framework/Versions/7.2/Resources/${PATH}"

Check which version of Cython is running:

$ cython --version
$ –version


1. Opster

Download Opster for MAC (, and type in terminal:

$ cd /path/to/downloads
$ tar -xzf opster-3.7.tar.gz
$ cd opster-3.7
$ python install

2. Install C-compiler:

Appendix: background information

Installing the sode module

Python imports modules that are on its import path. You can see the import path from a python terminal by printing the value of sys.path:

>>> import sys
>>> sys.path

When you download a python package there is usually a file called in the root directory of the download. This file is used to install the python package so that it is on your python path. If you run:

$ python install

Then the package will be copied into a directory on your python path so that its modules can be imported from within python. If the package also has c code or other code that needs to be compiled, then the will also compile those for you. For example, sode has some cython modules that need compiling. To do this you would run:

$ python build

This compiles everything and places the compiled files in a subdirectory called build/lib along with copies of all the python files. Then when you run:

$ python install

it will copy the compiled files and the python files onto your python path so that they can be imported from within python.

Using sode without installation If you don't install the files you can temporarily add them to your python path before running python by setting the PYTHONPATH environment variable:

$ export PYTHONPATH=/home/username/work/sode
$ python
>>> import sode

If you just want to set PYTHONPATH for one command in the terminal, you can do:

$ PYTHONPATH=/home/username/work/sode python
>>> import sode

This is done automatically by using "", which adds the current directory, ".", to PYTHONPATH and adds the "./scripts" directory to PATH so that the shell finds the scripts in there.


Normally when you run a script any changes it makes to environment variables will only affect programs that are run from within that script. This means that to run this script you need to source it:

$ source

or (note the "." at the start):

$ . ./

After this any python scripts that use sode should be able to import it. If you want to use the file "in-place" rather than installing them you will first need to build the cython files in the current directory (rather than build/lib) using the command:

$ python build_ext --inplace

This places the compiled files in the same place as the other files.