30
30
# Generates random parameter values (which can generate all steady states cases).
31
31
p = [:v => 1.0 + 3 * rand (rng), :K => 0.5 + 2 * rand (rng), :n => rand (rng,[1 ,2 ,3 ,4 ]), :d => 0.5 + rand (rng)]
32
32
33
+ # Computes stability using various jacobian options.
33
34
sss = hc_steady_states (rn, p)
34
35
stabs_1 = steady_state_stability (sss, rn, p)
35
36
stabs_2 = steady_state_stability (sss, rn, p; sparse= true )
36
37
stabs_3 = steady_state_stability (sss, rn, p; ss_jac= ss_jac)
37
38
stabs_4 = steady_state_stability (sss, rn, p; ss_jac= ss_jac_sparse)
38
39
40
+ # Confirms stability using simulations.
39
41
for (idx,ss) in enumerate (sss)
40
42
oprob = ODEProblem (rn, [1.001 , 0.999 ] .* ss, (0.0 ,1000.0 ), p)
41
43
sol_end = solve (oprob, Rosenbrock23 ())[end ]
42
44
stabs_5 = ss ≈ sol_end
43
45
@test stabs_1[idx] == stabs_2[idx] == stabs_3[idx] == stabs_4[idx] == stabs_5
46
+
47
+ # Checks stability when steady state is given on a pair form ([:X => x_val, :Y => y_val]).
48
+ stabs_6 = steady_state_stability (Pair .(states (rn),ss), rn, p)
49
+ @test stabs_5 == stabs_6
44
50
end
45
51
end
46
52
end
49
55
# Tests for system with conservation laws.
50
56
# Tests for various input forms of u0 and ps.
51
57
let
58
+ # Creates model.
52
59
rn = complete (@reaction_network begin
53
60
k1+ Z, Y --> 2 X
54
61
k2, 2 X --> X + Y
55
62
k3, X + Y --> Y
56
63
k4, X --> 0
57
64
(kD1+ X, kD2), 2 Z <--> Z2
58
65
end )
66
+
67
+ # Creates various forms of input.
59
68
@unpack k1, k2, k3, k4, kD1, kD2, X, Y, Z, Z2 = rn
60
69
u0_1 = [X => 1.0 , Y => 1.0 , Z => 1.0 , Z2 => 1.0 ]
61
70
u0_2 = [:X => 1.0 , :Y => 1.0 , :Z => 1.0 , :Z2 => 1.0 ]
66
75
ps_3 = [rn. k1 => 8.0 , rn. k2 => 2.0 , rn. k3 => 1.0 , rn. k4 => 1.5 , rn. kD1 => 0.5 , rn. kD2 => 4.0 ]
67
76
ps_4 = [8.0 , 2.0 , 1.0 , 1.5 , 0.5 , 4.0 ]
68
77
78
+ # Computes stability using various input forms, and checks that the output is correct.
69
79
sss = hc_steady_states (rn, ps_1; u0= u0_1)
70
80
for u0 in [u0_1, u0_2, u0_3, u0_4], ps in [ps_1, ps_2, ps_3, ps_4]
71
81
stab_1 = steady_state_stability (sss, rn, ps)
77
87
@test length (stab_2) == 3
78
88
@test count (stab_2) == 2
79
89
end
90
+
91
+ # Confirms error when computing Jacobian with wrong length of u0.
92
+ @test_throws Exception steady_state_jac (rn; u0= [1.0 , 1.0 ])
80
93
end
0 commit comments