Skip to content

Commit 7c384d9

Browse files
committed
up
1 parent d52f005 commit 7c384d9

File tree

6 files changed

+96
-2
lines changed

6 files changed

+96
-2
lines changed

docs/src/api/catalyst_api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ netstoichmat
180180
reactionrates
181181
```
182182

183-
## Functions to extend or modify a network
183+
## (Functions to extend or modify a network)(@id api_network_extension_and_modification)
184184
`ReactionSystem`s can be programmatically extended using
185185
[`@add_reactions`](@ref), [`addspecies!`](@ref), [`addparam!`](@ref) and
186186
[`addreaction!`](@ref), or using [`ModelingToolkit.extend`](@ref) and

docs/src/catalyst_applications/bifurcation_diagrams.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ This bifurcation diagram does not contain any interesting features (such as bifu
110110
- When providing the concentrations for computing the conserved quantities (in `u0`), we only have to designate the concentrations of species that are actually involved in conservation laws. For larger systems, determining which one are may, however, be difficult. In this case, it might still be wise to provide concentrations for all species.
111111
- The steady state guess in `u_guess` does not actually have to fulfil the conserved concentrations provided in `u0`.
112112

113+
!!! note
114+
Computing bifurcation diagrams for [hierarchical models created using compostability](@ref compositional_modeling), that also contain conservations laws, is currently not supported. For these, please [flatten](@ref api_network_extension_and_modification) the system first.
115+
116+
113117
---
114118
## [Citation](@id bifurcation_kit_citation)
115119
If you use this functionality in your research, please cite the following paper to support the author of the BifurcationKit package:

ext/CatalystBifurcationKitExtension/bifurcation_kit_extension.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function BK.BifurcationProblem(rs::ReactionSystem, u0_bif, ps, bif_par, args...;
1010
(u0 isa Vector{Pair{Symbol, Float64}}) && (u0 = symmap_to_varmap(rs, u0))
1111

1212
# Creates NonlinearSystem.
13-
Catalyst.conservationlaw_errorcheck(rs, vcat(ps, u0))
13+
#Catalyst.conservationlaw_errorcheck(rs, vcat(ps, u0))
1414
nsys = convert(NonlinearSystem, rs; remove_conserved=true, defaults=Dict(u0))
1515

1616
# Makes BifurcationProblem.

src/miscellaneous.jl

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

33

44
# If u0s are not given while conservation laws are present, throws an error.
5+
# If the system is nested, the function is skipped (conservation laws cannot be computed for nested systems).
56
# Used in HomotopyContinuation and BifurcationKit extensions.
67
function conservationlaw_errorcheck(rs, pre_varmap)
8+
isempty(get_systems(rs)) || return
79
vars_with_vals = Set(p[1] for p in pre_varmap)
810
any(s -> s in vars_with_vals, species(rs)) && return
911
isempty(conservedequations(rs)) ||

test/extensions/bifurcation_kit.jl

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,62 @@ let
8080
p = rand(rng, 4)
8181
@test bprob_BK.VF.F(u0, p) == bprob.VF.F(u0, p)
8282
end
83+
end
84+
85+
# Creates a system where rn is composed of 4, somewhat nested, networks.
86+
# Tests with defaults within nested networks.
87+
let
88+
rn1 = @reaction_network rn1 begin
89+
@parameters p=1.0
90+
(p, d), 0 <--> X
91+
end
92+
rn2 = @reaction_network rn2 begin
93+
@parameters p=2.0
94+
(p, d), 0 <--> X
95+
end
96+
rn3 = @reaction_network rn3 begin
97+
@parameters p=3.0
98+
(p, d), 0 <--> X
99+
end
100+
rn4 = @reaction_network rn4 begin
101+
@parameters p=4.0
102+
(p, d), 0 <--> X
103+
end
104+
@named rn3 =compose(rn3, [rn4])
105+
@named rn = compose(rn1, [rn2, rn3])
106+
107+
# Declares parameter values and initial u guess.
108+
@unpack X, d = rn
109+
u0_guess = [X => 1.0, rn2.X => 1.0, rn3.X => 1.0, rn3.rn4.X => 1.0]
110+
p_start = [d => 1.0, rn2.d => 1.0, rn3.d => 1.0, rn3.rn4.d => 1.0]
111+
112+
113+
# Computes bifurcation diagrams and check them (the final point at [p_value = 6] should be =[p/d]).
114+
p_span = (0.1, 6.0)
115+
116+
let
117+
# Checks top layer.
118+
bprob = BifurcationProblem(rn, u0_guess, p_start, d; plot_var = X)
119+
opts_br = ContinuationPar(dsmin = 0.0001, dsmax = 0.001, ds = 0.0001, max_steps = 10000, p_min = p_span[1], p_max = p_span[2], n_inversion = 4)
120+
bif_dia = bifurcationdiagram(bprob, PALC(), 2, (args...) -> opts_br; bothside = true)
121+
@test bif_dia.γ.branch[end].x 1.0/6
122+
123+
# Checks second layer (1).
124+
bprob = BifurcationProblem(rn, u0_guess, p_start, rn2.d; plot_var = rn2.X)
125+
opts_br = ContinuationPar(dsmin = 0.0001, dsmax = 0.001, ds = 0.0001, max_steps = 10000, p_min = p_span[1], p_max = p_span[2], n_inversion = 4)
126+
bif_dia = bifurcationdiagram(bprob, PALC(), 2, (args...) -> opts_br; bothside = true)
127+
@test bif_dia.γ.branch[end].x 2.0/6
128+
129+
# Checks second layer (2).
130+
bprob = BifurcationProblem(rn, u0_guess, p_start, rn3.d; plot_var = rn3.X)
131+
opts_br = ContinuationPar(dsmin = 0.0001, dsmax = 0.001, ds = 0.0001, max_steps = 10000, p_min = p_span[1], p_max = p_span[2], n_inversion = 4)
132+
bif_dia = bifurcationdiagram(bprob, PALC(), 2, (args...) -> opts_br; bothside = true)
133+
@test bif_dia.γ.branch[end].x 3.0/6
134+
135+
# Checks third layer.
136+
bprob = BifurcationProblem(rn, u0_guess, p_start, rn3.rn4.d; plot_var = rn3.rn4.X)
137+
opts_br = ContinuationPar(dsmin = 0.0001, dsmax = 0.001, ds = 0.0001, max_steps = 10000, p_min = p_span[1], p_max = p_span[2], n_inversion = 4)
138+
bif_dia = bifurcationdiagram(bprob, PALC(), 2, (args...) -> opts_br; bothside = true)
139+
@test bif_dia.γ.branch[end].x 4.0/6
140+
end
83141
end

test/programmatic_model_creation/component_based_model_creation.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,33 @@ let
451451
@test numspecies(rs123) == 6
452452
@test issetequal(nonspecies(rs123), [V1, rs23.V2, rs23.rs3.V3])
453453
end
454+
455+
# Tests that conversion with defaults works for a composed model.
456+
let
457+
rn1 = @reaction_network rn1 begin
458+
@parameters p=1.0 r=2.0
459+
@species X(t) = 3.0 Y(t) = 4.0
460+
(p1, d), 0 <--> X
461+
(p2, r), 0 <--> Z
462+
end
463+
rn2 = @reaction_network rn1 begin
464+
@parameters p=10. q=20.0
465+
@species X(t) = 30.0 Z(t) = 40.0
466+
(p1, d), 0 <--> X
467+
(p2, q), 0 <--> Z
468+
end
469+
composed_reaction_system = compose(rn1, [rn2])
470+
osys = convert(ODESystem, composed_reaction_system)
471+
parameters(osys)[1].metadata
472+
473+
osys.defaults
474+
@unpack p, r, X, Y = rn1
475+
osys.defaults[p] == 1.0
476+
osys.defaults[r] == 2.0
477+
osys.defaults[X] == 3.0
478+
osys.defaults[Y] == 4.0
479+
osys.defaults[rn2.p] == 10.0
480+
osys.defaults[rn2.q] == 20.0
481+
osys.defaults[rn2.X] == 30.0
482+
osys.defaults[rn2.Z] == 40.0
483+
end

0 commit comments

Comments
 (0)