Skip to content

Add AlgebraicEpiMech - #3

Merged
SamuelBrand1 merged 14 commits into
masterfrom
add-algebraicepimech
Sep 21, 2026
Merged

SamuelBrand1 merged 14 commits into
masterfrom
add-algebraicepimech

Conversation

@SamuelBrand1

Copy link
Copy Markdown
Collaborator

Summary

This PR introduces the core package that gives:

  • Tooling for defining various common structures in epidemiological models and features as structs
  • Tooling for defining various population structures to allow typing of the model features
  • Methods for generating undirected wiring diagrams (UWDs) which encode these structs as an algebraic structure that can be used by AlgebraicPetri, in particular using oapply_typed to generate typed petri nets. This allows categorical pullback composition across other typed petri nets
  • Methods for generating various observation models that take either species (e.g. prevalence of infection) or transitions (e.g. incidence of infection) as catalysing another observation model petri net. These are composed with the petri net that defines the epidemiological dynamics with categorical pushout composition on these joins.

Package details

Core type system and model abstractions:

  • Added the AlgebraicEpiMech module, defining the abstract base type EpiMechModel and exporting a comprehensive set of model types and utility functions. The module includes submodules for epidemiological typing, mechanisms, compartmental models, multistrain models, immune history, stratification, model construction, vectorfield utilities, and observation attachment. (AlgebraicEpiMech/src/AlgebraicEpiMech.jl)
  • Introduced abstract and concrete types for compartmental models (e.g., SI, SEI, SIR, SEIR, SIS, SEIS, SEIRS), each with relevant fields and constructors, enabling clean dispatch and extensibility for various epidemiological dynamics. (AlgebraicEpiMech/src/CompartmentalModel.jl)
  • Added abstract and concrete types for multistrain models (NoCrossImmunity, CompleteCrossImmunity), supporting different cross-immunity assumptions and flexible strain naming. (AlgebraicEpiMech/src/MultiStrainModel.jl)
  • Defined immune-history stratification via ImmuneHistoryMode and ImmuneHistory types, supporting both full and latest-infection immune tracking, with internal utilities for immune class computation and naming. (AlgebraicEpiMech/src/ImmuneHistory.jl)

Observation metadata:

  • Implemented ObservationChainLayout and ObservationLayout types, along with the observation_layout function, to provide deterministic metadata for observation chains in augmented Petri nets. This centralizes observation-state naming and ordering for downstream analysis. (AlgebraicEpiMech/src/ObservationLayout.jl)

Project and CI setup:

  • Added a Project.toml for the AlgebraicEpiMech package, specifying dependencies, authorship, and Julia compatibility for versions 1.11–1.13. (AlgebraicEpiMech/Project.toml)
  • Introduced a GitHub Actions workflow (test.yaml) to run tests on Julia versions 1.11, 1.12, and 1.13, ensuring CI coverage for the supported Julia versions. (.github/workflows/test.yaml)

Introduce `ObservationChainLayout` and `ObservationLayout` types for observation metadata, and update `observation_layout` to return them. Export the new types and add tests for constructor validation and derived cumulative names.
Build model UWDs without predeclared outer ports and let `oapply_typed` derive the boundary from junctions. Update shared construction helpers to add internal junctions only, simplify stage setup, and adjust tests to assert empty outer boundaries for the generated diagrams.
Extracted model-specific junction selection into `_strain_junction` methods for `NoCrossImmunity` and `CompleteCrossImmunity`, and updated `generate_transition_names` to use this dispatch-based logic. This removes inline branching, keeps strain resolution clearer, and preserves explicit failure behavior via `only(...)` when junction assumptions are violated. The doc example comments were also corrected to reflect 3 boxes per strain (6 names for 2 strains) instead of 4.
Improve `create_model` documentation by clarifying the UWD intermediate role and tightening wording around typed Petri-net construction. In `vectorfield_flat`, simplify and rename accumulator helpers (`_zeroed_accumulator`, `_writeback_accumulator!`), make zeroing behavior explicit when accumulating directly into `du`, and trim overly specific performance commentary while keeping core implementation notes.
Refines `ObservationTarget.jl` comments to better explain pullback-based model composition versus pushout-based observation attachment, and rewrites the optimization rationale with clearer performance context. Also clarifies prevalence sampling behavior by noting detection is non-removing.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Unresolved name-collision, input-validation, typing, and observation-chain issues can produce failures or incorrect models.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 3 High severity · 5 Medium severity · 6 Low severity

Open (14)
What changed in this PR

Introduces AlgebraicEpiMech, a Julia package for constructing, composing, observing, and simulating typed epidemiological Petri-net models.

Changes:

  • Adds compartmental, multistrain, immune-history, and stratification abstractions.
  • Adds model construction, observation attachment/layout, and flattened vector fields.
  • Adds comprehensive tests and Julia CI.
