Skip to content

Performance: Midpoint Spin Push for Thin Kicks - #4

Merged
cemitch99 merged 1 commit into
cemitch99:spin_push_thin_kicksfrom
ax3l:thin_kick_spin_midpoint
Aug 12, 2026
Merged

cemitch99 merged 1 commit into
cemitch99:spin_push_thin_kicksfrom
ax3l:thin_kick_spin_midpoint

Conversation

@ax3l

@ax3l ax3l commented Aug 12, 2026 •

Copy link
Copy Markdown

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_out back to p_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:

element half kicks midpoint ratio
Kicker 3.215e-03 1.597e-03 2.01x
Buncher 5.694e-12 2.753e-12 2.07x
NonlinearLens 2.260e-07 1.130e-07 2.00x
ThinDipole 2.430e-07 1.005e-07 2.42x

The 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. ThinDipole sits above 2x because its +h frame-rotation term is momentum-independent and contributes no error to either scheme.

It is also cheaper, at 1 tbmt_precession_vector + 1 rotate_spin per particle instead of 2 of each:

element half kicks midpoint spin push spin-only part
Kicker 7.77 ms 4.91 ms -37% -43%
Buncher 7.54 ms 5.05 ms -33% -43%
NonlinearLens 11.90 ms 9.21 ms -23% -37%
ThinDipole 3.98 ms 2.86 ms -28% -43%

"spin-only part" subtracts the [nospin] time of the same element. NonlinearLens gains least in total because its F'(zeta) evaluation dominates and is unaffected.

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.

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.

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>

@cemitch99 cemitch99 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks.

@cemitch99
cemitch99 merged commit 0c24f29 into cemitch99:spin_push_thin_kicks Aug 12, 2026
@ax3l
ax3l deleted the thin_kick_spin_midpoint branch August 12, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants