Repository navigation
Performance: Midpoint Spin Push for Thin Kicks - #4
Merged
cemitch99 merged 1 commit intoAug 12, 2026
Merged
Conversation
Evaluate the Thomas-BMT generator once, at the momentum halfway through the kick, instead of applying two half rotations around the phase space kick. This is the structure already used by TaperedPL. Both forms are exactly reversible and second order: the reversed element maps p_out back to p_in, so it sees the same midpoint, and the negated strength gives the inverse rotation. They differ at third order, where the midpoint rule has half the error constant of the trapezoidal rule that two half kicks amount to. Per particle this costs 1 tbmt_precession_vector + 1 rotate_spin instead of 2 of each. Measured on the thin Multipole, which has the same structure, that was ~28% off the spin push (~39% of the spin-specific part) and 2x smaller error against a converged reference. Applies to Kicker, Buncher, NonlinearLens and ThinDipole, whose fields depend only on coordinates the kick leaves unchanged. Buncher also changes the energy deviation, so pt is averaged along with the transverse momenta. ShortRF keeps the half kick form: it changes the reference energy, so px/py/pt are renormalized across the kick and a plain average would mix two normalizations. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
7 tasks done
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.
Evaluate the Thomas-BMT generator once, at the momentum halfway through the kick, instead of applying two half rotations around the phase space kick. This is the structure already used by
TaperedPL.Reversibility is preserved exactly. The reversed element maps
p_outback top_in, so it sees the same midpoint, and the negated strength gives the inverse rotation. Roundtrip residual stays at round-off for all four elements (≤ 2.7e-16 either way).Accuracy improves by 2x. Both forms are second order; they differ at third order, where the midpoint rule has half the error constant of the trapezoidal rule that two half kicks amount to. Error against a converged reference:
KickerBuncherNonlinearLensThinDipoleThe reference applies each element N times at strength/N. These kicks depend only on coordinates the kick leaves unchanged, so the N-fold product reproduces the identical phase space result (
|dp| < 9e-16) while the spin resolves N substeps, making N->inf an exact reference for the same impulse. Converged at N=1e4.ThinDipolesits above 2x because its+hframe-rotation term is momentum-independent and contributes no error to either scheme.It is also cheaper, at 1
tbmt_precession_vector+ 1rotate_spinper particle instead of 2 of each:KickerBuncherNonlinearLensThinDipole"spin-only part" subtracts the
[nospin]time of the same element.NonlinearLensgains least in total because itsF'(zeta)evaluation dominates and is unaffected.Applies to
Kicker,Buncher,NonlinearLensandThinDipole, whose fields depend only on coordinates the kick leaves unchanged.Buncheralso changes the energy deviation, soptis averaged along with the transverse momenta.ShortRFkeeps the half kick form: it changes the reference energy, sopx/py/ptare renormalized across the kick and a plain average would mix two normalizations.Measured locally (GCC, OMP, SIMD, double, 1M particles, min of 3, ~4% run-to-run spread), not CodSpeed. Error numbers are at 100x the benchmark-file element strengths, chosen so the difference is resolvable — at nominal strengths it falls below the reference round-off floor and is irrelevant in practice.