Browse Source

[WIP] Documentation dependency fix (#36)

* Test new catlab branch to fix compose version resolution

* Fix syntax

* Fix trailing paren

* Fixed export of object that doesn't exist and updated examples

* Added second simple example

* First attempt at codecov

* update catlab dev branch

* Added code coverage badge

* Use newest version of catlab
pull/37/head
Micah Halter 4 months ago
committed by GitHub
parent
commit
516cc0df96
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 74 additions and 87 deletions
  1. +19
    -0
      .github/workflows/codecov.yml
  2. +1
    -1
      .github/workflows/docs.yml
  3. +1
    -1
      Project.toml
  4. +1
    -0
      README.md
  5. +1
    -0
      docs/make.jl
  6. +0
    -84
      docs/src/usage.md
  7. +9
    -0
      examples/epidemiology.jl
  8. +41
    -0
      examples/lotka-volterra.jl
  9. +1
    -1
      src/Petri.jl

+ 19
- 0
.github/workflows/codecov.yml View File

@ -0,0 +1,19 @@
name: Code Coverage
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@latest
with:
version: '1.5'
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
file: lcov.info
fail_ci_if_error: true

+ 1
- 1
.github/workflows/docs.yml View File

@ -16,7 +16,7 @@ jobs:
sudo apt-get update
sudo apt-get install graphviz ttf-dejavu
- name: "Install Julia dependencies"
run: julia --project=docs -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate(); Pkg.update();'
run: julia --project=docs -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate();'
- name: "Build and deploy docs"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


+ 1
- 1
Project.toml View File

@ -15,7 +15,7 @@ StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0"
[compat]
AutoHashEquals = "^0.2.0"
Catlab = "^0.7.0"
Catlab = "^0.7.4"
DiffEqBase = "^6"
DiffEqJump = "^6"
OrdinaryDiffEq = "^5"


+ 1
- 0
README.md View File

@ -2,6 +2,7 @@
[![Documentation](https://github.com/mehalter/Petri.jl/workflows/Documentation/badge.svg)](https://mehalter.github.io/Petri.jl/stable/)
![Tests](https://github.com/mehalter/Petri.jl/workflows/Tests/badge.svg)
[![codecov](https://codecov.io/gh/mehalter/Petri.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/mehalter/Petri.jl)
[![DOI](https://zenodo.org/badge/203420191.svg)](https://zenodo.org/badge/latestdoi/203420191)


+ 1
- 0
docs/make.jl View File

@ -40,6 +40,7 @@ makedocs(
"Petri.jl" => "index.md",
"Examples" => Any[
"examples/epidemiology.md",
"examples/lotka-volterra.md",
],
"Library Reference" => "api.md",
]


+ 0
- 84
docs/src/usage.md View File

@ -1,84 +0,0 @@
# Basic Usage
We need to include our dependencies. `Petri` is the only requirement to build the models. `OrdinaryDiffEq` is required for simulating the network with and ordinary differential equation. `Plots` can be used to plot the solutions generated by `OrdinaryDiffEq`. `LabelledArrays` can be used to make things more readable, but is not necessary. Lastly, `Catlab` is required for visualizing the models as graphviz diagrams.
```julia
using Petri
using LabelledArrays
using OrdinaryDiffEq
using Plots
using Catlab.Graphics.Graphiz
import Catlab.Graphics.Graphviz: Graph
```
The SIR model represents the epidemiological dynamics of an infectious disease that causes immunity in its victims. There are three *states:* `Suceptible ,Infected, Recovered`. These states interact through two *transitions*. Infection has the form `S+I -> 2I` where a susceptible person meets an infected person and results in two infected people. The second transition is recovery `I -> R` where an infected person recovers spontaneously.
![The SIR model system shown as a Petri net with ODE formulas](img/sir_petri+ode.png)
```julia
# define the structure of the model
sir = Petri.Model([:S,:I,:R],LVector(
inf=(LVector(S=1,I=1), LVector(I=2)),
rec=(LVector(I=1), LVector(R=1))))
# define the initial conditions
u0 = LVector(S=100.0, I=1, R=0)
# define the parameters of the model, each rate corresponds to a transition
p = LVector(inf=0.05, rec=0.35)
# evaluate the expression to create a runnable function
f = vectorfields(sir)
# this is regular OrdinaryDiffEq problem setup
prob = ODEProblem(f,u0,(0.0,365.0),p)
sol = OrdinaryDiffEq.solve(prob,Tsit5())
# generate a graphviz visualization of the model
graph = Graph(sir)
# visualize the solution
plt = plot(sol)
```
![A solution to the SIR model system](img/sir_sol.png)
Petri Nets are a simple language for describing reaction networks, you can make increasingly complex diseases. For example the `SEIR` model has an `Exposed` phase where people have the disease, but are not infectious yet.
![The SEIR model system shown as a Petri net](img/seir.png)
```julia
seir = Petri.Model([:S,:E,:I,:R],LVector(
exp=(LVector(S=1,I=1), LVector(I=1,E=1)),
inf=(LVector(E=1), LVector(I=1)),
rec=(LVector(I=1), LVector(R=1))))
u0 = LVector(S=100.0, E=1, I=0, R=0)
p = (exp=0.35, inf=0.05, rec=0.05)
f = vectorfields(seir)
prob = ODEProblem(f,u0,(0.0,365.0),p)
sol = OrdinaryDiffEq.solve(prob,Tsit5())
plt = plot(sol)
```
![A solution to the SEIR model system](img/seir_sol.png)
The previous models have transitory behavior, the infection spreads and then terminates as you end up with no infected people in the population. The following `SEIRS` model has a non-trivial steady state, because recovered people lose their immunity and become susceptible again.
![The SEIRS model system shown as a Petri net](img/seirs.png)
```julia
seirs = Petri.Model([:S,:E,:I,:R],LVector(
exp=(LVector(S=1,I=1), LVector(I=1,E=1)),
inf=(LVector(E=1), LVector(I=1)),
rec=(LVector(I=1), LVector(R=1)),
deg=(LVector(R=1), LVector(S=1))))
u0 = LVector(S=100.0, E=1, I=0, R=0)
p = LVector(exp=0.35, inf=0.05, rec=0.07, deg=0.3)
f = vectorfields(seirs)
prob = ODEProblem(f,u0,(0.0,365.0),p)
sol = OrdinaryDiffEq.solve(prob,Tsit5())
plt = plot(sol)
```
![A solution to the SEIRS model system](img/seirs_sol.png)

+ 9
- 0
examples/epidemiology.jl View File

@ -37,6 +37,15 @@ tspan = (0.0,40.0)
# as is dependent on the current state of the system
β = LVector(inf=((u,t)->((3/sum(u))/(t+1))), rec=0.25);
# each transition rates can one of three options:
#
# - constant: `β = [.25]`
# - where the rate is specified by a value of type `Number`
# - time dependent: `β = [t->((3/1000)/(t+1))]`
# - where `t` is the current time step
# - state and time dependent: `β = [(u,t)->((3/sum(u))/(t+1))]`
# - where `u` is the current state of `u0` and `t` is the current time step
# Petri.jl provides interfaces to StochasticDiffEq.jl, DiffEqJump.jl, and
# OrdinaryDiffEq.jl Here, we call the `JumpProblem` function that returns an
# DiffEqJump problem object that can be passed to the DiffEqJump solver which


+ 41
- 0
examples/lotka-volterra.jl View File

@ -0,0 +1,41 @@
# # [Lotka-Volterra Model](@id lotka_volterra_example)
#
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/examples/lotka-volterra.ipynb)
using Petri
using LabelledArrays
using Plots
using OrdinaryDiffEq
# **Step 1:** Define the states and transitions of the Petri Net
#
# Here we have 2 states, wolves and rabbits, and transitions to
# model predation between the two species in the system
S = [:rabbits, :wolves]
Δ = LVector(
birth=(LVector(rabbits=1), LVector(rabbits=2)),
predation=(LVector(wolves=1, rabbits=1), LVector(wolves=2)),
death=(LVector(wolves=1), LVector()),
)
lotka = Petri.Model(S, Δ)
Graph(lotka)
# **Step 2:** Define the parameters and transition rates
#
# Once a model is defined, we can define out initial parameters `u0`, a time
# span `tspan`, and the transition rates of the interactions `β`
u0 = LVector(wolves=10.0, rabbits=100.0)
tspan = (0.0,100.0)
β = LVector(birth=.3, predation=.015, death=.7);
# **Step 3:** Generate a solver and solve
#
# Finally we can generate a solver and solve the simulation
prob = ODEProblem(lotka, u0, tspan, β)
sol = OrdinaryDiffEq.solve(prob,Tsit5(),reltol=1e-8,abstol=1e-8)
plot(sol)

+ 1
- 1
src/Petri.jl View File

@ -6,7 +6,7 @@ Provides a modeling framework for representing and solving stochastic petri nets
"""
module Petri
export Model, Problem, NullPetri, EmptyPetri, vectorfield, Graph
export Model, NullPetri, EmptyPetri, vectorfield, Graph
include("types.jl")
include("solvers.jl")


Loading…
Cancel
Save