Skip to main content

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

Project description

Epimodels

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.0.tar.gz (16.3 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.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for epimodels-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4657d8eb1eb2f434d0eb14ef6834fc3394ffa831036549ff7d208d0edeffa204
MD5 94407619299de0f31b107088ec8e2527
BLAKE2b-256 60e10f1b474c29bd0314515f8a622bcaa4430ff1e209d40da9df694804f806c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for epimodels-1.0.0.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.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for epimodels-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e0ea7a1ed97e1794f27e183f6d9564ccf2cf755429458a764d66fef967de1b98
MD5 5880fca70fff7b8630bea2366faf2c7c
BLAKE2b-256 38e76c896a9769cf086468685db8cd5f0a0d48baa6117110ef10734d1f97d12f

See more details on using hashes here.

Provenance

The following attestation bundles were made for epimodels-1.0.0-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