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:
objectThe training and validation workers of one tracking fit, from start to shutdown.
turn_batchesandvalidation_turn_batchesare the training and held-out turns, one list per worker batch;file_turn_mapmaps each turn to its measurement file andworker_planseach file to the workers one of its batches fans out to (plan_workers()). Pass an emptyvalidation_turn_batchesto run without validation workers.- Parameters:
accelerator (Accelerator)
runtime (WorkerRuntime)
tracking_data (TrackingDataConfig)
parameters (TrackingParameters)
turn_batches (list[list[int]])
validation_turn_batches (list[list[int]])
file_turn_map (dict[int, int])
worker_plans (dict[int, list[TrackingWorkerConfig]])
machine_deltaps (list[float])
gain_bpms (tuple[str, ...])
- 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_pointsandn_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, pyto every training and validation worker.new_coordsmust be a float64 array of shape(n_total_particles, 4)whose columns arex, px, y, pyand 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, pystart coordinates of the running workers, fromtracks.Returns a float64 array of shape
(n_total_particles, 4)suitable forsend_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, orNonewithout 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
knobsinto 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
AandBof the training workers per Hessian.hessiansdefaults to the configured one;()stops without computing. The true Hessian is replaced by Gauss-Newton, with the reason inskipped, 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:
- Parameters:
n_knobs (int)
hessians (tuple[str, ...] | None)
on_progress (Callable[[int, int, float, float | None], None] | None)