Skip to content

Commit b466c10

Browse files
committed
up
1 parent f839ff9 commit b466c10

File tree

12 files changed

+43
-44
lines changed

12 files changed

+43
-44
lines changed

HISTORY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ plot(bif_dia; xguide="k1", yguide="X")
8585
```
8686
- Automatically handles elimination of conservation laws for computing bifurcation diagrams.
8787
- Updated Bifurcation documentation with respect to this new feature.
88-
- Added function `is_autonomous` to check if a `ReactionSystem` is autonomous.
88+
- Added function `isautonomous` to check if a `ReactionSystem` is autonomous.
8989
- Added function `steady_state_stability` to compute stability for steady states. Example:
9090
```julia
9191
# Creates model.
@@ -98,6 +98,7 @@ p = [:p => 1.0, :d => 0.5]
9898
steady_state = [2.0]
9999
steady_state_stability(steady_state, rn, p)
100100
```
101+
Here, `steady_state_stability` take an optional argument `tol = 10*sqrt(eps())`, which is used to determine whether a eigenvalue real part is reliably less that 0.
101102

102103
## Catalyst 13.5
103104
- Added a CatalystHomotopyContinuationExtension extension, which exports the `hc_steady_state` function if HomotopyContinuation is exported. `hc_steady_state` finds the steady states of a reaction system using the homotopy continuation method. This feature is only available for julia versions 1.9+. Example:

docs/src/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ speciesmap
166166
paramsmap
167167
reactionparamsmap
168168
isspecies
169-
is_autonomous
169+
isautonomous
170170
Catalyst.isconstant
171171
Catalyst.isbc
172172
```

