accelmo.tracking.config.tracking

Tracking-mode planning for arc-by-arc, kicker- and AC-dipole-excited runs.

This module owns everything mode-specific about a training run: one TrackingPlan per mode fixes the simulation-config entries and start points that are not free choices for the mode, and expands BPM points into worker ranges.

accelmo.tracking.config.tracking.extract_bpm_range_names(all_bpms, start_bpm, end_bpm, sdir)[source]

Extract BPM names between start and end BPMs, handling circular wrapping.

Parameters:
  • all_bpms (list[str]) – List of all BPM names

  • start_bpm (str) – Starting BPM name

  • end_bpm (str) – Ending BPM name

  • sdir (int) – Direction (1 for forward, -1 for reverse)

Return type:

list[str]

Returns:

List of BPM names in the range

Parameters:
  • all_bpms (list[str])

  • start_bpm (str)

  • end_bpm (str)

  • sdir (int)

accelmo.tracking.config.tracking.create_bpm_range_specs(bpm_start_points, bpm_end_points, use_fixed_bpm, fixed_start=None, fixed_end=None)[source]

Create BPM range specifications for optimisation workers.

Parameters:
  • bpm_start_points (list[str]) – List of starting BPM names

  • bpm_end_points (list[str]) – List of ending BPM names

  • use_fixed_bpm (bool) – If True, use fixed BPM pairs; if False, create cartesian product

  • fixed_start (str | None) – Fixed start BPM for backward tracking (only used if use_fixed_bpm=True)

  • fixed_end (str | None) – Fixed end BPM for forward tracking (only used if use_fixed_bpm=True)

Return type:

list[tuple[str, str, int]]

Returns:

List of (start_bpm, end_bpm, sdir) tuples where sdir is 1 for forward, -1 for reverse

Parameters:
  • bpm_start_points (list[str])

  • bpm_end_points (list[str])

  • use_fixed_bpm (bool)

  • fixed_start (str | None)

  • fixed_end (str | None)

class accelmo.tracking.config.tracking.WorkerRangeSpec(start_bpm, end_bpm, sdir)[source]

Bases: object

Logical BPM range assigned to a worker.

Parameters:
  • start_bpm (str)

  • end_bpm (str)

  • sdir (int)

start_bpm: str
end_bpm: str
sdir: int
property init_bpm: str

Return the BPM used to initialise tracking for this direction.

class accelmo.tracking.config.tracking.TrackingPlan[source]

Bases: object

Mode-specific tracking policy; the base class is arc-by-arc BPM tracking.

Subclasses override the class-level flags and the range-planning hooks below.

enable_validation: ClassVar[bool] = True
turns_per_track: ClassVar[int] = 1

Turns tracked from each start; an arc range is one turn.

one_start_per_worker: ClassVar[bool] = False
tracking_anchor_mode: ClassVar[str | None] = None
property init_marker: str | None

Element supplying tracking initial conditions instead of a range BPM.

property cycle_marker: str | None

Optional unobserved element used only for sequence cycling.

property extra_markers: tuple[str, ...]

Non-BPM markers that must be kept in measurement data.

property start_points: tuple[str, ...]

Fixed tracking start points of marker-anchored modes; empty means the caller’s BPMs.

property first_bpm_fallback: str | None

Per-file fallback for the BPM the measurement turns are recorded from.

configure(tracking_data)[source]

tracking_data with the entries this mode fixes; arc ranges fix none.

Return type:

TrackingDataConfig

Parameters:

tracking_data (TrackingDataConfig)

property tracking_anchor_sources: tuple[str, ...]

Elements the model prepares for marker-anchored tracking.

initial_condition_marker(range_spec)[source]

Return the measured marker used for a worker’s initial coordinates.

Return type:

str | None

Parameters:

range_spec (WorkerRangeSpec)

observed_bpms(bpms_in_range, all_bpms)[source]

Return the BPMs compared against measurements.

Return type:

list[str]

Parameters:
  • bpms_in_range (list[str])

  • all_bpms (list[str])

select_available_turns(*, bunch_turns_by_file, available_turns)[source]

Return boundary turns and the filtered list of usable start turns.

A start turn is unusable when the multi-turn track it seeds would cross a bunch boundary. Each bunch’s first/last turns are therefore removed, using the per-file bunch_number grouping read from the measurement data.

Return type:

tuple[dict[int, set[int]], list[int]]

Parameters:
  • bunch_turns_by_file (dict[int, dict[int, list[int]]])

  • available_turns (list[int])

build_range_specs(ctx)[source]

Return the worker range specs for this plan.

Return type:

list[WorkerRangeSpec]

Parameters:

ctx (BpmRanges)

get_range_bpm_names(*, all_bpms, start_bpm, end_bpm, sdir, bad_bpms)[source]

Return the BPMs in one logical observation range.

Return type:

list[str]

Parameters:
  • all_bpms (list[str])

  • start_bpm (str)

  • end_bpm (str)

  • sdir (int)

  • bad_bpms (list[str] | None)

class accelmo.tracking.config.tracking.KickerTrackingPlan(kicker_name, turns_per_track=1)[source]

Bases: TrackingPlan

Forward-only tracking starting from a kicker initial-condition marker.

The measured kicker marker supplies the initial coordinates, while the MAD sequence is cycled to an unobserved centre marker so the observed BPM order begins just after the kicker; only real BPMs are compared.

