Skip to content

Introduce Pydantic Models for Builtin Models#25

Open
olivia-banks wants to merge 7 commits intoEpiForeSITE:mainfrom
olivia-banks:ob-spec-model
Open

Introduce Pydantic Models for Builtin Models#25
olivia-banks wants to merge 7 commits intoEpiForeSITE:mainfrom
olivia-banks:ob-spec-model

Conversation

@olivia-banks
Copy link
Copy Markdown
Member

Introduce Pydantic models for builtin models, and hook this up to the UI. Fixed some reactivity issues, and enabled better diagnostics when a YAML file doesn't look right.

For example, here's what happens when we try to upload Measles parameters to the Tuberculosis model.

image image

As with #24, this is based on #17, and the files to look at are:

modified:   src/epicc/__main__.py
modified:   src/epicc/model/base.py
modified:   src/epicc/models/measles_outbreak.py
modified:   src/epicc/models/tb_isolation.py
modified:   src/epicc/utils/parameter_loader.py

@olivia-banks olivia-banks added this to the MVP milestone Mar 31, 2026
@olivia-banks olivia-banks self-assigned this Mar 31, 2026
Copilot AI review requested due to automatic review settings March 31, 2026 17:46
@olivia-banks olivia-banks added the enhancement New feature or request label Mar 31, 2026
Copy link
Copy Markdown
Contributor

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

This PR migrates the app from ad-hoc Python/YAML handling to a structured, typed approach: built-in simulation models now declare Pydantic parameter schemas, parameter files are loaded via a unified format layer (YAML/XLSX), and the Streamlit UI is rewired to validate and surface better diagnostics when uploads don’t match a model’s schema.

Changes:

  • Introduces a BaseSimulationModel contract plus Pydantic parameter models for the built-in TB Isolation and Measles Outbreak simulations (including default YAML parameter files).
  • Adds a generic “formats” layer (BaseFormat, YAMLFormat, XLSXFormat) with template generation utilities and new unit tests.
  • Replaces the legacy top-level app.py + utils/ loaders with a packaged Streamlit entrypoint (src/epicc/__main__.py) and src/epicc/utils/* helpers.

Reviewed changes

Copilot reviewed 35 out of 43 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
utils/section_renderer.py Removed legacy non-packaged section renderer (moved under src/epicc/utils).
utils/parameter_ui.py Removed legacy non-packaged sidebar parameter UI (moved under src/epicc/utils).
utils/parameter_loader.py Removed legacy YAML/XLSX parameter loader (replaced by epicc.formats + typed loading).
utils/model_loader.py Removed legacy dynamic module discovery/loader (replaced by explicit built-in registry).
src/epicc/web/sidebar.css Adds sidebar styling used by the packaged Streamlit app.
src/epicc/utils/section_renderer.py New packaged section rendering with safer defaults (get() for missing keys).
src/epicc/utils/parameter_ui.py Packaged sidebar parameter widgets + reset logic.
src/epicc/utils/parameter_loader.py Loads/validates uploaded params via format layer + Pydantic, then flattens for UI.
src/epicc/utils/model_loader.py Defines built-in model registry returned to the UI.
src/epicc/utils/excel_model_runner.py Refactors formatting and reuses shared flatten_dict.
src/epicc/models/tb_isolation.yaml Adds default TB Isolation parameter YAML.
src/epicc/models/tb_isolation.py Adds TB Isolation built-in model + Pydantic parameter schema + YAML defaults loader.
src/epicc/models/measles_outbreak.yaml Adds default Measles Outbreak parameter YAML.
src/epicc/models/measles_outbreak.py Adds Measles Outbreak built-in model + Pydantic parameter schema + YAML defaults loader.
src/epicc/model/schema.py Adds a typed schema for declarative YAML-defined models (Model, Parameter, Equation, etc.).
src/epicc/model/base.py Introduces BaseSimulationModel abstract interface for Python models.
src/epicc/model/init.py Adds load_model() for YAML-defined models using the formats layer.
src/epicc/formats/base.py Adds BaseFormat abstraction for YAML/XLSX IO + template writing.
src/epicc/formats/yaml.py Adds YAML format reader/writer.
src/epicc/formats/xlsx.py Adds XLSX format reader/writer + template writer.
src/epicc/formats/template.py Adds Pydantic-based template generation utilities.
src/epicc/formats/init.py Adds format registry, validation helpers, and read_from_format().
src/epicc/config/schema.py Adds typed config schema (Config, DefaultsConfig, etc.).
src/epicc/config/default.yaml Adds packaged default configuration YAML.
src/epicc/config/init.py Adds packaged config loader and exports CONFIG.
src/epicc/main.py New packaged Streamlit entrypoint wired to built-in models + typed validation errors.
tests/epicc/test_model_loader.py Adds tests for epicc.model.load_model().
tests/epicc/test_formats.py Adds tests for format selection and typed read helper.
tests/epicc/test_formats_yaml.py Adds YAML format read/write tests.
tests/epicc/test_formats_xlsx.py Adds XLSX format read/write tests.
tests/epicc/test_formats_template.py Adds integration tests for template generation.
sample/TB Isolation.xlsx Adds sample TB Isolation workbook.
sample/Measles Outbreak.xlsx Adds sample Measles Outbreak workbook.
sample/~$TB Isolation.xlsx Adds an Excel lock/temp file (should not be committed).
pyproject.toml Adds Pydantic + ruamel.yaml deps, pytest dev dep, and pytest pythonpath config.
models/tb_isolation.py Removes legacy TB Isolation model module (superseded by packaged model).
models/measles_outbreak.py Removes legacy Measles model module (superseded by packaged model).
config/paths.yaml Removes legacy app configuration file (superseded by packaged config).
config/global_defaults.yaml Removes legacy defaults file (superseded by packaged config).
config/app.yaml Removes legacy app config (superseded by packaged config).
app.py Removes legacy top-level Streamlit app entrypoint (replaced by src/epicc/__main__.py).
.gitignore Expands ignored editor/build artifacts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@olivia-banks
Copy link
Copy Markdown
Member Author

Blocked by #17.

@gvegayon gvegayon requested a review from EddW1219 April 2, 2026 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants