Skip to content

feat(tuning_tools): first-turn trajectory correction tool - #1

Merged
thellert merged 2 commits into
apgfrom
feat/trajectory-tool-apg
Oct 16, 2026
Merged

thellert merged 2 commits into
apgfrom
feat/trajectory-tool-apg

Conversation

@thellert

Copy link
Copy Markdown

What

Adds pyaml.tuning_tools.trajectory.Trajectory, a first-turn trajectory correction tool ported from the ALS MATLAB threading code (SCgetPinv / calcCMstep order).

  • One joint H/V solve through a Tikhonov-regularised SVD inverse with tail discard, a rank guard, and exact-zero rows for dead corrector columns.
  • Threading by beam reach: every corrector downstream of the last BPM with beam is zeroed, per plane.
  • A closed Reason verdict on every step (NO_BEAM … OK).
  • A pure calculator: it reads no BPM and writes no corrector. The caller applies the returned step.

Proof

tests/tuning_tools/test_trajectory.py runs 494 tests. 156 of them compare against goldens frozen from MATLAB R2026a over the 19-case table in trajectory_cases.json. The golden tests skip with a reason when trajectory_goldens.npz is absent; a file named through PYAML_TRAJECTORY_GOLDENS is required.

Scope

This lands on apg only. The tool stays on the fork until it has threaded beam on the ALS-U accumulator ring; the upstream pyAML PR follows after that. No PyPI release is cut for it yet; consumers pin the merged commit by git ref.

Relation to the existing Orbit tool: the RM data type, loader pattern, registration and per-call overrides follow Orbit. The inverse is its own (pySC's build_pseudoinverse does not expose Tikhonov with tail discard, which MATLAB parity needs). The RM validation duplicates what an upstream RM primitive should own and is a candidate to drop when one lands.

pyAML had no tool for steering the beam through the first turn, when only
the BPMs upstream of the loss point see a trajectory and an orbit
correction cannot be applied.

Trajectory is a tuning tool built from a trajectory response matrix
(OrbitResponseMatrixData file, mapping or instance) plus default alpha,
n_discard and gain. It validates the matrix once on load and publishes its
facts as a read-only layout. pseudo_inverse() returns the Tikhonov- and
truncation-regularised pseudo-inverse, and correct() returns one frozen
corrector step that zeroes the correctors downstream of the last BPM with
beam, plane by plane, together with a Reason saying why it did so. It
reads no hardware.

The test module checks the tool against goldens frozen from the ALS MATLAB
sources (SCgetPinv.m and SCexp_ALS_calcCMstep.m) run in MATLAB
26.1.0.3276743 (R2026a) Update 3 on appsdev2.als.lbl.gov, over the 19
cases in trajectory_cases.json:

  trajectory_goldens.npz  a00777fa45100b887c515ffee265dc641d128b7d1f01972cda42733aece62fef
  trajectory_cases.json   5c98dfb1e64e6d303aa38069d0b56fde2fd364573117813831e9cff72e0243be
  SCgetPinv.m             e35239d6c5cafae8477adfdbccfba6d7c3d65d48d11c3a581de7fbc768575d1f
  calcCMstep.m            592b1a6cf05f7f5889f7b20aac26945ce80c3673e2d581563ac5a9e65a167f78
  MATLAB driver           df9cc13c5986a1922616619f6aefc4488fea4865da0567b6dd3f0d65c908341f

Set PYAML_TRAJECTORY_GOLDENS to test against another goldens file; tests
that need the goldens carry "golden" in their name.
A checkout without tests/tuning_tools/trajectory_goldens.npz now skips the
156 golden tests with a reason instead of erroring, so the module runs on a
tree that does not ship the binary. A file named through
PYAML_TRAJECTORY_GOLDENS stays required: a wrong path still errors.
@thellert
thellert merged commit f4eadfa into apg Oct 16, 2026
4 checks passed
@thellert
thellert deleted the feat/trajectory-tool-apg branch October 16, 2026 19:35

This branch was successfully deployed

1 active deployment
pypi — f4eadfae Deployed Oct 16, 2026 by thellert via deploy #2
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.

1 participant