Skip to content

Commit 42607e8

Browse files
authored
Merge pull request #1101 from vyudu/BK
BifurcationKit test
2 parents a5ebaeb + f83cdf3 commit 42607e8

File tree

6 files changed

+55
-9
lines changed

6 files changed

+55
-9
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.4"
4646
CairoMakie = "0.12"
4747
Combinatorics = "1.0.2"
4848
DataStructures = "0.18"

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
4545

4646
[compat]
4747
BenchmarkTools = "1.5"
48-
BifurcationKit = "0.3.4"
48+
BifurcationKit = "0.4.4"
4949
CairoMakie = "0.12"
5050
Catalyst = "14.4"
5151
DataFrames = "1.6"

docs/pages.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pages = Any[
4141
"steady_state_functionality/homotopy_continuation.md",
4242
"steady_state_functionality/nonlinear_solve.md",
4343
"steady_state_functionality/steady_state_stability_computation.md",
44-
#"steady_state_functionality/bifurcation_diagrams.md",
44+
"steady_state_functionality/bifurcation_diagrams.md",
4545
"steady_state_functionality/dynamical_systems.md"
4646
],
4747
"Inverse problems" => Any[

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ etc).
3939
- [Latexify](https://korsbo.github.io/Latexify.jl/stable/) can be used to [generate LaTeX expressions](@ref visualisation_latex) corresponding to generated mathematical models or the underlying set of reactions.
4040
- [Graphviz](https://graphviz.org/) can be used to generate and [visualize reaction network graphs](@ref visualisation_graphs) (reusing the Graphviz interface created in [Catlab.jl](https://algebraicjulia.github.io/Catlab.jl/stable/)).
4141
- Model steady states can be [computed through homotopy continuation](@ref homotopy_continuation) using [HomotopyContinuation.jl](https://github.com/JuliaHomotopyContinuation/HomotopyContinuation.jl) (which can find *all* steady states of systems with multiple ones), by [forward ODE simulations](@ref steady_state_solving_simulation) using [SteadyStateDiffEq.jl)](https://github.com/SciML/SteadyStateDiffEq.jl), or by [numerically solving steady-state nonlinear equations](@ref steady_state_solving_nonlinear) using [NonlinearSolve.jl](https://github.com/SciML/NonlinearSolve.jl).
42-
<!--- [BifurcationKit.jl](https://github.com/bifurcationkit/BifurcationKit.jl) can be used to compute bifurcation diagrams of model steady states (including finding periodic orbits).-->
42+
[BifurcationKit.jl](https://github.com/bifurcationkit/BifurcationKit.jl) can be used to compute bifurcation diagrams of model steady states (including finding periodic orbits).
4343
- [DynamicalSystems.jl](https://github.com/JuliaDynamics/DynamicalSystems.jl) can be used to compute model [basins of attraction](@ref dynamical_systems_basins_of_attraction), [Lyapunov spectrums](@ref dynamical_systems_lyapunov_exponents), and other dynamical system properties.
4444
<!--- [StructuralIdentifiability.jl](https://github.com/SciML/StructuralIdentifiability.jl) can be used to perform structural identifiability analysis.-->
4545
- [Optimization.jl](https://github.com/SciML/Optimization.jl), [DiffEqParamEstim.jl](https://github.com/SciML/DiffEqParamEstim.jl), and [PEtab.jl](https://github.com/sebapersson/PEtab.jl) can all be used to [fit model parameters to data](https://sebapersson.github.io/PEtab.jl/stable/Define_in_julia/).

src/reactionsystem.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ const reactionsystem_fields = (
229229
:eqs, :rxs, :iv, :sivs, :unknowns, :species, :ps, :var_to_name,
230230
:observed, :name, :systems, :defaults, :connection_type,
231231
:networkproperties, :combinatoric_ratelaws, :continuous_events,
232-
:discrete_events, :metadata, :complete)
232+
:discrete_events, :metadata, :complete, :parent)
233233

234234
"""
235235
$(TYPEDEF)
@@ -325,11 +325,16 @@ struct ReactionSystem{V <: NetworkProperties} <:
325325
complete: if a model `sys` is complete, then `sys.x` no longer performs namespacing.
326326
"""
327327
complete::Bool
328+
"""
329+
The hierarchical parent system before simplification that MTK now seems to require for
330+
hierarchical namespacing to work in indexing.
331+
"""
332+
parent::Any
328333

329334
# inner constructor is considered private and may change between non-breaking releases.
330335
function ReactionSystem(eqs, rxs, iv, sivs, unknowns, spcs, ps, var_to_name, observed,
331336
name, systems, defaults, connection_type, nps, cls, cevs, devs,
332-
metadata = nothing, complete = false; checks::Bool = true)
337+
metadata = nothing, complete = false, parent = nothing; checks::Bool = true)
333338

334339
# Checks that all parameters have the appropriate Symbolics type.
335340
for p in ps
@@ -358,7 +363,7 @@ struct ReactionSystem{V <: NetworkProperties} <:
358363
rs = new{typeof(nps)}(
359364
eqs, rxs, iv, sivs, unknowns, spcs, ps, var_to_name, observed,
360365
name, systems, defaults, connection_type, nps, cls, cevs,
361-
devs, metadata, complete)
366+
devs, metadata, complete, parent)
362367
checks && validate(rs)
363368
rs
364369
end

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
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_broken @. 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)