accelmo.poco.calibration

Measure map for BPM gain and corrector kick calibration in closed-orbit fits.

A measured orbit change is the model’s change at the kick nominal + (1 + g_corrector) * delta (the corrector calibration acts on the kick put into the lattice), scaled per BPM and plane by (1 + b) (a readout error). The corrector kick is a parameter of the MAD-NG damap, so d(orbit)/d(kick) is exact and the orbit’s nonlinearity in the kick is kept; the BPM gains are linear scalings and their columns are analytic. BPM gain columns are one-hot (one column per BPM and plane), so the normal matrix is block-structured and the BPM gains are eliminated by a Schur complement (schur_step()) instead of carrying a dense matrix.

Parameter blocks: u = (q, g) (magnet knobs then corrector gains, dense) and b (BPM gains, diagonal Hessian).

accelmo.poco.calibration.corrector_gain_name(corrector)[source]

Fit-parameter name of the gain of corrector.

Return type:

str

Parameters:

corrector (str)

accelmo.poco.calibration.corrector_gain_knob_name(corrector)[source]

Model knob (constant part 0) added to a corrector’s 1 + g, so its Jacobian column is d(orbit)/d(g).

Return type:

str

Parameters:

corrector (str)

class accelmo.poco.calibration.CalibrationSpec(bpms, correctors, kick_prefix='k_')[source]

Bases: object

Global gain layout shared by every series: BPM names (both planes), corrector names and the kick globals’ prefix.

Parameters:
  • bpms (tuple[str, ...])

  • correctors (tuple[str, ...])

  • kick_prefix (str)

bpms: tuple[str, ...]
correctors: tuple[str, ...]
kick_prefix: str = 'k_'

A corrector’s kick global is <kick_prefix><corrector> (case-insensitive), e.g. k_dhz2l4.

corrector_of(global_name)[source]

The upper-case corrector a kick global belongs to, or None if global_name is not a kick.

Return type:

str | None

Parameters:

global_name (str)

class accelmo.poco.calibration.CalibrationBlocks(n_q, n_g, n_b, buffer=None, *, zero=True)[source]

Bases: object

Summed loss, gradient and Gauss-Newton Hessian blocks (2 JᵀWJ convention, unnormalised).

Parameters:
  • n_q (int)

  • n_g (int)

  • n_b (int)

  • zero (bool)

ARRAYS = ('grad_u', 'hess_uu', 'hess_ub', 'hess_bb', 'grad_b')
grad_u: ndarray
hess_uu: ndarray
hess_ub: ndarray
hess_bb: ndarray
grad_b: ndarray
classmethod shapes(n_q, n_g, n_b)[source]

Array shape of each block.

Return type:

dict[str, tuple[int, ...]]

Parameters:
  • n_q (int)

  • n_g (int)

  • n_b (int)

classmethod nbytes(n_q, n_g, n_b)[source]

Size in bytes of all blocks.

Return type:

int

Parameters:
  • n_q (int)

  • n_g (int)

  • n_b (int)

add(other)[source]

Add other to these blocks.

Return type:

None

Parameters:

other (CalibrationBlocks)

to_payload()[source]

The scalars; the arrays travel through shared memory (a pickle would copy ~170 MB twice).

Return type:

dict

symmetrise()[source]

Mirror the upper triangle of the magnet-knob block, which add_series() fills alone, onto the lower one.

Return type:

None

accelmo.poco.calibration.add_series(blocks, model, jacobian, d_gain, targets, weights, bpm_gain, bpm_cols, corrector_indices)[source]

Add one series’ contribution.

The magnet-knob block of hess_uu gets its upper triangle only; call CalibrationBlocks.symmetrise() once all series are in.

model is the orbit change with every corrector kick scaled by 1 + g (reference subtracted) and jacobian its quad derivatives; d_gain[..., j] is its derivative with respect to the gain of corrector corrector_indices[j]. Only the BPM gains scale the model: (1 + b) * model against the target.

Return type:

None

Parameters:
  • blocks (CalibrationBlocks)

  • model (numpy.ndarray)

  • jacobian (numpy.ndarray)

  • d_gain (numpy.ndarray)

  • bpm_gain (numpy.ndarray)

  • bpm_cols (numpy.ndarray)

  • corrector_indices (list[int])

accelmo.poco.calibration.apply_prior(blocks, u, b, sigma_g, sigma_b, sigma_q=None, *, zero_mean=None, loss_only=False)[source]

Gaussian priors g²/σ_g², b²/σ_b² and q²/σ_q² added to the chi² blocks.

sigma_q holds one absolute width per magnet knob (the knob’s units); an entry of 0 leaves that knob free. loss_only adds the priors to blocks.loss alone (blocks then needs only loss and n_q): a loss-only trial evaluation has no gradient or Hessian blocks. zero_mean (indices into g) holds the mean of those gains at 0 with width ZERO_MEAN_SIGMA.

Parameters:
  • blocks (CalibrationBlocks)

  • u (np.ndarray)

  • b (np.ndarray)

  • sigma_g (float)

  • sigma_b (float)

  • sigma_q (np.ndarray | None)

  • zero_mean (np.ndarray | None)

  • loss_only (bool)

accelmo.poco.calibration.reduce_blocks(blocks)[source]

Schur complement over b: reduced (gradient, Hessian) of u.

Return type:

tuple[ndarray, ndarray]

Parameters:

blocks (CalibrationBlocks)

accelmo.poco.calibration.gain_covariance(blocks)[source]

Physical normal matrix of u, and the 1-sigma of u and of b, from blocks that include the priors.

The blocks hold the chi² Hessian, so hess / 2 is the inverse-variance normal matrix and its inverse the posterior covariance (the priors are part of the fit). b is marginalised over u: with the diagonal H_bb, Cov_bb = H_bb⁻¹ + H_bb⁻¹ H_ubᵀ Cov_u H_ub H_bb⁻¹ and only its diagonal is formed.

Return type:

tuple[ndarray, ndarray, ndarray]

Parameters:

blocks (CalibrationBlocks)

accelmo.poco.calibration.back_substitute(blocks, delta_u)[source]

Step of b that is optimal for the step delta_u (conditional Gauss-Newton minimiser).

Return type:

ndarray

Parameters: