accelmo.fitting.worker¶
Abstract base class for all worker process types.
AbstractWorker.run() owns the process lifecycle and the message loop of
accelmo.fitting.protocol; subclasses build their backend engine
(accelmo.backend.protocol) and answer Evaluate and
Command messages.
- class accelmo.fitting.worker.WorkerConfig(accelerator, magnet_range, machine_state=None, b2_errors=None, bad_bpms=None, debug=False, mad_logfile=None, python_logfile=None)[source]¶
Bases:
objectConfiguration shared by all worker processes.
The accelerator bundles machine-specific setup; the other fields are the model options and log files. Tracking workers add their geometry (
TrackingWorkerConfig).- Parameters:
accelerator (Accelerator)
magnet_range (str)
machine_state (MachineState | None)
b2_errors (Path | None)
bad_bpms (list[str] | None)
debug (bool)
mad_logfile (Path | None)
python_logfile (Path | None)
- accelerator: Accelerator¶
- magnet_range: str¶
- machine_state: Mapping[str, float] | str | Path | None = None¶
- b2_errors: Path | None = None¶
- bad_bpms: list[str] | None = None¶
- debug: bool = False¶
- mad_logfile: Path | None = None¶
- python_logfile: Path | None = None¶
- class accelmo.fitting.worker.AbstractWorker[WorkerDataType, ConfigType: WorkerConfig](conn, worker_id, data, config, runtime)[source]¶
Bases:
Process,ABC,Generic[WorkerDataType,ConfigType]Abstract base class for all worker process implementations.
Subclasses implement
prepare_data(),on_start()(which buildsself.engine) andevaluate(), and overrideon_start(),handle_command(),on_stop()andclose()where they need to.- Type Parameters:
WorkerDataType: The type of data structure this worker uses
- Parameters:
conn (Connection)
worker_id (int)
data (WorkerDataType)
config (ConfigType)
runtime (WorkerRuntime)
- engine: Any¶
- config: ConfigType¶
- abstractmethod prepare_data(data)[source]¶
Process and prepare worker-specific data.
This method should extract relevant data from the input structure, compute weights, split into batches, etc.
- Parameters:
data (
WorkerDataType) – Worker-specific data structure- Return type:
None- Parameters:
data (WorkerDataType)
- abstractmethod on_start(knobs)[source]¶
Build
self.enginefrom theStartknobs.- Return type:
None- Parameters:
knobs (dict[str, float])
- on_stop(failed)[source]¶
Called once the message loop ends, before the engine is closed.
- Return type:
None- Parameters:
failed (bool)
- property backend¶
The backend module of this worker’s accelerator.
- property engine_logfile: Path | None¶
This worker’s backend log file.
- send_reply(reply)[source]¶
Send one reply to the parent.
- Return type:
None- Parameters:
reply (object)
- send_error_payload(exc, *, phase)[source]¶
Best-effort send of the failure to the parent.
- Return type:
None- Parameters:
exc (BaseException)
phase (str)