Skip to content

Commit c564bac

Browse files
committed
up
1 parent 7be2f68 commit c564bac

File tree

6 files changed

+43
-17
lines changed

6 files changed

+43
-17
lines changed

docs/src/catalyst_applications/bifurcation_diagrams.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,6 @@ Finally, for additional clarity, we reiterate the purpose of the two `u` argumen
112112
- `u_guess`: A guess of the initial steady states (which BifurcationKit uses to find its starting point). Typically, most trivial guesses work (e.g. setting all species concentrations to `1.0`). `u_guess` *does not* have to fulfill the conserved concentrations provided in `u0`.
113113
- `u0`: Used to compute the concentrations of any conserved quantities (e.g. in our example $X + Xp = 1.0$). Technically, values are only required for species that are involved in conservation laws (in our case we do not need to provide a value for $K$). However, sometimes determining which species are actually involved in conservation laws can be difficult, and it might be easier to simply provide concentrations for all species.
114114

115-
!!! note
116-
Computing bifurcation diagrams for [hierarchical models created by composing multiple systems](@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.
117-
118115

119116
---
120117
## [Citation](@id bifurcation_kit_citation)
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
### Dispatch for BifurcationKit BifurcationProblems ###
22

33
# Creates a BifurcationProblem, using a ReactionSystem as an input.
4-
function BK.BifurcationProblem(rs::ReactionSystem, u0_bif, ps, bif_par, args...; plot_var=nothing, record_from_solution=BK.record_sol_default, jac=true, u0=[], kwargs...)
4+
function BK.BifurcationProblem(rs::ReactionSystem, u0_bif, ps, bif_par, args...;
5+
plot_var=nothing, record_from_solution=BK.record_sol_default, jac=true, u0=[], kwargs...)
6+
57
# Converts symbols to symbolics.
68
(bif_par isa Symbol) && (bif_par = rs.var_to_name[bif_par])
79
(plot_var isa Symbol) && (plot_var = rs.var_to_name[plot_var])
8-
(u0_bif isa Vector{Pair{Symbol, Float64}}) && (u0_bif = symmap_to_varmap(rs, u0_bif))
9-
(ps isa Vector{Pair{Symbol, Float64}}) && (ps = symmap_to_varmap(rs, ps))
10-
(u0 isa Vector{Pair{Symbol, Float64}}) && (u0 = symmap_to_varmap(rs, u0))
10+
((u0_bif isa Vector{<:Pair{Symbol,<:Any}}) || (u0_bif isa Dict{Symbol, <:Any})) && (u0_bif = symmap_to_varmap(rs, u0_bif))
11+
((ps isa Vector{<:Pair{Symbol,<:Any}}) || (ps isa Dict{Symbol, <:Any})) && (ps = symmap_to_varmap(rs, ps))
12+
((u0 isa Vector{<:Pair{Symbol,<:Any}}) || (u0 isa Dict{Symbol, <:Any})) && (u0 = symmap_to_varmap(rs, u0))
1113

1214
# Creates NonlinearSystem.
13-
#Catalyst.conservationlaw_errorcheck(rs, vcat(ps, u0))
15+
Catalyst.conservationlaw_errorcheck(rs, vcat(ps, u0))
1416
nsys = convert(NonlinearSystem, rs; remove_conserved=true, defaults=Dict(u0))
1517

16-
# Makes BifurcationProblem.
17-
return BK.BifurcationProblem(nsys, u0_bif, ps, bif_par, args...; plot_var=plot_var, record_from_solution=record_from_solution, jac=jac, kwargs...)
18+
# Makes BifurcationProblem (this call goes through the ModelingToolkit-based BifurcationKit extension).
19+
return BK.BifurcationProblem(nsys, u0_bif, ps, bif_par, args...; plot_var=plot_var,
20+
record_from_solution=record_from_solution, jac=jac, kwargs...)
1821
end

src/Catalyst.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ export @compound
106106
export components, iscompound, coefficients
107107
export balance_reaction
108108

109-
# for functions I am unsure where to best place them.
110-
include("miscellaneous.jl")
111-
112109
### Extensions ###
113110

114111
# HomotopyContinuation

src/miscellaneous.jl

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/networkapi.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,13 +1279,11 @@ conservedquantities(state, cons_laws) = cons_laws * state
12791279

12801280

12811281
# If u0s are not given while conservation laws are present, throws an error.
1282-
# If the system is nested, the function is skipped (conservation laws cannot be computed for nested systems).
12831282
# Used in HomotopyContinuation and BifurcationKit extensions.
12841283
function conservationlaw_errorcheck(rs, pre_varmap)
1285-
isempty(get_systems(rs)) || return
12861284
vars_with_vals = Set(p[1] for p in pre_varmap)
12871285
any(s -> s in vars_with_vals, species(rs)) && return
1288-
isempty(conservedequations(rs)) ||
1286+
isempty(conservedequations(Catalyst.flatten(rs))) ||
12891287
error("The system has conservation laws but initial conditions were not provided for some species.")
12901288
end
12911289

test/extensions/bifurcation_kit.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,36 @@ let
138138
bif_dia = bifurcationdiagram(bprob, PALC(), 2, (args...) -> opts_br; bothside = true)
139139
@test bif_dia.γ.branch[end].x 4.0/6
140140
end
141+
end
142+
143+
# Tests for nested model with conservation laws.
144+
let
145+
# Creates model.
146+
rn1 = @reaction_network rn1 begin
147+
(k1, k2), X1 <--> X2
148+
end
149+
rn2 = @reaction_network rn2 begin
150+
(l1, l2), Y1 <--> Y2
151+
end
152+
@named rn = compose(rn1, [rn2])
153+
154+
# Creates input parameter and species vectors.
155+
@unpack X1, X2, k1, k2 = rn1
156+
u_guess = [X1 => 1.0, X2 => 1.0, rn2.Y1 => 1.0, rn2.Y2 => 1.0]
157+
p_start = [k1 => 1.0, k2 => 1.0, rn2.l1 => 1.0, rn2.l2 => 1.0]
158+
u0 = [X1 => 1.0, X2 => 0.0, rn2.Y1 => 1.0, rn2.Y2 => 0.0]
159+
160+
# Computes bifurcation diagram.
161+
p_span = (0.2, 5.0)
162+
bprob = BifurcationProblem(rn, u_guess, p_start, k1; plot_var = X1, u0=u0)
163+
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)
164+
bif_dia = bifurcationdiagram(bprob, PALC(), 2, (args...) -> opts_br; bothside = true)
165+
166+
# Checks that the bifurcation diagram is correct.
167+
xs = getfield.(bif_dia.γ.branch, :x)
168+
k1s = getfield.(bif_dia.γ.branch, :param)
169+
all(1 ./ k1s .* (1 .- xs) .≈ xs)
170+
171+
# Checks that there is an error if information for conserved quantities computation is not provided.
172+
@test_throws Exception bprob = BifurcationProblem(rn, u_guess, p_start, k1; plot_var = X1)
141173
end

0 commit comments

Comments
 (0)