Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
489e71d
added metwork.py and patch.py
shreyamukherji Nov 6, 2025
6d5279e
added metwork.py and patch.py
shreyamukherji Nov 6, 2025
a16412f
added metwork.py and patch.py
shreyamukherji Nov 6, 2025
7239bf7
added support for per-patch parameters
shreyamukherji Nov 13, 2025
d2f2f8c
added pytests
shreyamukherji Nov 13, 2025
39ee214
added pytests
shreyamukherji Nov 13, 2025
7510819
added pytests
shreyamukherji Nov 13, 2025
25b325b
mkdocs
shreyamukherji Nov 26, 2025
c7fdaf5
mkdocs
shreyamukherji Nov 26, 2025
25279ce
updated model.py
shreyamukherji Dec 12, 2025
6bf96b5
added patch and network files
shreyamukherji Dec 16, 2025
f35da97
added model_runner.py
shreyamukherji Dec 16, 2025
5698d7f
added model_runner.py
shreyamukherji Dec 17, 2025
84df389
added model_runner.py
shreyamukherji Dec 18, 2025
b6e0b6e
added csv data files
shreyamukherji Dec 19, 2025
a6f9356
added csv data files
shreyamukherji Dec 19, 2025
d41d7b3
updated network.py and patch.py
shreyamukherji Dec 22, 2025
3a3ebcf
updated config
shreyamukherji Dec 22, 2025
a1a406f
updated config
shreyamukherji Dec 22, 2025
61d8bd1
updated config
shreyamukherji Dec 24, 2025
f02c11c
updated docs
shreyamukherji Dec 31, 2025
1aa81ee
updated docs
shreyamukherji Dec 31, 2025
ca55514
updated docs
shreyamukherji Dec 31, 2025
d969ded
updated docs
shreyamukherji Dec 31, 2025
592eb4c
updated docs
shreyamukherji Dec 31, 2025
80e9e99
updated docs
shreyamukherji Dec 31, 2025
7ab8190
updated docs
shreyamukherji Dec 31, 2025
e98488f
updated docs
shreyamukherji Dec 31, 2025
4380b40
pypi deploy
shreyamukherji Feb 18, 2026
2f06ac1
pypi deploy
shreyamukherji Feb 18, 2026
14d79dc
pypi deploy
shreyamukherji Feb 18, 2026
bf225e3
smoketests
shreyamukherji Feb 24, 2026
5861e35
smoketests
shreyamukherji Feb 24, 2026
44c5240
smoketests
shreyamukherji Feb 25, 2026
b9ad465
smoketests
shreyamukherji Feb 25, 2026
7dea882
smoketests
shreyamukherji Feb 27, 2026
8c1bc21
smoketests
shreyamukherji Feb 27, 2026
27ace26
smoketests
shreyamukherji Feb 27, 2026
714ab8f
smoke tests
shreyamukherji Mar 6, 2026
e6667ba
smoke tests
shreyamukherji Mar 6, 2026
0c87b75
fixed transitions
shreyamukherji Mar 23, 2026
7a49563
applied pypi readiness and sdk/cli changes
shreyamukherji Mar 27, 2026
ba11329
removed dead code
shreyamukherji Mar 31, 2026
d73a554
setting up ci/cd
shreyamukherji Mar 31, 2026
38d12eb
setting up ci/cd
shreyamukherji Mar 31, 2026
5fc702c
setting up ci/cd
shreyamukherji Mar 31, 2026
d305ee6
fixed issues based on coderabbit PR review
shreyamukherji Mar 31, 2026
cc94719
fixed issues based on coderabbit PR review
shreyamukherji Mar 31, 2026
45d195f
fixed issues based on coderabbit PR review
shreyamukherji Mar 31, 2026
2534755
fixed issues based on coderabbit PR review
shreyamukherji Mar 31, 2026
1f170f0
fixed issues based on coderabbit PR review
shreyamukherji Mar 31, 2026
25f97c8
changed ci.yml, publish.yml, cli.py and docs
shreyamukherji Apr 3, 2026
73d32ce
changed ci.yml, publish.yml, cli.py and docs
shreyamukherji Apr 3, 2026
d09df22
changed ci.yml, publish.yml, cli.py and docs
shreyamukherji Apr 7, 2026
b9ce994
changed ci.yml, publish.yml, cli.py and docs
shreyamukherji Apr 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: CI

