Compositional Modeling with Stock and Flow Diagrams
John Baez (Department of Mathematics, University of California,, Riverside), Xiaoyan Li (Department of Computer Science, University of, Saskatchewan), Sophie Libkind (Department of Mathematics, Stanford, University), Nathaniel D. Osgood (Department of Computer Science

TL;DR
This paper introduces StockFlow, a new software package that uses category theory to improve the compositional modeling of population dynamics with stock and flow diagrams, exemplified by a COVID-19 model.
Contribution
The paper presents a novel category-theoretic framework for compositional modeling with stock and flow diagrams, implemented in the StockFlow software package.
Findings
StockFlow enables intuitive composition of diagrams.
The framework separates syntax from semantics.
Application to a COVID-19 model demonstrates practical utility.
Abstract
Stock and flow diagrams are widely used in epidemiology to model the dynamics of populations. Although tools already exist for building these diagrams and simulating the systems they describe, we have created a new package called StockFlow, part of the AlgebraicJulia ecosystem, which uses ideas from category theory to overcome notable limitations of existing software. Compositionality is provided by the theory of decorated cospans: stock and flow diagrams can be composed to form larger ones in an intuitive way formalized by the operad of undirected wiring diagrams. Our approach also cleanly separates the syntax of stock and flow diagrams from the semantics they can be assigned. We consider semantics in ordinary differential equations, although others are possible. As an example, we explain code in StockFlow that implements a simplified version of a COVID-19 model used in Canada.
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsGeochemistry and Geologic Mapping · Reservoir Engineering and Simulation Methods · Hydrocarbon exploration and reservoir analysis
