Skip to content

Extend plot support for entanglementplot and transferplot to Makie.jl - #428

Open
borisdevos wants to merge 33 commits into
mainfrom
bd/plotting
Open

borisdevos wants to merge 33 commits into
mainfrom
bd/plotting

Conversation

@borisdevos

Copy link
Copy Markdown
Member

Deals with #249. This works locally, below I attach the results for both Plots.jl and CairoMakie.jl*. I didn't really test any other Makie backend, but I think CairoMakie is the one you want anyways in this context.

As you can see in the attachment, I didn't really bother to make the Plots.jl plots any prettier than they were, and they remain equally blurry. Anyone willing to prettify these, feel free to do so. I put slightly more effort in the Makie plots, but even there plenty of improvements can be added.

I added todo's here and there, mostly stylistic choices.

*There are two plots per function, just to show that keyword arguments are being taken correctly:

# gs is the ground-state of the Ising Hamiltonian at g = 0.1
entanglementplot(gs)
entanglementplot(gs, expand_symmetry = true, sortby = maximum, sector_formatter = c -> "Sector $c")

transferplot(gs)
transferplot(gs; sectors = [Z2Irrep(0), Z2Irrep(1)], transferkwargs = (; num_vals = 1))

someplots.pdf

@lkdvos lkdvos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This definitely looks great!
I have a couple questions, mostly since it has been a while since I looked at Makie:

Do you know if the other attributes can still be set/changed? For example, what happens if I want to override the default title/ticks/...?

I seem to recall also that there was some system with observables etc, where various parts where dynamically recalculated. Do you know if this is still relevant?

Comment thread test/Project.toml Outdated
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
BlockTensorKit = "5f87ffc2-9cf1-4a46-8172-465d160bd8cd"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should probably be a weakdep?

Comment thread Project.toml Outdated
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
HalfIntegers = "f0d1745a-41c9-11e9-1dd9-e5d34d218721"
KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this make sense to have as a default dependency? We could in principle also have a default xlabel that uses Unicode, and require people that wish Latex strings to specify the xlabel themselves (which I would assume people typically want anyways)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

At least for Makie I could keep the default latexstring expressions and put it as a weakdep, since it's explicitly in the deps of Makie. I put it here in deps to get it working for Plots, but we can indeed default to whatever and let the user overwrite themselves (if possible for Plots, I think I've got it working for Makie right now)

@borisdevos

Copy link
Copy Markdown
Member Author
entspec_makie_plotkwargs transpec_makie_plotkwargs

I just tried some random keyword arguments for the Makie plots, and they seem to work. I'll test tomorrow if I can do the same for Plots.
(Also I realised I was running Z2-symmetric MPS in the Z2 SSB phase 🫠)

@borisdevos

Copy link
Copy Markdown
Member Author

I don't understand the current aqua test failing. It seems to be complaining about missing compat bounds for every package under extras of the main project.toml (but are specified in the test project.toml), but this previously wasn't failing.

Comment thread Project.toml Outdated
@codecov

codecov Bot commented May 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.86957% with 44 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ext/MPSKitMakieExt.jl 82.05% 28 Missing ⚠️
ext/MPSKitPlotsExt.jl 78.37% 16 Missing ⚠️
Files with missing lines Coverage Δ
src/MPSKit.jl 100.00% <ø> (ø)
ext/MPSKitPlotsExt.jl 78.37% <78.37%> (ø)
ext/MPSKitMakieExt.jl 82.05% <82.05%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@borisdevos

Copy link
Copy Markdown
Member Author

Okay, I finally managed to look into this again. I'm happy with how things are in terms of being able to use these backends with some customisation. What remains is some stylistic decisions. In particular, I don't know how useful it is to plot transfer matrix spectra the way we are now. These phases don't matter in many cases, so if we allow some toggle to not plot them, there's then a way to plot the different sectors next to each other, similar to the current entanglement plots.

Some other style choices are in todos, though I'm sure there are many more.

Comment thread test/runtests.jl
Comment thread Project.toml Outdated
Comment thread ext/MPSKitMakieExt.jl Outdated
Comment on lines +11 to +30
#TODO: remove once the recipes publish their axis attributes instead of setting them
function with_current_axis(f, target)
target isa Makie.AbstractAxis || return f()
previous = Makie.current_axis()
Makie.current_axis!(target)
try
return f()
finally
isnothing(previous) || Makie.current_axis!(previous)
end
end

# overwrite user-provided axis attributes
function apply_plotkwargs!(ax, plotkwargs)
ax isa Makie.AbstractAxis || return ax
for (k, v) in pairs(plotkwargs)
setproperty!(ax, k, v)
end
return ax
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks a little backwards, I feel like it should be possible to make the attributes respect what was provided, and somehow it feels like we are doing too much work with providing ticks etc, for which there should just be a default that is sensible and otherwise user-overridable?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

So this part of the code exists to deal with the in-place versions of the plot functions, but you want these things to be attributes of the default?

The workaround here was because some of the default attributes I set are of the axis, and not of the scatter plot itself. I looked at the whole ComputeGraph machinery you once mentioned to me, and I think that's exactly you want. I'll try this out

Comment thread ext/MPSKitMakieExt.jl Outdated
Comment thread ext/MPSKitMakieExt.jl Outdated
Comment thread ext/MPSKitMakieExt.jl Outdated

ax.ylabel = L"\log(\lambda)"
ax.ylabelsize = 24
smallest = minimum(Iterators.filter(>(0), Iterators.flatten(spectrum)); init = 1.0) # safety net

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this mean that we are effectively hiding pathological cases? Do you think there is a way of still showing them so we can diagnose the issue?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can filter on ==0, give a warning but still plot the way it is currently?

This branch has not been deployed

No deployments
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