accelmo.poco.fitter¶
Levenberg-Marquardt base fitter of POCO and the measured-optics observables.
- accelmo.poco.fitter.MEASUREMENT_COLUMNS: dict[str, tuple[str, str]] = {'alfx': ('ALFX', 'ERRALFX'), 'alfy': ('ALFY', 'ERRALFY'), 'betx': ('BETX', 'ERRBETX'), 'bety': ('BETY', 'ERRBETY'), 'dpx': ('DPX', 'ERRDPX'), 'dpy': ('DPY', 'ERRDPY'), 'dx': ('DX', 'ERRDX'), 'dy': ('DY', 'ERRDY'), 'mu1': ('MUX', 'mu1_var'), 'mu2': ('MUY', 'mu2_var'), 'x': ('X', 'ERRX'), 'y': ('Y', 'ERRY')}¶
Measurement columns backing each fittable observable, as
observable -> (value column, error column)in the measured optics frame.mu1/mu2are special: the measured frame carries the cumulative phase and its cumulative variance, which are differenced into per-interval advances (with the variance difference) by_advance_targets().betx/bety/alfx/alfyare the physical-plane projections, neverbeta11/beta22/alfa11/alfa22(MAD-NG’s generalised-mode columns, only meaningful withcoupling=true– seerun_closed_twiss_init.mad). Phase advance has no such projected name in MAD-NG (confirmed against its own optical-function name list: onlymu/dmuwith a mode-index suffix exist, nomux/muy), somu1/mu2remain mode-indexed on both sides here.
- accelmo.poco.fitter.DEFAULT_OBSERVABLES: tuple[str, ...] = ('x', 'y', 'betx', 'bety', 'alfx', 'alfy', 'mu1', 'mu2', 'dx', 'dy')¶
everything the closed twiss and an omc3 optics measurement independently have in common. All of them are fitted by default: each family constrains a different combination of the knobs, and inverse-variance weighting gives a noisy family little weight. Narrow this only to isolate an effect, as the tests do.
dpx/dpyare the one exclusion, and it is required for correctness: omc3 does not measure them independently but derives them fromDX/DYthrough the model transfer matrix, so including them counts one measurement twice. In the vertical it is worse than redundant - the derivation assumes no vertical dispersion source exists anywhere, which is exactly the hypothesis aDyfit is testing. They remain available for callers whose dispersion errors come from somewhere else.- Type:
Observables fitted when the caller does not choose
- class accelmo.poco.fitter.LMFitter(accelerator, sequence_config, *, runtime, lm_config=None, initial_knob_strengths=None, true_strengths=None, use_errors=True, knob_sigmas=None, output_config=None, b2_errors=None, machine_state=None, debug=False)[source]¶
Bases:
objectShared lifecycle and Levenberg-Marquardt solve of the full-ring closed-orbit/closed-twiss fitters.
Subclasses set
worker_classand buildworker_payloads, one(WorkerConfig, data)per worker, in their own__init__.- Parameters:
accelerator (Accelerator)
sequence_config (SequenceConfig)
runtime (WorkerRuntime)
lm_config (LevenbergMarquardtConfig | None)
initial_knob_strengths (dict[str, float] | None)
true_strengths (Path | dict[str, float] | None)
use_errors (bool)
knob_sigmas (Mapping[str, float] | None)
output_config (OutputConfig | None)
b2_errors (Path | None)
machine_state (MachineState | None)
debug (bool)
- worker_class: type¶
- log_suffix: str¶
- fit_label: str¶
- supports_energy: bool = False¶
ptis then fitted as the last knob.- Type:
Whether
accelerator.optimise_energyis supported
- loss_only_trials: bool = False¶
Whether a rejected step costs a plain-orbit chi² instead of a full evaluation (orbit-only workers).
- diagnostics: FitDiagnostics | None¶
- history: list[tuple[dict[str, float], float]]¶
(knobs, loss)of every accepted iteration, in order
- posterior_normal: Optional[ndarray]¶
Posterior inverse covariance (data + prior) at the best knobs of the last run, in knob order.
- worker_payloads: list¶
- b2_errors¶
Known LHC dipole b2 error table, applied to every worker’s sequence; the interface also needs the tune knobs that compensate it, from
machine_state.
- knob_sigma¶
Gaussian prior width of each knob (0 = free); see
knob_sigma_array().
- accelmo.poco.fitter.load_measurement(measurement, observables)[source]¶
Validate a measured optics set (DataFrame indexed by BPM name) for the fit.
- Parameters:
measurement (
DataFrame) – DataFrame carrying the columns listed inMEASUREMENT_COLUMNS.observables (
tuple[str,...]) – Observable names that must be present.
- Return type:
DataFrame- Returns:
Copy of
measurement. Missing error columns are filled with NaN. Individual NaN errors drop their own points; an observable whose errors are all unusable is rejected bybuild_observable()unless the caller passesuse_errors=False, because a family with no variances cannot be weighted commensurably against families that have them.- Parameters:
measurement (pd.DataFrame)
observables (tuple[str, ...])
- accelmo.poco.fitter.measured_bpms(all_bpms, measurement, label)[source]¶
The model BPMs that have a measurement, in model order; at least two.
- Return type:
list[str]- Parameters:
all_bpms (list[str])
measurement (pd.DataFrame)
label (str)