pdmlabs.energy.instrument#
Per-trial energy instrumentation for the HPO objective.
One decorator, applied at the single point in
PdMExperiment._run_optimizer where the objective is handed to the adapter,
covers every one of the six optimizer backends โ each of them ultimately calls
the same objective_fn(**params).
Hard constraints, each learned from the existing code#
Plain nested function, not a class or ``functools.partial``. Mango assigns attributes to the objective (
mango/scheduler.pysetsfunc.is_wrappedandfunc.batch_size;mango/tuner.pyreadsobjective.batch_sizeto size its batches). A__slots__instance or apartialwould break Mango outright.The return value passes through untouched. Adapters do
float(objective_fn(**params)).Exceptions propagate untouched. Every flavor does
if self.debug: raise eanddebug=Trueis the default, so swallowing here would silently change HPO behaviour.Nothing in ``finally`` may raise, or a measurement failure would abort a search.
Picklable, since the closure ships to loky/dask workers when
n_jobs>1. It carries only anEnergySink(strings only) and plain dicts โ never a tracker, file handle or lambda.
Four exit paths, not three#
normal
return best_metrics_dict[...]->exit_path="normal"the flavorโs own handled-exception path, which returns
0in six flavors but1inSA_experiment.py. From here this is indistinguishable from a normal return โ the flavor catches the exception internally and returns a sentinel โ so it is recorded asexit_path="normal"with that sentinel asobjective_value. Identifying it after the fact means joining on the flavorโs own MLflow record viamlflow_run_id. The energy is still charged either way, which is the point: a failed trial burns real energy, and E-LQO likewise charges timed-out exploratory plans up to termination.the
_check_cached_runshort-circuit ->exit_path="cached", so cache hits are excluded from per-trial distributions rather than dragging the mean toward zeroan exception that escapes entirely (
debug=True, the default) ->exit_path="error", re-raised unchanged
Functions
|
Wrap a raw |
- pdmlabs.energy.instrument.measured_trial(objective_fn, sink, phase='SEARCH', dims=None)#
Wrap a raw
(**params) -> floatobjective with per-trial energy accounting.The backend is looked up per process via
pdmlabs.energy.context.get_active_backend(). In a worker process there is none, so the trial is recorded with wall-clock only andattribution="phase_only"โ which is the correct and safe behaviour, since concurrent trials share machine-wide counters and cannot be attributed individually.