Repository navigation
Share the compiled solve across VMEC Tracings - #230
Merged
Merged
Conversation
The axis-regular vector field was a new closure per Tracing, so the static key never matched and every VMEC trace recompiled. Make it a comparable callable, and make Vmec a pytree (coefficient tables as leaves, mode numbers and counts static) so Vmec fields with the same shapes share it.
eduardolneto
approved these changes
Nov 13, 2026
eduardolneto
left a comment
Contributor
There was a problem hiding this comment.
Makes axis_regular condition a pytree for optimization.Should be merged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR #213's cache never hit for VMEC guiding centers:
_axis_regularreturned a new closure for every Tracing, so the static part of the key differed each time andjit(solve)was rebuilt (3 backend compiles per steady call, 0 recompiles in the coil case). AlsoVmecwas an opaque leaf compared by identity, so a second Vmec with the same shapes could not share the compile, and an in-place edit silently reused stale coefficients.Changes:
_axis_regularreturns a small callable that compares equal when the wrapped vector field is the same (dynamics.py).Vmecis a pytree: coefficient tables are leaves, nfp/ns/mpol/ntor and the mode-number tables (read concretely by_radial_interp) are static (fields.py).Measured, gc_vmec, 500 ARIES-CS alphas, interleaved A/B x3 on one A4000 (steady, 3 reps each): recompiles per steady call 3 -> 0; first call 12.7-13.3 s -> about 20 s on the first run after the fix (the solve now compiles as one unit; same compile cost is paid once per process, not per call); steady 8.4 s median -> 8.3 s. So the steady wall time is kernel-bound; the win is the removed retracing/compiles, not a large speed-up. 142 tests in test_dynamics.py and test_fields.py pass.
Overlap: #207 and #209 also edit essos/dynamics.py; this touches only
_axis_regular(about 15 lines), so conflicts should be small.