Skip to content

Commit 16d1186

Browse files
committed
BK
1 parent bef4566 commit 16d1186

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ CatalystHomotopyContinuationExtension = "HomotopyContinuation"
4242
# CatalystStructuralIdentifiabilityExtension = "StructuralIdentifiability"
4343

4444
[compat]
45-
BifurcationKit = "0.3"
45+
BifurcationKit = "0.4.3"
4646
CairoMakie = "0.12"
4747
Combinatorics = "1.0.2"
4848
DataStructures = "0.18"

test/extensions/bifurcation_kit.jl

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ let
7676
K, = p
7777
return [0.1 + 5.0*(X^3)/(X^3 + K^3) - 1.0*X]
7878
end
79-
bprob_BK = BifurcationProblem(bistable_switch_BK, [1.0], [2.5], (@lens _[1]); record_from_solution = (x, p) -> x[1])
79+
bprob_BK = BifurcationProblem(bistable_switch_BK, [1.0], [2.5], (BifurcationKit.@optic _[1]); record_from_solution = (x, p; k...) -> x[1])
8080

8181
# Check the same function have been generated.
8282
bprob.u0 == bprob_BK.u0
@@ -230,4 +230,45 @@ let
230230

231231
# Attempts to build a BifurcationProblem.
232232
@test_throws Exception BifurcationProblem(rn, u0_guess, p_start, :p)
233-
end
233+
end
234+
235+
# Tests the bifurcation when one of the parameters depends on another parameter, initial condition, etc.
236+
let
237+
rn = @reaction_network begin
238+
@parameters k ksq = k^2 ratechange
239+
(k, ksq), A <--> B
240+
end
241+
242+
rn = complete(rn)
243+
u0_guess = [:A => 1., :B => 1.]
244+
p_start = [:k => 2.]
245+
246+
bprob = BifurcationProblem(rn, u0_guess, p_start, :k; plot_var = :A, u0 = [:A => 5., :B => 3.])
247+
p_span = (0.1, 6.0)
248+
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)
249+
bif_dia = bifurcationdiagram(bprob, PALC(), 2, (args...) -> opts_br; bothside = true)
250+
plot(bif_dia, xlabel = "k", ylabel = "A", xlims = (0, 6), ylims=(0,8))
251+
252+
xs = getfield.(bif_dia.γ.branch, :x)
253+
ks = getfield.(bif_dia.γ.branch, :param)
254+
# @test @. 8 * (ks / (ks + ks^2)) ≈ xs
255+
256+
# Test that parameter updating happens correctly in ODESystem
257+
t = default_t()
258+
kval = 4.
259+
@parameters k ksq = k^2 tratechange = 10.
260+
@species A(t) B(t)
261+
rxs = [(@reaction k, A --> B), (@reaction ksq, B --> A)]
262+
ratechange = (t == tratechange) => [k ~ kval]
263+
u0 = [A => 5., B => 3.]
264+
tspan = (0.0, 30.0)
265+
p = [k => 1.0]
266+
267+
@named rs2 = ReactionSystem(rxs, t, [A, B], [k, ksq, tratechange]; discrete_events = ratechange)
268+
rs2 = complete(rs2)
269+
270+
oprob = ODEProblem(rs2, u0, tspan, p)
271+
sol = OrdinaryDiffEq.solve(oprob, Tsit5(); tstops = 10.0)
272+
xval = sol.u[end][1]
273+
@test isapprox(xval, 8 * (kval / (kval + kval^2)), atol=1e-3)
274+
end

0 commit comments

Comments
 (0)