A modular simulation framework for patch-based metapopulation epidemiology
Project description
PatchSim
⚠️ WARNING: Active Development
PatchSim is currently under heavy development. Features are experimental and subject to change. Not recommended for production use at this stage.
PatchSim is a modular metapopulation simulation framework for multi-disease epidemiological modelling.
Vision
To develop a general-purpose, modular simulation framework for patch-based metapopulation epidemiology, enabling modellers and researchers to simulate disease transmission under diverse scenarios, diseases, and intervention strategies. The framework balances robust scientific modelling with flexibility for exploratory research and translational use cases.
Unique Selling Point (USP)
PatchSim combines metapopulation network dynamics with a lightweight, configuration-first workflow:
- Network-aware compartment transitions across connected patches
- Arrow-map transition syntax in YAML for explicit model specification
- Fast iteration loop from config edits to reproducible outputs
Unique Value Proposition (UVP)
Compared to many epidemiology tools that are either code-heavy or tightly bound to a specific disease model, PatchSim offers:
- Model flexibility: define SIR/SIRS-style variants through config transitions
- Research-friendly reproducibility: deterministic inputs, logged runs, and versioned config files
- Dual interface: SDK import for programmatic workflows and CLI for operational runs
- Extensibility path: built-in structure for adding custom models and project templates
Core Features
PatchSim aims to support a range of modelling features commonly used in metapopulation disease simulations:
- 🗺️ Spatial Networks: Represent geographical units (e.g., subdistricts, regions) as interconnected patches with movement/contact matrices.
- 👥 Stratification by Population Attributes:
- Age groups
- Species (e.g., cattle, buffalo)
- Risk groups or occupations
- 🧪 Disease Agnostic Compartment Models:
- SIR, SEIR, SIRS and extensions
- Supports both discrete timestep and ODE-based solvers
- 🛠️ Scenario and Parameter Management:
- Batch simulations for scenario comparison
- Sensitivity analysis and parameter sweeps
- 🧵 Reproducibility:
- Random seed control and metadata logging
- Version-tracked configurations
- 📦 Modularity:
- Plug-in architecture for solvers, interventions, and input data pipelines
Installation
Install from PyPI:
pip install patchsim
Install from source using uv:
# Clone the repository
git clone https://github.com/dsih-artpark/patchsim
cd patchsim
# Create a virtual environment and install dependencies
uv venv
source .venv/bin/activate
uv pip install -e .
# For development (with dev dependencies)
uv pip install -e .[dev]
Usage
Command Line Interface
PatchSim provides a subcommand-based CLI. Always run using uv run to ensure correct dependency resolution:
# Show help and available options
uv run patchsim --help
# Show package version
uv run patchsim --version
# Initialize a new self-contained project
uv run patchsim init my-project
# Initialize with a starter template
uv run patchsim init my-project --template seir
# Validate config without running
uv run patchsim validate -c my-project/config.yaml
# Print the JSON Schema for configs
uv run patchsim validate --schema
# Emit machine-readable JSON output
uv run patchsim validate -c my-project/config.yaml --json
# Run simulation
uv run patchsim run -c my-project/config.yaml
# Run and emit machine-readable JSON output
uv run patchsim run -c my-project/config.yaml --json
# List built-in model references and YAML templates
uv run patchsim list-models
# List models as JSON
uv run patchsim list-models --json
Python SDK
import patchsim
config = patchsim.load_config("config.yaml")
net, y0, patches, n = patchsim.setup_simulation(config)
patchsim.run_simulation(config, "my-model", net, y0, patches, n)
The simulation outputs are saved in the following structure:
output/
├── logs/
│ └── cli_YYYYMMDD_HHMMSS.log # Timestamped log files
└── sample-sir-ode/ # Model-specific output directory
├── plots/
│ └── patch_timeseries_sample-sir-ode_ode.png
└── runs/
└── all_patches_sample-sir-ode_ode.csv
Configuration
Simulations are configured using YAML files. The configuration file specifies:
- Model parameters (e.g., transmission rates)
- Input files (patch populations, seed data, network)
- Simulation settings (time horizon, output directory)
Example configuration:
# Model parameters
Beta: 0.3
Gamma: 0.1
# Input files
PatchFile: data/patch/sample-sir-ode-patch-population.csv
SeedFile: data/seeds/sample-sir-ode-patchA-2.csv
NetworkFile: data/networks/sample-network-static.csv
# Simulation settings
OutputDir: output/sample-sir-ode
TMax: 50
Contributing
We welcome contributions!
To contribute: fork the repo, create a branch, make your changes, and open a pull request.
For major changes, please open an issue first to discuss.
Thanks for helping improve the framework!
License
This project is licensed under the GNU General Public License v3.0.
You may use, modify, and share this project under the same license terms. See the LICENSE file for full details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file patchsim-0.1.0b1.tar.gz.
File metadata
- Download URL: patchsim-0.1.0b1.tar.gz
- Upload date:
- Size: 44.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a04547b281ebda4402b44d5469fa32d3abe1dd3bfdfe2306a8d6ffc41d4ef6ce
|
|
| MD5 |
d054352357d27a993e869f9ab6f27930
|
|
| BLAKE2b-256 |
e29168ee68fe1b225ac9e0d63f530ab2f90316ca8bea2ba7a6f126ae32ea343f
|
Provenance
The following attestation bundles were made for patchsim-0.1.0b1.tar.gz:
Publisher:
pypi-release.yml on dsih-artpark/patchsim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
patchsim-0.1.0b1.tar.gz -
Subject digest:
a04547b281ebda4402b44d5469fa32d3abe1dd3bfdfe2306a8d6ffc41d4ef6ce - Sigstore transparency entry: 1825862331
- Sigstore integration time:
-
Permalink:
dsih-artpark/patchsim@5cc744cbf9d48f804de0ad4a5c21dcfc98c6e754 -
Branch / Tag:
refs/tags/v0.1.0b1 - Owner: https://github.com/dsih-artpark
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-release.yml@5cc744cbf9d48f804de0ad4a5c21dcfc98c6e754 -
Trigger Event:
release
-
Statement type:
File details
Details for the file patchsim-0.1.0b1-py3-none-any.whl.
File metadata
- Download URL: patchsim-0.1.0b1-py3-none-any.whl
- Upload date:
- Size: 47.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
138c697d47894ca80bc926de13d1b06d75a52b5a5f4b593c7eb9beafdfa1818b
|
|
| MD5 |
9de1eafd9b7ffdba2c6f1c4c23cd947b
|
|
| BLAKE2b-256 |
196728b4fa287603ff914905c157da0e8d561499e7e8fd4ce4f15c07775f5d5e
|
Provenance
The following attestation bundles were made for patchsim-0.1.0b1-py3-none-any.whl:
Publisher:
pypi-release.yml on dsih-artpark/patchsim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
patchsim-0.1.0b1-py3-none-any.whl -
Subject digest:
138c697d47894ca80bc926de13d1b06d75a52b5a5f4b593c7eb9beafdfa1818b - Sigstore transparency entry: 1825862382
- Sigstore integration time:
-
Permalink:
dsih-artpark/patchsim@5cc744cbf9d48f804de0ad4a5c21dcfc98c6e754 -
Branch / Tag:
refs/tags/v0.1.0b1 - Owner: https://github.com/dsih-artpark
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-release.yml@5cc744cbf9d48f804de0ad4a5c21dcfc98c6e754 -
Trigger Event:
release
-
Statement type: