accelmo.fitting.protocol¶
The parent <-> worker protocol: typed messages and the parent-side channels that carry them.
A worker receives Start once, then any number of Evaluate and
Command messages, then Stop. Each Evaluate is answered
with a GradReply, each Command with an Ack or a
LossReply. A failure is answered with an ErrorReply, which the
receiving WorkerChannels raises.
- class accelmo.fitting.protocol.Start(knobs)[source]¶
Bases:
objectThe first message: the model values the worker builds its MAD-NG session with.
- Parameters:
knobs (dict[str, float])
- knobs: dict[str, float]¶
- class accelmo.fitting.protocol.Evaluate(knobs, batch=0, loss_only=False, curvature=False)[source]¶
Bases:
objectEvaluate the loss and, unless
loss_only, its knob derivatives atknobs.batchselects a tracking worker’s particle batch.loss_onlyasks a closed-orbit worker for the loss alone, from plain closed-orbit solves without knob derivatives (about 6x cheaper); the LM fit uses it for trial points.curvatureasks a tracking worker for the Gauss-Newton matrixJᵀWJtoo (the tracking LM fit); loss and gradient are the chi-square sums either way.- Parameters:
knobs (dict[str, float])
batch (int)
loss_only (bool)
curvature (bool)
- knobs: dict[str, float]¶
- batch: int = 0¶
- loss_only: bool = False¶
- curvature: bool = False¶
- class accelmo.fitting.protocol.TotalChi2(knobs)[source]¶
Bases:
objectChi-square of every batch at
knobs; answered with aLossReply.- Parameters:
knobs (dict[str, float])
- knobs: dict[str, float]¶
- class accelmo.fitting.protocol.SetKnobs(knobs)[source]¶
Bases:
objectLoad
knobsinto the model without evaluating.- Parameters:
knobs (dict[str, float])
- knobs: dict[str, float]¶
- class accelmo.fitting.protocol.UpdateInitCoords(coords)[source]¶
Bases:
objectReplace the start coordinates;
coordshas shape(particles, 4): x, px, y, py.- Parameters:
coords (np.ndarray)
- coords: ndarray¶
- class accelmo.fitting.protocol.SetUncertaintyMode(hessians)[source]¶
Bases:
objectThe Hessians (
"true","gauss_newton") to compute onStop; none disables it.- Parameters:
hessians (tuple[str, ...])
- hessians: tuple[str, ...]¶
- accelmo.fitting.protocol.Command = accelmo.fitting.protocol.TotalChi2 | accelmo.fitting.protocol.SetKnobs | accelmo.fitting.protocol.UpdateInitCoords | accelmo.fitting.protocol.SetUncertaintyMode¶
Control commands a tracking worker answers between evaluations with an
Ackor, forTotalChi2, aLossReply.
- class accelmo.fitting.protocol.Stop[source]¶
Bases:
objectEnd the worker. A tracking worker first answers with its uncertainty part.
- class accelmo.fitting.protocol.GradReply(worker_id, loss, grad, normal=None, extra=None)[source]¶
Bases:
objectOne evaluation’s result.
lossis NaN when the worker lost its particles or its closed orbit, and the caller rejects the step.normalisJᵀWJ(the chi² Gauss-Newton Hessian is twice it), sent only when curvature is asked for.extracarries worker-specific results: a calibrated worker’s block header, or the orbit a reference worker published.- Parameters:
worker_id (int)
loss (float)
grad (np.ndarray)
normal (np.ndarray | None)
extra (Any)
- worker_id: int¶
- loss: float¶
- grad: ndarray¶
- normal: ndarray | None = None¶
- extra: Any = None¶
- class accelmo.fitting.protocol.LossReply(worker_id, loss)[source]¶
Bases:
objectA loss without derivatives.
- Parameters:
worker_id (int)
loss (float)
- worker_id: int¶
- loss: float¶
- class accelmo.fitting.protocol.Ack(worker_id)[source]¶
Bases:
objectA control command was applied.
- Parameters:
worker_id (int)
- worker_id: int¶
- class accelmo.fitting.protocol.UncertaintyProgress(worker_id)[source]¶
Bases:
objectOne more batch of the second-order pass is done; sent before the final reply.
- Parameters:
worker_id (int)
- worker_id: int¶
- class accelmo.fitting.protocol.ErrorReply(worker_id, phase, error_type, error, traceback)[source]¶
Bases:
objectThe worker failed during
phase.- Parameters:
worker_id (int)
phase (str)
error_type (str)
error (str)
traceback (str)
- worker_id: int¶
- phase: str¶
- error_type: str¶
- error: str¶
- traceback: str¶
- class accelmo.fitting.protocol.WorkerChannels(parent_conns, workers)[source]¶
Bases:
objectReusable worker communication state for fast send/receive rounds.
- Parameters:
parent_conns (list[Connection])
workers (list[Process])
- parent_conns¶
- workers¶
- send_all(message)[source]¶
Send one message to every worker.
- Return type:
None- Parameters:
message (object)
- send_to(index, message)[source]¶
Send one message to the worker at
index.- Return type:
None- Parameters:
index (int)
message (object)
- recv_all(on_progress=None)[source]¶
Receive one message from each worker, preserving connection order.
- Return type:
list[Any]- Parameters:
on_progress (Callable[[UncertaintyProgress], None] | None)
- recv_some(indices, on_progress=None)[source]¶
Receive one message from each listed worker, in the order of
indices.UncertaintyProgressmessages are passed toon_progressand are not replies.- Return type:
list[Any]- Parameters:
indices (Iterable[int])
on_progress (Callable[[UncertaintyProgress], None] | None)
- ack_all(command)[source]¶
Send
commandto every worker and require anAckfrom each.- Return type:
None- Parameters:
command (TotalChi2 | SetKnobs | UpdateInitCoords | SetUncertaintyMode)
- accelmo.fitting.protocol.FD_SETSIZE = 1024¶
pymadng waits on each MAD process with
select(), which rejects fd numbers >= 1024.
- accelmo.fitting.protocol.FDS_PER_WORKER = 4¶
Descriptors a forked worker leaves open in every later worker (pipe pair, both ends).
- accelmo.fitting.protocol.FD_RESERVE = 64¶
Descriptors the main process and each MAD-NG process need before any worker exists.