Skip to content

Commit cf46e42

Browse files
committed
remove option for sparsity in Jacobian (requires a special package)
1 parent 9cc5f9c commit cf46e42

File tree

3 files changed

+17
-24
lines changed

3 files changed

+17
-24
lines changed

docs/src/steady_state_functionality/steady_state_stability_computation.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,5 @@ stability_2 = steady_state_stability(steady_states_2, sa_loop, ps_2; ss_jac=ss_j
5353
nothing # hide
5454
```
5555

56-
It is possible to designate that a [sparse Jacobian](@ref ref) should be used using the `sparse = true` option (either to `steady_state_jac` or directly to `steady_state_stability`):
57-
```@example stability_1
58-
ss_jac = steady_state_jac(sa_loop; sparse = true)
59-
nothing # hide
60-
```
61-
6256
!!! warn
6357
For systems with [conservation laws](@ref homotopy_continuation_conservation_laws), `steady_state_jac` must be supplied a `u0` vector (indicating species concentrations for conservation law computation). This is required to eliminate the conserved quantities, preventing a singular Jacobian. These are supplied using the `u0` optional argument.

src/steady_state_stability.jl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
"""
44
stability(u::Vector{T}, rs::ReactionSystem, p; tol = 10*sqrt(eps())
5-
sparse = false, ss_jac = steady_state_jac(u, rs, p; sparse=sparse))
5+
ss_jac = steady_state_jac(u, rs, p))
66
77
Compute the stability of a steady state (Returned as a `Bool`, with `true` indicating stability).
88
@@ -16,8 +16,7 @@ stable if the corresponding Jacobian's maximum eigenvalue real part is < 0. Howe
1616
eigenvalue is in the range `-tol< eig < tol`, and error is throw, as we do not deem that stability
1717
can be ensured with enough certainty. The choice `tol = 10*sqrt(eps())` has *not* been subject
1818
to much analysis.
19-
- `sparse = false`: If we wish to create a sparse Jacobian for the stability computation.
20-
- `ss_jac = steady_state_jac(u, rs; sparse = sparse)`: It is possible to pre-compute the
19+
- `ss_jac = steady_state_jac(u, rs)`: It is possible to pre-compute the
2120
Jacobian used for stability computation using `steady_state_jac`. If stability is computed
2221
for many states, precomputing the Jacobian may speed up evaluation.
2322
@@ -47,7 +46,7 @@ however, have not been subject to further analysis (and can be changed through t
4746
```
4847
"""
4948
function steady_state_stability(u::Vector, rs::ReactionSystem, ps; tol = 10*sqrt(eps(ss_val_type(u))),
50-
sparse = false, ss_jac = steady_state_jac(rs; u0 = u, sparse = sparse))
49+
ss_jac = steady_state_jac(rs; u0 = u))
5150
# Warning checks.
5251
if !is_autonomous(rs)
5352
error("Attempting to compute stability for a non-autonomous system (e.g. where some rate depend on $(rs.iv)). This is not possible.")
@@ -62,6 +61,11 @@ function steady_state_stability(u::Vector, rs::ReactionSystem, ps; tol = 10*sqrt
6261

6362
# Computes stability (by checking that the real part of all eigenvalues are negative).
6463
# Here, `ss_jac` is a `ODEProblem` with dummy values for `u0` and `p`.
64+
65+
if isdefined(Main, :Infiltrator)
66+
Main.infiltrate(@__MODULE__, Base.@locals, @__FILE__, @__LINE__)
67+
end
68+
6569
J = zeros(length(u), length(u))
6670
ss_jac = remake(ss_jac; u0 = u, p = ps)
6771
ss_jac.f.jac(J, ss_jac.u0, ss_jac.p, Inf)
@@ -79,15 +83,14 @@ ss_val_type(u::Vector{Pair{S,T}}) where {S,T} = T
7983
ss_val_type(u::Dict{S,T}) where {S,T} = T
8084

8185
"""
82-
steady_state_jac(rs::ReactionSystem; u0 = [], sparse = false)
86+
steady_state_jac(rs::ReactionSystem; u0 = [])
8387
8488
Creates the Jacobian function which can be used as input to `steady_state_stability`. Useful when
8589
a large number of stability computation has to be carried out in a performant manner.
8690
8791
Arguments:
8892
- `rs`: The reaction system model for which we want to compute stability.
8993
- `u0 = []`: For systems with conservation laws, a `u` is required to compute the conserved quantities.
90-
- `sparse = false`: If we wish to create a sparse Jacobian for the stability computation.
9194
9295
Example:
9396
```julia
@@ -110,7 +113,7 @@ Notes:
110113
```
111114
"""
112115
function steady_state_jac(rs::ReactionSystem; u0 = [sp => 0.0 for sp in unknowns(rs)],
113-
sparse = false, combinatoric_ratelaws = get_combinatoric_ratelaws(rs))
116+
combinatoric_ratelaws = get_combinatoric_ratelaws(rs))
114117
# If u0 is a vector of values, must be converted to something MTK understands.
115118

116119
# Converts u0 to values MTK understands, and checks that potential conservation laws are accounted for.
@@ -119,7 +122,7 @@ function steady_state_jac(rs::ReactionSystem; u0 = [sp => 0.0 for sp in unknowns
119122

120123
# Creates an `ODEProblem` with a Jacobian. Dummy values for `u0` and `ps` must be provided.
121124
ps = [p => 0.0 for p in parameters(rs)]
122-
return ODEProblem(rs, u0, 0, ps; jac = true, remove_conserved = true, sparse = sparse,
125+
return ODEProblem(rs, u0, 0, ps; jac = true, remove_conserved = true,
123126
combinatoric_ratelaws = combinatoric_ratelaws)
124127
end
125128

test/miscellaneous_tests/stability_computation.jl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ rng = StableRNG(12345)
1212

1313
# Tests that stability is correctly assessed (using simulation) in multi stable system.
1414
# Tests that `steady_state_jac` function works.
15-
# Tests with and without sparsity.
1615
# Tests using symbolic input.
1716
let
1817
# System which may have between 1 and 7 fixed points.
@@ -22,31 +21,28 @@ let
2221
d, (X,Y) --> 0
2322
end
2423
ss_jac = steady_state_jac(rn)
25-
ss_jac_sparse = steady_state_jac(rn; sparse = true)
2624

2725
# Repeats several times, most steady state stability cases should be encountered several times.
28-
for repeat = 1:50
26+
for repeat = 1:20
2927
# Generates random parameter values (which can generate all steady states cases).
3028
ps = (:v => 1.0 + 3*rand(rng), :K => 0.5 + 2*rand(rng), :n => rand(rng,[1,2,3,4]),
3129
:d => 0.5 + rand(rng))
3230

3331
# Computes stability using various jacobian options.
3432
sss = hc_steady_states(rn, ps)
3533
stabs_1 = [steady_state_stability(ss, rn, ps) for ss in sss]
36-
stabs_2 = [steady_state_stability(ss, rn, ps; sparse = true) for ss in sss]
37-
stabs_3 = [steady_state_stability(ss, rn, ps; ss_jac = ss_jac) for ss in sss]
38-
stabs_4 = [steady_state_stability(ss, rn, ps; ss_jac = ss_jac_sparse) for ss in sss]
34+
stabs_2 = [steady_state_stability(ss, rn, ps; ss_jac = ss_jac) for ss in sss]
3935

4036
# Confirms stability using simulations.
4137
for (idx, ss) in enumerate(sss)
4238
ssprob = SteadyStateProblem(rn, [1.001, 0.999] .* ss, ps)
4339
sol = solve(ssprob, DynamicSS(Vern7()); abstol = 1e-8, reltol = 1e-8)
44-
stabs_5 = isapprox(ss, sol.u; atol = 1e-6)
45-
@test stabs_1[idx] == stabs_2[idx] == stabs_3[idx] == stabs_4[idx] == stabs_5
40+
stabs_3 = isapprox(ss, sol.u; atol = 1e-6)
41+
@test stabs_1[idx] == stabs_2[idx] == stabs_3
4642

4743
# Checks stability when steady state is given on a pair form ([X => x_val, Y => y_val]).
48-
stabs_6 = steady_state_stability(Pair.(unknowns(rn), ss), rn, ps)
49-
@test stabs_5 == stabs_6
44+
stabs_4 = steady_state_stability(Pair.(unknowns(rn), ss), rn, ps)
45+
@test stabs_3 == stabs_4
5046
end
5147
end
5248
end

0 commit comments

Comments
 (0)