-
-
Notifications
You must be signed in to change notification settings - Fork 82
Bifurcationkit periodic orbits example #1216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
cfea71f
create example
TorkelE 81b7da3
minor updates
TorkelE 2218262
up
TorkelE ddf27d4
next pass through text checking grammar etc.
TorkelE a41a7c0
pages update
TorkelE cded4ee
Pr interdependency fix
TorkelE 7222a07
reference fix
TorkelE 7a5f65d
add internal ref
TorkelE 34a51db
bk docs link update
TorkelE e6f3cb9
better plot label
TorkelE bc9f48a
typo fix
TorkelE 5b81a52
add citation
TorkelE File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
docs/src/steady_state_functionality/examples/bifurcationkit_periodic_orbits.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| # [Computing Periodic Orbits (Oscillations) Using BifurcationKit.jl](@id bifurcationkit_periodic_orbits) | ||
| Previously, we have shown how to [compute bifurcation diagrams](@ref bifurcation_diagrams) using [BifurcationKit.jl](https://github.com/bifurcationkit/BifurcationKit.jl). In this example we will consider a system which exhibits an oscillation and show how to use BifurcationKit to track not just the system's (potentially unstable) steady state, but also the periodic orbit itself. More information on how to track periodic orbits can be found in the [BifurcationKit documentation](https://bifurcationkit.github.io/BifurcationKitDocs.jl/stable/tutorials/tutorials/#Periodic-orbits). | ||
|
|
||
| ## [Computing the bifurcation diagram for the Repressilator](@id bifurcationkit_periodic_orbits_bifdia) | ||
| We will first compute the bifurcation diagram, using the same approach as in the [corresponding tutorial](@ref bifurcation_diagrams). For this example, we will use the oscillating [Repressilator](@ref basic_CRN_library_repressilator) model. | ||
| ```@example bifurcationkit_periodic_orbits | ||
| using Catalyst | ||
| repressilator = @reaction_network begin | ||
| hillr(Z,v,K,n), ∅ --> X | ||
| hillr(X,v,K,n), ∅ --> Y | ||
| hillr(Y,v,K,n), ∅ --> Z | ||
| d, (X, Y, Z) --> ∅ | ||
| end | ||
| ``` | ||
| Next, we create a `BifurcationProblem` for our model. We will compute the bifurcation diagram with respect to the parameter $v$, and plot the species $X$ in the diagram. | ||
| ```@example bifurcationkit_periodic_orbits | ||
| using BifurcationKit | ||
| bif_par = :v | ||
| u_guess = [:X => 20.0, :Y => 15.0, :Z => 15.0] | ||
| p_start = [:v => 10.0, :K => 15.0, :n => 3, :d => 0.2] | ||
| plot_var = :X | ||
| bprob = BifurcationProblem(repressilator, u_guess, p_start, bif_par; plot_var) | ||
| nothing # hide | ||
| ``` | ||
| We compute the bifurcation diagram using the `bifurcationdiagram` function. We will compute it across the interval $v \in (0,20)$. | ||
| ```@example bifurcationkit_periodic_orbits | ||
| v_span = (0.0, 20.0) | ||
| opts_br = ContinuationPar(p_min = v_span[1], p_max = v_span[2]) | ||
| bifdia = bifurcationdiagram(bprob, PALC(), 3, opts_br; bothside = true) | ||
| nothing # hide | ||
| ``` | ||
| Finally, we plot the bifurcation diagram. | ||
| ```@example bifurcationkit_periodic_orbits | ||
| using Plots | ||
| plot(bifdia; xguide = bif_par, yguide = plot_var, xlimit = v_span, branchlabel = "Steady state concentration", | ||
| linewidthstable = 5) | ||
| ``` | ||
| We note that for small values of $v$ the system's single steady state is stable (where the line is thicker). After a [Hopf](https://en.wikipedia.org/wiki/Hopf_bifurcation) bifurcation (the red point), the state turns unstable (where the line is thinner). For chemical reaction networks (which mostly are well-behaved) a single unstable steady state typically corresponds to an oscillation. We can confirm that the system oscillates in the unstable region (while it reaches a stable steady state in the stable region) using simulations: | ||
| ```@example bifurcationkit_periodic_orbits | ||
| using OrdinaryDiffEqDefault | ||
| p_nosc = [:v => 5.0, :K => 15.0, :n => 3, :d => 0.2] | ||
| p_osc = [:v => 15.0, :K => 15.0, :n => 3, :d => 0.2] | ||
| prob_nosc = ODEProblem(repressilator, u_guess, 80.0, p_nosc) | ||
| prob_osc = ODEProblem(repressilator, u_guess, 80.0, p_osc) | ||
| sol_nosc = OrdinaryDiffEqDefault.solve(prob_nosc) | ||
| sol_osc = OrdinaryDiffEqDefault.solve(prob_osc) | ||
| plot(plot(sol_nosc; title = "v = 5"), plot(sol_osc; title = "v = 15"), size = (1000,400), lw = 4) | ||
| ``` | ||
|
|
||
| ## [Tracking the periodic orbits](@id bifurcationkit_periodic_orbits_pos) | ||
| Next, we will use BifurcationKit.jl's [`continuation` function](https://bifurcationkit.github.io/BifurcationKitDocs.jl/dev/library/#BifurcationKit.continuation) (the [`bifurcationdiagram` function](https://bifurcationkit.github.io/BifurcationKitDocs.jl/dev/library/#BifurcationKit.bifurcationdiagram), which we previously have used, works by calling `continuation` recursively) to track the periodic orbit which appears with the Hopf bifurcation point. | ||
|
|
||
| Firs,t we set the options for the continuation. Just like for bifurcation diagrams we must set our [continuation parameters](@ref bifurcation_diagrams_continuationpar). Here we will use the same one as for the initial diagram (however, additional ones can be supplied). | ||
| ```@example bifurcationkit_periodic_orbits | ||
| opts_po = ContinuationPar(opts_br) | ||
| nothing # hide | ||
| ``` | ||
| During the continuation we will compute the periodic orbit using the [Collocation](https://bifurcationkit.github.io/BifurcationKitDocs.jl/stable/periodicOrbit/#Collocation-method) method (however, the [Trapezoid](https://bifurcationkit.github.io/BifurcationKitDocs.jl/stable/periodicOrbit/#Trapezoid-method) and [Shooting](https://bifurcationkit.github.io/BifurcationKitDocs.jl/stable/periodicOrbit/#Shooting-method) method also exist, with each having their advantages and disadvantages). For this, we create a [`PeriodicOrbitOCollProblem`](https://bifurcationkit.github.io/BifurcationKitDocs.jl/stable/library/#BifurcationKit.PeriodicOrbitOCollProblem) which we will supply to our continuation computation. | ||
| ```@example bifurcationkit_periodic_orbits | ||
| poprob = PeriodicOrbitOCollProblem(50, 4) | ||
| nothing # hide | ||
| ``` | ||
| Finally, we will also create a `record_from_solution` function. This is a function which records information of the solution at each step of the continuation (which we can later plot or investigate using other means). | ||
| ```@example bifurcationkit_periodic_orbits | ||
| X_idx = findfirst(isequal(repressilator.X), unknowns(complete(convert(NonlinearSystem, repressilator)))) | ||
| function record_from_solution(x, p; kwargs...) | ||
| xtt = get_periodic_orbit(p.prob, x, p.p) | ||
| min, max = extrema(xtt[1,:]) | ||
| period = getperiod(p.prob, x, p.p) | ||
| return (; min, max, period) | ||
| end | ||
| nothing # hide | ||
| ``` | ||
| Here, `get_periodic_orbit` computes the system's periodic orbit. From it we extract the $X$ species's minimum and maximum values (using `extrema`) and the period length (using `getperiod`). We return these quantities as a [`NamedTuple`](https://docs.julialang.org/en/v1/base/base/#Core.NamedTuple). | ||
|
|
||
| We can now compute the periodic orbit. First we must extract a branch from our bifurcation diagram (using [`get_branch`](https://bifurcationkit.github.io/BifurcationKitDocs.jl/stable/library/#BifurcationKit.get_branch)), as `continuation` do not work on bifurcation diagrams directly (our bifurcation diagram consists of a single branch, which we here extract). Next, we can call `continuation` on it, designating that we wish to do continuation from the second point on the branch (which corresponds to the Hopf bifurcation, the first point is one of the branch's two endpoints). | ||
TorkelE marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ```@example bifurcationkit_periodic_orbits | ||
| branch = get_branch(bifdia, ()).γ | ||
| br_po = continuation(branch, 2, opts_po, poprob; record_from_solution) | ||
| nothing # hide | ||
| ``` | ||
| Finally, we can plot the periodic orbit. We use the `vars` argument to designate what we wish to plot. Here we first provide `(:param, :min)` (designating that we wish to plot the `min` value returned by `record_from_solution`, i.e. the minimum value throughout the periodic orbit) against the continuation parameter's ($v$) value. Next, we plot the maximum periodic orbit value using `(:param, :max)`. | ||
| ```@example bifurcationkit_periodic_orbits | ||
| plot(bifdia; xlimit = v_span, branchlabel = "Steady state concentration", linewidthstable = 5) | ||
| plot!(br_po, vars = (:param, :min); color = 2, branchlabel = "Oscillation amplitude (min/max)") | ||
| plot!(br_po, vars = (:param, :max); color = 2, xguide = bif_par, yguide = plot_var, branchlabel = "") | ||
| ``` | ||
| Here we can see that, as $v$ increases, the oscillation amplitude increases with it. | ||
|
|
||
| Previously, we had `record_from_solution` record the periodic orbit's period. This means that we can plot it as well. Here, we plot it against $v$ using `vars = (:param, :period)`. | ||
| ```@example bifurcationkit_periodic_orbits | ||
| plot(br_po, vars = (:param, :period); xguide = bif_par, yguide = "Period length", xlimit = v_span, ylimit = (0.0, Inf)) | ||
| ``` | ||
| In the plot we see that the period starts at around $18$ time units, and slowly increase with $v$. | ||
|
|
||
|
|
||
| --- | ||
| ## [Citation](@id bifurcationkit_periodic_orbits_citation) | ||
TorkelE marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| If you use this functionality in your research, please cite the following paper to support the author of the BifurcationKit package: | ||
| ``` | ||
| @misc{veltz:hal-02902346, | ||
| title = {{BifurcationKit.jl}}, | ||
| author = {Veltz, Romain}, | ||
| url = {https://hal.archives-ouvertes.fr/hal-02902346}, | ||
| institution = {{Inria Sophia-Antipolis}}, | ||
| year = {2020}, | ||
| month = Jul, | ||
| keywords = {pseudo-arclength-continuation ; periodic-orbits ; floquet ; gpu ; bifurcation-diagram ; deflation ; newton-krylov}, | ||
| pdf = {https://hal.archives-ouvertes.fr/hal-02902346/file/354c9fb0d148262405609eed2cb7927818706f1f.tar.gz}, | ||
| hal_id = {hal-02902346}, | ||
| hal_version = {v1}, | ||
| } | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.