Repository navigation
Analysis - FEATURE! - Plot from a result or a gpec.h5 path and list the available plots - #650
Conversation
|
@logan-nc this is PR 2/3 of my overhaul of how users interact with outputs. It allows for the Analysis library to do plotting through either a saved gpec.h5 file like before, or through an in-memory result object obtained by running one of our modules. This means you are able to do something like |
…he available plots
…es instead of a MethodError
2d7718c to
8f40f6a
Compare
There was a problem hiding this comment.
@matt-pharr — nothing pushed. I read this together with #658 (Makie plots), which rewrites most of the drawing code here, so I only raise what survives to #658's head. The ErrorFields "No … data" placeholders that remain at this head, for example, are gone there and need no work here.
Structure
- One extractor per source feeding one drawing body, with a registry that says what a run must change, is a good design, and
available_plotson a result is a real usability gain. - A capability is tested on one dataset but the extractor reads several.
:singular_couplingchecksresonant_area_weighted_field;_coupling_data(h5path)then readsresonant_current,island_half_width,chirikov_parameter,Delta_prime, …, and the writer (PerturbedEquilibrium/Utils.jl:126-138) drops each of those separately when empty. A file that has the first but lacks another passes_requireand then fails with an HDF5KeyError, which is the failure this PR set out to remove. The same holds for:edge_scan(checkspsi, readsqand the energies) and:ballooning_scan. Either let a capability name every dataset its extractors read, or have the extractors raise the registry reason on a missing key. - The two capability records can drift.
capabilities(result)and_H5_CAPABILITIESare separate lists kept in step by hand; the test checks one direction only (caps ∩ path_needs ⊆ capabilities(h5)). Checking equality on the fixture, for the capabilities both sides can hold, would catch a predicate that goes stale. _loadforErrorFieldstakesfd_step_shift_m/fd_step_tilt_degfrom the control in memory, but from the recorded deck, falling back to theErrorFieldsControl()defaults, in a file. Does a run made through the API with non-default steps then label its linearity plot differently from memory and from file? If so the steps belong in theErrorFieldsoutput group.
Tests
- The "same data from both sources" check covers seven extractors. Not covered:
_profile_dataand_geometry_data(five equilibrium plots),_eigenvalue_data,_ballooning_data, and the Galerkin branches of_mode_displacement_dataand_delta_prime_data. The first four are one tuple each in theextractorslist. - The draw checks assert only that a plot object comes back, so the extractor comparison is the whole evidence that both sources draw the same thing; that makes the gap above worth closing.
plot_counts(ret.ffs) == (11, 13)will need editing every time a plot is registered (it already changes in #658).ok <= n && n == count(registered for this type)says the same without the constants.
Merge order
- #650 → #658 → #676 (Riccati overhaul) → #666 are stacked. Since #658 replaces most of the drawing code added here, I would rather approve the pair together than polish this one alone: fix the items above on whichever of the two branches still holds the code.
No merge without approval from a human reviewer. This comment is not an approval.
| function _plots_row(io, x) | ||
| ok, n = Analysis.plot_counts(x) | ||
| n == 0 || _row(io, "Plots", "$ok of $n available (see available_plots)") | ||
| return nothing | ||
| end |
There was a problem hiding this comment.
show now runs every capabilities predicate, so one that throws on an unusual result (a nothing field, say) takes the whole REPL summary down with it. The plots row is the least important line of the summary; let it drop out instead.
| function _plots_row(io, x) | |
| ok, n = Analysis.plot_counts(x) | |
| n == 0 || _row(io, "Plots", "$ok of $n available (see available_plots)") | |
| return nothing | |
| end | |
| function _plots_row(io, x) | |
| # A failing capability predicate must not break the summary this row is appended to. | |
| ok, n = try | |
| Analysis.plot_counts(x) | |
| catch | |
| return nothing | |
| end | |
| n == 0 || _row(io, "Plots", "$ok of $n available (see available_plots)") | |
| return nothing | |
| end |
|
@logan-nc thanks. #658 rewrites most of this, so the fixes are there and the two merge as a pair.
|
Release note
ArgumentErrornaming what to change in the run, instead of drawing a "No … data" placeholder, returningnothingor warning (plot_cond_fbar,plot_gse_by_thetaandplot_gse_integratedused to returnnothingwithout their data).plot_delta_primeplots the Δ′ matrix of a Riccati or Galerkin solve, so it throws on Forward results.available_plots(r)shows beforehand what a result can draw.Every Analysis plot now takes the result in memory as well as the path of the
gpec.h5it was saved to:plot_ffs_summary(ffs)works likeplot_ffs_summary("gpec.h5").available_plots(r)lists the plots for a result, a file, or the named tuplemainreturns, with what to change for each one the run cannot draw; a Riccati run, for example, offers no solution-profile plot and says why.What changed
src/Analysis/Registry.jl): each plot registers the sources it takes and the capabilities it needs.capabilities(src)is the single record of what a result or file holds, andREASONSgives one sentence per capability saying what to change in the run.available_plotsis exported at the top level._require, which throws the registry's reason. The FFS, PE and ErrorFields summaries skip the panels a run cannot supply and throw only when no panel can be drawn.plot_delta_primeplots the diagonal Δ′_ii of the inter-surface Δ′ matrix from a Riccati or Galerkin solve, which is what the REPL summary shows. It used to plot a per-surface estimate from the asymptotic coefficients, whichOdeState's docstring calls a stub that is not physically valid.ErrorFieldsResult, and the coil-forcing plots (plot_coil_geometry_3d,plot_coil_geometry_rz,plot_mode_spectrum) aPerturbedEquilibriumState.PlasmaEquilibrium,LocalStabilityResult,ForceFreeStatesResult,PerturbedEquilibriumStateandErrorFieldsResultend with aPlots k of n available (see available_plots)row.docs/src/api.mdhas a new "Plotting a result" section anddocs/src/analysis.mddocuments the registry.CLAUDE.mdsays how to add a plot, a capability and a summary row.examples/Solovev_ideal_example/analyze_example.jlplots results in memory, which also fixes its reference to an undefinedp_pe.Example:
available_plotson a Riccati resultRegression report
develop @ 4463e6fbcagainstfeature/analysis-result-plots @ eaeb1625e(fan-out on ITER's SDCC cluster, Julia 1.12.6, pinned manifest): 28 cases, 389 quantities, all unchanged.Per-case report
Tests on ITER's SDCC cluster at b8c6526 plus the 2d7718c fix: analysis plots 207/207, ForceFreeStatesResult 280/280, solve API 182/182, error fields 397/397, Tearing 166/166.
Notes for reviewers
errors in place of placeholder plots, and the result summaries with plot availability. Its
GPECResultwrapper andplot(result, :name)were dropped by design: the typed stage results arethe objects, every plot takes one or a
gpec.h5path, andavailable_plotslists real function names._plot_x(data)functions. A follow-up plots-overhaul PR will restyle them and addplot(r)/plot!(p, r)overlay recipes; this PR leaves them alone so that work is not done twice.test/runtests_analysis_plots.jlruns a Forward run with coil forcing, PE and local stability, a Riccati run and a kinetic run. For every registered plot it checks that the plot has a method for each source it declares, reads the same data from the result and the file, and draws from both or throws the registry's reason from both.test/runtests_error_fields.jldoes the same forErrorFieldsResult, andtest/display_check.jlchecks the summaries' Plots row is present exactly when the type has registered plots.componentandmatrix_typechecks now throwArgumentErrorinstead ofErrorException.🤖 Generated with Claude Code