Repository navigation
Fix winding-surface optimization example - #66
rogeriojorge wants to merge 42 commits into
Conversation
c846c00 to
659ae6b
Compare
|
@dseidita1919 Doing my own tests, to see if a couple things might help:
|
88a1dc1 to
659ae6b
Compare
|
The resolved comparison is now included in the PR under examples/winding_surface_comparison. Main findings:
Resolved sheet and filament metrics: Resolved current potentials and coil contours: Resolved winding surfaces and coils: The remaining figures and CSV tables are in the same folder. |
|
Added the requested Pareto definition and current-complexity comparison. For each trial surface, the inner problems are with The outer objective minimizes the mean normalized The new figure compares For QA, the Pareto surface has essentially the same complexity as the normal offset: The dimensional |
|
Added a second, additive study with eight coils per half field period. The original ten-coil results are unchanged. The new study also adds Landreman-Paul QH. Main results from the independent 96x96 validation:
Resolved metrics: Current potential and coil contours: Winding surfaces and coils: The reproducible driver, CSV tables, complexity plot, convergence plot, and remaining figures are in |
|
@dseidita1919 I tested a simpler entropy formulation on QA, QH and QI. The full-torus induction matrix contains several Bloch sectors, but a field-periodic plasma and repeated coil set use only the symmetric sector: This changes the calculation from With eight coils per half field period, relative to the normal-offset surface:
A simple stage-1 use would be:
Fixing The main gain is a smaller and faster objective with consistent improvement in cut-coil maximum |
|
@dseidita1919 Four-coil follow-up. The winding surfaces and current-potential solutions are unchanged; only the extracted contours are reduced from eight to four coils per half field period. This isolates the sparse-coil realization. Actual independently evaluated filament maximum
The symmetric objective changes maximum Resolved current potential; white contours are the coil cuts: Resulting coils: Winding surfaces and coils: Symmetric entropy remains almost identical to full-sector entropy while using one SVD. It reduces the worst pointwise error in all three cases; integrated |
|
@dseidita1919 Last idea from these tests: keep the SVD solve, but make the surface objective know how many coils will be cut. “Finite-coil SVD” refers to the combination below; the SVD acts on the current-sheet operator. 1. Current-normalized SVD solve. For current-potential coefficients Let Substituting the SVD and defining Setting its derivative to zero gives The factor 2. Error from cutting contours. The continuous potential gives Its normal-field error is A shift of the first contour changes the phase The first term is the continuous-sheet error. The second estimates the added error from replacing that sheet by All surfaces below were re-solved with REGCOIL at 96x96, with the same
On the same QA surface, ESSOS, REGCOIL and QUADCOIL give max Advantages: one physical field-error objective, explicit coil-count dependence, differentiable, and usually 1-2 s for the surface solve. Limits: leading-harmonic and equal-current approximation; omitted coil clearance, forces and ports; and 21.5 s spent in QH L-BFGS-B line searches. The absolute four-coil errors are still 0.11-0.18. A subsequent ESSOS filament run can refine these coils, with the added cost of weights and several initial conditions. The minimal runnable example is |
…ds testing to see if it leads to improved current density or other metrics.
…wplasma/ESSOS into rj/winding-surface-proxy-fixes
…VD/entropy surrogate Represents the winding surface's current potential as a truncated Fourier series (mpol=ntor=6, matching the REGCOIL validation basis) instead of dipole strengths at grid points, as an alternative to the existing "ESSOS entropy" method in winding_surface_comparison_8_coils. Benchmarked against the tracked comparison study's own methodology (48x48, 48/56/64, and 96x96 REGCOIL validation) across all three PR cases. Not integrated into winding_surface_comparison_8_coils.py's SURFACE_METHODS (that file's SURFACE_METHODS-keyed color maps/bar-chart offsets are a known footgun); this is a self-contained script that reuses its helper functions directly, so every metric is defined identically to the tracked study. Same-machine result (96x96 sheet fB): beats the dipole "ESSOS entropy" method on all three cases (26% / 32% / 6% lower for QA / QH / W7-X), at 2-9x the optimization wall-time (still <20s absolute). While reproducing baselines, found winding_surface_comparison_8_coils/data/ and winding_surface_comparison/data/'s W7-X rows for "normal offset" and "ESSOS entropy" are stale (predate an unpromoted Sep 4 output/ cache update, not a cross-machine difference -- fresh reruns here match that cache to machine precision). Documented in the new README; not fixed here since it's an independent, pre-existing gap. Also adds a memory-watchdog pattern (RSS-based polling, not resource.setrlimit(RLIMIT_AS, ...) which fires on JAX/XLA's virtual-memory reservations long before real memory pressure exists) for running REGCOIL-touching steps safely on this machine's 12 GB WSL ceiling. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Fourier-coefficient induction matrix: a new SVD/entropy surrogate variantThis adds an alternative to Not folded into Result (96×96, sheet fB — dipole entropy vs. the new Fourier method, both freshly rerun on the same machine)
The Fourier method beats the dipole entropy method it's meant to replace on all three cases. It costs more wall-time per optimization (2–9× dipole entropy: 2.4s/8.0s/19.4s vs. 1.0s/1.3s/2.1s for QA/QH/W7-X), but stays well under 20s absolute. Resolution stability (48/56/64) is comparable to or better than the dipole method's own (see figures).
|
…tion change fourier_induction_matrix took 2-9x longer to optimize than the dipole "ESSOS entropy" method it's meant to replace. A follow-up investigation profiled it (per-iteration matrix construction dominated, not one-time JIT compilation) and found two resolution-independent, machine-precision-exact optimizations: 1. nfp-fold periodicity reduction: the Fourier basis functions sin(m*theta - n*nfp*phi) are exactly periodic (xn is always a multiple of nfp), so only one field period of plasma/winding points is needed, and the kernel contribution from all nfp copies of each winding point can be summed before contracting with the potential basis rather than after -- an O(nfp^2) -> O(nfp) reduction in the dominant cost. 2. dipole_kernel_matmul: algebraically identical to ws.dipole_kernel, but uses the |a-b|^2 = |a|^2 - 2a.b + |b|^2 identity to replace a (P,Q,3) pairwise-difference tensor with four (P,3)@(3,Q) BLAS matrix multiplications. Verified end to end: identical L-BFGS-B iteration/evaluation counts on all three PR cases (same optimizer path), sheet fB matching the pre-optimization version to 13-14 significant figures at both 48x48 and 96x96. Speedups: QA 1.80x (2.37s -> 1.32s), QH 4.30x (8.04s -> 1.87s), W7-X 5.33x (19.37s -> 3.63s). float32 and eigvalsh-on-the-Gram-matrix alternatives were tried and rejected: eigvalsh produces NaN gradients from the near-degenerate tail of the singular-value spectrum, and float32 corrupts that tail by ~9 orders of magnitude for a smaller win than the two changes above -- see the new "Performance" section in winding_surface_fourier_comparison/README.md. Also fills in the resolution-convergence data that the memory watchdog had previously aborted for W7-X and Landreman-Paul QH (freed machine memory allowed 4 of 5 missing points to complete this session); documents that W7-X's "normal offset" resolution-64 point consistently needs more memory than this machine currently has available, in unmodified, shared build_operators code -- not something this change introduces. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
… comment, add v2
The unsuffixed fourier_comparison_{validation_96,resolution_convergence,
optimization_cost}.png are referenced by branch-relative URL from the first
PR comment (#66, issuecomment-5736019555), which is already
posted. The previous commit overwrote them in place with the post-speedup
(v2) data, so that comment's embedded images silently started showing
already-optimized numbers instead of what it actually describes.
Restores those three files to the pre-optimization (v1) data -- verified
byte-identical to what was originally committed -- and adds
"_v2"-suffixed copies with the current, now-more-complete data (after
retrying the previously-memory-aborted resolution-64 points; only W7-X's
"normal offset" row still doesn't fit in available memory after four
attempts). A follow-up PR comment should reference the "_v2" figures plus
the existing fourier_v1_vs_v2_*.png performance comparison.
winding_surface_fourier_comparison_plots.py's main() now takes an optional
data_dir/figures_dir/suffix so both datasets render from the same plotting
code instead of duplicating it.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Following up on the Fourier-coefficient induction matrix comment above: the first working version cost 2–9× the dipole method's optimization wall-time. This is a performance-only follow-up — same method, same accuracy, same resolutions throughout, no new modeling assumptions. 1.8–5.3× faster, verified bit-for-bit on the physicsProfiling showed the per-iteration induction-matrix construction dominated (not one-time JIT compilation). Two resolution-independent, machine-precision-exact changes to
Verified end to end: identical L-BFGS-B iteration and evaluation counts on all three cases (the optimizer takes the exact same path, just faster), sheet fB matching the pre-optimization version to 13–14 significant figures at both 48×48 and 96×96.
Two other candidates were tried and rejected: swapping the SVD for Updated "vs other methods" comparison (same numbers as before, now cheaper to produce)
These are the same physical numbers as the comment above — the point of this follow-up is the runtime column, not new results. (Full writeup, including why two sets of figures now live side by side in the repo — the comment above embeds the original ones by URL, so they're frozen rather than overwritten — is in Also: resolution-convergence data is more complete nowFreeing some background memory on this machine let 4 of the 5 previously-watchdog-aborted resolution-64 points complete (Landreman-Paul QH's Fourier-method point, and W7-X's dipole-entropy and Fourier-entropy points). W7-X's |
The step that crosses the LCFS ends outside the |B| and profile tables, where the spline extrapolation can return a meaningless |B|. Its end point was kept as the held state and its energy error entered energy_error. Saved states now hold the last interior state; the exterior end point and its energy error are reported separately in terminal_states and terminal_energy_error (NaN unless lost). Loss and failure classification is unchanged. Fixes #115
…n' into rj/winding-surface-proxy-fixes
Keep Boozer splines continuous and avoid duplicate m=0 storage
Boozer tracer: keep exterior terminal step out of interior diagnostics





























This updates the winding-surface optimization example and adds a resolved comparison with REGCOIL and QUADCOIL.
Corrections
close=Falseto exclude duplicate periodic endpoints4*pi^2normalizationESSOS peak-current Pareto objective
For every trial winding surface, ESSOS solves the regularized current-potential problem at three nearby peak-current limits:
where
and$K_i=(0.95,1.00,1.05)K_{\mathrm{target}}$ . The winding surface minimizes
The three samples cover a short section of the trade-off between$f_B$ and $K_{\max}$ and reduce sensitivity to one regularization value. The geometry term preserves volume, controls the Fourier spectrum, retains at least 90% of the initial plasma clearance, and penalizes small Jacobian or nonlocal self-approach. The result is a local three-point approximation to the Pareto curve.
The optimization uses 32 points per angle per field period. Surface motion is capped at 2% of the plasma minor radius per active Fourier coefficient.
Results
For the included QA example at 7 MA/m, a separate 96x96 REGCOIL evaluation gives:
At 10 MA/m, the Pareto surface reduces resolved sheet fB by 27.6% relative to the normal offset for QA and by 88.2% for W7-X. W7-X filament fB is reduced by 88.1%. The QA filament result worsens despite its improved sheet result, which limits the coil-improvement result to W7-X in this comparison.
The current-complexity comparison uses the same$f_K$ as the inner regularization. Relative to the normal offset, ESSOS Pareto changes $f_K$ by +0.24% for QA and +22.2% for W7-X. W7-X RMS current increases from 2.208 to 2.432 MA/m while both surfaces satisfy the same 10 MA/m peak limit. The field-error improvement therefore has a visible current-complexity cost.
The driver, numerical tables, all figures, and detailed notes are under
examples/winding_surface_comparison/. The W7-X QUADCOIL solves are labeled failed after exceeding the convergence limit.Eight-coil study
An additive study under
examples/winding_surface_comparison_8_coils/repeats the comparison with eight coils per half field period and adds Landreman-Paul QH. At 96x96, the QH Pareto iterate reduces sheet fB by 75.1% and filament fB by 73.6% relative to the normal offset. The QA case shows the limitation clearly: its sheet result improves, but filament fB is 15.7% worse with the reduced coil count. The QH Pareto outer solve stopped on a line-search failure, so it is reported as a valid non-converged iterate.