pdmlabs.energy.reading#
The value type returned by every energy backend.
Canonical unit is the joule. kWh is kept as a convenience view but is never
the source of truth: a sub-second trial is O(1e-9) kWh, where float noise and
downstream round() calls silently destroy precision. Joules keep every
measured quantity in a range where addition is exact enough to sum thousands of
trials without drift.
Classes
|
One energy measurement over a closed time interval. |
- class pdmlabs.energy.reading.EnergyReading(duration_s: float, cpu_j: float | None = None, gpu_j: float | None = None, ram_j: float | None = None, total_j: float | None = None, co2e_g: float | None = None, power_source_cpu: str = 'unknown', power_source_gpu: str = 'unknown', ram_source: str = 'unknown', backend: str = 'unknown', quality: str = 'ok', carbon_intensity_g_per_kwh: float | None = None)#
Bases:
objectOne energy measurement over a closed time interval.
Every field that can be absent is
Nonerather than0.0. The distinction matters: a missing DRAM rail and a rail that genuinely drew no energy must not be summed into the same total, or a machine without adramRAPL domain would silently report lower total energy than one with.- as_dict()#
- property avg_power_w#
- backend: str = 'unknown'#
- carbon_intensity_g_per_kwh: float | None = None#
- co2e_g: float | None = None#
- cpu_j: float | None = None#
- duration_s: float#
- dynamic_j(idle_w, clamp=True)#
Idle-subtracted energy, and whether the clamp fired.
Returns
(value, clamped). Short or noisy intervals can yield a negative result; clamping to zero is right, but doing so silently is not β the clamp rate is itself a data-quality signal, so it is returned rather than swallowed.
- classmethod from_kwh(duration_s, cpu_kwh=None, gpu_kwh=None, ram_kwh=None, total_kwh=None, co2e_kg=None, **provenance)#
Build from CodeCarbonβs kWh/kg convention.
- gpu_j: float | None = None#
- property is_measured#
True only when CPU energy came from hardware counters.
This is the single predicate that decides whether a run is a measurement or a model. Nothing may infer it from the shape of the numbers β a TDP*utilisation model also varies with load, which is exactly how such a fallback gets mistaken for a real reading.
- power_source_cpu: str = 'unknown'#
- power_source_gpu: str = 'unknown'#
- quality: str = 'ok'#
- ram_j: float | None = None#
- ram_source: str = 'unknown'#
- total_j: float | None = None#
- property total_kwh#