Compositional Modeling

An SEIR model and a quarantine policy, drawn as two Petri nets, composed into a third
An SEIR model composed with a quarantine policy, from the AlgebraicPetri.jl documentation.

AlgebraicPetri.jl · AlgebraicDynamics.jl

A scientific model is usually written as a whole and then edited as a whole. Adding an age structure to an epidemic model, or a second species to a reaction network, means rewriting the equations by hand, which is slow and leaves no record of what the change was supposed to mean.

In this project we build models whose structure survives that kind of change. We represent a model as a Petri net, an undirected wiring diagram, or a regulatory network, which turns the operations modelers already perform into operations on the representation: stratifying by age or region, composing two subsystems, refining one species into several. The dynamics are then generated from the representation.

Three formalisms recur across this work. Petri nets carry epidemiological and reaction models, regulatory networks carry the promoting and inhibiting interactions of a biochemical system, and threshold-linear networks carry the dynamics of neural codes. Each has a composition operation, and for each we ask the same question: what does the whole do, given what the parts do?

Much of this work was carried out with the wider AlgebraicJulia community, including Sophie Libkind and Evan Patterson at the Topos Institute.

Project team

How the papers fit together

James Fairbanks leads this project and is an author on the papers below, so each entry names the rest of the collaborators.

An algebraic framework for structured epidemic modelling, led by Sophie Libkind with Andrew Baas, Micah Halter and Evan Patterson, is the project’s flagship: stratification, composition, analysis and calibration as operations on a model’s structure rather than edits to a codebase.

Operadic modeling of dynamical systems, with Sophie Libkind, Andrew Baas and Evan Patterson, is the machinery underneath it – operads of wiring diagrams, dynamical systems as their algebras, and the functoriality of Euler’s method that lets a composite system’s simulator be built from its parts'.

A compositional account of motifs, mechanisms, and dynamics in biochemical regulatory networks, with Rebekah Aduddell, Amit Kumar, Pablo S. Ocal, Evan Patterson and Brandon Shapiro, carries the same pattern into biochemistry: motifs, mechanisms and Lotka-Volterra dynamics all become functors out of one category of signed graphs.

Compositional exploration of combinatorial scientific models, with Kris Brown and Tyler Hanks, turns from building one model to searching the space of models you could have built.

The SemanticModels papers, with Micah Halter, Christine Herlihy, Sreenath Raparti, Kun Cao, Erica Briscoe, Andrew Baas and Evan Patterson, are the project’s prehistory: they tried to recover a model’s meaning from its code by program analysis. The later work inverts that, specifying the structure up front instead – and the reason it does is in those papers.

Software

Written elsewhere

On the AlgebraicJulia blog, Micah Halter and Evan Patterson wrote the epidemic modeling work up as compositional epidemiological modeling using structured cospans and its second part, and Sophie Libkind and James Fairbanks introduced the dynamical systems side in directed and undirected composition. Modeling frameworks: what is a scientific model? is the argument behind all of it.

Sophie Libkind’s Composing springs on the Topos Institute blog is a good small example of composition doing real work.

Project articles

