Skip to main content

pySODM

Simulating and Optimising Dynamical Models in Python 3

Resources: documentation, peer-reviewed paper, pyPI

build docs

Quick installation

pip install pySODM

Aim & Scope

All the simulation projects I've undertaken over the past six years required me to do most of the following,

  1. Integrate a system dynamical model
  2. Its states may be represented by n-dimensional numpy arrays, labeled using coordinates
  3. Its parameters may have time-dependencies
  4. Its intial conditions may vary
  5. Its parameters may be stochastic
  6. It may have to be calibrate to a dataset(s) by defining and optimising a cost function

all these features required me to wrap code around an ODE solver, typically scipy.solve_ivp, and I got tired of recycling the same code over and over again, so I packaged it into pySODM.

Other simuation software exists in Python, but a lot of them rely on symbolic transitions, which places a limit on the attainable complexity of a model, making it unfit for academic research. I wanted a piece a software that nicely does all the nasty bookkeeping like keeping track of state sizes, time dependencies on parameters, aligning simulations with datasets etc. and does so in a generically applicable way so that I'd never hit a software wall mid-project.

Overview of features

Workflow Features
Construct a dynamical model Implement systems of coupled differential equations
Labeled n-dimensional model states, states can have different sizes
Leverages xarray.Dataset to store labeled n-dimensional simulation output
Simulating the model Deterministic (ODE) or stochastic simulation (Jump process)
Time-dependent model parameter functions to vary parameters during the course of a simulation
Draw functions to vary model parameters during consecutive simulations.
Initial condition functions to vary the initial condition during consecutive simulations
Calibrate the model Construct and maximize a posterior probability function
Automatically aligns data and model forecast
Nelder-Mead Simplex and Particle Swarm Optimization
Bayesian inference with emcee.EnsembleSampler

Getting started

  • Detailed installation instructions.

  • The quistart tutorial teaches the basics of building and simulating models with n-dimensional labeled states in pySODM. It demonstrates the use of time-dependent parameter functions (TDPFs) to vary model parameters over the course of a simulation and draw functions to vary model parameters during consecutive simulations.

  • The workflow tutorial provides a step-by-step introduction to building a mathematical model and calibrating its parameters to a dataset. An SIR disease model is built and the basic reproduction number during an outbreak is determined by calibrating the model to the outbreak data.

  • The enzyme kinetics and influenza 17-18 case studies apply the workflow to more advanced, real-world problems. In the enzyme kinetics case study, a 1D packed-bed reactor model is implemented in pySODM by reducing the PDEs to a set of coupled ODEs by using the method-of-lines. In the Influenza 17-18 case study, a stochastic, age-structured model for influenza is developped and calibrated to the Influenza incidence data reported by the Belgian Federal Institute of Public Health. These case studies mainly serve to demonstrate pySODM's capabilities across scientific disciplines and highlight the arbitrarily complex nature of the models that can be built with pySODM. For an academic exposee of pySODM, the Enzyme Kinetics and Influenza 17-18 case studies, checkout our peer-reviewed paper.

