Skip to content

Commit 75537d8

Browse files
Merge pull request #3 from dsih-artpark/feature
PyPI readiness: Finalization of patchsim
2 parents 6a2bb83 + b9ce994 commit 75537d8

44 files changed

Lines changed: 2620 additions & 1290 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, feature, dev, develop]
6+
pull_request: null
7+
8+
jobs:
9+
test-and-lint:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Setup uv
17+
uses: astral-sh/setup-uv@v5
18+
19+
- name: Setup Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version-file: .python-version
23+
24+
- name: Sync dependencies (including dev)
25+
run: uv sync --extra dev --frozen
26+
27+
- name: Ruff lint
28+
run: uv run --no-sync --frozen ruff check .
29+
30+
- name: Ruff format check
31+
run: uv run --no-sync --frozen ruff format --check .
32+
33+
- name: Run tests
34+
run: uv run --no-sync --frozen pytest -q
35+
36+
build:
37+
runs-on: ubuntu-latest
38+
needs: test-and-lint
39+
40+
steps:
41+
- name: Checkout
42+
uses: actions/checkout@v4
43+
44+
- name: Setup uv
45+
uses: astral-sh/setup-uv@v5
46+
47+
- name: Setup Python
48+
uses: actions/setup-python@v5
49+
with:
50+
python-version-file: .python-version
51+
52+
- name: Sync dependencies
53+
run: uv sync --frozen
54+
55+
- name: Build package
56+
run: uv build

.github/workflows/publish.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch: null
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
id-token: write
13+
contents: read
14+
15+
environment:
16+
name: pypi
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Setup uv
23+
uses: astral-sh/setup-uv@v5
24+
25+
- name: Setup Python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version-file: .python-version
29+
30+
- name: Sync dependencies (including dev)
31+
run: uv sync --extra dev --frozen
32+
33+
- name: Lint
34+
run: uv run --no-sync --frozen ruff check .
35+
36+
- name: Format check
37+
run: uv run --no-sync --frozen ruff format --check .
38+
39+
- name: Test
40+
run: uv run --no-sync --frozen pytest -q
41+
42+
- name: Build
43+
run: uv build
44+
45+
- name: Publish
46+
uses: pypa/gh-action-pypi-publish@release/v1

.gitignore

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ profile_default/
8585
ipython_config.py
8686

8787
# pyenv
88-
.python-version
88+
# .python-version is tracked for CI reproducibility
8989

