pdmlabs.energy.base#
Abstract base class for all PdMLabs energy backends.
Mirrors pdmlabs.optimization.base.BaseOptimizerAdapter: backends
translate a vendor API (CodeCarbon, raw RAPL/NVML) into one uniform contract so
the experiment layer never imports a vendor package directly.
Nesting contract#
A backend supports exactly one open phase and, inside it, one open task. CodeCarbonβs task API is single-level, so this interface deliberately does not promise arbitrary nesting β promising it would make the CodeCarbon backend a lie rather than an implementation.
Classes
Uniform start/stop energy measurement. |
- class pdmlabs.energy.base.BaseEnergyBackend#
Bases:
ABCUniform start/stop energy measurement.
Implementations must honour three rules, because this object runs inside an HPO trial and must never be able to break one:
stop_*returns anEnergyReading, never raises. A measurement failure degrades the study; it must not abort an optimisation run.Provenance is always populated, even on failure, so no record can be mistaken for a hardware measurement.
start_taskwhile a task is open is an error the backend resolves itself (close-and-warn), never a silent overwrite that would attribute one taskβs energy to another.
- name: str = 'base'#
- phase(label)#
Measure a phase, yielding a one-element list that receives the reading.
The reading is delivered through a mutable cell rather than as the
asvalue because the value is only known at__exit__.
- abstractmethod probe() dict#
Report what this backend can actually measure, without measuring.
Returns a dict with at least
power_source_cpu,power_source_gpu,ram_sourceandavailable(bool). Called by the preflight gate.
- shutdown() None#
Release any long-lived resource. Idempotent.
- abstractmethod start_phase(label: str) None#
- abstractmethod start_task(label: str) object | None#
- abstractmethod stop_phase() EnergyReading#
- abstractmethod stop_task(token: object | None) EnergyReading#