Versions

  • Version 0.2.0 (2023-01-19, PR #25)

    Introduction of dimensions_per_state in model declaration, allowing the user to define models where states can have different sizes.

    • Version 0.2.1 (2023-01-27, PR #30)

      Fixed bugs encountered when incorporating pySODM into the SARS-CoV-2 Dynamic Transmission Models. More thorough checks on bounds in the log posterior probability function. Finished manuscript.

    • Version 0.2.2 (2023-01-27, PR #31)

      Published to pyPI.

    • Version 0.2.3 (2023-05-04, PR #46)

      Fixed minor bugs encountered when using pySODM for a dynamic input-output model of the Belgian economy. Published to pyPI.

    • Version 0.2.4 (2023-12-04, PR #62)

      Validated the use of Python 3.11. Efficiency gains in simulation of jump processes. Ommitted dependency on Numba. All changes related to publishing our software manuscript in Journal of Computational Science. Improved nomenclature in model defenition.

    • Version 0.2.5 (2024-10-08, PR #106)

      Validated the use of Python 3.12. Validated pySODM on macOS Sonoma 14.5. 'draw functions' only have 'parameters' as mandatory input, followed by an arbitrary number of additional parameters (PR #75). Tutorial environment can now be found in tutorial_env.yml and was renamed PYSODM-TUTORIALS (PR #76). Users can choose when the simulation starts when calibrating a model (PR #92). Initial model states can now be a function returning a dictionary of states. This initial condition function can have arguments, which become part of the model's parameters, and can therefore be optimised (PR #99). Deprecation of legacy 'warmup' parameter (PR #100). Change 'states' --> 'initial_states' as input needed to initialize a model (PR #102).

    • Version 0.2.6 (2025-04-04, PR #143)

      Harmonize NM and PSO optimizer output (PR #115). Add regularisation weights and input checks to log prior functions (PR #119). Use of emcee_to_samples_dictionary deprecated in favor of xarray.Dataset to save samples long-term (PR #124). Deprecated output_timestep in pySODM model's sim() function, and added functionality to define the unit of time when using dates (PR #133). Validate the use of Python 3.13, and add a minimum required Python version (PR #138).

    • Version 0.2.8 (2025-05-12, PR #145)

      Fixed broken badges for "succesfull completion unit tests" and "compilation documentation website" in the readme (PR #144). Added a lognormal prior distribution (PR #145). Forgot to merge PR #145 before publishing 0.2.7 to pyPI, so this one is now called 0.2.8.

    • Version 0.2.9 (2026-01-04, PR #148)

      Validated the use of Python 3.14 (PR #146). Added exponential and halfnormal prior distributions (PR #147).

  • Version 0.1 (2022-12-23, PR #14)

    Application pySODM to three use cases. Documentation website. Unit tests for ODE, JumpProcess and calibration.

    • Version 0.1.1 (2023-01-09, PR #20)

      Start of semantic versions: Major.Minor.Patch

    • Version 0.1.2 (2023-01-11, PR #23)

      Calibration of 1-D model parameters generalized to n-dimensions. Added 'aggregation functions' to the log_posterior_probability class to perform custom aggregations of model output before matching with data. xarray.DataArray/xarray.Dataset can be used as datasets during calibration. Internally converted to pd.DataFrame.

  • Version 0.0 (2022-11-14)
    • First pySODM version. Obtained by splitting the generally applicable parts from the ad-hoc parts in UGentBiomath/COVID19-Model. Without documentation website.
  • Pre-development (2020-05-01 - 2022-11-24)
    • Code developped to model the spread of SARS-CoV-2 in Belgium (UGentBiomath/COVID19-Model).

Metadata

Release files for pySODM 0.2.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pySODM 0.2.9
File Size Uploaded
pysodm-0.2.9.tar.gz 56.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pySODM 0.2.9
File Interpreter ABI Platform
pysodm-0.2.9-py3-none-any.whl Python 3 none any Details

Total release size: 114.1 kB

Release files / pysodm-0.2.9.tar.gz

Download URL pysodm-0.2.9.tar.gz
Size 56.7 kB
Tags Source
SHA-256 checksum
How to use checksums
733c960dd1529c8b021830be34222aaa29f0aefc67f3221b685098743bb9c83c
BLAKE2b-256 checksum
How to use checksums
44f704f0f89a4d71fa507e998ed4aa3192f9066455eaf864e7f73774951a4bbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release files / pysodm-0.2.9-py3-none-any.whl

Download URL pysodm-0.2.9-py3-none-any.whl
Size 57.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0bd28fc0c28fe725a3096de880e9bad6b4d56c86334f17604777bd9ca32236bd
BLAKE2b-256 checksum
How to use checksums
5720e4ac5031929568aa5bced8d01e88f31857a0fed044d1e85feb57d590ac09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release history Release notifications | RSS feed

This release

0.2.9 This release

2 release files

0.2.8

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

1 release file

0.2.3

2 release files

0.2.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page