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_search HPO: fit on the training episodes, scored on the VALIDATION

episodes (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 *_FINAL test 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_cache is forced off. A cache hit does no work but still runs an O(n^2) mlflow.search_runs, which collapses sum(E_trial) while E_search stays large – indistinguishable from enormous optimizer overhead.

  • The final pass uses INITIAL_RANDOM=0. With MAX_RUNS=1 and INITIAL_RANDOM=1, validate_budget_feasibility computes a minimum of two evaluations and raises.

  • Single-evaluation stages (the defaults baseline, and the final pass) are run with the mango backend 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 where mango_random raises KeyError: 'best_params' whenever n_iterations == 0, which is precisely what calculate_optimizer_budget returns for MAX_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_JOBS is 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_j derived from it is suspect – so the drift is recorded rather than averaged away.

Module Attributes

SINGLE_EVAL_OPTIMIZER

Backend used for stages that evaluate exactly one configuration.

SEQUENTIAL_BACKENDS

Backends that ignore n_jobs and always run trials sequentially.

Functions

run_concurrency_study(study_name,Β ...[,Β ...])

Energy and wall-clock against parallelism -- the E-LQO RQ3 analogue.

run_energy_study(study_name,Β train_dataset,Β ...)

Run a full lifecycle energy study and export a tidy record set.

pdmlabs.energy.study.SEQUENTIAL_BACKENDS = {'hyperopt'}#

Backends that ignore n_jobs and 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_random is broken at n_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 > 1 trials 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 any n_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 RuntimeError from the preflight when CPU energy would be a model rather than a measurement, unless allow_estimated is set – see pdmlabs.energy.preflight().