Skip to main content

Library of mathematical epidemic models for use in simulation studies and inference.

Project description

Epimodels

PyPI version Python License: MIT Documentation Status GitHub Actions Workflow Status GitHub stars GitHub forks GitHub issues GitHub last commit Code style: ruff pre-commit

This library a simple interface to simulate mathematical epidemic models.

Getting started

Simple SIR simulation

from epimodels.continuous.models import SIR

model = SIR()
model([1000, 1, 0], [0, 50], 1001, {'beta': 2, 'gamma': .1})
model.plot_traces()

Solvers

Epimodels supports multiple ODE solvers through a unified interface. You can choose between scipy (CPU-only) and diffrax (JAX-accelerated with GPU support) backends.

Available Solvers

Backend Class Methods Best For
scipy ScipySolver RK45, RK23, DOP853, Radau, BDF, LSODA General use, CPU-bound
diffrax DiffraxSolver Tsit5, Dopri5, Dopri8, Euler, Heun, Midpoint, Ralston GPU acceleration, batch simulations

Usage Examples

from epimodels.continuous import SIR
from epimodels.solvers import ScipySolver, DiffraxSolver

# Default scipy solver (RK45)
model = SIR()
model([999, 1, 0], [0, 100], 1000, {'beta': 0.3, 'gamma': 0.1})

# Explicit scipy solver with specific method
solver = ScipySolver(method='LSODA')
model = SIR()
model([999, 1, 0], [0, 100], 1000, {'beta': 0.3, 'gamma': 0.1}, solver=solver)

# JAX-accelerated solver (requires: pip install diffrax jax)
solver = DiffraxSolver(solver='Tsit5', rtol=1e-6, atol=1e-9)
model = SIR()
model([999, 1, 0], [0, 100], 1000, {'beta': 0.3, 'gamma': 0.1}, solver=solver)

Performance Benchmarks

Benchmarks run on SIR model with N=1,000,000, t=[0,365], β=0.4, γ=0.1.

Scipy Methods

Method Time (ms) Accuracy* Stiff Handling Notes
LSODA 2.4 Good Excellent Auto stiffness detection
RK23 6.5 Good Poor Fastest explicit method
DOP853 4.9 Excellent Poor Highest accuracy
RK45 48.3 Good Poor Default, robust
Radau 23.5 Excellent Excellent Implicit, for stiff systems
BDF 31.5 Good Excellent Implicit multi-step

*Accuracy measured as deviation from DOP853 reference solution.

Diffrax Methods (JAX)

Method CPU Time GPU Time* Notes
Tsit5 ~2x faster than scipy 10-50x faster Recommended default
Dopri5 Similar to Tsit5 10-50x faster Classic Dormand-Prince
Dopri8 Slower 5-20x faster High accuracy

*GPU speedup observed on batch simulations (100+ concurrent models)

When to Use Each Solver

Scenario Recommended Solver Reason
General use ScipySolver('LSODA') Fast, handles stiffness automatically
High accuracy needed ScipySolver('DOP853') 8th order method
Stiff systems ScipySolver('BDF') or ScipySolver('Radau') Implicit methods
Batch simulations DiffraxSolver('Tsit5') GPU parallelization
Parameter sweeps DiffraxSolver JAX JIT compilation
Quick prototyping Default (RK45) Robust and reliable

Installing Diffrax

For GPU acceleration, install the JAX backend:

# CPU only
pip install diffrax jax

# GPU (CUDA 12)
pip install diffrax "jax[cuda12]"

# GPU (CUDA 11)
pip install diffrax "jax[cuda11]"

Related libraries

For stochastic epidemic models check this.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

epimodels-1.0.2.tar.gz (94.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

epimodels-1.0.2-py3-none-any.whl (79.8 kB view details)

Uploaded Python 3

File details

Details for the file epimodels-1.0.2.tar.gz.

File metadata

  • Download URL: epimodels-1.0.2.tar.gz
  • Upload date:
  • Size: 94.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for epimodels-1.0.2.tar.gz
Algorithm Hash digest
SHA256 9a382ee756e7b9b727c3bf07803b3f5384032b1c2cc6b55fc7ba0cacb484d6b5
MD5 d3df98713553bd8d5ab8c033e68df306
BLAKE2b-256 f02f7c3bb92c18f0ee60ee7cbe8c9db1773c1a9b21ff2487c43095ce00434709

See more details on using hashes here.

Provenance

The following attestation bundles were made for epimodels-1.0.2.tar.gz:

Publisher: python-publish.yml on fccoelho/epimodels

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file epimodels-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: epimodels-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 79.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for epimodels-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 921f65e7ca44e01e308b4b52e06f76e49c6f99478787a417dc9c1e25de990858
MD5 97cb0b9ebadb20c54d5e5c3b534a0e9b
BLAKE2b-256 4b9fc7e410827786f0c08fe1ddc64b795af84cf7d3f37dbf91ebfb20d54b2a1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for epimodels-1.0.2-py3-none-any.whl:

Publisher: python-publish.yml on fccoelho/epimodels

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page