Parameters:
  • kicker_name (str)

  • turns_per_track (int)

kicker_name: str
enable_validation: ClassVar[bool] = False
tracking_anchor_mode: ClassVar[str | None] = 'kicker'
configure(tracking_data)[source]

One batch: each bunch gives a single track, so batches cannot split the turns.

Return type:

TrackingDataConfig

Parameters:

tracking_data (TrackingDataConfig)

property start_points: tuple[str, ...]

The kicker marker.

property first_bpm_fallback: str

Kicker files are recorded from the kicker marker.

property init_marker: str

The kicker marker.

property extra_markers: tuple[str, ...]

The kicker marker.

property tracking_anchor_sources: tuple[str, ...]

The kicker marker.

property cycle_marker: str

Marker at the kicker centre.

observed_bpms(bpms_in_range, all_bpms)[source]

Every BPM.

Return type:

list[str]

Parameters:
  • bpms_in_range (list[str])

  • all_bpms (list[str])

select_available_turns(*, bunch_turns_by_file, available_turns)[source]

Each bunch contributes exactly one track, seeded from its first turn.

Return type:

tuple[dict[int, set[int]], list[int]]

Parameters:
  • bunch_turns_by_file (dict[int, dict[int, list[int]]])

  • available_turns (list[int])

build_range_specs(ctx)[source]

One forward range from the first BPM round the ring.

Return type:

list[WorkerRangeSpec]

Parameters:

ctx (BpmRanges)

class accelmo.tracking.config.tracking.ACDTrackingPlan(acd_name)[source]

Bases: _AcdPlan

Bidirectional tracking initialised at AC-dipole markers.

Parameters:

acd_name (str)

property start_points: tuple[str, ...]

The after and before markers.

property extra_markers: tuple[str, ...]

The before and after markers.

observed_bpms(bpms_in_range, all_bpms)[source]

Every BPM.

Return type:

list[str]

Parameters:
  • bpms_in_range (list[str])

  • all_bpms (list[str])

build_range_specs(ctx)[source]

Forward from after and backward from before.

Return type:

list[WorkerRangeSpec]

Parameters:

ctx (BpmRanges)

initial_condition_marker(range_spec)[source]

Initialise each direction from the marker at its tracking start.

Return type:

str

Parameters:

range_spec (WorkerRangeSpec)

class accelmo.tracking.config.tracking.ACDSinusoidTrackingPlan(acd_name, turns_per_track=1)[source]

Bases: _AcdPlan

Forward multi-turn tracking from the AC-dipole before-marker through the AC kickers.

Each file is cut into back-to-back tracks of turns_per_track turns: one starts at the file’s first turn and a new one every turns_per_track turns, each seeded from the measured before-marker at its start turn. The kick comes from the model AC kickers AC_KICKERS (PSB acd_drive_tunes).

Parameters:
  • acd_name (str)

  • turns_per_track (int)

enable_validation: ClassVar[bool] = False
one_start_per_worker: ClassVar[bool] = True
configure(tracking_data)[source]

One batch: each worker holds one track (its own AC-kicker phase).

Return type:

TrackingDataConfig

Parameters:

tracking_data (TrackingDataConfig)

property start_points: tuple[str, ...]

The before marker.

property init_marker: str

The before marker.

property extra_markers: tuple[str, ...]

The before and after markers.

observed_bpms(bpms_in_range, all_bpms)[source]

BPMs in the range.

Return type:

list[str]

Parameters:
  • bpms_in_range (list[str])

  • all_bpms (list[str])

select_available_turns(*, bunch_turns_by_file, available_turns)[source]

Start turns every turns_per_track turns of each file.

Return type:

tuple[dict[int, set[int]], list[int]]

Parameters:
  • bunch_turns_by_file (dict[int, dict[int, list[int]]])

  • available_turns (list[int])

build_range_specs(ctx)[source]

One forward range from before round the ring.

Return type:

list[WorkerRangeSpec]

Parameters:

ctx (BpmRanges)

class accelmo.tracking.config.tracking.ACDArcByArcTrackingPlan(acd_name)[source]

Bases: _AcdPlan

Arc-by-arc tracking of AC-dipole data over ordinary BPM ranges.

Unlike ACDTrackingPlan (which tracks bidirectionally from the AC-dipole before/after markers), this plan tracks the caller’s cartesian product of bpm_start_points x bpm_end_points. The exciter is a driven, turn-varying element, so a range that crosses it would compare BPMs on opposite sides of a kick the free-oscillation model cannot reproduce.

Rather than drop such a range, this plan reroutes it: two BPMs are joined by two arcs around the ring, and only one contains the AC dipole, so a crossing pair keeps start and end connected via the complementary long-way-round arc (in both tracking directions).

The before/after monitors are installed (tracking_anchor_mode == "acd") only so they appear in all_bpms and mark the exciter’s ring position for the crossing test; they are not observed against the measurement.

Parameters:

acd_name (str)

observed_bpms(bpms_in_range, all_bpms)[source]

BPMs in the range, without the AC-dipole markers.

Return type:

list[str]

Parameters:
  • bpms_in_range (list[str])

  • all_bpms (list[str])

build_range_specs(ctx)[source]

Arc ranges, rerouted round the ring when they contain the AC dipole.

Return type:

list[WorkerRangeSpec]

Parameters:

ctx (BpmRanges)