accelmo.poco.workers.closed_twiss

Closed-twiss observables and their weighted least-squares blocks.

One closed-orbit engine solve (ClosedOrbitEngine) gives the periodic closed orbit, beta, alpha, phase and dispersion at every BPM and their knob derivatives; ClosedOrbitWorker fits them.

accelmo.poco.workers.closed_twiss.ORBIT_COORDS = ('x', 'px', 'y', 'py')

Observables that are phase-space coordinates rather than optical functions.

class accelmo.poco.workers.closed_twiss.ObservableKind(*values)[source]

Bases: StrEnum

How a per-BPM observable is turned into a residual.

POINTWISE

The model value at each BPM is compared directly against the measurement: closed orbit, beta, alpha, dispersion.

ADVANCE

Consecutive BPM values are differenced first, so a cumulative model quantity is compared against a measured advance. Used for phase, where only the BPM-to-BPM advance is measurable and the absolute value carries an arbitrary origin.

POINTWISE = 'pointwise'
ADVANCE = 'advance'
accelmo.poco.workers.closed_twiss.OBSERVABLE_KINDS: dict[str, ObservableKind] = {'alfx': ObservableKind.POINTWISE, 'alfy': ObservableKind.POINTWISE, 'betx': ObservableKind.POINTWISE, 'bety': ObservableKind.POINTWISE, 'dpx': ObservableKind.POINTWISE, 'dpy': ObservableKind.POINTWISE, 'dx': ObservableKind.POINTWISE, 'dy': ObservableKind.POINTWISE, 'mu1': ObservableKind.ADVANCE, 'mu2': ObservableKind.ADVANCE, 'px': ObservableKind.POINTWISE, 'py': ObservableKind.POINTWISE, 'x': ObservableKind.POINTWISE, 'y': ObservableKind.POINTWISE}

Observables the MAD-NG side knows how to evaluate on the closed twiss, mapped to how their residual is formed. Names are gphys.optfun function names, except the closed-orbit coordinates which are read off the map’s constant part.

betx/bety/alfx/alfy are the coupled Edwards-Teng/physical-plane projections, requested via coupling=true on the twiss{} call in run_closed_twiss_init.mad. They are computed live as part of that twiss (the beam is attached throughout), not read back off a bare saved map afterward – only the orbit coordinates (x/y/px/py, via ORBIT_COORDS) take that route, for their knob Jacobian. Never use the uncoupled Ripken beta11/beta22/alfa11/alfa22 columns here: under real coupling their mode/plane identity is not guaranteed to track x/y, so they are not comparable to an omc3 BETX/ALFX measurement by name coincidence alone.

mu1/mu2 stay mode-indexed: MAD-NG has no mux/muy optical function at all (confirmed against its own name list – only mu/dmu with a mode-index suffix exist), so there is no physical-plane phase-advance column to request in the first place.

dx/dy are d(x)/d(pt) and d(y)/d(pt) - the MAD-X DX convention. dpx/dpy are available but should normally be left out when fitting omc3 output: omc3 derives its DPY from DY through the model transfer matrix, so including both double-counts one measurement.

class accelmo.poco.workers.closed_twiss.Observable(name, targets, variances)[source]

Bases: object

One measured observable family, aligned to the series’ bpm_names.

targets and variances have one entry per BPM for a POINTWISE observable and one per interval (n_bpms - 1) for an ADVANCE one. A non-finite or non-positive variance drops that point from the fit, which is how partially-measured planes are handled without special-casing.

Parameters:
  • name (str)

  • targets (numpy.ndarray)

  • variances (numpy.ndarray)

name: str
targets: ndarray
variances: ndarray
property kind: ObservableKind

Residual form for this observable.

accelmo.poco.workers.closed_twiss.align_observables(observables, measured_index, twiss_names, *, worker_id)[source]

Align observable targets and weights to the model BPM ordering.

Parameters:
  • measured_index (dict[str, int])

  • twiss_names (list[str])

  • worker_id (int)

accelmo.poco.workers.closed_twiss.weighted_chi2(model, targets, weights)[source]

Chi² of the inverse-variance weighted residuals of every orbit observable block.

Return type:

float

Parameters:

model (numpy.ndarray)

accelmo.poco.workers.closed_twiss.weighted_least_squares(model, jacobian, observables, targets, weights)[source]

(gradient, chi², JᵀWJ) of the inverse-variance weighted residuals of every observable block.

Return type:

tuple[ndarray, float, ndarray]

Parameters:
  • model (numpy.ndarray)

  • jacobian (numpy.ndarray)