on:
push:
branches: [main, feature, dev, develop]
pull_request: null

jobs:
test-and-lint:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup uv
uses: astral-sh/setup-uv@v5

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version-file: .python-version

- name: Sync dependencies (including dev)
run: uv sync --extra dev --frozen

- name: Ruff lint
run: uv run --no-sync --frozen ruff check .

- name: Ruff format check
run: uv run --no-sync --frozen ruff format --check .

- name: Run tests
run: uv run --no-sync --frozen pytest -q

build:
runs-on: ubuntu-latest
needs: test-and-lint

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup uv
uses: astral-sh/setup-uv@v5

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version-file: .python-version

- name: Sync dependencies
run: uv sync --frozen

- name: Build package
run: uv build
46 changes: 46 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Publish to PyPI

on:
release:
types: [published]
workflow_dispatch: null

jobs:
publish:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read

environment:
name: pypi

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup uv
uses: astral-sh/setup-uv@v5

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version-file: .python-version

- name: Sync dependencies (including dev)
run: uv sync --extra dev --frozen

- name: Lint
run: uv run --no-sync --frozen ruff check .

- name: Format check
run: uv run --no-sync --frozen ruff format --check .

- name: Test
run: uv run --no-sync --frozen pytest -q

- name: Build
run: uv build

- name: Publish
uses: pypa/gh-action-pypi-publish@release/v1
25 changes: 23 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ profile_default/
ipython_config.py

