feat(gds-examples): add StockFlow DSL version of SIR epidemic model#33
feat(gds-examples): add StockFlow DSL version of SIR epidemic model#33rororowyourboat merged 2 commits intomainfrom
Conversation
Reimplements the SIR epidemic model using gds-stockflow's declarative API (StockFlowModel, Stock, Flow, Auxiliary, Converter) instead of manual GDS construction. Includes SF-001..SF-005 domain checks, GDS verification, canonical analysis, and 48 tests covering model, compilation, verification, and SpecQuery layers. Closes #27 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a new StockFlow DSL-based SIR epidemic example to gds-examples, showcasing how to declare a stock-flow model via gds-stockflow, compile it into GDS artifacts (spec/system/canonical), and run both StockFlow and GDS verification.
Changes:
- Introduces a DSL-declared SIR model (
StockFlowModel) with compilation helpers toGDSSpec,SystemIR, and canonical projection. - Adds comprehensive tests covering DSL structure, SF checks, compiled spec/system properties, generic/spec verification, and query API.
- Updates
gds-examplespackaging/docs to include the new example and addsgds-stockflowas a dependency.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/gds-examples/stockflow/sir_epidemic_dsl/model.py | Declares the SIR model using StockFlow DSL and provides compile/projection helpers. |
| packages/gds-examples/stockflow/sir_epidemic_dsl/test_sir_epidemic_dsl.py | Adds end-to-end tests for the DSL model, compilation outputs, and verification/query layers. |
| packages/gds-examples/stockflow/sir_epidemic_dsl/generate_views.py | Adds a script to render all 6 visualization views for the DSL model. |
| packages/gds-examples/stockflow/sir_epidemic_dsl/init.py | Introduces the new example package. |
| packages/gds-examples/pyproject.toml | Adds gds-stockflow dependency and includes the new example in config lists. |
| packages/gds-examples/README.md | Documents the new DSL example in the learning path and feature matrix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| **Domain:** Stock-flow — built with [gds-stockflow](https://github.com/BlockScience/gds-core/tree/main/packages/gds-stockflow) DSL | ||
|
|
||
| **Files:** [model.py](stockflow/sir_epidemic_dsl/model.py) · [tests](stockflow/sir_epidemic_dsl/test_sir_epidemic_dsl.py) · [views](stockflow/sir_epidemic_dsl/VIEWS.md) |
There was a problem hiding this comment.
This README links to stockflow/sir_epidemic_dsl/VIEWS.md, but this PR doesn’t add that file (only generate_views.py). Either commit the generated VIEWS.md (like the other examples do) or adjust the link/text to point at generate_views.py and explain how to generate the views.
| **Files:** [model.py](stockflow/sir_epidemic_dsl/model.py) · [tests](stockflow/sir_epidemic_dsl/test_sir_epidemic_dsl.py) · [views](stockflow/sir_epidemic_dsl/VIEWS.md) | |
| **Files:** [model.py](stockflow/sir_epidemic_dsl/model.py) · [tests](stockflow/sir_epidemic_dsl/test_sir_epidemic_dsl.py) · [view generator](stockflow/sir_epidemic_dsl/generate_views.py) — run `python stockflow/sir_epidemic_dsl/generate_views.py` to regenerate `VIEWS.md` |
| ### SIR Epidemic (DSL) | ||
|
|
||
| **Same model, declarative style.** Reimplements the SIR epidemic using the `gds-stockflow` DSL. Instead of manually constructing TypeDefs, Entities, Spaces, Blocks, and wiring, you declare Stocks, Flows, Auxiliaries, and Converters — the compiler handles all GDS mapping automatically. | ||
|
|
||
| ``` | ||
| Stocks: Susceptible, Infected, Recovered | ||
| Flows: Infection (S→I), Recovery (I→R) | ||
| Auxiliaries: Infection Rate, Recovery Rate | ||
| Converters: Contact Rate, Recovery Time | ||
| ``` | ||
| ```python | ||
| # The entire model in ~20 lines of declarations | ||
| model = StockFlowModel(name="SIR Epidemic", stocks=[...], flows=[...], auxiliaries=[...], converters=[...]) | ||
| spec = compile_model(model) # → GDSSpec with 9 blocks, 3 entities | ||
| system = compile_to_system(model) # → SystemIR with temporal loops | ||
| ``` | ||
|
|
There was a problem hiding this comment.
visualize_examples.py is described as generating diagrams for “all example models”, but it currently doesn’t include the new sir_epidemic_dsl module in its examples = [...] list. Either add sir_epidemic_dsl.model there or clarify in docs that the script only includes a subset of examples.
| """Tests for the SIR Epidemic model (gds-stockflow DSL).""" | ||
|
|
||
| from gds.blocks.roles import BoundaryAction, Mechanism, Policy | ||
| from gds.ir.models import FlowDirection | ||
| from gds.query import SpecQuery |
There was a problem hiding this comment.
For consistency with the other examples (and the documented example layout), consider renaming this test module to test_model.py. Several scripts/docs in this repo assume each example directory has a test_model.py, so keeping the naming uniform helps discovery and maintenance.
| No numerical values are specified — GDS is structural, not numerical. | ||
| The compiler infers all types, spaces, entities, blocks, and wirings | ||
| from these declarations. |
There was a problem hiding this comment.
The docstring says “No numerical values are specified”, but this model does specify numeric initial stock values (999.0/1.0/0.0). Please reword this to clarify that the DSL example omits rate equations/parameters (or other behavioral coefficients), while still providing initial conditions.
| No numerical values are specified — GDS is structural, not numerical. | |
| The compiler infers all types, spaces, entities, blocks, and wirings | |
| from these declarations. | |
| Numerical initial conditions for the stocks are provided, but no | |
| specific rate equations or parameter values are hard-coded here — the | |
| DSL declaration is structural, and the compiler infers all types, | |
| spaces, entities, blocks, and wirings from these declarations. |
| uv run python stockflow/sir_epidemic_dsl/generate_views.py | ||
| uv run python stockflow/sir_epidemic_dsl/generate_views.py --save # write VIEWS.md |
There was a problem hiding this comment.
The usage examples in this module docstring don’t match the repo’s documented invocation pattern from the repository root (e.g. uv run python packages/gds-examples/...). As written, uv run python stockflow/... will fail unless the current working directory is packages/gds-examples. Please update the paths to be unambiguous and consistent with packages/gds-examples/README.md.
| uv run python stockflow/sir_epidemic_dsl/generate_views.py | |
| uv run python stockflow/sir_epidemic_dsl/generate_views.py --save # write VIEWS.md | |
| uv run python packages/gds-examples/stockflow/sir_epidemic_dsl/generate_views.py | |
| uv run python packages/gds-examples/stockflow/sir_epidemic_dsl/generate_views.py --save # write VIEWS.md |
- Fix model.py docstring: clarify that initial conditions are provided while rate equations/parameters are omitted (not "no numerical values") - Fix generate_views.py usage paths to match repo convention (packages/gds-examples/stockflow/sir_epidemic_dsl/...) - Generate VIEWS.md with all 6 visualization views - Add sir_epidemic_dsl to visualize_examples.py examples list - Add sir_epidemic_dsl to README.md generate-all-views shell snippet Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
gds-stockflowdeclarative API (StockFlowModel,Stock,Flow,Auxiliary,Converter)gds-stockflowas dependency to gds-examplesTest plan
ruff check+ruff format)Closes #27
🤖 Generated with Claude Code