Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions test/reactionsystem_core/symbolic_stoichiometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Fetch packages.
using Catalyst, JumpProcesses, OrdinaryDiffEq, StochasticDiffEq, Statistics, Test
using Symbolics: unwrap
import SymbolicIndexingInterface as SII

# Mock integrator type for testing generated VRJ affect functions.
Expand Down Expand Up @@ -207,35 +206,26 @@ let
end
end

# Tests that non-species unknowns (regular variables) in stoichiometry are properly wrapped in Pre().
# This ensures MTKBase generates explicit affects rather than implicit ones.
# Tests jump simulation with a non-species unknown in symbolic stoichiometry.
let
@parameters k
@variables V(t)
@species X(t) Y(t)

# Reaction where V (a non-species variable) appears in the stoichiometry
rs = @reaction_network begin
@parameters k
@variables V(t)
k, X --> V*Y
k, X --> V * Y
end

# The jump System should have explicit affects (no equations after mtkcompile)
jsys = jump_model(rs)
js = ModelingToolkitBase.jumps(jsys)
@test length(js) == 1

# Check that V appears as Pre(V(t)) in the affect equations
affect_str = string(js[1].affect!)
@test occursin("Pre(V(t))", affect_str)

# Verify it creates an explicit affect (empty equations after mtkcompile)
iv = unwrap(t)
aff = ModelingToolkitBase.AffectSystem(js[1].affect!; iv)
affsys = ModelingToolkitBase.system(aff)
eqs = ModelingToolkitBase.equations(ModelingToolkitBase.unhack_system(affsys))
@test isempty(eqs) # Should be explicit, not implicit
jprob = JumpProblem(
rs, [X => 1, Y => 0, V => 2], (0.0, 1.0), [k => 100.0];
rng = StableRNG(12345)
)
sol = solve(jprob, SSAStepper())
@test sol[X][end] == 0
@test sol[Y][end] == 2
@test sol[V][end] == 2
end

# Tests symbolic stoichiometries in simulations.
Expand Down
Loading