# pyenv
.python-version
# .python-version is tracked for CI reproducibility

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
Expand Down Expand Up @@ -152,6 +152,16 @@ dmypy.json
*.xlsx
output/**

# Keep package template scaffold files tracked
!src/patchsim/templates/project/data/
!src/patchsim/templates/project/data/networks/
!src/patchsim/templates/project/data/networks/*.csv
!src/patchsim/templates/project/data/patch/
!src/patchsim/templates/project/data/patch/*.csv
!src/patchsim/templates/project/data/seeds/
!src/patchsim/templates/project/data/seeds/*.csv
!src/patchsim/templates/project/output/.gitkeep

# Additions for GeoJSON, .zip files, and shapefiles
*.geojson
*.zip
Expand All @@ -164,4 +174,15 @@ output/**
.pdm-build/

# Exception for .png files in assets/
!assets/*.png
!assets/*.png

# Allow tracked data CSVs
!data/
!data/networks/
!data/networks/*.csv

!data/patch/
!data/patch/*.csv

!data/seeds/
!data/seeds/*.csv
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-yaml
- id: check-toml

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.8
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
Empty file added CHANGELOG.md
Empty file.
60 changes: 53 additions & 7 deletions README.md
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This document expects users to be running patchsim directly in their root. The recommended pattern should be uv run patchsim --help to let the user utilise the right dependencies.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@ To develop a general-purpose, modular simulation framework for patch-based metap

---

## 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:
Expand All @@ -40,7 +61,13 @@ PatchSim aims to support a range of modelling features commonly used in metapopu

## Installation

To install PatchSim using [uv](https://github.com/astral-sh/uv):
Install from PyPI:

```bash
pip install patchsim
```

Install from source using [uv](https://github.com/astral-sh/uv):

```bash
# Clone the repository
Expand All @@ -62,17 +89,36 @@ uv pip install -e .[dev]

### Command Line Interface

PatchSim provides a command-line interface for running simulations:
PatchSim provides a subcommand-based CLI. Always run using `uv run` to ensure correct dependency resolution:

```bash
# Show help and available options
patchsim --help
uv run patchsim --help

# Show package version
uv run patchsim --version

# Initialize a new self-contained project
uv run patchsim init my-project

# Validate config without running
uv run patchsim validate -c my-project/config.yaml

# Run simulation
uv run patchsim run -c my-project/config.yaml

# List built-in models
uv run patchsim list-models
```

### Python SDK

# Run simulation with sample SIR model
patchsim --config configs/sample-sir-ode.yaml
```python
import patchsim

# Run simulation with custom model
patchsim --config path/to/your/config.yaml
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:
Expand Down
10 changes: 7 additions & 3 deletions configs/sample-sir-ode.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ StartDate: 2020-01-01
EndDate: 2022-12-31
OutputDir: output/sample-sir-ode
compartments: ["S", "I", "R"]
Parameters: {"beta": 0.5, "gamma": 0.1}
Transitions: [{"from": "S", "to": "I", "rate": "beta * S * I / (S + I + R)"}, {"from": "I", "to": "R", "rate": "gamma * I"}]

Parameters:
beta: 0.08
gamma: 0.1
#PatchParameters: [{"patch": "PatchA", "parameters": {"beta": 0.2, "gamma": 0.1}}, {"patch": "PatchB", "parameters": {"beta": 0.25, "gamma": 0.1}}]
Transitions:
"S -> I": "beta"
"I -> R": "gamma * I"
5 changes: 5 additions & 0 deletions data/networks/sample-network-static.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
day,source,target,weight
0,A,A,0.9
0,A,B,0.1
0,B,B,0.9
0,B,A,0.1
3 changes: 3 additions & 0 deletions data/patch/sample-sir-ode-patch-population.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
patch,Population
A, 1000
B, 500
3 changes: 3 additions & 0 deletions data/seeds/sample-sir-ode-patchA-2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
patch,S,I,R
A,999,1,0
B,500,0,0
25 changes: 25 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

# Architecture

PatchSim follows a layered architecture:

## Core components

### Patch
Represents a single subpopulation with:
- Fixed population size
- Compartment state vector
- Parameter dictionary
- Validation logic

### Network
Defines interactions between patches via a weighted directed graph.

### Model
Orchestrates:
- ODE construction
- Numerical integration
- Visualization of results

This separation ensures that changes to network structure do not require
rewriting patch-level dynamics.
30 changes: 30 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Configuration

PatchSim simulations are configured using YAML files.

## Model definition

```yaml
# Input files (required)
PatchFile: data/patch/patch-population.csv
NetworkFile: data/networks/network.csv
SeedFile: data/seeds/seed-initial.csv

# Model configuration
ModelName: sample-sir-ode

# Simulation parameters
TMax: 50
Tolerance: 1e-8
MaxIter: 10000
StartDate: 2020-01-01
EndDate: 2022-12-31
OutputDir: output/sample-sir-ode
compartments: ["S", "I", "R"]
Parameters:
beta: 0.08
gamma: 0.1
Transitions:
"S -> I": "beta"
"I -> R": "gamma * I"
```
23 changes: 23 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@


# Getting Started

## Installation

### From PyPI (Recommended)

Install patchsim from PyPI:

```bash
pip install patchsim
```

### For Contributors

Clone the repository and install in editable mode for development:

```bash
git clone https://github.com/dsih-artpark/patchsim.git
cd patchsim
pip install -e .
```
24 changes: 18 additions & 6 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
# PatchSim

PatchSim is a modular, general-purpose metapopulation epidemiological simulation framework designed for research and translation use cases.
PatchSim is a modular, general-purpose metapopulation epidemiological simulation framework designed for research and translation use cases. It is a flexible and modular system for simulating epidemiological compartment models across single or multiple interacting patches.

The framework generalizes classical compartmental models (e.g. SIR) by allowing multiple subpopulations ("patches") to interact through a weighted directed network.

PatchSim emphasizes:
- Explicit separation between patch dynamics and network structure
- Continuous-time ODE-based simulation
- Configurable parameters via YAML
- Extensibility toward richer network and mobility models

## Features
- ODE and discrete-time simulation modes
- Supports multiple diseases and problem types
- Integrated CLI for running models
- Built-in reproducibility and parameter management
- Extensible and user-friendly

- **Flexible Compartment Models**: Define custom SIR, SEIR, or other compartmental models that support multiple diseases and problem types
- **Multi-Patch Networks**: Simulate disease spread across connected geographical regions
- **CLI Integration**: Integrated CLI for running models
- **Multiple Simulation Methods**: Support for both ODE and discrete-time simulation modes
- **YAML Configuration**: Structured, readable configuration files
- **Per-Patch Parameters**: Built-in reproducibility and management of different parameters for each patch
- **Network Connectivity**: Define custom mixing matrices between patches
- **Extensibility**: Extensible and user-friendly

## Documentation
- [Core Module](reference/core.md)
Expand Down
Loading
Loading