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

Eigenmode viewer hooks #180

Merged
merged 5 commits into from
Oct 26, 2023
Merged

Conversation

Lazersmoke
Copy link
Contributor

This includes all helper functions and hooks needed to make the eigenmode viewer work.

@Lazersmoke
Copy link
Contributor Author

(since this is getting merged first, we'll see how the diff between main and asymmetric looks afterwards and proceed from there)

(also note this includes plot_band_intensities which is used in un-exported form by the eigenmode viewer)

@kbarros kbarros force-pushed the eigenmode-viewer-hooks branch from d5ae01d to b012b5e Compare October 26, 2023 16:51
@kbarros
Copy link
Member

kbarros commented Oct 26, 2023

I pushed some updates:

  • Now colors can also be animated using colorfn argument.
  • The dipoles to be animated can no longer be detached from sys.dipoles. To support that use case, use clone_system. The memory costs will probably be much less than all the GLMakie objects anyway.
  • The result of plot_spins is an object that supports both display and notify. This way users don't see observables.

Why not expose Makie Observables? Ultimately, that interface is not a nice abstraction for complicated objects with interior mutability. Later, for example, notify(fig) might animate other things besides the dipoles and colors, and users will get it automatically. I tried to make color an Observable following Makie conventions, but the code ended up being much less clean (both on the Sunny side, and the user interface side). I think the final result here is very nice to use. See, e.g., the new Heisenberg animation example: https://github.com/Lazersmoke/Sunny.jl/blob/eigenmode-viewer-hooks/examples/extra/heisenberg_animation.jl

@Lazersmoke
Copy link
Contributor Author

This will be very slow because it empties the whole array of points and dipole vectors and then rebuilds it on every single frame. The point of having spin_data be separate is that it is fast to redraw (and modular to notify, unlike NotifiableFigure).

If this is the way that you want this in main Sunny, that's fine, and I'll write my own viewer function in SunnyContributed :)

@kbarros kbarros merged commit 0dfc4ce into SunnySuite:main Oct 26, 2023
2 checks passed
@kbarros
Copy link
Member

kbarros commented Oct 26, 2023 via email

@kbarros
Copy link
Member

kbarros commented Oct 26, 2023

Following discussion on Slack and various benchmarks, it appears that this implementation is getting about maximal speed. In particular, Makie is intelligent in ignoring extra notifications if the data hasn't changed. That is, these extra notifications don't matter.

notify.((vecs, pts, pts_shifted, arrowcolor))

For a system with 10k spins, I get these results for one notify

[COLORS ON]  0.012429 seconds (141.15 k allocations: 6.590 MiB)
[COLORS OFF] 0.009867 seconds (81.16 k allocations: 4.759 MiB)

This is much slower than I like, but I think the slowdown is fundamentally on the Makie side. Note the speedup we get if the arrowcolor data is unchanged, even though we spuriously notify(arrowcolor).

Another important thing to know is that this pattern is non-allocating:

function f(a)
    l = length(a)
    empty!(a)
    for i in 1:l
        push!(a, 42)
    end
end

r = randn(10)

using BenchmarkTools
@btime f(r)

In particular, empty! will not actually free the underlying data -- it will be saved for future use. To actually free, you would need something like size_hint!.

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.

2 participants