Skip to content

Analysis - FEATURE - Redraw every Analysis plot with Makie, loaded as a package extension - #658

Merged
matt-pharr merged 41 commits into
developfrom
feature/analysis-plots-overhaul
Nov 26, 2026
Merged

matt-pharr merged 41 commits into
developfrom
feature/analysis-plots-overhaul

Conversation

@matt-pharr

@matt-pharr matt-pharr commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Release note

  • Audience: users
  • Numerical impact: none (harness @ 9880101)
  • Migration: Load a Makie backend before plotting (using CairoMakie to save files, using GLMakie for interactive windows); without one, a plot call throws and says so. Plots return a Makie Figure instead of a Plots.Plot, and Plots and PlotlyJS are no longer dependencies. plot_fixed_boundary_stability_criterion is now plot_critical_determinant, and plot_gse_by_theta and plot_gse_integrated are one plot_gse(gse) that takes Equilibrium.equilibrium_gse!'s result; the gse.h5 reader is removed, so the residual is plotted from memory only. Plots no longer pass extra keywords to the plotting library: plot_coil_geometry_3d, plot_coil_geometry_rz, plot_mode_spectrum, plot_bn_contour, plot_edge_stability_scan and plot_surface_3d now reject them. Keywords removed: zoom from plot_cond_fbar, ylims from plot_edge_stability_scan, camera and colorbar_title from plot_surface_3d (which gains label). Keywords replaced: plot_energy_eigenvectors takes nmodes instead of matrix_type, plot_dominant_mode_spectrum takes modes=1:3 instead of mode, and plot_surface_overlay takes top instead of levels. Defaults changed: plot_eigenvalues draws matrix_type=:all (was :total), and plot_mode_displacement draws the six largest harmonics (modes=nothing, was 1:5). Outside plotting, RMPField now checks its source when it is built: a missing or malformed forcing file, a non-integer n or m in an ASCII mode table, an unknown normalization, or a coil set without geometry or currents throws an ArgumentError at construction instead of when the perturbed equilibrium runs.

Overhaul and visual polish of the existing plots. Guidance on when to add a standard plot and when not to (mostly to prevent AI agents from running wild adding superfluous junk). Both interactive/zoomable and panable plots and can be saved to pdf or png in a script. Replaced Plotly library with Makie which is generally the more polished and julia-y option.

The goal of this PR is to make sure all the main plots that were widely used from the OMFIT module are included in some easily accessible form, that diagnosing a run is relatively easy from the REPL, and that the plots that we see are roughly of publication quality. That means that we cannot have anything be difficult to read, look like a first-pass plot, or have overlapping text. This must be balanced by making sure the included plots are not too busy and do not look like vibe code output.

We also add guidance on when to add a plot. All plots to be added as standard plots must be viewed as mockups by a human before an AI adds them, to avoid our standard plots becoming polluted by random one-off plots from rogue claude sessions. AI agents should not propose new plots to the standard plots unless making an entirely new module, or unless they are requested to consider new plots. New plots should be added sparingly otherwise the available_plots() function will become crowded and lose its usefulness.

Regression report