Where an entry carries a note, it says what the paper establishes and what to read it for.

  1. Aduddell, R., Fairbanks, J. P., Kumar, A., Ocal, P. S., Patterson, E., & Shapiro, B. T. (2024). A compositional account of motifs, mechanisms, and dynamics in biochemical regulatory networks. Compositionality, 6, 2. https://doi.org/10.32408/compositionality-6-2

    Regulatory networks as signed graphs, with signed functors describing when one network occurs inside another – which is what a network motif is. From there, functors relate regulatory networks to reaction networks, making precise when a reaction network is a mechanism for a regulatory one, and to Lotka-Volterra dynamics, for open systems as well as closed ones. It is the project’s biochemistry arm, and its clearest example of the same pattern used three ways: motifs, mechanisms and dynamics all become functors out of one category of networks.

    Read it for The motif-as-functor definition, then the Lotka-Volterra functor. The open systems extension is the technical heart.

  2. Libkind, S., Bumpus, B. M., Garcia, J. L., Sorkatti, L. H., & Tenka, S. (2023). Additive Invariants of Open Petri Nets. arXiv. https://doi.org/10.48550/arxiv.2303.01643

    A complete classification of the additive invariants of open Petri nets – the natural-number-valued quantities that add under both sequential and parallel composition. Two theorems: for open Petri nets the invariants are fixed by their values on single-transition nets, and for monically open nets by their values on transitionless nets together with all single-transition nets. The modeling project composes Petri nets constantly, and this says exactly which numerical quantities survive that composition – which ones can be computed on the parts and added, instead of recomputed on the whole.

    Read it for The two classification theorems, and the definition of what it means for an invariant of an open system to be additive.

  3. Libkind, S., Baas, A., Patterson, E., & Fairbanks, J. P. (2022). Operadic Modeling of Dynamical Systems: Mathematics and Computation. Electronic Proceedings in Theoretical Computer Science, 372, 192-206. https://doi.org/10.4204/EPTCS.372.14

    Deterministic dynamical systems, discrete and continuous, compose hierarchically: the paper reformulates existing operads of wiring diagrams and introduces new ones in the language of C-sets, establishes dynamical systems as algebras of those operads, and shows Euler’s method is functorial for undirected systems as well as directed ones. It is where the lab’s dynamical systems machinery is defined, and the functoriality of Euler’s method is the reason a composite system’s simulator can be assembled from its parts’ simulators.

    Read it for The operads and the functoriality result. The AlgebraicDynamics code follows the paper closely enough to read alongside it.

  4. Libkind, S., Baas, A., Halter, M., Patterson, E., & Fairbanks, J. P. (2022). An algebraic framework for structured epidemic modelling. Philosophical Transactions of the Royal Society A: Mathematical, Physical and Engineering Sciences, 380(2233), 20210309. https://doi.org/10.1098/rsta.2021.0309

    A compositional framework for epidemiological modeling in which the structure of a model – its submodels and how they interact – is explicit and algebraic rather than implicit in code. Stratification, composition, analysis and calibration all become operations on that structure, so a local change to a component no longer means a global edit to a codebase. It is the modeling project’s flagship paper, and the clearest statement of the whole lab’s motivation: the gap between how a scientist thinks about a model and the program that implements it is the thing being closed.

    Read it for The stratification example. It is the operation that makes the case on its own.

  5. Libkind, S., Baas, A., Halter, M., Patterson, E., & Fairbanks, J. P. (2022). Typed and stratified models with slice categories. In Applied Category Theory (pp. 1-3). https://msp.cis.strath.ac.uk/act2022/papers/ACT2022_paper_3530.pdf

    The construction behind stratification. One Petri net is chosen as a type system, a typed model is then an object of the category of Petri nets sliced over it, and the product in that slice category is the stratified model – so stratifying by age, region or host and vector is a categorical operation rather than a hand edit to a reaction network. The flagship paper says what stratification buys; this is the four-page account of the construction that AlgebraicPetri.jl actually implements, and of how it reproduces stratified models already in the epidemiological literature.

    Read it for The slice-category definition and the host/vector example. It is a technical demonstration, so there is little to skip.

    Read first An algebraic framework for structured epidemic modelling

  6. Brown, K., Hanks, T., & Fairbanks, J. P. (2022). Compositional Exploration of Combinatorial Scientific Models. In Applied Category Theory. https://doi.org/10.48550/ARXIV.2206.08755

    A space of models is represented as a diagram over a category of models, and limits and colimits of those diagrams build larger model spaces out of smaller ones. The paper implements the computer algebra of finitely presented categories and diagram categories needed to do this, with strategies for picking a model out of the space, demonstrated on mass-action kinetic models fitted to data. Composition builds one model; this is the lab’s answer to searching the space of models you could have built, which is what a modeler actually does.

    Read it for The model space construction and the epidemiology case study.

  7. Halter, M., Herlihy, C., & Fairbanks, J. P. (2020). A Compositional Framework for Scientific Model Augmentation. In Electronic Proceedings in Theoretical Computer Science (pp. 172-182). Opn Publishing Association. https://doi.org/10.4204/EPTCS.323.12

    Model augmentation, combination and comparison are treated as metamodeling tasks, and static and dynamic program analysis is used to extract enough semantics from executable scientific models to perform them – metamodeling as metaprogramming, with a categorical account of what the tasks are. It is where the lab first tried to recover a model’s meaning from its code. The later work inverts the problem, specifying structure up front instead, and this paper is the reason why.

    Read it for The definition of the metamodeling tasks, and the case study.

  8. Halter, M., Patterson, E., Baas, A., & Fairbanks, J. P. (2020). Compositional Scientific Computing with Catlab and SemanticModels. In Applied Category Theory. http://arxiv.org/abs/2005.04831

    An early statement of the programme: applied category theory supplies reusable software components for scientific computing, with Catlab.jl as the categorical infrastructure and SemanticModels.jl as the modeling layer on top, composing systems as cospan algebras. It is the origin point for Catlab and, through it, for most of what the lab has built since. Read it as history rather than as current practice.

    Read it for The framing in the introduction. The software described has been superseded.

  9. Halter, M., Raparti, S., Cao, K., Herlihy, C., & Fairbanks, J. P. (2020). SemanticModels. jl: a julia package for scientific model augmentation. In Proceedings of the JuliaCon conferences (pp. 57).

    The software half of the SemanticModels work: a Julia package that automates model augmentation and creation by metamodeling and metaprogramming. The argument for Julia is the substance – its type system, its reachable syntax tree, and the embedded domain-specific languages that multiple dispatch makes possible let a model be manipulated at run time and still compile to efficient code. It is the implementation the rest of the SemanticModels papers describe, and the lab’s first attempt to treat model manipulation as a programming-language problem rather than a modeling one.

    Read it for The argument for Julia as the host language. The package itself has been superseded by AlgebraicPetri.jl.

    Read first A Compositional Framework for Scientific Model Augmentation

  10. Herlihy, C., Cao, K., Reparti, S., Briscoe, E., & Fairbanks, J. P. (2019). Semantic Program Analysis for Scientific Model Augmentation. Modeling the World’s Systems, 7.

    SemanticModels.jl builds a knowledge graph linking elements of scientific code – variables, values, functions, expressions – to elements of scientific understanding, and reasons over it to augment, synthesize and validate epidemiological models. The earliest paper in the project, and the clearest statement of the extraction approach the lab later moved away from.

    Read it for The knowledge graph construction. Historical interest unless you work on model extraction.