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:
StrEnumHow a per-BPM observable is turned into a residual.
POINTWISEThe model value at each BPM is compared directly against the measurement: closed orbit, beta, alpha, dispersion.
ADVANCEConsecutive 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.optfunfunction names, except the closed-orbit coordinates which are read off the map’s constant part.betx/bety/alfx/alfyare the coupled Edwards-Teng/physical-plane projections, requested viacoupling=trueon thetwiss{}call inrun_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, viaORBIT_COORDS) take that route, for their knob Jacobian. Never use the uncoupled Ripkenbeta11/beta22/alfa11/alfa22columns here: under real coupling their mode/plane identity is not guaranteed to track x/y, so they are not comparable to an omc3BETX/ALFXmeasurement by name coincidence alone.mu1/mu2stay mode-indexed: MAD-NG has nomux/muyoptical function at all (confirmed against its own name list – onlymu/dmuwith a mode-index suffix exist), so there is no physical-plane phase-advance column to request in the first place.dx/dyared(x)/d(pt)andd(y)/d(pt)- the MAD-XDXconvention.dpx/dpyare available but should normally be left out when fitting omc3 output: omc3 derives itsDPYfromDYthrough the model transfer matrix, so including both double-counts one measurement.
- class accelmo.poco.workers.closed_twiss.Observable(name, targets, variances)[source]¶
Bases:
objectOne measured observable family, aligned to the series’
bpm_names.targetsandvarianceshave one entry per BPM for aPOINTWISEobservable and one per interval (n_bpms - 1) for anADVANCEone. 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)