pdmlabs.energy.metrics#

Lifecycle energy metrics, adapted from E-LQO (SIGMOD 2027) to PdM.

Two layers, deliberately separated:

Layer 1 – measured, assumption-free. Phase shares, optimizer overhead, exploration waste, energy-per-quality-point, energy-to-target, and the diminishing-returns fit. Everything here is computable from the exported records alone and involves no judgement about what a failure costs.

Layer 2 – payoff-dependent. eroi() and ept() need a payoff per deployment cycle, which in PdM means converting detection quality into avoided maintenance energy or cost. That conversion lives in pdmlabs.energy.payoff; this module only does the amortisation algebra, so the same functions serve the energy-denominated and cost-denominated models.

Why the adaptation is not a straight port#

E-LQO’s payoff is more energy saved: a better query plan executes more cheaply, so the return on inference energy is itself energy. A better-tuned anomaly detector does not make inference cheaper – it makes maintenance cheaper. There is therefore no E_exec analogue, and the numerator of EROI has to come from outside the energy measurement. Everything downstream of that substitution keeps E-LQO’s algebra exactly, including its boundary cases.

Vocabulary#

E_search HPO over the train split: all trials plus optimizer overhead.

The analogue of E-LQO’s E_collect, and expected to dominate.

E_final_fit Refit of the winning configuration (E_train). E_infer Scoring the test split with the winning configuration. debt E_search + E_final_fit – the one-time investment. cycle One pass over the test split, e.g. one month of fleet operation.

Functions

convergence_trace(trials[, maximize, ...])

Cumulative search energy against incumbent quality.

energy_per_quality_point(search_j, q_tuned, ...)

Joules of search bought each unit of quality over a baseline.

energy_to_target(trace[, fractions, maximize])

Cumulative energy at which the incumbent first reached a quality target.

ept(debt, delta_payoff, e_infer)

Energy Payback Time in cycles -- E-LQO Eq.

ept_effective(ept_value, rho)

EPT under distribution shift -- E-LQO Eq.

ept_from_eroi(debt, delta_payoff, eroi_value)

EPT via E-LQO Eq.

eroi(delta_payoff, e_infer)

Energy Return on Investment -- E-LQO Eq.

exploration_waste(trials[, maximize])

Energy spent on trials that never improved the incumbent.

fit_diminishing_returns(trace[, maximize])

Fit Q(e) ~= Q* - beta / (1 + gamma * e) over normalised energy.

lifecycle_summary(search_j, final_fit_j, infer_j)

Assemble the lifecycle picture, including phase shares and payback.

optimizer_overhead(search_j, trial_js)

Energy the optimizer itself spent, outside any trial.

payback_regime(delta_payoff, e_infer)

Name the regime, so undefined EPT is explained rather than blank.

pdmlabs.energy.metrics.convergence_trace(trials, maximize=True, energy_field='total_j')#

Cumulative search energy against incumbent quality.

The input to the convergence-vs-energy plot, which is the fairest cross-optimizer comparator available: it asks how much energy each optimizer needed to reach a given quality, rather than how good it got given a fixed trial count. Trial count is not comparable across backends whose trials cost different amounts.

pdmlabs.energy.metrics.energy_per_quality_point(search_j, q_tuned, q_baseline)#

Joules of search bought each unit of quality over a baseline.

None when the tuned run did not beat the baseline: dividing by a non-positive gain would produce a number that is not just meaningless but actively misleading in a table.

pdmlabs.energy.metrics.energy_to_target(trace, fractions=(0.9, 0.95, 0.99, 1.0), maximize=True)#

Cumulative energy at which the incumbent first reached a quality target.

Targets are fractions of the best value this run actually achieved, so the measure is self-normalising and comparable across datasets with different attainable quality.

pdmlabs.energy.metrics.ept(debt, delta_payoff, e_infer)#

Energy Payback Time in cycles – E-LQO Eq. 5.

min{k in Z+ : k * (payoff - e_infer) >= debt}.

Returns None for the two no-payback regimes E-LQO separates out, and says which one via payback_regime(). They must never be averaged into an aggregate: a mean EPT computed over runs where some never pay back is not a payback time.

pdmlabs.energy.metrics.ept_effective(ept_value, rho)#

EPT under distribution shift – E-LQO Eq. 14, EPT_eff ~= EPT / rho^2.

Quadratic because similarity degrades both per-cycle savings and the accuracy of the predictions that produce them. Drift is more natural in PdM than in query workloads: sensors age and equipment is replaced.

pdmlabs.energy.metrics.ept_from_eroi(debt, delta_payoff, eroi_value)#

EPT via E-LQO Eq. 13, as an independent check on ept().

ceil(debt / (payoff * (1 - 1/EROI))). Algebraically identical to Eq. 5 because payoff * (1 - e_infer/payoff) == payoff - e_infer; implemented separately so the two can be asserted equal in tests.

pdmlabs.energy.metrics.eroi(delta_payoff, e_infer)#

Energy Return on Investment – E-LQO Eq. 4.

(payoff per cycle) / (online overhead per cycle). Above 1 means a cycle returns more than the inference it cost. Negative when the tuned pipeline is worse than the baseline, which is reported rather than hidden.

pdmlabs.energy.metrics.exploration_waste(trials, maximize=True)#

Energy spent on trials that never improved the incumbent.

The direct analogue of E-LQO’s finding that data collection – executing plans that were mostly discarded – dominates lifecycle energy. Cached trials are excluded: they did no work, so counting them would understate the waste fraction.

pdmlabs.energy.metrics.fit_diminishing_returns(trace, maximize=True)#

Fit Q(e) ~= Q* - beta / (1 + gamma * e) over normalised energy.

E-LQO’s Eq. 12, with exploration coverage replaced by normalised cumulative search energy. The useful output is the half-saturation point e_half = 1 / gamma: the fraction of the energy budget at which half the attainable quality gain has been captured, i.e. where to stop searching.

Falls back to a coarse empirical estimate when SciPy is unavailable or the fit does not converge, flagged by method.

pdmlabs.energy.metrics.lifecycle_summary(search_j, final_fit_j, infer_j, baseline_infer_j=None, delta_payoff=None, expected_cycles=None)#

Assemble the lifecycle picture, including phase shares and payback.

pdmlabs.energy.metrics.optimizer_overhead(search_j, trial_js)#

Energy the optimizer itself spent, outside any trial.

E_opt = E_search - sum(E_trial): surrogate fitting, acquisition optimisation, space conversion and backend bookkeeping. This has no E-LQO analogue and is the natural question to ask of a cross-optimizer study – does a smarter search cost more in the optimizer than it saves in trials?

Sound only when the phase envelope strictly enclosed every trial, which is why a negative residual is surfaced rather than clamped.

pdmlabs.energy.metrics.payback_regime(delta_payoff, e_infer)#

Name the regime, so undefined EPT is explained rather than blank.