docs/src/steady_state_functionality/steady_state_stability_computation.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ Next, we can apply `steady_state_stability` to each steady state yielding a vect
3636
[steady_state_stability(sstate, sa_loop, ps) for sstate in steady_states]
3737
```
3838

39+
Finally, as described above, Catalyst uses an optional argument, `tol`, to determine how strict to make the stability check. I.e. below we set the tolerance to `1e-6` (a larger value, that is stricter, than the default of `10*sqrt(eps())`)
40+
```@example stability_1
41+
[steady_state_stability(sstate, sa_loop, ps; tol = 1e-6) for sstate in steady_states]
42+
nothing# hide
43+
```
44+
3945
## Pre-computing the Jacobian to increase performance when computing stability for many steady states
4046
Catalyst uses the system Jacobian to compute steady state stability, and the Jacobian is computed once for each call to `steady_state_stability`. If you repeatedly compute stability for steady states of the same system, pre-computing the Jacobian and supplying it to the `steady_state_stability` function can improve performance.
4147

ext/CatalystBifurcationKitExtension/bifurcation_kit_extension.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Creates a BifurcationProblem, using a ReactionSystem as an input.
44
function BK.BifurcationProblem(rs::ReactionSystem, u0_bif, ps, bif_par, args...;
55
plot_var=nothing, record_from_solution=BK.record_sol_default, jac=true, u0=[], kwargs...)
6-
if !is_autonomous(rs)
6+
if !isautonomous(rs)
77
error("Attempting to create a `BifurcationProblem` for a non-autonomous system (e.g. where some rate depend on $(rs.iv)). This is not possible.")
88
end
99

ext/CatalystHomotopyContinuationExtension/homotopy_continuation_extension.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Notes:
3636
```
3737
"""
3838
function Catalyst.hc_steady_states(rs::ReactionSystem, ps; filter_negative=true, neg_thres=-1e-20, u0=[], kwargs...)
39-
if !is_autonomous(rs)
39+
if !isautonomous(rs)
4040
error("Attempting to compute steady state for a non-autonomous system (e.g. where some rate depend on $(rs.iv)). This is not possible.")
4141
end
4242
ss_poly = steady_state_polynomial(rs, ps, u0)

src/Catalyst.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ using DynamicQuantities#, Unitful # Having Unitful here as well currently gives
1818

1919
@reexport using ModelingToolkit
2020
using Symbolics
21-
21+
using LinearAlgebra
2222
using RuntimeGeneratedFunctions
2323
RuntimeGeneratedFunctions.init(@__MODULE__)
2424

@@ -42,7 +42,6 @@ import Base: (==), hash, size, getindex, setindex, isless, Sort.defalg, length,
4242
import MacroTools, Graphs
4343
import Graphs: DiGraph, SimpleGraph, SimpleDiGraph, vertices, edges, add_vertices!, nv, ne
4444
import DataStructures: OrderedDict, OrderedSet
45-
import LinearAlgebra.eigvals
4645
import Parameters: @with_kw_noshow
4746
import Symbolics: occursin, wrap
4847

@@ -103,7 +102,7 @@ export species, nonspecies, reactionparams, reactions, nonreactions, speciesmap,
103102
export numspecies, numreactions, numreactionparams, setdefaults!
104103
export make_empty_network, reactionparamsmap
105104
export dependants, dependents, substoichmat, prodstoichmat, netstoichmat
106-
export is_autonomous
105+
export isautonomous
107106
export reactionrates
108107
export isequivalent
109108
export set_default_noise_scaling

src/reactionsystem.jl

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,35 +1204,32 @@ function dependants(rx, network)
12041204
end
12051205

12061206
"""
1207-
is_autonomous(rs::ReactionSystem)
1207+
isautonomous(rs::ReactionSystem)
12081208
12091209
Checks if a system is autonomous (i.e. no rate or equation depend on the independent variable(s)).
12101210
Example:
12111211
```julia
12121212
rs1 = @reaction_system
12131213
(p,d), 0 <--> X
12141214
end
1215-
is_autonomous(rs1) # Returns `true`.
1215+
isautonomous(rs1) # Returns `true`.
12161216
12171217
rs2 = @reaction_system
12181218
(p/t,d), 0 <--> X
12191219
end
1220-
is_autonomous(rs2) # Returns `false`.
1220+
isautonomous(rs2) # Returns `false`.
12211221
```
12221222
"""
1223-
function is_autonomous(rs::ReactionSystem)
1224-
# Get all variables occuring in reactions and then other equations.
1225-
dep_var_param_rxs = [ModelingToolkit.get_variables(rate) for rate in reactionrates(rs)]
1226-
dep_var_param_eqs = [ModelingToolkit.get_variables(eq) for eq in filter(eq -> !(eq isa Reaction), equations(rs))]
1227-
if isempty(dep_var_param_rxs) && isempty(dep_var_param_eqs)
1228-
dep_var_param = []
1229-
else
1230-
dep_var_param = reduce(vcat,[dep_var_param_rxs; dep_var_param_eqs])
1223+
function isautonomous(rs::ReactionSystem)
1224+
# Get all variables occurring in reactions and equations.
1225+
vars = Set()
1226+
for eq in equations(rs)
1227+
(eq isa Reaction) ? get_variables!(vars, eq.rate) : get_variables!(vars, eq)
12311228
end
12321229

12331230
# Checks for iv and spatial ivs
1234-
any(isequal(get_iv(rs), var) for var in dep_var_param) && (return false)
1235-
any(isequal(siv, var) for siv in get_sivs(rs) for var in dep_var_param) && (return false)
1231+
(get_iv(rs) in vars) && return false
1232+
any(in(vars), get_sivs(rs)) && return false
12361233
return true
12371234
end
12381235

src/reactionsystem_conversions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ function Base.convert(::Type{<:NonlinearSystem}, rs::ReactionSystem; name = name
521521
# Error checks.
522522
iscomplete(rs) || error(COMPLETENESS_ERROR)
523523
spatial_convert_err(rs::ReactionSystem, NonlinearSystem)
524-
if !is_autonomous(rs)
524+
if !isautonomous(rs)
525525
error("Attempting to convert a non-autonomous `ReactionSystem` (e.g. where some rate depend on $(rs.iv)) to a `NonlinearSystem`. This is not possible. if you are intending to compute system steady states, consider creating and solving a `SteadyStateProblem.")
526526
end
527527

src/steady_state_stability.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ computed eigenvalue is far away enough from 0 to be reliably used. This selected
4747
function steady_state_stability(u::Vector, rs::ReactionSystem, ps; tol = 10*sqrt(eps(ss_val_type(u))),
4848
ss_jac = steady_state_jac(rs; u0 = u))
4949
# Warning checks.
50-
if !is_autonomous(rs)
50+
if !isautonomous(rs)
5151
error("Attempting to compute stability for a non-autonomous system (e.g. where some rate depend on $(rs.iv)). This is not possible.")
5252
end
5353

test/miscellaneous_tests/api.jl

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ let
447447
@test_throws MethodError Catalyst.to_multivariate_poly(neweqs)
448448
end
449449

450-
# Tests `is_autonomous` function.
450+
# Tests `isautonomous` function.
451451
let
452452
# Using default iv.
453453
rn1 = @reaction_network begin
@@ -462,9 +462,9 @@ let
462462
(p + X*(p1+p2),d), 0 <--> X
463463
(kB,kD), 2X <--> X
464464
end
465-
@test !is_autonomous(rn1)
466-
@test !is_autonomous(rn2)
467-
@test is_autonomous(rn3)
465+
@test !isautonomous(rn1)
466+
@test !isautonomous(rn2)
467+
@test isautonomous(rn3)
468468

469469
# Using non-default iv.
470470
rn4 = @reaction_network begin
@@ -487,15 +487,23 @@ let
487487
(p + X*(p1+p2),d), 0 <--> X
488488
(kB,kD), 2X <--> X
489489
end
490-
@test !is_autonomous(rn4)
491-
@test !is_autonomous(rn5)
492-
@test !is_autonomous(rn6)
493-
@test is_autonomous(rn7)
490+
@test !isautonomous(rn4)
491+
@test !isautonomous(rn5)
492+
@test !isautonomous(rn6)
493+
@test isautonomous(rn7)
494494

495495
# Using a coupled CRN/equation model.
496496
rn7 = @reaction_network begin
497497
@equations D(V) ~ X/(1+t) - V
498498
(p,d), 0 <--> X
499499
end
500-
@test !is_autonomous(rn7)
500+
@test !isautonomous(rn7)
501+
502+
# Using a registered function.
503+
f(d,t) = d/(1 + t)
504+
Symbolics.@register_symbolic f(d,t)
505+
rn8 = @reaction_network begin
506+
f(d,t), X --> 0
507+
end
508+
@test !isautonomous(rn8)
501509
end

0 commit comments

Comments
 (0)