Skip to content

Commit 24ac103

Browse files
authored
Merge pull request #12 from isaacsas/update_to_catalyst13
Update to Catalyst 13 and latest Symbolics
2 parents 3beaccb + 8b992dc commit 24ac103

13 files changed

Lines changed: 90 additions & 84 deletions

File tree

.github/workflows/ci.yml

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,40 @@
1-
name: CI
2-
on:
3-
- push
4-
- pull_request
5-
jobs:
6-
test:
7-
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
8-
runs-on: ${{ matrix.os }}
9-
strategy:
10-
fail-fast: false
11-
matrix:
12-
version:
13-
- '1.5'
14-
- '1.6'
15-
- '1.7'
16-
os:
17-
- ubuntu-latest
18-
arch:
19-
- x64
20-
steps:
21-
- uses: actions/checkout@v2
22-
- uses: julia-actions/setup-julia@v1
23-
with:
24-
version: ${{ matrix.version }}
25-
arch: ${{ matrix.arch }}
26-
- uses: actions/cache@v1
27-
env:
28-
cache-name: cache-artifacts
29-
with:
30-
path: ~/.julia/artifacts
31-
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
32-
restore-keys: |
33-
${{ runner.os }}-test-${{ env.cache-name }}-
34-
${{ runner.os }}-test-
35-
${{ runner.os }}-
36-
- uses: julia-actions/julia-buildpkg@v1
37-
- uses: julia-actions/julia-runtest@v1
38-
- uses: julia-actions/julia-processcoverage@v1
39-
- uses: codecov/codecov-action@v1
40-
with:
41-
file: lcov.info
1+
name: CI
2+
on:
3+
- push
4+
- pull_request
5+
jobs:
6+
test:
7+
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
version:
13+
- '1.6'
14+
- '1.9'
15+
os:
16+
- ubuntu-latest
17+
arch:
18+
- x64
19+
steps:
20+
- uses: actions/checkout@v2
21+
- uses: julia-actions/setup-julia@v1
22+
with:
23+
version: ${{ matrix.version }}
24+
arch: ${{ matrix.arch }}
25+
- uses: actions/cache@v1
26+
env:
27+
cache-name: cache-artifacts
28+
with:
29+
path: ~/.julia/artifacts
30+
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
31+
restore-keys: |
32+
${{ runner.os }}-test-${{ env.cache-name }}-
33+
${{ runner.os }}-test-
34+
${{ runner.os }}-
35+
- uses: julia-actions/julia-buildpkg@v1
36+
- uses: julia-actions/julia-runtest@v1
37+
- uses: julia-actions/julia-processcoverage@v1
38+
- uses: codecov/codecov-action@v1
39+
with:
40+
file: lcov.info

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "FiniteStateProjection"
22
uuid = "069e79ea-d681-44e8-b935-95bdaf9e8f28"
33
authors = ["kaandocal"]
4-
version = "0.2.1"
4+
version = "0.3.0"
55

66
[deps]
77
Catalyst = "479239e8-5488-4da2-87a7-35f2df7eef83"
@@ -12,12 +12,12 @@ RuntimeGeneratedFunctions = "7e49a35a-f44a-4d26-94aa-eba1b4ca6b47"
1212
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1313

1414
[compat]
15-
Catalyst = "9, 10, 11, 12"
15+
Catalyst = "13"
1616
DiffEqBase = "6"
1717
MacroTools = "^0.5.5"
1818
Reexport = "1"
1919
RuntimeGeneratedFunctions = "0.5"
20-
julia = "1.5"
20+
julia = "1.6"
2121

2222
[extras]
2323
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Finite State Projection [[1]](#1) algorithms for chemical reaction networks bas
99
- FSP equations are generated as `ODEFunction`/`ODEProblem`s and can be solved with [DifferentialEquations.jl](https://github.com/SciML/DifferentialEquations.jl), with on-the-fly generation of targeted functions for improved performance
1010
- The Chemical Master Equation can be represented as a `SparseMatrixCSC`
1111

12-
More information is available in the [documentation](https://kaandocal.github.io/FiniteStateProjection.jl/dev/). Please feel free to open issues and submit pull requests!
12+
More information is available in the [documentation](https://kaandocal.github.io/FiniteStateProjection.jl/dev/). Please feel free to open issues and submit pull requests!
1313

1414
## Examples
1515
### Birth-Death System
@@ -20,7 +20,7 @@ using OrdinaryDiffEq
2020
rn = @reaction_network begin
2121
σ, 0 --> A
2222
d, A --> 0
23-
end σ d
23+
end
2424

2525
sys = FSPSystem(rn)
2626

@@ -30,7 +30,7 @@ ps = [ 10.0, 1.0 ]
3030
# Initial distribution (over 1 species)
3131
# Here we start with 0 copies of A
3232
u0 = zeros(50)
33-
u0[1] = 1.0
33+
u0[1] = 1.0
3434

3535
prob = convert(ODEProblem, sys, u0, (0, 10.0), ps)
3636
sol = solve(prob, Vern7())
@@ -47,7 +47,7 @@ rn = @reaction_network begin
4747
σ_off, G_on --> 0
4848
ρ, G_on --> G_on + M
4949
d, M --> 0
50-
end σ_on σ_off ρ d
50+
end
5151

5252
sys = FSPSystem(rn)
5353

demo/birth_death.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using PyPlot
77
rs = @reaction_network begin
88
r1, 0 --> A
99
r2, A --> 0
10-
end r1 r2
10+
end
1111

1212
##
1313

demo/telegraph.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ rs = @reaction_network begin
99
r2, G_on --> 0
1010
r3, G_on --> G_on + M
1111
r4, M --> 0
12-
end r1 r2 r3 r4
12+
end
1313

1414
##
1515

@@ -20,9 +20,9 @@ ps = [ 0.25, 0.15, 15.0, 1.0 ]
2020

2121
# Initial values
2222
# Since G_on + G_off = const. we do not have to model the two
23-
# separately. Use reduced_species(sys) to get the list of
23+
# separately. Use reduced_species(sys) to get the list of
2424
# species we actually have to model:
25-
#
25+
#
2626
# julia> reduced_species(sys)
2727
# 2-element Vector{Int64}:
2828
# 1

docs/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[deps]
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
4+
[compat]
5+
Documenter = "0.27"

docs/src/examples.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ using OrdinaryDiffEq
1111
rn = @reaction_network begin
1212
σ, 0 --> A
1313
d, A --> 0
14-
end σ d
14+
end
1515

1616
sys = FSPSystem(rn)
1717

@@ -21,7 +21,7 @@ ps = [ 10.0, 1.0 ]
2121
# Initial distribution (over 1 species)
2222
# Here we start with 0 copies of A
2323
u0 = zeros(50)
24-
u0[1] = 1.0
24+
u0[1] = 1.0
2525

2626
prob = ODEProblem(sys, u0, (0, 10.0), ps)
2727
sol = solve(prob, Vern7())
@@ -47,7 +47,7 @@ rn = @reaction_network begin
4747
σ_off, G_on --> 0
4848
ρ, G_on --> G_on + M
4949
d, M --> 0
50-
end σ_on σ_off ρ d
50+
end
5151

5252
sys = FSPSystem(rn)
5353

docs/src/troubleshoot.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ This point might seem obvious, but errors in the rate functions, or an incorrect
4242
rn = @reaction_network begin
4343
σ * (N - I), I --> 2I
4444
ρ, I --> 0
45-
end σ ρ N
45+
end
4646

4747
sys_fsp = FSPSystem(rn)
4848
```

src/fspsystem.jl

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
"""
2-
Thin wrapper around `Catalyst.ReactionSystem` for use with this package.
1+
"""
2+
Thin wrapper around `Catalyst.ReactionSystem` for use with this package.
33
44
Constructor: `FSPSystem(rs::ReactionSystem[, ih=DefaultIndexHandler(); combinatoric_ratelaw::Bool=true])`
55
"""
@@ -10,22 +10,27 @@ struct FSPSystem{IHT <: AbstractIndexHandler, RT}
1010
end
1111

1212
function FSPSystem(rs::ReactionSystem, ih=DefaultIndexHandler(); combinatoric_ratelaw::Bool=true)
13+
isempty(Catalyst.get_systems(rs)) ||
14+
error("Supported Catalyst models can not contain subsystems. Please use `rs = Catalyst.flatten(rs::ReactionSystem)` to generate a single system with no subsystems from your Catalyst model.")
15+
any(eq -> !(eq isa Reaction), equations(rs)) &&
16+
error("Catalyst models that include constraint ODEs or algebraic equations are not supported.")
17+
1318
rfs = create_ratefuncs(rs, ih; combinatoric_ratelaw=combinatoric_ratelaw)
1419
FSPSystem(rs, ih, rfs)
1520
end
1621

17-
"""
22+
"""
1823
build_ratefuncs(rs, ih; state_sym::Symbol, combinatoric_ratelaw::Bool)::Vector
1924
20-
Return the rate functions converted to Julia expressions in the state variable
25+
Return the rate functions converted to Julia expressions in the state variable
2126
`state_sym`. Abundances of the species are computed using `getsubstitutions`.
2227
2328
See also: [`getsubstitutions`](@ref), [`build_rhs`](@ref)
2429
"""
2530
function build_ratefuncs(rs::ReactionSystem, ih::AbstractIndexHandler; state_sym::Symbol, combinatoric_ratelaw::Bool=true)
2631
substitutions = getsubstitutions(ih, rs, state_sym=state_sym)
27-
28-
return map(Catalyst.get_eqs(rs)) do reac
32+
33+
return map(Catalyst.reactions(rs)) do reac
2934
jrl = jumpratelaw(reac; combinatoric_ratelaw)
3035
jrl_s = substitute(jrl, substitutions)
3136
toexpr(jrl_s)
@@ -34,12 +39,12 @@ end
3439

3540
function create_ratefuncs(rs::ReactionSystem, ih::AbstractIndexHandler; combinatoric_ratelaw::Bool=true)
3641
paramsyms = Symbol.(Catalyst.parameters(rs))
37-
38-
return tuple(map(ex -> compile_ratefunc(ex, paramsyms),
42+
43+
return tuple(map(ex -> compile_ratefunc(ex, paramsyms),
3944
build_ratefuncs(rs, ih; state_sym=:idx_in, combinatoric_ratelaw))...)
40-
end
45+
end
4146

42-
function compile_ratefunc(ex_rf, params)
47+
function compile_ratefunc(ex_rf, params)
4348
# Make this nicer in the future
4449
ex = :((idx_in, t, $(params...)) -> $(ex_rf)) |> MacroTools.flatten
4550
@RuntimeGeneratedFunction(ex)

src/indexhandlers.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,7 @@ end
112112
Defines the abundance of species ``S_i`` to be `state_sym[i] - offset`.
113113
"""
114114
function getsubstitutions(ih::DefaultIndexHandler, rs::ReactionSystem; state_sym::Symbol)
115-
Dict(symbol => Term{Number}(Base.getindex, (state_sym, i)) - ih.offset for (i, symbol) in enumerate(species(rs)))
115+
nspecs = numspecies(rs)
116+
state_sym_vec = ModelingToolkit.value.(ModelingToolkit.scalarize((@variables ($state_sym)[1:nspecs])[1]))
117+
Dict(symbol => state_sym_vec[i] - ih.offset for (i, symbol) in enumerate(species(rs)))
116118
end

0 commit comments

Comments
 (0)