pdmlabs.energy.study#
Lifecycle energy study driver.
run_experiment searches over a single dataset dict; it has no notion of a
held-out test split and performs no final pass. The established protocol lives
in the test/ scripts: split with Dataset
(every get_*_dataset returns (train, test)), search on the first half,
then score the second. This module formalises that and wraps energy envelopes
around each stage, producing the phase decomposition the analysis needs:
E_searchHPO: fit on the training episodes, scored on the VALIDATIONepisodes (the targets of the first dict) β all trials plus optimizer overhead
E_final Refit + score the winning configuration on the TEST dict
E_baseline_* The untuned-defaults and random-search references, scored on
validation like SEARCH; each also gets a
*_FINALtest pass so tuned and baseline quality are compared on the same split
Two baselines, answering different questions#
defaults answers βwas tuning worth the energy at all?β; random search at an equal trial budget answers the sharper question for an HPO comparison, βwas smart tuning worth the energy over dumb tuning?β. A method can easily win the first and lose the second.
Protocol notes that are easy to get wrong#
use_cacheis forced off. A cache hit does no work but still runs an O(n^2)mlflow.search_runs, which collapsessum(E_trial)whileE_searchstays large β indistinguishable from enormous optimizer overhead.The final pass uses
INITIAL_RANDOM=0. WithMAX_RUNS=1andINITIAL_RANDOM=1,validate_budget_feasibilitycomputes a minimum of two evaluations and raises.Single-evaluation stages (the defaults baseline, and the final pass) are run with the
mangobackend regardless of the optimizer under test. With one configuration there is nothing to search, so the choice is immaterial to the result β and it sidesteps a pre-existing defect wheremango_randomraisesKeyError: 'best_params'whenevern_iterations == 0, which is precisely whatcalculate_optimizer_budgetreturns forMAX_RUNS=1. The optimizer a final pass belongs to is recorded in its experiment name.Repeats are interleaved (repeat outer, optimizer inner) rather than run back to back, so thermal drift is spread across conditions instead of being confounded with whichever optimizer ran last.
MAX_JOBSis forced to 1: concurrent trials share machine-wide energy counters and cannot be attributed individually.Each repeat gets its own seed (
base_seed + repeat_idx) and every record is stamped with both. Repeats that share a seed rerun the identical search, so their spread measures hardware noise rather than the optimizerβs run-to-run variance β which is usually the quantity of interest.BLAS thread counts are pinned for the duration of the study. Left at their default, libraries use every core, and a method whose internals happen to parallelise more makes its optimizer look energy-hungry for reasons that have nothing to do with search.
Idle is measured before and after each repeat. A baseline that drifts between the two means ambient conditions moved, and every
dynamic_jderived from it is suspect β so the drift is recorded rather than averaged away.
Module Attributes
Backend used for stages that evaluate exactly one configuration. |
|
Backends that ignore |
Functions
|
Energy and wall-clock against parallelism -- the E-LQO RQ3 analogue. |
|
Run a full lifecycle energy study and export a tidy record set. |
- pdmlabs.energy.study.SEQUENTIAL_BACKENDS = {'hyperopt'}#
Backends that ignore
n_jobsand always run trials sequentially. Including them in a concurrency sweep produces flat lines that look like a finding.
- pdmlabs.energy.study.SINGLE_EVAL_OPTIMIZER = 'mango'#
Backend used for stages that evaluate exactly one configuration. See the module docstring: with nothing to search the choice cannot affect the result, and
mango_randomis broken atn_iterations == 0.
- pdmlabs.energy.study.run_concurrency_study(study_name, train_dataset, methods, param_space_dict_per_method, method_names, experiments, experiment_names, optimizers=('mango',), n_jobs_levels=(1, 4, 8), MAX_RUNS=20, INITIAL_RANDOM=2, optimization_param='AD1_AUC', maximize=True, energy_tracking='codecarbon', energy_backend_kwargs=None, output_dir='./energy_runs', base_seed=42, blas_threads=4, measure_idle=True, idle_duration_s=60.0, allow_estimated=False, **run_experiment_kwargs)#
Energy and wall-clock against parallelism β the E-LQO RQ3 analogue.
Parallelism trades wall-clock for contention: more workers finish sooner but each is slower, and total energy can move either way. Answering βdoes running the search wider cost more energy overall?β needs the sweep.
Phase-level energy only, by construction. With
n_jobs > 1trials run concurrently in worker processes and share machine-wide counters, so no trial can be attributed its own energy β the instrumentation degrades to wall-clock automatically there. Phase energy stays valid at anyn_jobs, and is all this comparison needs.Returns
{'rows', 'summary', 'results', 'machine', 'idle', 'spool_dir'}.
- pdmlabs.energy.study.run_energy_study(study_name, train_dataset, test_dataset, methods, param_space_dict_per_method, method_names, experiments, experiment_names, optimizers=('mango',), MAX_RUNS=20, INITIAL_RANDOM=2, optimization_param='AD1_AUC', maximize=True, energy_tracking='codecarbon', energy_backend_kwargs=None, output_dir='./energy_runs', n_repeats=1, measure_idle=True, idle_duration_s=60.0, base_seed=42, blas_threads=4, bracket_idle=True, include_default_baseline=True, include_random_baseline=True, allow_estimated=False, run_final_pass=True, **run_experiment_kwargs)#
Run a full lifecycle energy study and export a tidy record set.
Returns
{'rows', 'summary', 'results', 'machine', 'idle', 'spool_dir'}.Raises
RuntimeErrorfrom the preflight when CPU energy would be a model rather than a measurement, unless allow_estimated is set β seepdmlabs.energy.preflight().