9090
# pipenv
9191
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
@@ -152,6 +152,16 @@ dmypy.json
152152
*.xlsx
153153
output/**
154154

155+
# Keep package template scaffold files tracked
156+
!src/patchsim/templates/project/data/
157+
!src/patchsim/templates/project/data/networks/
158+
!src/patchsim/templates/project/data/networks/*.csv
159+
!src/patchsim/templates/project/data/patch/
160+
!src/patchsim/templates/project/data/patch/*.csv
161+
!src/patchsim/templates/project/data/seeds/
162+
!src/patchsim/templates/project/data/seeds/*.csv
163+
!src/patchsim/templates/project/output/.gitkeep
164+
155165
# Additions for GeoJSON, .zip files, and shapefiles
156166
*.geojson
157167
*.zip
@@ -164,4 +174,15 @@ output/**
164174
.pdm-build/
165175

166176
# Exception for .png files in assets/
167-
!assets/*.png
177+
!assets/*.png
178+
179+
# Allow tracked data CSVs
180+
!data/
181+
!data/networks/
182+
!data/networks/*.csv
183+
184+
!data/patch/
185+
!data/patch/*.csv
186+
187+
!data/seeds/
188+
!data/seeds/*.csv

.pre-commit-config.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v6.0.0
4+
hooks:
5+
- id: end-of-file-fixer
6+
- id: trailing-whitespace
7+
- id: check-yaml
8+
- id: check-toml
9+
10+
- repo: https://github.com/astral-sh/ruff-pre-commit
11+
rev: v0.15.8
12+
hooks:
13+
- id: ruff
14+
args: [--fix]
15+
- id: ruff-format

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.11

CHANGELOG.md

Whitespace-only changes.

README.md

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@ To develop a general-purpose, modular simulation framework for patch-based metap
1515

1616
---
1717

18+
## Unique Selling Point (USP)
19+
20+
PatchSim combines metapopulation network dynamics with a lightweight, configuration-first workflow:
21+
22+
- Network-aware compartment transitions across connected patches
23+
- Arrow-map transition syntax in YAML for explicit model specification
24+
- Fast iteration loop from config edits to reproducible outputs
25+
26+
---
27+
28+
## Unique Value Proposition (UVP)
29+
30+
Compared to many epidemiology tools that are either code-heavy or tightly bound to a specific disease model, PatchSim offers:
31+
32+
- **Model flexibility**: define SIR/SIRS-style variants through config transitions
33+
- **Research-friendly reproducibility**: deterministic inputs, logged runs, and versioned config files
34+
- **Dual interface**: SDK import for programmatic workflows and CLI for operational runs
35+
- **Extensibility path**: built-in structure for adding custom models and project templates
36+
37+
---
38+
1839
## Core Features
1940

2041
PatchSim aims to support a range of modelling features commonly used in metapopulation disease simulations:
@@ -40,7 +61,13 @@ PatchSim aims to support a range of modelling features commonly used in metapopu
4061

4162
## Installation
4263

43-
To install PatchSim using [uv](https://github.com/astral-sh/uv):
64+
Install from PyPI:
65+
66+
```bash
67+
pip install patchsim
68+
```
69+
70+
Install from source using [uv](https://github.com/astral-sh/uv):
4471

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

6390
### Command Line Interface
6491

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

6794
```bash
6895
# Show help and available options
69-
patchsim --help
96+
uv run patchsim --help
97+
98+
# Show package version
99+
uv run patchsim --version
100+
101+
# Initialize a new self-contained project
102+
uv run patchsim init my-project
103+
104+
# Validate config without running
105+
uv run patchsim validate -c my-project/config.yaml
106+
107+
# Run simulation
108+
uv run patchsim run -c my-project/config.yaml
109+
110+
# List built-in models
111+
uv run patchsim list-models
112+
```
113+
114+
### Python SDK
70115

71-
# Run simulation with sample SIR model
72-
patchsim --config configs/sample-sir-ode.yaml
116+
```python
117+
import patchsim
73118

74-
# Run simulation with custom model
75-
patchsim --config path/to/your/config.yaml
119+
config = patchsim.load_config("config.yaml")
120+
net, y0, patches, n = patchsim.setup_simulation(config)
121+
patchsim.run_simulation(config, "my-model", net, y0, patches, n)
76122
```
77123

78124
The simulation outputs are saved in the following structure:

configs/sample-sir-ode.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ StartDate: 2020-01-01
1515
EndDate: 2022-12-31
1616
OutputDir: output/sample-sir-ode
1717
compartments: ["S", "I", "R"]
18-
Parameters: {"beta": 0.5, "gamma": 0.1}
19-
Transitions: [{"from": "S", "to": "I", "rate": "beta * S * I / (S + I + R)"}, {"from": "I", "to": "R", "rate": "gamma * I"}]
20-
18+
Parameters:
19+
beta: 0.08
20+
gamma: 0.1
21+
#PatchParameters: [{"patch": "PatchA", "parameters": {"beta": 0.2, "gamma": 0.1}}, {"patch": "PatchB", "parameters": {"beta": 0.25, "gamma": 0.1}}]
22+
Transitions:
23+
"S -> I": "beta"
24+
"I -> R": "gamma * I"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
day,source,target,weight
2+
0,A,A,0.9
3+
0,A,B,0.1
4+
0,B,B,0.9
5+
0,B,A,0.1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
patch,Population
2+
A, 1000
3+
B, 500

0 commit comments

Comments
 (0)