Skip to content

Commit

Permalink
Merge branch 'AlgebraicJulia:main' into foot_error_messages
Browse files Browse the repository at this point in the history
  • Loading branch information
neonWhiteout authored Nov 17, 2023
2 parents c25866c + e2b3ca8 commit e82fa18
Show file tree
Hide file tree
Showing 55 changed files with 52,174 additions and 3,757 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ matrix:
- julia_version: nightly
branches:
only:
- master
- main
- /release-.*/
notifications:
- provider: Email
Expand Down
16 changes: 0 additions & 16 deletions .github/workflows/CompatHelper.yml

This file was deleted.

19 changes: 17 additions & 2 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,27 @@ on:
types:
- created
workflow_dispatch:
inputs:
lookback:
default: 3
permissions:
actions: read
checks: read
contents: write
deployments: read
issues: read
discussions: read
packages: read
pages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: read
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
runs-on: ubuntu-latest
steps:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
ssh: ${{ secrets.DOCUMENTER_KEY }}
token: ${{ secrets.SERVICE_TOKEN }}
50 changes: 50 additions & 0 deletions .github/workflows/julia_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Julia CI/CD

on:
schedule:
- cron: 0 0 * * *
push:
branches: ["main"]
tags: ["*"]
pull_request:
workflow_dispatch:
inputs:
action:
description: "Action"
required: true
default: "test"
type: choice
options:
- test
- release
version:
description: "Tag and release version:"
required: false

permissions:
actions: read
checks: read
contents: write
deployments: read
discussions: read
issues: read
packages: read
pages: read
pull-requests: write
repository-projects: read
security-events: read
statuses: read

jobs:
CI:
if: github.event_name == 'pull_request' || github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.action == 'test')
uses: AlgebraicJulia/.github/.github/workflows/julia_ci.yml@main
secrets: inherit
CompatHelper:
if: github.event_name == 'schedule'
uses: AlgebraicJulia/.github/.github/workflows/julia_compat.yml@main
secrets: inherit
Release:
if: github.event_name == 'workflow_dispatch' && inputs.action == 'release' && inputs.version != ''
uses: AlgebraicJulia/.github/.github/workflows/julia_release.yml@main
secrets: inherit
22 changes: 0 additions & 22 deletions .github/workflows/tests.yml

This file was deleted.

50 changes: 0 additions & 50 deletions .github/workflows/validate-notebooks.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
137 changes: 68 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,79 @@
# AlgebraicStockFlow
[![Tests](https://github.com/AlgebraicJulia/StockFlow.jl/actions/workflows/tests.yml/badge.svg)](https://github.com/AlgebraicJulia/StockFlow.jl/actions/workflows/tests.yml)
<!-- TODO: Set up on codecov.io for repo [![codecov](https://codecov.io/github/AlgebraicJulia/StockFlow.jl/branch/maaster/graph/badge.svg)](https://app.codecov.io/github/AlgebraicJulia/StockFlow.jl) -->

[![Stable Documentation](https://img.shields.io/badge/docs-stable-blue.svg)](https://algebraicjulia.github.io/StockFlow.jl/dev/)
[![CI/CD](https://github.com/AlgebraicJulia/StockFlow.jl/actions/workflows/julia_ci.yml/badge.svg)](https://github.com/AlgebraicJulia/StockFlow.jl/actions/workflows/julia_ci.yml)
[![Code Coverage](https://codecov.io/gh/AlgebraicJulia/StockFlow.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/AlgebraicJulia/StockFlow.jl)

StockFlow.jl is a Julia library for the creation and execution of [stock and flow modeling diagrams](https://en.wikipedia.org/wiki/System_dynamics#Stock_and_flow_diagrams), designed with model composition and stratification in mind through a [categorical approach](https://arxiv.org/abs/2211.01290).

Stock-flow diagrams are used to represent systems where its population can move between different states, such as tracking how many people have been infected or recovered from a disease. By providing initial values, and values for the parameters, we can solve the differential equation which the stock-flow diagram represents, which gives us a graph for how the population varies over time.
Stock-flow diagrams are used to represent systems where its population can move between different states, such as tracking how many people have been infected or recovered from a disease. By providing initial values, and values for the parameters, we can solve the differential equation which the stock-flow diagram represents, which gives us a graph for how the population varies over time.

In this particular schema, stock-flow diagrams consist of stocks, flows, dynamic variables, sum variables, parameters, and the links between them.

* Stocks represent accumulations of a population in a particular state, such as 'susceptible', 'infected', 'recovered', etc.
* Flows represent transitions between states. A flow can go from a stock to a stock, from nothing to a stock, or from a stock to nothing, the latter two representing a population entering or leaving a model. Flows are dependent on a dynamic variable, which determines its rate.
* Dynamic variables are the equations which determine flow rates. For instance, if the rate at which people move from uninfected to infected is the uninfected stock S times the parameter c, we can say v\_infectionRate = c * S, and use this as a flow variable. Dynamic variables can contain stocks, sum variables, parameters and other dynamic variables (but the definition can't be circular; you can't set a dynamic variable equal to itself, for instance). Currently supports common binary and unary operations such as addition, multiplication, log, exp.
* Sum variables represent the sum of a subpopulation. The value of a sum variable is the sum of all the stocks which link to it. Common examples include the sum of the entire population N, the sum of infected individuals NI, or the sum of a particular subpopulation NS.
* Parameters are variables for which the particular values are defined outside the model definition. You can provide parameters and initial values, then solve the differential equation.
- Stocks represent accumulations of a population in a particular state, such as 'susceptible', 'infected', 'recovered', etc.
- Flows represent transitions between states. A flow can go from a stock to a stock, from nothing to a stock, or from a stock to nothing, the latter two representing a population entering or leaving a model. Flows are dependent on a dynamic variable, which determines its rate.
- Dynamic variables are the equations which determine flow rates. For instance, if the rate at which people move from uninfected to infected is the uninfected stock S times the parameter c, we can say v_infectionRate = c \* S, and use this as a flow variable. Dynamic variables can contain stocks, sum variables, parameters and other dynamic variables (but the definition can't be circular; you can't set a dynamic variable equal to itself, for instance). Currently supports common binary and unary operations such as addition, multiplication, log, exp.
- Sum variables represent the sum of a subpopulation. The value of a sum variable is the sum of all the stocks which link to it. Common examples include the sum of the entire population N, the sum of infected individuals NI, or the sum of a particular subpopulation NS.
- Parameters are variables for which the particular values are defined outside the model definition. You can provide parameters and initial values, then solve the differential equation.

Stock-flow diagrams can be created and manipulated using the `StockFlow` and `StockFlow.Syntax` modules, the latter of which includes the domain specific language for easier creation.

Stock-flow diagrams can be composed and stratified - that is, combined on stocks and sum variables or split into subpopulations. One can also do algebraic rewriting for more manual, specific fixes, such as preventing a dynamic variable from unnecessarily being computed twice, or substituting one parameter for another.

Examples of the domain specific language, composition, stratification and algebraic rewriting can be seen in the [examples](examples) folder. In particular, full\_fledged\_schema\_examples\_new contains examples which use the domain specific language.



## Example interpretation of a stock and flow diagram using an ODE solver

From the [SEIR Composition Example](examples/full_fledged_schema_examples_new/composition/SEIR_full_model_measles_chickenpox.ipynb):

```julia
seir = @stock_and_flow begin
:stocks
S
E
I
R

:parameters
μ
β
tlatent
trecovery
δ

:flows
=> fbirth* N) => S # dynamic variables can be defined implicitly or with :dynamic_variables
S => fincid* S * I / N) => E
S => fdeathS(S * δ) =>
E => finf(E / tlatent) => I
E => fdeathE(E * δ) =>
I => frec(I / trecovery) => R
I => fdeathI(I * δ) =>
R => fdeathR(R * δ) =>

:sums
N = [S, E, I, R]

end

# define parameter values and initial values of stocks
# define constant parameters
p_measles = LVector(
β=49.598, μ=0.03/12, δ=0.03/12, tlatent=8.0/30, trecovery=5.0/30
)

# define initial values for stocks
u0_measles = LVector(
S=90000.0-930.0, E=0.0, I=930.0, R=773545.0
)

prob_measles = ODEProblem(vectorfield(seir),u0_measles,(0.0,120.0),p_measles);
sol_measles = solve(prob_measles,Tsit5(),abstol=1e-8);
plot(sol_measles)
```

See the full example for additional comments and the chickenpox model.
## Note

This library is under active development and does not yet have an official release.

Stock-flow diagrams can be composed and stratified - that is, combined on stocks and sum variables or split into subpopulations. One can also do algebraic rewriting for more manual, specific fixes, such as preventing a dynamic variable from unnecessarily being computed twice, or substituting one parameter for another.

Examples of the domain specific language, composition, stratification and algebraic rewriting can be seen in the [examples](examples) folder. In particular, full_fledged_schema_examples_new contains examples which use the domain specific language.

## Example interpretation of a stock and flow diagram using an ODE solver

From the [SEIR Composition Example](examples/full_fledged_schema_examples_new/composition/SEIR_full_model_measles_chickenpox.ipynb):

```julia
seir = @stock_and_flow begin
:stocks
S
E
I
R

:parameters
μ
β
tlatent
trecovery
δ

:flows
=> fbirth* N) => S # dynamic variables can be defined implicitly or with :dynamic_variables
S => fincid* S * I / N) => E
S => fdeathS(S * δ) =>
E => finf(E / tlatent) => I
E => fdeathE(E * δ) =>
I => frec(I / trecovery) => R
I => fdeathI(I * δ) =>
R => fdeathR(R * δ) =>

:sums
N = [S, E, I, R]

end

# define parameter values and initial values of stocks
# define constant parameters
p_measles = LVector(
β=49.598, μ=0.03/12, δ=0.03/12, tlatent=8.0/30, trecovery=5.0/30
)

# define initial values for stocks
u0_measles = LVector(
S=90000.0-930.0, E=0.0, I=930.0, R=773545.0
)

prob_measles = ODEProblem(vectorfield(seir),u0_measles,(0.0,120.0),p_measles);
sol_measles = solve(prob_measles,Tsit5(),abstol=1e-8);
plot(sol_measles)
```

See the full example for additional comments and the chickenpox model.

## Note

This library is under active development and does not yet have an official release.
7 changes: 7 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
[deps]
AlgebraicRewriting = "725a01d3-f174-5bbd-84e1-b9417bad95d9"
Catlab = "134e5e36-593f-5add-ad60-77f754baafbe"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
GraphViz = "f526b714-d49f-11e8-06ff-31ed36ee7ee0"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
StockFlow = "58c4a0e8-2944-4d18-9fa2-e17726aee9e5"
TikzPictures = "37f6aa50-8035-52d0-81c2-5a1d08754b2d"
Loading

0 comments on commit e82fa18

Please sign in to comment.