Skip to content
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

Improve BifurcationKit extension #2337

Merged
merged 5 commits into from
Nov 7, 2023
Merged

Improve BifurcationKit extension #2337

merged 5 commits into from
Nov 7, 2023

Conversation

TorkelE
Copy link
Member

@TorkelE TorkelE commented Nov 1, 2023

Changes:

  • If the MTK system has default values for e.g. parameters, this is now properly handled.
  • If the MTK system has observables (e.g. due to structural simplify, or because it has been generated by certain Catalyst systems), these can now be selected as the plotting variables of the diagram.
  • Much improved test cases.

E.g. this should now work:

using BifurcationKit, ModelingToolkit
# Creates model, and uses `structural_simplify` to generate observables.
@parameters μ p=2
@variables t x(t) y(t) z(t)
D = Differential(t)
eqs = [0 ~ μ - x^3 + 2x^2,
       0 ~ p*μ - y,
       0 ~ y - z]    
@named nsys = NonlinearSystem(eqs, [x, y, z], [μ, p])
nsys = structural_simplify(nsys)

# Creates BifurcationProblem.
bif_par = μ
p_start ==> 1.0]
u0_guess = [x => 1.0, y => 0.1, z => 0.1]
plot_var = x;
bprob = BifurcationProblem(nsys, u0_guess, p_start, bif_par; plot_var=plot_var)

# Computes bifurcation diagram.
p_span = (-4.3, 12.0)
opt_newton = NewtonPar(tol = 1e-9, max_iterations = 20)
opts_br = ContinuationPar(dsmin = 0.001, dsmax = 0.05, ds = 0.01,
    max_steps = 100, nev = 2, newton_options = opt_newton,
    p_min = p_span[1], p_max = p_span[2],
    detect_bifurcation = 3, n_inversion = 4, tol_bisection_eigenvalue = 1e-8, dsmin_bisection = 1e-9);   
bif_dia = bifurcationdiagram(bprob, PALC(), 2, (args...) -> opts_br; bothside=true)
plot(bif_dia)

@TorkelE
Copy link
Member Author

TorkelE commented Nov 5, 2023

The formatter updated a lot of other files as well, right now I only pushed those affecting files this PR adds.
(but could push the rest, if that is desired)

@isaacsas
Copy link
Member

isaacsas commented Nov 5, 2023

Don’t run format. It is still broken. Sorry, missed this was a PR on MTK...

@YingboMa
Copy link
Member

YingboMa commented Nov 6, 2023

It seems like you need to update local JuliaFormatter.

And yeah, I am very committed to not merging any PR that doesn't pass format-check.

@TorkelE
Copy link
Member Author

TorkelE commented Nov 6, 2023

No, I agree fully. Given the formatter is in place and used, it should be run fully for every PR. Had Catalyst used in currently I would have been the same there.

I have updated the formatted and rerun it, hopefully it should work now.

@YingboMa YingboMa merged commit 397ab12 into SciML:master Nov 7, 2023
15 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants