accelmo.tracking.lm_problem

The tracking Levenberg-Marquardt objective: knobs, BPM gains and optionally the particle starts.

accelmo.tracking.lm_problem.LM_REFRESH_ATOL = 1e-12

A refresh that moves no start coordinate by more than this (m, rad) leaves the objective unchanged.

class accelmo.tracking.lm_problem.StartGainMap(starts, jacobian, gains)[source]

Bases: object

Starts as a linear function of the BPM gains: s(g) = starts + jacobian @ (g - gains).

starts (n_particles, 4) in TrackingSession.send_init_condition_updates() order, jacobian (n_particles, 4, n_gains) and gains (n_gains,) in TrackingFitter.gain_names order. See docs/start_gain_chain_rule.md.

Parameters:
  • starts (numpy.ndarray)

  • jacobian (numpy.ndarray)

  • gains (numpy.ndarray)

starts: ndarray
jacobian: ndarray
gains: ndarray
at(gains)[source]

Starts at gains.

Return type:

ndarray

Parameters:

gains (numpy.ndarray)

accelmo.tracking.lm_problem.chain_starts_through_gains(grad, hessian, start_grad, knob_start, blocks, jacobian, gains)[source]

Gradient and Gauss-Newton Hessian of L(k, g, s(g)) from those of L(k, g, s).

start_grad (4P,), knob_start (n, 4P) and blocks (P, 4, 4) are the start blocks, jacobian (P, 4, n_gains) is ds/dg and gains the gains’ slice of the n parameters. Derivation: docs/start_gain_chain_rule.md.

Return type:

tuple[ndarray, ndarray]

Parameters:
  • grad (numpy.ndarray)

  • hessian (numpy.ndarray)

  • start_grad (numpy.ndarray)

  • knob_start (numpy.ndarray)

  • blocks (numpy.ndarray)

  • jacobian (numpy.ndarray)

  • gains (slice)

class accelmo.tracking.lm_problem.TrackingLMProblem(session, names, n_gains, num_batches, parameters, knob_sigma, gain_ridge, callback, model_values)[source]

Bases: LMProblem

Loss, gradient and Gauss-Newton Hessian of the tracking fit over every batch.

The parameters are the names (magnet knobs, then the BPM gains, the last n_gains). With fit_start_coords every training particle’s start (x, px, y, py) follows them in session particle order and is pushed to the workers before each evaluation. With starts_follow_gains the starts are the callback’s StartGainMap at the trial gains.

Parameters:
  • session (TrackingSession)

  • names (list[str])

  • n_gains (int)

  • num_batches (int)

  • parameters (TrackingParameters)

  • knob_sigma (np.ndarray)

  • gain_ridge (float)

  • callback (Callable[[dict[str, float], dict[str, float]], np.ndarray | StartGainMap | None] | None)

  • model_values (dict[str, float])

start_map: StartGainMap | None
initial_params(knobs)[source]

Knobs in names order; with fitted starts, the workers’ measured starts follow.

Return type:

ndarray

Parameters:

knobs (dict[str, float])

param_names()[source]

names then one start_param{i} per fitted start coordinate.

Return type:

list[str]

starts(params)[source]

The fitted (n_particles, 4) starts in params; empty without fitted starts.

Return type:

ndarray

Parameters:

params (numpy.ndarray)

knobs(params)[source]

The names entries of params as a knob dict.

Return type:

dict[str, float]

Parameters:

params (numpy.ndarray)

evaluate(params, iteration)[source]

Push the starts for params, evaluate every batch and chain/prior the result.

Return type:

LMPoint

Parameters:
  • params (numpy.ndarray)

  • iteration (int)

refresh(params)[source]

Rebuild the start conditions from the accepted knobs; True if they moved.

Return type:

bool

Parameters:

params (numpy.ndarray)