Skip to content

feat(gds-examples): add StockFlow DSL version of SIR epidemic model#33

Merged
rororowyourboat merged 2 commits intomainfrom
feat/examples-stockflow-sir-dsl
Feb 27, 2026
Merged

feat(gds-examples): add StockFlow DSL version of SIR epidemic model#33
rororowyourboat merged 2 commits intomainfrom
feat/examples-stockflow-sir-dsl

Conversation

@rororowyourboat
Copy link
Collaborator

Summary

  • Reimplements SIR epidemic model using gds-stockflow declarative API (StockFlowModel, Stock, Flow, Auxiliary, Converter)
  • Runs SF-001..SF-005 domain checks + GDS generic/semantic verification
  • Adds gds-stockflow as dependency to gds-examples

Test plan

  • 48 tests passing (model, DSL verification, spec, canonical, system, GDS verification, query)
  • Lint clean (ruff check + ruff format)

Closes #27

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings February 27, 2026 08:13
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 to GDSSpec, SystemIR, and canonical projection.
  • Adds comprehensive tests covering DSL structure, SF checks, compiled spec/system properties, generic/spec verification, and query API.
  • Updates gds-examples packaging/docs to include the new example and adds gds-stockflow as 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)
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
**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`

Copilot uses AI. Check for mistakes.
Comment on lines +124 to +140
### 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
```

Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +5
"""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
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +50 to +52
No numerical values are specified — GDS is structural, not numerical.
The compiler infers all types, spaces, entities, blocks, and wirings
from these declarations.
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
No numerical values are specifiedGDS 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 herethe
DSL declaration is structural, and the compiler infers all types,
spaces, entities, blocks, and wirings from these declarations.

Copilot uses AI. Check for mistakes.
Comment on lines +4 to +5
uv run python stockflow/sir_epidemic_dsl/generate_views.py
uv run python stockflow/sir_epidemic_dsl/generate_views.py --save # write VIEWS.md
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
- 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>
@rororowyourboat rororowyourboat merged commit 2e617b1 into main Feb 27, 2026
9 checks passed
@rororowyourboat rororowyourboat deleted the feat/examples-stockflow-sir-dsl branch February 27, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(gds-examples): add StockFlow DSL version of SIR epidemic model

2 participants