File Description
.github/​workflows/​test.yaml Adds multi-version Julia CI.
.gitignore Ignores manifests and macOS metadata.
AlgebraicEpiMech/​Project.toml Defines package dependencies and compatibility.
AlgebraicEpiMech/​src/​AlgebraicEpiMech.jl Defines module exports and includes.
AlgebraicEpiMech/​src/​CompartmentalModel.jl Defines compartmental model types.
AlgebraicEpiMech/​src/​ImmuneHistory.jl Implements immune-history classes.
AlgebraicEpiMech/​src/​MultiStrainModel.jl Defines multistrain models.
AlgebraicEpiMech/​src/​ObservationLayout.jl Extracts observation-chain metadata.
AlgebraicEpiMech/​src/​ObservationTarget.jl Attaches event and compartment observations.
AlgebraicEpiMech/​src/​Stratification.jl Defines contact stratifications.
AlgebraicEpiMech/​src/​construction_helpers.jl Adds shared UWD construction helpers.
AlgebraicEpiMech/​src/​create_model.jl Provides unified model construction.
AlgebraicEpiMech/​src/​create_model_uwd.jl Builds model-specific UWDs.
AlgebraicEpiMech/​src/​docstrings.jl Configures documentation templates.
AlgebraicEpiMech/​src/​generate_transition_names.jl Generates model transition names.
AlgebraicEpiMech/​src/​mechanisms.jl Defines epidemiological UWD mechanisms.
AlgebraicEpiMech/​src/​typing.jl Defines epidemiological type systems.
AlgebraicEpiMech/​src/​vectorfield_flat.jl Implements flattened-name vector fields.
AlgebraicEpiMech/​test/​Aqua.jl Adds Aqua quality checks.
AlgebraicEpiMech/​test/​Project.toml Defines test dependencies.
AlgebraicEpiMech/​test/​runtests.jl Runs package test items.
AlgebraicEpiMech/​test/​test_age_stratification.jl Tests legacy age stratification.
AlgebraicEpiMech/​test/​test_compartmental_models.jl Tests compartmental constructors.
AlgebraicEpiMech/​test/​test_construction_helpers.jl Tests construction helpers.
AlgebraicEpiMech/​test/​test_contact_stratification.jl Tests stratification types.
AlgebraicEpiMech/​test/​test_create_age_stratification.jl Tests age-model generation.
AlgebraicEpiMech/​test/​test_create_basic_model.jl Tests basic model generation.
AlgebraicEpiMech/​test/​test_create_contact_stratification.jl Tests contact-model generation.
AlgebraicEpiMech/​test/​test_create_model_uwd.jl Tests UWD construction.
AlgebraicEpiMech/​test/​test_create_multistrain_model.jl Tests multistrain generation.
AlgebraicEpiMech/​test/​test_epi_schema.jl Tests typing schemas.
AlgebraicEpiMech/​test/​test_immune_history.jl Tests immune-history behavior.
AlgebraicEpiMech/​test/​test_mechanisms.jl Tests mechanism primitives.
AlgebraicEpiMech/​test/​test_observation_chain.jl Tests observation layouts.
AlgebraicEpiMech/​test/​test_observation_rewriting.jl Tests observation attachment.
AlgebraicEpiMech/​test/​test_stratification.jl Tests stratification composition.
AlgebraicEpiMech/​test/​test_transition_naming.jl Tests transition naming.
AlgebraicEpiMech/​test/​test_vectorfield_flat.jl Tests flattened vector fields.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread AlgebraicEpiMech/src/create_model_uwd.jl Outdated
Comment thread AlgebraicEpiMech/src/create_model_uwd.jl Outdated
Comment thread AlgebraicEpiMech/src/vectorfield_flat.jl
Comment thread AlgebraicEpiMech/src/MultiStrainModel.jl
Comment thread AlgebraicEpiMech/src/ObservationTarget.jl Outdated
Comment thread AlgebraicEpiMech/src/ObservationTarget.jl Outdated
Comment thread AlgebraicEpiMech/src/create_model_uwd.jl
Comment thread AlgebraicEpiMech/src/create_model_uwd.jl Outdated
Comment thread AlgebraicEpiMech/src/create_model_uwd.jl Outdated
Comment thread AlgebraicEpiMech/src/create_model_uwd.jl Outdated
Add constructor and helper checks for positive stage counts, unique strain names, and flattened symbol collisions before building models or vector fields. Observation attachment now treats repeated applications as idempotent only when the existing chain shape matches, and throws a clear error when the same prefix/target is reused incompatibly. The multistrain APIs and docs were also tightened to reflect the required typing and the removal of observation reflexives from composition.
@SamuelBrand1
SamuelBrand1 merged commit 4aba194 into master Sep 21, 2026
4 checks passed
@SamuelBrand1
SamuelBrand1 deleted the add-algebraicepimech branch September 21, 2026 18:26
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.

2 participants