develop @ b11dfb244 against feature/analysis-plots-overhaul @ 9880101a7 (fan-out on ITER's SDCC cluster, Julia 1.12.6): 28 cases, 389 quantities, all unchanged. Each branch ran under its own pinned manifest, since this PR replaces Plots with Makie and neither branch loads under the other's package set; the report compares the two sets of cached runs.

Per-case report
ccc_ray_q5i                  4 unchanged
diiid_error_field            10 unchanged
diiid_kinetic_multi_n        8 unchanged
diiid_multi_n                19 unchanged
diiid_n1                     53 unchanged
diiid_n1_riccati             17 unchanged
diiid_n1_riccati_precompiled 17 unchanged
diiid_slayer_n1              22 unchanged
diiid_slayer_n1_chi_perp_e   22 unchanged
diiid_slayer_n1_coupled      7 unchanged
diiid_slayer_n1_toroidal     5 unchanged
diiid_slayer_n1_winding      22 unchanged
diiid_truncation_n1          12 unchanged
efit_fixedbdy_separatrix     5 unchanged
gal_resistive_diiid          11 unchanged
gal_resistive_diiid_galinner 11 unchanged
ggj_ray_q500i                4 unchanged
ggj_reference                4 unchanged
lar_ggj_tearing_n1           3 unchanged
lar_reversed_shear_n1        22 unchanged
solovev_kinetic_nuzero       14 unchanged
solovev_multi_n              15 unchanged
solovev_n1                   22 unchanged
tj_kinetic_calculated        20 unchanged
tj_kinetic_multiion          6 unchanged
tj_kinetic_ntv               7 unchanged
tj_kinetic_ntv_rates         2 unchanged
tj_n1                        25 unchanged

Plot registry, before and after

34 registered plots before, 42 after, by module

Equilibrium

Plot In #650's registry What it draws
plot_equilibrium_summary ✓ flux surfaces and profiles
plot_qprofile ✓ q against ψ_N with the rational surfaces
plot_pressure_profile ✓ μ₀p against ψ_N
plot_f_profile ✓ 2πF against ψ_N
plot_flux_surfaces ✓ flux surfaces and θ spokes in (R, Z)
plot_gse_by_theta merged into plot_gse(gse) (unregistered) Grad-Shafranov error against ψ_N per θ slice
plot_gse_integrated merged into plot_gse(gse) (unregistered) flux-surface-integrated Grad-Shafranov error

ForceFreeStates

Plot In #650's registry What it draws
plot_ffs_summary ✓ the stability panels the run supplies
plot_critical_determinant renamed from plot_fixed_boundary_stability_criterion critical determinant against ψ_N
plot_eigenvalues ✓ free-boundary energy eigenvalues
plot_mode_displacement ✓ |ξ^ψ_m| of the least stable mode
plot_energy_eigenvectors ✓ free-boundary energy eigenvectors per m
plot_edge_stability_scan ✓ edge energies against the truncation q
plot_delta_prime ✓ Δ′ matrix between rational surfaces
plot_delta_prime_raw new raw outer-region matching matrix D′
plot_delta_coil new Δ_coil: surface response to each edge harmonic
plot_cond_fbar ✓ cond(F̄) scan for kinetic singular surfaces
plot_ballooning_alpha_boundary ✓ ballooning α against its first stability boundary

PerturbedEquilibrium

Plot In #650's registry What it draws
plot_perturbed_equilibrium_summary ✓ resonant field, edge b̄^ψ spectrum, ξ^ψ spectrogram and b_n on the poloidal plane
plot_resonant_area_weighted_field ✓ resonant coupling rows per rational surface
plot_resonant_area_weighted_field_amplitude ✓ |b̄_res| per rational surface
plot_island_widths ✓ island half-width per rational surface
plot_chirikov_parameter ✓ effective island-overlap Chirikov parameter per rational surface
plot_driven_delta_prime ✓ forcing-driven Δ′ per rational surface
plot_mode_spectrogram ✓ response harmonics against ψ_N (component = :xi_psi, :b_psi, :Jb_theta, :Jb_zeta)
plot_dominant_mode_surface new a dominant resonant-coupling mode as b_n on the control surface
plot_singular_mode_rz new dominant resonant-coupling modes as b_n on the control-surface cross-section
plot_coupling_matrix new resonant coupling matrix |C| with its singular values and left and right singular vectors
plot_perturbed_field_rz new b_n or ξ_n on the poloidal plane (deform = true for the displaced boundary)
plot_effective_islands new island chains from the effective resonant flux
plot_islands new island chains from the penetrated field

CoilForcing

Plot In #650's registry What it draws
plot_bn_contour existed, now registered applied b_n on the control surface (coils = true for the coils)
plot_coil_geometry_3d ✓ 3D coils and plasma boundary
plot_coil_geometry_rz ✓ coils over the plasma boundary in (R, Z)
plot_mode_spectrum ✓ |Φ_x(m, n)| forcing spectrum
plot_sources new the coil sources in 3D, coloured by current or by set

ErrorFields

Plot In #650's registry What it draws
plot_error_field_summary ✓ overlap against the threshold, locking risk and coil sensitivities
plot_coil_sensitivities ✓ per-coil dominant-mode sensitivities
plot_overlap_phasors ✓ as-designed overlap δ of each coil set in the complex plane
plot_linearity_residuals ✓ linearity residuals of the coil sensitivities
plot_dominant_mode_spectrum ✓ spectra of the dominant resonant-coupling modes
plot_tolerance_pdf ✓ Monte Carlo distribution of |δ|
plot_threshold_scaling ✓ |δ| distribution against the threshold's CDF
plot_locking_risk ✓ locking risk against tolerance scale

Notes for reviewers

🤖 Generated with Claude Code

…gure theme and a plots CI group

Makie becomes a weak dependency with the GPECMakieExt extension, which holds the figure theme, the label
helpers and saving with whichever backend is loaded. Analysis._draw is the entry point ported plots use; it
throws an ArgumentError naming `using CairoMakie` or `using GLMakie` when no backend is loaded. The plot tests
move to a new `plots` group whose CI job stacks a CairoMakie environment onto LOAD_PATH, so Makie stays out of
the package's own dependencies; changes under ext/ now trigger the test workflow.
…d add the control-surface, (R, Z) and island views
@matt-pharr
matt-pharr requested a review from logan-nc November 6, 2026 10:05
@matt-pharr matt-pharr self-assigned this Nov 6, 2026
@matt-pharr
matt-pharr changed the base branch from develop to feature/analysis-result-plots November 6, 2026 16:24
@matt-pharr
matt-pharr added this pull request to stack #651 November 6, 2026 16:24

@logan-nc logan-nc left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@matt-pharr — nothing pushed. I reviewed the structure, the API surface and the tests from the source; I did not render the figures here (no Makie backend on this machine), so nothing below is a judgment of how they look beyond the four PNGs in the docs.

Structure

  • Data extraction in src/Analysis, drawing in ext/GPECMakieExt, and a plain ArgumentError when no backend is loaded: this is the right split, and it takes Plots and PlotlyJS out of every user's load time.
  • benchmarks/ still does using Plots in at least five scripts (benchmark_against_fortran_run.jl, equil_spline_comparison.jl, benchmark_diiid_ideal_ntv_torque.jl, benchmark_q_vs_iota_edge.jl, plot_grid_knot_placement.jl, …), and Plots is no longer in Project.toml. They now run only where Plots happens to be in the global environment. Port them, or say so in docs/development/benchmarking.md.
  • Loading GPEC changes the user's own Makie figures. __init__ calls set_texfont_family! on the session-wide MathTeXEngine, so every LaTeX string in the session switches face once the extension loads. Set it inside themed() and restore it afterwards, as the theme itself is scoped.
  • using Makie without a backend sets _BACKEND[] = true, so the helpful error is skipped and the failure comes from inside Makie. Test Makie.current_backend() at draw time instead of a flag set at load.
  • src/ForcingTerms/ForcingTerms.jl changes behavior outside plotting: RMPField constructors now validate eagerly, the ASCII reader rejects non-integer n, m rows, and the coil-set constructor takes new argument forms. That is fine, but it is not in the release note and "Numerical impact: none" hides that a malformed forcing file now fails at construction. Add a line to Migration.

Interface changes not in the release note

The Migration line names two renames. The diff also has:

Function Change
plot_cond_fbar zoom removed
plot_edge_stability_scan ylims and kwargs... removed
plot_eigenvalues default matrix_type :total → :all
plot_energy_eigenvectors matrix_type replaced by nmodes
plot_mode_displacement default modes 1:5 → nothing
plot_dominant_mode_spectrum mode::Int → modes=1:3
plot_surface_overlay levels → top
plot_surface_3d camera, colorbar_title, kwargs... removed; label added
plot_coil_geometry_3d/rz, plot_mode_spectrum, plot_bn_contour kwargs... pass-through removed
plot_gse_by_theta, plot_gse_integrated replaced by plot_gse(gse), in memory only
  • Any analysis script that passed Plots keywords through kwargs... (titles, limits, sizes) now gets a MethodError. List these in Migration, and put the ! on the title's tag, since the interface changes.
  • The Grad-Shafranov residual can no longer be plotted from a saved run. #650 made "result or gpec.h5 path" the contract for every plot, and this PR removes the only reader of gse.h5 along with the :gse_files capability. Is that intended? If the sidecar files are going away, say so; if not, keep a path method.

Publication figures

The body sets "roughly publication quality" as the goal. Three things fall short of what we need for papers and slides:

  • The theme is sans-serif (Makie default, TeXGyreHeros for math) at regular weight. Journals set Times; our paper figures use bold serif.
  • Figure sizes are in pixels (820×440, 900×560, …), not at a print width, so 15 pt labels come out at an arbitrary size once the figure is scaled to a 3.4 in column.
  • save_path writes one file. A paper needs the PDF and slides need a PNG of the same figure.

I am not asking to change the default look for REPL diagnosis. A second theme (themed(; paper=true) or GPEC_PAPER_THEME: serif bold, widths 3.4 / 5.0 / 7.0 in at 10 pt) and a save_path without extension writing both formats would cover it. Your call whether here or as a follow-up.

Tests

  • julia --project=. test/runtests.jl with no group now includes the plot files, which using CairoMakie from the global environment. On a machine without it the full suite fails at load. Skip the plots group with a printed reason when CairoMakie cannot be loaded, and add the requirement to the test commands in CLAUDE.md.
  • CI adds CairoMakie to a temporary environment on JULIA_LOAD_PATH rather than declaring it under [extras]/[targets]. That works for runtests.jl but not for Pkg.test, which is how a missing dependency is normally caught; note it next to the workflow step.
  • Most draw checks are isa Figure. The stronger ones (stairs padding, axis scales, line counts) are good; the summaries would benefit from one check each on which panels were drawn.

Docs

  • Four PNGs (2.0 MB, pe_summary.png alone 0.96 MB) are committed and regenerated by hand. They will go stale silently. Either build them in the docs job, or record the generating commit in docs/src/figures/manifest.toml so staleness is visible.
  • The rule in plotting.md that agents do not add plots without a human asking is a good one.

No merge without approval from a human reviewer. This comment is not an approval.

Comment thread src/Analysis/ErrorFields.jl Outdated
displacements rather than at the step, see [`plot_linearity_check`](@ref).
Plot how linear each coil set's field is in its rigid motions: for the six taps (shift and tilt about `x`, `y`, `z`)
the ratio of the central second difference to the largest first difference among the set's taps, as stored in
`ErrorFields/CoilSensitivities/*_linearity_residual`. `at = :step` shows it at the finite-difference steps; `at = :tolerance` rescales each tap by `tolerance / step` to the coil's own tolerance range. Tolerances come from the file's

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

232 characters; the margin is 180.

Suggested change
`ErrorFields/CoilSensitivities/*_linearity_residual`. `at = :step` shows it at the finite-difference steps; `at = :tolerance` rescales each tap by `tolerance / step` to the coil's own tolerance range. Tolerances come from the file's
`ErrorFields/CoilSensitivities/*_linearity_residual`. `at = :step` shows it at the finite-difference steps;
`at = :tolerance` rescales each tap by `tolerance / step` to the coil's own tolerance range. Tolerances come from the file's

@matt-pharr

matt-pharr commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator Author

@logan-nc for your claude, these are my opinions:

  • the intention is for all plotting to happen through gpec.h5 or the output structs. The GSE sidecar was a relic, and I was not particularly interested in adding a new field to gpec.h5 in this PR since we are avoiding changing the physics interface here (hence no ! in PR title). We can add GSE to gpec.h5 but my perspective was that would constitute a larger change than just removing gse.h5 altogether. So it is up to you if we want to add gse to gpec.h5, and if/when we do that can be plotted from a saved run.
  • "publication quality" was labeled "roughly" because these figures are not intended to be immediately usable in publication. The main purpose of the analysis suite is to serve someone who is actively using the code; style parameters can be set by the user when making publication figures if they so desire. This applies to both the figure size (which the user will typically display on a hi dpi display while working) and the font, which is subjective and not enforced serif in plasma physics journals in my experience. All of my own published figures have been in bold or unbold DejaVu Sans. And I do not want to overengineer something for the save path. I will look into adding a second theme and a save path if it is easy and idiomatic but this is definitely follow up territory.
  • I will look into your first two test bullets but I disagree with going super hard on figure tests... seems like a prime source for pointless AI code that nobody will look at. I may go one step further than current and just make sure that each panel is not empty if that is easy.
  • The rule in plotting.md was very intentional because I do not want agents to add random plots willy nilly like we have had with benchmarks. Plots are only to be added as standard, committed, in-repo plots when explicitly brought up by a human, I do not even want agents suggesting users "do you want to make this a new standard plot?" because the temptation to let that get out of hand will be great lol.

Edits as described above will follow.

@logan-nc

logan-nc commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

the intention is for all plotting to happen through gpec.h5. The GSE sidecar was a relic, and I was not particularly interested in adding a new field to gpec.h5 in this PR since we are avoiding changing the physics interface here (hence no ! in PR title). We can add GSE to gpec.h5 but my perspective was that would constitute a larger change than just removing gse.h5 altogether. So it is up to you if we want to add gse to gpec.h5, and if/when we do that can be plotted from a saved run.

Ok. then lets make an issue that gse needs to go into gpec.h5. My original vision was for all outputs to be contained in ONE h5 - a reaction to fortran's sprawling file io. These "sidecars" slipped through in the v2.0 release rush and should all be cleaned up.

"publication quality" was labeled "roughly" because these figures are not intended to be immediately usable in publication. The main purpose of the analysis suite is to serve someone who is actively using the code; style parameters can be set by the user when making publication figures if they so desire. This applies to both the figure size (which the user will typically display on a hi dpi display while working) and the font, which is subjective and not enforced serif in plasma physics journals in my experience. All of my own published figures have been in bold or unbold DejaVu Sans. And I do not want to overengineer something for the save path. I will look into adding a second theme and a save path if it is easy and idiomatic but this is definitely follow up territory.

My claude was very proactive there and picked up my personal claude.md matplotlib style guidance. Sarifs were a reaction to Freddie changing the CFRC slide template to that after a slack poll. The idea of a theme comes from a good place though - I hate having to tell every student/user their fonts are too small on slides. I do feel like a primary purpose of any plot is to be able to convey information to both the plotter and the wider community the plotter needs to show their work to. As such, I do hereby formally humanly request larger fonts. Look at this one (squint to pretend you have old eyes that never used sunglasses enough as a kid like mine):

image

I will look into your first two test bullets but I disagree with going super hard on figure tests... seems like a prime source for pointless AI code that nobody will look at. I may go one step further than current and just make sure that each panel is not empty if that is easy.
I agree with not going hard on tests - I think the review items were just to get the dependencies robustly sorted, which seems good to do.

@matt-pharr

Copy link
Copy Markdown
Collaborator Author

@logan-nc changes since your review:

  • Larger text: every figure is now laid out on a canvas 1/1.35 of its old size, so text, lines and markers are 35% larger relative to the figure, about 9 pt when a single panel is printed 5 inches wide. Harmonic and eigenmode axes tick on whole numbers, and surface labels no longer collide.
  • using Makie without a backend now gets the helpful error; the backend is checked at draw time.
  • A full test run skips the plots group with a warning when CairoMakie is missing, and CLAUDE.md says how to install it.
  • Migration note: lists every keyword removed, replaced or re-defaulted, the gse.h5 reader removal, and the RMPField construction checks.
  • GSE in gpec.h5: Equilibrium - FEATURE - Write the Grad-Shafranov residual to gpec.h5 instead of gse.h5 #684.
  • benchmarks/: benchmarking.md names the seven scripts that still draw with Plots; porting them is separate.
  • Docs figures: manifest.toml already records the generating commit of each; regenerated at the current head.
  • Docstring line: rewrapped.
  • Not changed: the session-wide math font, and no per-panel checks in the summary tests.

@matt-pharr
matt-pharr requested a review from logan-nc November 20, 2026 15:39
Base automatically changed from feature/analysis-result-plots to develop November 23, 2026 15:52
@matt-pharr matt-pharr linked an issue Nov 23, 2026 that may be closed by this pull request
@jhalpern30

Copy link
Copy Markdown
Collaborator

@matt-pharr I'll take a look at this soon, but I think the best test for it will be post merge when I create the perturbed fields PR chain, which will require adding new plots to Analysis and I can give direct feedback on how easy it is to conform new plots to this standard.

Also, I found this way funnier than it probably should have been
image

@matt-pharr

Copy link
Copy Markdown
Collaborator Author

@jhalpern30 lmao. And yeah it is ok if feedback on this is more big picture, we can adjust plots as things go, but the riccati overhaul PR is blocked on this one so I would like to get this one merged so that can make it into develop soon.

@matt-pharr
matt-pharr removed this pull request from stack #680 November 24, 2026 18:25
@matt-pharr
matt-pharr added this pull request to stack #690 November 24, 2026 18:25
@matt-pharr
matt-pharr added this pull request to the merge queue Nov 26, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Nov 26, 2026
@matt-pharr
matt-pharr added this pull request to the merge queue Nov 26, 2026
@matt-pharr
matt-pharr removed this pull request from the merge queue due to a manual request Nov 26, 2026
@matt-pharr
matt-pharr merged commit 8298701 into develop Nov 26, 2026
21 of 22 checks passed
@matt-pharr
matt-pharr deleted the feature/analysis-plots-overhaul branch November 26, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New capability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Analysis UX: smoke-test every plot in CI to prevent staleness

3 participants