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

Support makie backends #181

Merged
merged 7 commits into from
Oct 6, 2024

Conversation

BambOoxX
Copy link
Contributor

@BambOoxX BambOoxX commented Oct 5, 2024

This is a first proposal to allow other Makie backends to be used with BifurcationKit.
The first main problem (solved in this draft) is that (un)stable branches are displayed with different line widths, which is incompatible with CairoMakie as is.
Another solution could be to have one plot per branch. But I'm not sure what is best.

Fixes #54 for CairoMakie at least.

@BambOoxX BambOoxX marked this pull request as draft October 5, 2024 19:04
Copy link

codecov bot commented Oct 5, 2024

Codecov Report

Attention: Patch coverage is 0% with 64 lines in your changes missing coverage. Please review.

Project coverage is 88.49%. Comparing base (f1503bc) to head (fd53c55).
Report is 20 commits behind head on master.

Files with missing lines Patch % Lines
ext/MakieExt/plot.jl 0.00% 64 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #181      +/-   ##
==========================================
- Coverage   88.69%   88.49%   -0.21%     
==========================================
  Files          65       66       +1     
  Lines        9460     9515      +55     
==========================================
+ Hits         8391     8420      +29     
- Misses       1069     1095      +26     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


function GLMakie.convert_arguments(::PointBased, contres::AbstractBranchResult, vars = nothing, applytoY = identity, applytoX = identity)
function Makie.convert_arguments(::PointBased, contres::AbstractBranchResult, vars=nothing, applytoY=identity, applytoX=identity)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My coding style is to have spaces around =

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, sorry about that, I hit auto indent and forgot to check it. I just don't know yet in vscode how to change the formatting settings. Would you know ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really

vars = nothing,
linewidthunstable = 1.0,
linewidthstable = 3.0linewidthunstable,
plotcirclesbif = true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My coding style is to have spaces around =

@rveltz
Copy link
Member

rveltz commented Oct 6, 2024

Wow, thank you for this new PR!!

One issue I found is that the following does not work

function TMvf!(dz, z, p, t = 0)
    (;J, α, E0, τ, τD, τF, U0) = p
    E, x, u = z
    SS0 = J * u * x * E + E0
    SS1 = α * log(1 + exp(SS0 / α))
    dz[1] = (-E + SS1) / τ
    dz[2] = (1.0 - x) / τD - u * x * E
    dz[3] = (U0 - u) / τF +  U0 * (1 - u) * E
    dz
end

par_tm = (α = 1.5, τ = 0.013, J = 3.07, E0 = -2.0, τD = 0.200, U0 = 0.3, τF = 1.5, τS = 0.007)
z0 = [0.238616, 0.982747, 0.367876 ]
prob = BifurcationProblem(TMvf!, z0, par_tm, (@optic _.E0); record_from_solution = (x, p; k...) -> (E = x[1], x = x[2], u = x[3]),)

opts_br = ContinuationPar(p_min = -10.0, p_max = 1., dsmax = 0.1, n_inversion = 8, nev = 3)
br = continuation(prob, PALC(tangent = Bordered()), opts_br; plot = false, normC = norminf, bothside = true)

BK.plot(br, plotfold=false)
####################################################################################################
br_fold = BK.continuation(br, 2, (@optic _.α), ContinuationPar(br.contparams, p_min = 0.2, p_max = 5.), bothside = true)
BK.plot(br_fold)

@BambOoxX
Copy link
Contributor Author

BambOoxX commented Oct 6, 2024

br_fold = BK.continuation(br, 2, (@optic _.α), ContinuationPar(br.contparams, p_min = 0.2, p_max = 5.), bothside = true)
BK.plot(br_fold)

This works on latest.

@rveltz
Copy link
Member

rveltz commented Oct 6, 2024

Yep but this one is broken now :(

# test vector field for event detection
function Feve(X, p)
	p1, p2, k = p
	x, y = X
	out = similar(X)
	out[1] = p1 + x - y - x^k/k
	out[2] = p1 + y + x - 2y^k/k
	out
end

# parameters for the vector field
par = (p1 = -3., p2 = -3., k = 3)

# bifurcation problem
prob = BifurcationProblem(Feve, -2ones(2), par, (@optic _.p1);
	record_from_solution = (x, p; k...) -> x[1])

# parameters for the continuation
opts = ContinuationPar(max_steps = 150, p_min = -3., p_max = 4.0,
    # we disable bifurcation detection to focus
    # on the user passed events
    detect_bifurcation = 0, detect_fold = false,
    # parameters specific to event detection
    detect_event = 2)
# arguments for continuation
args = (prob, PALC(), opts)
kwargs = (plot = false, verbosity = 0,)
br = continuation(args...; kwargs...,)
BK.plot(br)


br = continuation(args...; kwargs...,
	event = SaveAtEvent((-2.,-1.); use_newton = true))

BK.plot(br)

@BambOoxX
Copy link
Contributor Author

BambOoxX commented Oct 6, 2024

It should be okay now, it was because empty indices were not handled properly. Now any edge case should be okay. Although I can't test everything easily, sorry.

@rveltz rveltz marked this pull request as ready for review October 6, 2024 13:55
@rveltz
Copy link
Member

rveltz commented Oct 6, 2024

Do you think it is good for merging?
I have tried deflated continuation, diagram and codim2, it seems to work well with CairoMakie

@BambOoxX
Copy link
Contributor Author

BambOoxX commented Oct 6, 2024

At this point, I think it works. The only question is if there are other uses of line widths I did not meet during my tests. It's really the only problem I met with CairoMakie.
Also, I was thinking about a function capable of altering the backend set_plot_backend!(::AbstracPlotBackend) so that people could switch between Makie and Plots upon request.
Do you want me to add a commit with that before merging ?

@rveltz
Copy link
Member

rveltz commented Oct 6, 2024

yes if you have a working solution, that would be awesome.
Thank you a lot for your work, it's really improved BK.

The Makie backend is slower than the Plots one during continuation. I think the Makie backend should rely on observables in that case but that's another issue.

@BambOoxX
Copy link
Contributor Author

BambOoxX commented Oct 6, 2024

yes if you have a working solution, that would be awesome.

So actually, it doesn't exactly require set_plot_backend!, BK.plot will plot with Makie backends and Plots.plot with Plots backend, although it would be better to have BK.plot work for all backends.

Thank you a lot for your work, it's really improved BK.

Thanks, but compared to all the difficult math stuff, this is very easy ;).

The Makie backend is slower than the Plots one during continuation. I think the Makie backend should rely on observables in that case but that's another issue.

Yep I could work on that if you have examples that show the problem.

@rveltz
Copy link
Member

rveltz commented Oct 6, 2024

Yep I could work on that if you have examples that show the problem.

Not really, when trying both backend on a simple example, I came to this subjective observation

@rveltz
Copy link
Member

rveltz commented Oct 6, 2024

You might also be interested by https://github.com/gszep/BifurcationExplorer.jl

@rveltz rveltz merged commit c773565 into bifurcationkit:master Oct 6, 2024
1 of 2 checks passed
@BambOoxX BambOoxX deleted the support-makie-backends branch October 6, 2024 15:16
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.

Allow using other Makie backends
2 participants