Skip to content

Commit

Permalink
Fixed merge conflict with diabetes examples
Browse files Browse the repository at this point in the history
  • Loading branch information
neonWhiteout committed Sep 25, 2023
2 parents 715dc0b + 0691f8d commit 68ca20b
Show file tree
Hide file tree
Showing 15 changed files with 404 additions and 4,707 deletions.
1 change: 0 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ jobs:
matrix:
julia-version: ['1.9']
os: [ubuntu-latest, macOS-latest]

steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@latest
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/validate-notebooks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Check notebook examples for regressions

on: [push, pull_request]

env:
JULIA_NUM_THREADS: 'auto'
jobs:
notebooks-examples-regression-test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Julia
uses: julia-actions/setup-julia@v1
with:
version: 1.9
- name: Cache Julia dependencies
uses: julia-actions/cache@v1
- name: Add IJulia Jupyter kernel
run: julia --color=yes --project=. -e 'ENV["JULIA_PKG_PRECOMPILE_AUTO"]=0; using Pkg; pkg"add IJulia"'
- name: Install Julia dependencies
run: julia --color=yes --project=. -e 'import Pkg; Pkg.instantiate(); Pkg.resolve(); Pkg.precompile()'
- uses: yaananth/run-notebook@v2
env:
RUNNER: ${{ toJson(runner) }}
SECRETS: ${{ toJson(secrets) }}
GITHUB: ${{ toJson(github) }}
with:
notebook: "examples/full_fledged_schema_examples_new/stratification/diabetes_diagnose.ipynb"
- uses: yaananth/run-notebook@v2
env:
RUNNER: ${{ toJson(runner) }}
SECRETS: ${{ toJson(secrets) }}
GITHUB: ${{ toJson(github) }}
with:
notebook: "examples/full_fledged_schema_examples_new/composition/diabetes_model.ipynb"
- uses: yaananth/run-notebook@v2
env:
RUNNER: ${{ toJson(runner) }}
SECRETS: ${{ toJson(secrets) }}
GITHUB: ${{ toJson(github) }}
with:
notebook: "examples/full_fledged_schema_examples_new/CausalLoopDiagrams/convert_from_SEIR_stockFlowDiagram.ipynb"
- uses: actions/upload-artifact@v3
if: always()
with:
name: output
path: ${{ RUNNER.temp }}/nb-runner
env:
RUNNER: ${{ toJson(runner) }}
2 changes: 2 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
src/generated/
59 changes: 59 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Documenter
using Literate

const literate_dir = joinpath(@__DIR__, "literate")
const generated_dir = joinpath(@__DIR__, "src", "generated")

@info "Loading StockFlow.jl"
using StockFlow

const no_literate = "--no-literate" in ARGS
if !no_literate
@info "Building Literate.jl docs"

# XXX: Work around old LaTeX distribution in GitHub CI.
if haskey(ENV, "GITHUB_ACTIONS")
import TikzPictures
TikzPictures.standaloneWorkaround(true)
end

# Set Literate.jl config if not being compiled on recognized service.
config = Dict{String,String}()
if !(haskey(ENV, "GITHUB_ACTIONS") || haskey(ENV, "GITLAB_CI"))
config["nbviewer_root_url"] = "https://nbviewer.jupyter.org/github/AlgebraicJulia/StockFlow.jl/blob/gh-pages/dev"
config["repo_root_url"] = "https://github.com/AlgebraicJulia/StockFlow.jl/blob/main/docs"
end

for (root, dirs, files) in walkdir(literate_dir)
out_dir = joinpath(generated_dir, relpath(root, literate_dir))
for file in files
if last(splitext(file)) == ".jl"
Literate.markdown(joinpath(root, file), out_dir;
config=config, documenter=true, credit=false)
Literate.notebook(joinpath(root, file), out_dir;
execute=true, documenter=true, credit=false)
end
end
end
end

@info "Building Documenter.jl docs"
makedocs(
modules = [StockFlow],
format = Documenter.HTML(
assets = ["assets/analytics.js"],
),
sitename = "StockFlow.jl",
doctest = false,
checkdocs = :none,
pages = Any[
"StockFlow.jl" => "index.md",
]
)

@info "Deploying docs"
deploydocs(
target = "build",
repo = "github.com/AlgebraicJulia/StockFlow.jl.git",
branch = "gh-pages"
)
10 changes: 10 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# [StockFlow](@id StockFlow)

```@autodocs
Modules = [
StockFlow,
StockFlow.Syntax,
StockFlow.PremadeModels
]
Private = false
```

Large diffs are not rendered by default.

3,016 changes: 5 additions & 3,011 deletions examples/full_fledged_schema_examples_new/composition/diabetes_model.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion src/CausalLoop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export TheoryCausalLoop, AbstractCausalLoop, CausalLoopUntyped, CausalLoop, nn,
sedge, tedge, convertToCausalLoop, nnames



