Skip to content

Commit 5dae207

Browse files
authored
Merge pull request #1121 from isaacsas/pdmps
Support Jump-ODE models
2 parents 733f50b + 4deb44b commit 5dae207

File tree

11 files changed

+755
-77
lines changed

11 files changed

+755
-77
lines changed

.github/workflows/Test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
- "pre"
3131
group:
3232
- Core
33+
- Hybrid
3334
- IO
3435
- Spatial
3536
- Extensions

Project.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
99
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1010
DynamicPolynomials = "7c1d4256-1411-5781-91ec-d7bc3513ac07"
1111
DynamicQuantities = "06fc5a27-2a28-4c7c-a15d-362465fb6821"
12+
EnumX = "4e289a0a-7415-4d19-859d-a7e5c4648b56"
1213
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
1314
JumpProcesses = "ccbc3e58-028d-4f4c-8cd5-9ae44345cda5"
1415
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
@@ -51,8 +52,8 @@ Combinatorics = "1.0.2"
5152
DataStructures = "0.18"
5253
DiffEqBase = "6.165.0"
5354
DocStringExtensions = "0.8, 0.9"
54-
DynamicPolynomials = "0.5, 0.6"
55-
DynamicQuantities = "0.13.2, 1"
55+
DynamicPolynomials = "0.6"
56+
DynamicQuantities = "1"
5657
GraphMakie = "0.5"
5758
Graphs = "1.4"
5859
HomotopyContinuation = "2.9"
@@ -64,7 +65,7 @@ Makie = "0.22.1"
6465
ModelingToolkit = "9.69"
6566
NetworkLayout = "0.4.7"
6667
Parameters = "0.12"
67-
Reexport = "0.2, 1.0"
68+
Reexport = "1.0"
6869
Requires = "1.0"
6970
RuntimeGeneratedFunctions = "0.5.12"
7071
SciMLBase = "2.77"

src/Catalyst.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ $(DocStringExtensions.README)
44
module Catalyst
55

66
using DocStringExtensions
7-
using SparseArrays, DiffEqBase, Reexport, Setfield
7+
using SparseArrays, DiffEqBase, Reexport, Setfield, EnumX
88
using LaTeXStrings, Latexify, Requires
99
using LinearAlgebra, Combinatorics
1010
using JumpProcesses: JumpProcesses, JumpProblem,
@@ -14,7 +14,7 @@ using JumpProcesses: JumpProcesses, JumpProblem,
1414
# ModelingToolkit imports and convenience functions we use
1515
using ModelingToolkit
1616
const MT = ModelingToolkit
17-
using DynamicQuantities#, Unitful # Having Unitful here as well currently gives an error.
17+
using DynamicQuantities #, Unitful # Having Unitful here as well currently gives an error.
1818

1919
@reexport using ModelingToolkit
2020
using Symbolics
@@ -78,7 +78,10 @@ const forbidden_symbols_error = union(Set([:im, :nothing, CONSERVED_CONSTANT_SYM
7878
# The `Reaction` structure and its functions.
7979
include("reaction.jl")
8080
export isspecies
81-
export Reaction
81+
export Reaction, PhysicalScale
82+
83+
# Union type for `Reaction`s and `Equation`s.
84+
const CatalystEqType = Union{Reaction, Equation}
8285

8386
# The `ReactionSystem` structure and its functions.
8487
include("reactionsystem.jl")

src/reaction.jl

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,6 @@ function Reaction(rate, subs, prods; kwargs...)
244244
Reaction(rate, subs, prods, sstoich, pstoich; kwargs...)
245245
end
246246

247-
# Union type for `Reaction`s and `Equation`s.
248-
const CatalystEqType = Union{Reaction, Equation}
249-
250247
### Base Function Dispatches ###
251248

252249
# Used by `Base.show`.
@@ -679,6 +676,48 @@ function getmisc(reaction::Reaction)
679676
end
680677
end
681678

679+
############## Metadata for the mathematical type of a reaction ##############
680+
681+
"""
682+
@enumx PhysicalScale
683+
684+
EnumX instance representing the physical scale of a reaction.
685+
686+
Notes: The following values are possible:
687+
- `Auto`: (DEFAULT) Lets Catalyst decide at the time of system conversion and/or
688+
problem generation at what physical scale to represent the reaction.
689+
- `ODE`: The reaction is to be treated via an ordinary differential equation term.
690+
- `SDE`: The reaction is to be treated via a stochastic differential equation (CLE) term.
691+
- `Jump`: The reaction is to be treated via a jump process (stochastic chemical kinetics)
692+
term, letting Catalyst decide the specific jump type.
693+
- `VariableRateJump`: The reaction is to be treated as a jump process (stochastic chemical
694+
kinetics) term, specifically assigning it to a VariableRateJump.
695+
"""
696+
@enumx PhysicalScale begin
697+
Auto # the default that lets Catalyst decide
698+
ODE
699+
SDE
700+
Jump # lets Catalyst decide the jump type
701+
VariableRateJump # forces a VariableRateJump
702+
end
703+
704+
const JUMP_SCALES = (PhysicalScale.Jump, PhysicalScale.VariableRateJump)
705+
const NON_CONSTANT_JUMP_SCALES = (PhysicalScale.ODE, PhysicalScale.SDE, PhysicalScale.VariableRateJump)
706+
707+
"""
708+
has_physical_scale(rx::Reaction)
709+
710+
Returns `true` if the input reaction has the `physical_scale` metadata field assigned,
711+
else `false`.
712+
"""
713+
function has_physical_scale(rx::Reaction)
714+
return hasmetadata(rx, :physical_scale)
715+
end
716+
717+
function get_physical_scale(rx::Reaction)
718+
return has_physical_scale(rx) ? getmetadata(rx, :physical_scale) : PhysicalScale.Auto
719+
end
720+
682721
### Units Handling ###
683722

684723
"""

src/reactionsystem.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,16 @@ function numreactions(network)
871871
nr
872872
end
873873

874+
"""
875+
has_nonreactions(network)
876+
877+
Check if the given `network` has any non-reaction equations such as ODEs or algebraic
878+
equations.
879+
"""
880+
function has_nonreactions(network)
881+
numreactions(network) != length(equations(network))
882+
end
883+
874884
"""
875885
nonreactions(network)
876886

0 commit comments

Comments
 (0)