Skip to content

Commit dc72438

Browse files
committed
add jacobian tests with simulations
1 parent 0079e96 commit dc72438

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

test/simulation_and_solving/jacobian_construction.jl

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### Prepares Tests ###
22

33
# Fetch packages.
4-
using Catalyst, DiffEqBase, Test
4+
using Catalyst, DiffEqBase, OrdinaryDiffEqRosenbrock, Test
55

66
# Sets stable rng number.
77
using StableRNGs
@@ -141,3 +141,33 @@ let
141141
@test jac_sparse * mat jac * mat
142142
end
143143
end
144+
145+
# Tests that simulations with different Jacobian and sparsity options are identical.
146+
let
147+
# Creates model (vaguely messy model without conserved quantities).
148+
rn = @reaction_network begin
149+
(v0 + mm(X,v,K),d), 0 <--> X + 2Y
150+
(k1,k2), X + Y <--> XY
151+
(k1,k2), X + Y2 <--> XY2
152+
(k3,k4), XY + XY2 <--> X2Y3
153+
1.0, (XY,XY2,X2Y3) --> 0
154+
mm(X2Y3,v,K), 0 --> Z
155+
(k3*X,k4*Y), 3Z <--> Z3
156+
d, Z --> 0
157+
end
158+
159+
# Generates initial conditions and parameter values. Creates problems with/o (sparse/dense) jacobian.
160+
u0 = rnd_u0(rn, rng)
161+
ps = rnd_ps(rn, rng)
162+
oprob = ODEProblem(rn, u0, 1.0, ps; jac = false, sparse = false)
163+
oprob_j = ODEProblem(rn, u0, 1.0, ps; jac = true, sparse = false)
164+
oprob_s = ODEProblem(rn, u0, 1.0, ps; jac = false, sparse = true)
165+
oprob_js = ODEProblem(rn, u0, 1.0, ps; jac = true, sparse = true)
166+
167+
# Simulates system with implicit solver. Checks that all solutions are identical.
168+
sol = solve(oprob, Rosenbrock23(), saveat = 0.1, abstol = 1e-8, reltol = 1e-8)
169+
sol_j = solve(oprob_j, Rosenbrock23(), saveat = 0.1, abstol = 1e-8, reltol = 1e-8)
170+
sol_s = solve(oprob_s, Rosenbrock23(), saveat = 0.1, abstol = 1e-8, reltol = 1e-8)
171+
sol_js = solve(oprob_sj, Rosenbrock23(), saveat = 0.1, abstol = 1e-8, reltol = 1e-8)
172+
@test sol sol_j sol_s sol_js
173+
end

0 commit comments

Comments
 (0)