accelmo.tracking.session

The running workers of one tracking fit.

A TrackingSession builds the worker payloads, spawns the training and held-out validation WorkerPool s, and talks to them until they are stopped: initial-condition updates, the validation loss and the uncertainty drain. Worker ranges come from setup, payload arrays from payloads.

class accelmo.tracking.session.TrackingSession(accelerator, runtime, tracking_data, parameters, *, turn_batches, validation_turn_batches, file_turn_map, worker_plans, machine_deltaps, gain_bpms=())[source]

Bases: object

The training and validation workers of one tracking fit, from start to shutdown.

turn_batches and validation_turn_batches are the training and held-out turns, one list per worker batch; file_turn_map maps each turn to its measurement file and worker_plans each file to the workers one of its batches fans out to (plan_workers()). Pass an empty validation_turn_batches to run without validation workers.

Parameters:
n_mad_knobs

no gains, and not pt.

Type:

Parameters of the MAD-NG maps (magnet knobs)

start(tracks, initial_knobs)[source]

Spawn the training and validation workers, each starting from initial_knobs.

Return type:

None

Parameters:
  • tracks (dict[int, FileTracks])

  • initial_knobs (dict[str, float])

build_payloads(tracks)[source]

Weighted training and held-out validation payloads from tracks, from disjoint turns.

Sets n_training_points and n_validation_points, the weighted points of each.

Return type:

tuple[list[tuple[TrackingData, TrackingWorkerConfig]], list[tuple[TrackingData, TrackingWorkerConfig]]]

Parameters:

tracks (dict[int, FileTracks])

create_worker_payloads(tracks, turn_batches)[source]

One payload per (worker, turn batch); each batch belongs to one file.

Return type:

list[tuple[TrackingData, TrackingWorkerConfig]]

Parameters:
  • tracks (dict[int, FileTracks])

  • turn_batches (list[list[int]])

training_losses(knobs)[source]

Each training worker’s chi-square at knobs.

Return type:

list[float]

Parameters:

knobs (dict[str, float])

send_init_condition_updates(new_coords)[source]

Push updated initial x, px, y, py to every training and validation worker.

new_coords must be a float64 array of shape (n_total_particles, 4) whose columns are x, px, y, py and whose rows are ordered: training workers first (in creation order), then validation workers (in creation order), and within each worker in particle order.

Positions travel with the momenta because the launch point can sit on a closed orbit that the fitted magnets themselves shape; see TrackingWorker._send_init_condition_update. A caller with nothing new to say about position passes the current x/y straight back.

Workers handle the update before processing the next gradient batch, so this method is safe to call between epochs (from the epoch-end hook).

Return type:

None

Parameters:

new_coords (numpy.ndarray)

build_update_coords(tracks)[source]

The combined x, px, y, py start coordinates of the running workers, from tracks.

Returns a float64 array of shape (n_total_particles, 4) suitable for send_init_condition_updates(): training worker rows first, followed by validation worker rows.

Return type:

ndarray

Parameters:

tracks (dict[int, FileTracks])

validation_loss(knobs)[source]

Held-out chi-square per weighted point at knobs, or None without validation workers.

The validation workers track turns that were removed from training, so this is a genuine out-of-sample loss on the training loss’s scale.

Return type:

float | None

Parameters:

knobs (dict[str, float])

set_training_knobs(knobs)[source]

Load knobs into every training worker, e.g. the best knobs before the uncertainty.

Return type:

None

Parameters:

knobs (dict[str, float])

stop_and_collect_uncertainty(n_knobs, hessians=None, on_progress=None)[source]

Stop every worker and return A and B of the training workers per Hessian.

hessians defaults to the configured one; () stops without computing. The true Hessian is replaced by Gauss-Newton, with the reason in skipped, when the backend has no second derivatives or one worker’s second-order maps do not fit in memory. on_progress(done, total, elapsed, eta) follows the second-order pass.

Return type:

UncertaintyCollection

Parameters:
  • n_knobs (int)

  • hessians (tuple[str, ...] | None)

  • on_progress (Callable[[int, int, float, float | None], None] | None)

terminate()[source]

Kill every worker without waiting, for aborting after an error or interrupt.

Workers may be stuck in a failed simulation and not respond to a stop message, so SIGTERM is sent and the processes are reaped.

Return type:

None