Skip to content

Commit 4292bf8

Browse files
authored
Merge pull request #1187 from isaacsas/move-reaction-sys-to-catalyst
mv ReactionSystems to Catalyst and fix dependencies for JumpSystems
2 parents 6d31f4b + 3a17f58 commit 4292bf8

File tree

12 files changed

+46
-1039
lines changed

12 files changed

+46
-1039
lines changed

docs/make.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ makedocs(
4040
"systems/NonlinearSystem.md",
4141
"systems/OptimizationSystem.md",
4242
"systems/ControlSystem.md",
43-
"systems/ReactionSystem.md",
4443
"systems/PDESystem.md",
4544
],
4645
"comparison.md",

docs/src/basics/AbstractSystem.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
The `AbstractSystem` interface is the core of the system level of ModelingToolkit.jl.
66
It establishes a common set of functionality that is used between systems
7-
from ODEs and chemical reactions, allowing users to have a common framework for
7+
representing ODEs, PDEs, SDEs and more, allowing users to have a common framework for
88
model manipulation and compilation.
99

1010
### Subtypes

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ is built on, consult the
7272
- Nonlinear systems
7373
- Optimization problems
7474
- Continuous-Time Markov Chains
75-
- Chemical Reactions
75+
- Chemical Reactions (via [Catalyst.jl](https://github.com/SciML/Catalyst.jl))
7676
- Nonlinear Optimal Control
7777

7878
## Model Import Formats

docs/src/systems/ReactionSystem.md

Lines changed: 0 additions & 69 deletions
This file was deleted.

src/ModelingToolkit.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ include("systems/control/controlsystem.jl")
135135

136136
include("systems/pde/pdesystem.jl")
137137

138-
include("systems/reaction/reactionsystem.jl")
139138
include("systems/dependency_graphs.jl")
140139

141140
include("systems/discrete_system/discrete_system.jl")
@@ -172,7 +171,6 @@ export alias_elimination, flatten, connect, @connector
172171
export ode_order_lowering, liouville_transform
173172
export runge_kutta_discretize
174173
export PDESystem
175-
export Reaction, ReactionSystem, ismassaction, oderatelaw, jumpratelaw
176174
export Differential, expand_derivatives, @derivatives
177175
export Equation, ConstrainedEquation
178176
export Term, Sym

src/systems/dependency_graphs.jl

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,25 @@ Notes:
1313
Example:
1414
```julia
1515
using ModelingToolkit
16-
@parameters β γ κ η t
17-
@variables S(t) I(t) R(t)
16+
@parameters β γ κ η
17+
@variables t S(t) I(t) R(t)
1818
19-
# use a reaction system to easily generate ODE and jump systems
20-
rxs = [Reaction(β, [S,I], [I], [1,1], [2]),
21-
Reaction(γ, [I], [R]),
22-
Reaction(κ+η, [R], [S])]
23-
rs = ReactionSystem(rxs, t, [S,I,R], [β,γ,κ,η])
19+
rate₁ = β*S*I
20+
rate₂ = γ*I+t
21+
affect₁ = [S ~ S - 1, I ~ I + 1]
22+
affect₂ = [I ~ I - 1, R ~ R + 1]
23+
j₁ = ConstantRateJump(rate₁,affect₁)
24+
j₂ = VariableRateJump(rate₂,affect₂)
2425
25-
# ODEs:
26-
odesys = convert(ODESystem, rs)
27-
28-
# dependency of each ODE on state variables
29-
equation_dependencies(odesys)
30-
31-
# dependency of each ODE on parameters
32-
equation_dependencies(odesys, variables=parameters(odesys))
33-
34-
# Jumps
35-
jumpsys = convert(JumpSystem, rs)
26+
# create a JumpSystem using these jumps
27+
@named jumpsys = JumpSystem([j₁,j₂], t, [S,I,R], [β,γ])
3628
3729
# dependency of each jump rate function on state variables
3830
equation_dependencies(jumpsys)
3931
4032
# dependency of each jump rate function on parameters
4133
equation_dependencies(jumpsys, variables=parameters(jumpsys))
34+
4235
```
4336
"""
4437
function equation_dependencies(sys::AbstractSystem; variables=states(sys))

src/systems/jumps/jumpsystem.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,12 @@ end
165165

166166
function numericrstoich(mtrs::Vector{Pair{V,W}}, statetoid) where {V,W}
167167
rs = Vector{Pair{Int,W}}()
168-
for (spec,stoich) in mtrs
168+
for (wspec,stoich) in mtrs
169+
spec = value(wspec)
169170
if !istree(spec) && _iszero(spec)
170171
push!(rs, 0 => stoich)
171172
else
172-
push!(rs, statetoid[value(spec)] => stoich)
173+
push!(rs, statetoid[spec] => stoich)
173174
end
174175
end
175176
sort!(rs)
@@ -178,7 +179,8 @@ end
178179

179180
function numericnstoich(mtrs::Vector{Pair{V,W}}, statetoid) where {V,W}
180181
ns = Vector{Pair{Int,W}}()
181-
for (spec,stoich) in mtrs
182+
for (wspec,stoich) in mtrs
183+
spec = value(wspec)
182184
!istree(spec) && _iszero(spec) && error("Net stoichiometry can not have a species labelled 0.")
183185
push!(ns, statetoid[spec] => stoich)
184186
end
@@ -301,7 +303,8 @@ end
301303

302304
### Functions to determine which states a jump depends on
303305
function get_variables!(dep, jump::Union{ConstantRateJump,VariableRateJump}, variables)
304-
(jump.rate isa Symbolic) && get_variables!(dep, jump.rate, variables)
306+
jr = value(jump.rate)
307+
(jr isa Symbolic) && get_variables!(dep, jr, variables)
305308
dep
306309
end
307310

0 commit comments

Comments
 (0)