accelmo.machine.accelerators.base¶
Base accelerator class defining the interface for all accelerators.
- class accelmo.machine.accelerators.base.KnobSpec(kind, attribute, pattern, nonzero_attr, label)[source]¶
Bases:
NamedTupleSpecification for a single optimisable knob type.
- Parameters:
kind (str)
attribute (str)
pattern (str)
nonzero_attr (str | None)
label (str)
- kind: str¶
Alias for field number 0
- attribute: str¶
Alias for field number 1
- pattern: str¶
Alias for field number 2
- nonzero_attr: str | None¶
Alias for field number 3
- label: str¶
Alias for field number 4
- class accelmo.machine.accelerators.base.MagnetFamily(patterns, errors=frozenset({}), misalignments=frozenset({}), nonzero_attr=None, attr_patterns=dict())[source]¶
Bases:
objectA group of magnets sharing name patterns and the attributes that may be fitted.
- Variables:
patterns (
Mapping[str,str]) – Element kind -> Lua name pattern (one entry per kind; seeaccelmo.machine.patterns.lua_to_regex()).errors (
frozenset[str]) – Field attributes that may be fitted (k1,k0s,knl[3],kick…).misalignments (
frozenset[str]) – Alignment attributes that may be fitted (subset ofMISALIGNMENT_ATTRS).nonzero_attr (
str|None) – Only create knobs on elements where this attribute is nonzero.attr_patterns (
Mapping[str,str]) – Per-attribute pattern overridingpatternsfor every kind.
- Parameters:
patterns (Mapping[str, str])
errors (frozenset[str])
misalignments (frozenset[str])
nonzero_attr (str | None)
attr_patterns (Mapping[str, str])
- patterns: Mapping[str, str]¶
- errors: frozenset[str] = frozenset({})¶
- misalignments: frozenset[str] = frozenset({})¶
- nonzero_attr: str | None = None¶
- attr_patterns: Mapping[str, str]¶
- class accelmo.machine.accelerators.base.Accelerator(sequence_file, kinetic_energy, bpm_pattern, particle='proton', errors=None, misalignments=None, optimise_energy=False, custom_knobs_to_optimise=None, backend='madng', **kwargs)[source]¶
Bases:
Accelerator,ABCAbstract base class for accelerator definitions.
This class encapsulates all backend-neutral machine configuration; the backend-specific code lives in
accelmo.backend.<name>.Subclasses declare
FAMILIES; callers pick what to fit witherrorsandmisalignments, both keyed by family name.- Parameters:
sequence_file (Path | str)
kinetic_energy (float)
bpm_pattern (str)
particle (str)
errors (Mapping[str, Iterable[str]] | None)
misalignments (Mapping[str, Iterable[str]] | None)
optimise_energy (bool)
custom_knobs_to_optimise (list[str] | None)
backend (str)
- FAMILIES: ClassVar[dict[str, MagnetFamily]] = {}¶
- selection_kwargs()[source]¶
Return the constructor kwargs describing what is optimised (for
copy_with).- Return type:
dict
- optimises(family, attribute)[source]¶
Return whether
attributeoffamilyis fitted (as error or misalignment).- Return type:
bool- Parameters:
family (str)
attribute (str)
- get_knob_specs()[source]¶
Expand the selected errors and misalignments into one spec per element kind.
- Return type:
list[KnobSpec]
- property ac_dipole_name: str¶
Return the AC-dipole exciter name for machines that define one.
- abstract property tune_variables: tuple[str, str]¶
Return the names of the horizontal and vertical tune variables.
- abstract property tune_integers: tuple[int, int]¶
Return the integer tune values.
- log_optimisation_targets()[source]¶
Log the optimisation targets for this accelerator.
- Return type:
None
- abstractmethod copy_with(**overrides)[source]¶
Return a new instance of the same type with selected parameters overridden.
- Return type:
- get_bend_lengths()[source]¶
Return bend lengths required for accelerator-specific normalisation.
- Return type:
dict[str,float] |None
- normalise_true_strengths(true_strengths, bend_lengths=None)[source]¶
Apply accelerator-specific normalisation to true strengths.
- Parameters:
true_strengths (
dict[str,float]) – Dictionary of true magnet strengthsbend_lengths (
dict[str,float] |None) – Bend lengths for normalisation (optional). If None, uses accelerator-ownedself.bend_lengths.
- Return type:
dict[str,float]- Returns:
Normalised strengths dictionary (default – unchanged)
- Parameters:
true_strengths (dict[str, float])
bend_lengths (dict[str, float] | None)
- normalise_initial_knobs(knobs)[source]¶
Map user-facing initial values into optimisation-space knob names.
- Return type:
dict[str,float]- Parameters:
knobs (dict[str, float])
- format_result_knob_names(knob_names)[source]¶
Format knob names for result reporting.
- Parameters:
knob_names (
list[str]) – Knob names as used in optimisation- Return type:
list[str]- Returns:
Knob names adjusted for reporting (default – unchanged)
- Parameters:
knob_names (list[str])
- format_result_knobs(knobs)[source]¶
Map optimisation-space knob values to user-facing result names.
- Return type:
dict[str,float]- Parameters:
knobs (dict[str, float])
- property has_ac_kickers: bool¶
True when the model has turn-dependent AC kickers (their phase depends on the start turn).
- ac_kicker_freqs(file_index)[source]¶
AC-kicker (h, v) drive tunes of measurement file
file_index.- Return type:
tuple[float,float] |None- Parameters:
file_index (int)
- ac_kicker_volt_knobs(file_index)[source]¶
Per-file volt (a, b) knob names of the AC kickers (
None: shared knobs).- Return type:
tuple[str,...] |None- Parameters:
file_index (int)