accelmo.tracking.worker

Particle tracking worker for multi-turn beam dynamics simulations.

A TrackingWorker tracks its particles through its BPM range and returns the weighted least-squares loss and its knob gradient. Constructed with validation=True it instead scores held-out turns: no knob parameters, no gradients, only the loss.

class accelmo.tracking.worker.PrecomputedTrackingWeights(x, y, px, py)[source]

Bases: object

Per-observable inverse-variance weights 1/σ² (0 drops a point).

Parameters:
  • x (numpy.ndarray)

  • y (numpy.ndarray)

  • px (numpy.ndarray)

  • py (numpy.ndarray)

x: ndarray
y: ndarray
px: ndarray
py: ndarray
class accelmo.tracking.worker.TrackingData(position_comparisons, momentum_comparisons, position_variances, momentum_variances, init_coords, init_pts, reading_ids, init_reading_ids, init_variances, start_turn_offsets, precomputed_weights, gain_bpms=(), point_gain_index=None)[source]

Bases: object

Reference data for a tracking-loss evaluation.

Position and momentum comparison arrays use shape (n_particles, n_data_points, 2), with the last axis storing the two transverse components for each observable family.

Reading ids identify one measured grid cell (file, turn, marker) across all workers, so the uncertainty propagation can add up every use of the same noisy reading – as an observation or as a start coordinate.

Parameters:
  • position_comparisons (np.ndarray)

  • momentum_comparisons (np.ndarray)

  • position_variances (np.ndarray)

  • momentum_variances (np.ndarray)

  • init_coords (np.ndarray)

  • init_pts (np.ndarray)

  • reading_ids (np.ndarray)

  • init_reading_ids (np.ndarray)

  • init_variances (np.ndarray)

  • start_turn_offsets (np.ndarray)

  • precomputed_weights (PrecomputedTrackingWeights | None)

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

  • point_gain_index (np.ndarray | None)

position_comparisons: ndarray
momentum_comparisons: ndarray
position_variances: ndarray
momentum_variances: ndarray
init_coords: ndarray
init_pts: ndarray
reading_ids: ndarray
init_reading_ids: ndarray
init_variances: ndarray
start_turn_offsets: ndarray

(n_particles,)

Type:

Start turn minus the file’s first turn (AC-kicker phase). Shape

precomputed_weights: PrecomputedTrackingWeights | None
gain_bpms: tuple[str, ...] = ()

BPMs with a fitted gain, in gain-knob order; empty when no gains are fitted.

point_gain_index: Optional[ndarray] = None

(n_data_points,)

Type:

Index of each point’s BPM in gain_bpms, -1 for none. Shape

exception accelmo.tracking.worker.ParticleLostError[source]

Bases: Exception

Raised when the backend reports lost particles.

accelmo.tracking.worker.READING_CODES: dict[str, int] = {'px': 2, 'py': 3, 'x': 0, 'y': 1}

which number in a (file, turn, marker) grid cell was read. The start coordinates x0, px0, y0, py0 are the readings of their cell.

Type:

Last digit of a reading id

accelmo.tracking.worker.START_CODES = [0, 2, 1, 3]

Reading codes in the order of the start coordinates, the rows of d{o}_dc0.

accelmo.tracking.worker.active_observables(kick_plane, include_momentum)[source]

Observables a worker of this kick plane compares.

Return type:

tuple[str, ...]

Parameters:
  • kick_plane (str)

  • include_momentum (bool)

class accelmo.tracking.worker.TrackingWorker(conn, worker_id, data, config, runtime, tracking_data, parameters, validation=False)[source]

Bases: AbstractWorker[TrackingData, TrackingWorkerConfig]

Worker for particle tracking simulations.

Tracks every particle of a batch through the worker’s range, compares the observed positions (and, with TrackingDataConfig.optimise_momenta, momenta) with the measurement, and returns the loss and its knob gradient from the differential-algebra map.

Parameters:
engine: TrackingEngine
prepare_data(data)[source]

Split the measurement and start coordinates into batches.

Return type:

None

Parameters:

data (TrackingData)

on_start(knobs)[source]

Build the tracking engine, load the particles and check the observation geometry.

Return type:

None

Parameters:

knobs (dict[str, float])

run_preflight_check()[source]

Validate the observation geometry once with a single-particle dry run.

Tracks one particle through the configured range and turns and confirms the engine observes exactly nbpms * n_turns points, the size every real run fills. A mis-scoped observe/range (e.g. an off-plane BPM left observed outside the range) then fails here with a clear message instead of deep in the optimisation loop.

Return type:

None

evaluate(message)[source]

Chi-square of one batch and its gradient (and Gauss-Newton blocks with curvature).

Return type:

GradReply

Parameters:

message (Evaluate)

total_chi2(knobs)[source]

Chi-square of every batch at knobs.

Return type:

float

Parameters:

knobs (dict[str, float])

handle_command(command)[source]

Answer a validation, diagnose, knob or start-coordinate command.

Return type:

Ack | LossReply

Parameters:

command (Command)

on_stop(failed)[source]

A training worker answers Stop with its uncertainty part.

A failed worker has already sent its ErrorReply and sends nothing more.

Return type:

None

Parameters:

failed (bool)

property n_uncertainty_params: int

the uncertainty covers both.

Type:

The magnet knobs, then every gain