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:
objectGlobal 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.
- class accelmo.poco.calibration.CalibrationBlocks(n_q, n_g, n_b, buffer=None, *, zero=True)[source]¶
Bases:
objectSummed loss, gradient and Gauss-Newton Hessian blocks (
2 JᵀWJconvention, 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
otherto 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_uugets its upper triangle only; callCalibrationBlocks.symmetrise()once all series are in.modelis the orbit change with every corrector kick scaled by1 + g(reference subtracted) andjacobianits quad derivatives;d_gain[..., j]is its derivative with respect to the gain of correctorcorrector_indices[j]. Only the BPM gains scale the model:(1 + b) * modelagainst 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²andq²/σ_q²added to the chi² blocks.sigma_qholds one absolute width per magnet knob (the knob’s units); an entry of 0 leaves that knob free.loss_onlyadds the priors toblocks.lossalone (blocksthen needs onlylossandn_q): a loss-only trial evaluation has no gradient or Hessian blocks.zero_mean(indices intog) holds the mean of those gains at 0 with widthZERO_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)ofu.- Return type:
tuple[ndarray,ndarray]- Parameters:
blocks (CalibrationBlocks)
- accelmo.poco.calibration.gain_covariance(blocks)[source]¶
Physical normal matrix of
u, and the 1-sigma ofuand ofb, from blocks that include the priors.The blocks hold the chi² Hessian, so
hess / 2is the inverse-variance normal matrix and its inverse the posterior covariance (the priors are part of the fit).bis marginalised overu: with the diagonalH_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
bthat is optimal for the stepdelta_u(conditional Gauss-Newton minimiser).- Return type:
ndarray- Parameters:
blocks (CalibrationBlocks)
delta_u (numpy.ndarray)