Repository navigation
Fused Biot-Savart B and dB/dx in one coil pass - #233
Open
rogeriojorge wants to merge 7 commits into
Open
rogeriojorge wants to merge 7 commits into
rogeriojorge wants to merge 7 commits into
Conversation
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.
The guiding-centre RHS now gets B and dB/dx from one pass over the coil filaments (analytic per-segment gradient, dB_i/dx_j = mu0 I/4pi sum [(dl x e_j)_i/r^3 - 3 (dl x r)_i r_j/r^5], accumulated in the same checkpointed scan step) instead of a forward-mode Jacobian of B.
BiotSavart.gc_quantitiesanddB_by_dXuse it; other fields fall back to jacfwd through a genericB_and_dB_by_dX. The chunk ismin(chunk, n_coils), so a set smaller than a chunk runs as a single step without a scan.Tests: dB/dx equals jacfwd(B) to 1e-12, tr(dB/dx) = 0 and curl B = 0 off the coils, and a loss through
gc_quantitieshas the same coil gradient as the old jacfwd path. test_fields, test_dynamics and test_objective_functions pass.GPU (RTX A4000, x64,
jax.profilertrace, summed GPU kernel time of one run; the office host was shared, so wall times were too noisy to compare and are not used).gc_coilsis 1000 guiding-centre markers on the LandremanPaulQA coils,fo_coils100 full-orbit protons (B only):The kernel writes 1/sqrt(r2)3 instead of r2-1.5, which was 30% slower for B alone on the A4000 (320 ms in fo_coils); the concatenated 15-channel sum and the checkpoint in the scan step cost nothing measurable. Candidates that were profiled and not kept: component-wise (no trailing axis of 3) layout, no checkpoint, dense sum without scan, and the #208 expression for B only. B, dB/dx and
gc_quantitiesagree with main to 1e-15 relative (x64, 2048 points).CPU (office, 8 pinned cores, loaded, gc_coils steady time, s): main 3.4 to 4.6, #208 7.4 to 10, this PR 6.5. On this machine the scan is slower than main on CPU; the memory reduction is unchanged.