@present TheoryCausalLoop(FreeSchema) begin
E::Ob
N::Ob
Expand All @@ -26,6 +25,10 @@ add_nodes!(c::AbstractCausalLoop,n;kw...) = add_parts!(c,:N,n;kw...)
add_edge!(c::AbstractCausalLoop,s,t;kw...) = add_part!(c,:E,s=s,t=t;kw...)
add_edges!(c::AbstractCausalLoop,n,s,t;kw...) = add_parts!(c,:E,n,s=s,t=t;kw...)

"""
CausalLoop(ns,es)
Create causal loop diagram from collection of nodes and collection of edges.
"""
CausalLoop(ns,es) = begin
c = CausalLoop()
ns = vectorify(ns)
Expand All @@ -42,15 +45,22 @@ CausalLoop(ns,es) = begin
end

# return the count of each components
""" return count of nodes of CLD """
nn(c::AbstractCausalLoop) = nparts(c,:N) #nodes
""" return count of edges of CLD """
ne(c::AbstractCausalLoop) = nparts(c,:E) #edges

""" return node's name with index n """
nname(c::AbstractCausalLoop,n) = subpart(c,n,:nname) # return the node's name with index of s
""" return edge's name with target number t """
sedge(c::AbstractCausalLoop,e) = subpart(c,e,:s)
""" return edge's name with edge number e """
tedge(c::AbstractCausalLoop,e) = subpart(c,e,:t)

""" return node names of CLD """
nnames(c::AbstractCausalLoop) = [nname(c, n) for n in 1:nn(c)]


function convertToCausalLoop(p::AbstractStockAndFlowStructure)

sns=snames(p)
Expand All @@ -73,6 +83,11 @@ function convertToCausalLoop(p::AbstractStockAndFlowStructure)
return CausalLoop(ns,es)
end

"""
Convert StockFlow to CLD.
Nodes: stocks, flows, sum variables, parameters, nonflow dynamic variables
Edges: morphisms in stock flow
"""
function convertToCausalLoop(p::AbstractStockAndFlowStructureF)

sns=snames(p)
Expand Down
50 changes: 31 additions & 19 deletions src/PremadeModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,30 @@ using ..StockFlow.Syntax

export seir, sis, sir, svi

"""
Return a new SEIR model
"""
function seir()
return deepcopy(seir_model)
end

"""
Return a new SIS model
"""
function sis()
return deepcopy(sis_model)
end

"""
Return a new SIR model
"""
function sir()
return deepcopy(sir_model)
end

"""
Return a new SVI model
"""
function svi()
return deepcopy(svi_model)
end
Expand All @@ -36,8 +48,8 @@ seir_model = @stock_and_flow begin
tlatent
trecovery
δ
c
c


:dynamic_variables
v_prevalence = NI / NS
Expand All @@ -49,14 +61,14 @@ seir_model = @stock_and_flow begin

v_inf = E / tlatent

v_rec = I / trecovery
v_rec = I / trecovery


v_deathS = δ * S
v_deathS = δ * S
v_deathE = δ * E
v_deathI = δ * I
v_deathR = δ * R


:flows
CLOUD => f_birth(v_birth) => S
Expand All @@ -80,15 +92,15 @@ sis_model = @stock_and_flow begin
S
I


:parameters
μ
β
trec # 1 / trecovery. This corresponds to σ.
δ
c


:dynamic_variables
v_deathsX = δ * S
v_births = μ * N
Expand All @@ -114,7 +126,7 @@ sis_model = @stock_and_flow begin
N = [S, I]
NI = [I]
NS = [S, I]

end


Expand All @@ -123,35 +135,35 @@ sir_model = @stock_and_flow begin
S
I
R

:parameters
c
β
rRec

:dynamic_variables
v_prevalence = NI / NS
v_meanInfectiousContactsPerS = c * v_prevalence
v_perSIncidenceRate = β * v_meanInfectiousContactsPerS
v_newInfections = S * v_perSIncidenceRate
v_newRecovery = I * rRec

:flows
S => f_inf(v_newInfections) => I
I => f_rec(v_newRecovery) => R

:sums
N = [S, I, R]
NI = [I]
NS = [S,I,R]


end



svi_model = @stock_and_flow begin

:stocks
S
V
Expand All @@ -165,9 +177,9 @@ svi_model = @stock_and_flow begin
β

:dynamic_variables
v_vacc = S * rvaccine
v_vacc = S * rvaccine
v_deathV = δ * V

v_prevalence = NI / NS
v_meanInfectiousContactsPerS = c * v_prevalence
v_perSIncidenceRate = β * v_meanInfectiousContactsPerS
Expand All @@ -178,9 +190,9 @@ svi_model = @stock_and_flow begin
:flows
S => f_vacc(v_vacc) => V
V => f_deathV(v_deathV) => CLOUD
V => f_infV(v_perSIncidenceVaccinated) => I
V => f_infV(v_perSIncidenceVaccinated) => I



:sums
N = [S, V, I]
NI = [I]
Expand Down
Loading

0 comments on commit 68ca20b

Please sign in to comment.