Skip to main content

Module sampler

Module sampler 

Expand description

The sampler seam: how a trial’s parameters are chosen.

§Deliberate divergences from prior art

Every one of these is a fix for something that hurt in a framework we looked at:

  • Fallible everywhere. Sampling returns Result. An infallible sample() forces implementations to panic when a space is exhausted or a numeric decomposition fails, and a panicking sampler takes the whole study down.
  • Joint-space aware. Sampler::sample_relative receives the entire relative space at once, so a sampler can model correlations between parameters. A strictly per-parameter API cannot express that, no matter how good the sampler is.
  • State is data, not object innards. Sampler::state returns a serializable StateBlob that the framework persists. No pickled objects, no in-instance caches that quietly break multi-process runs.
  • Pending trials are always visible. StudyView::running exposes in-flight trials to every sampler, so constant-liar and qEI-style repulsion is possible without each sampler plumbing its own bookkeeping.
  • Seeds are handed in, not taken. The framework precomputes TrialMeta::sampler_seed; a stateless sampler that seeds ChaCha8Rng from it is deterministic per trial number by construction.

§The built-in samplers

SamplerChoosesKeyed onDeterminism
Randomuniformly over each support, independently(sampler seed, parameter name)promise 2 (stateless)
Gridevery point of a finite space, once eachthe trial numberpromise 2 (stateless)
Qmca low-discrepancy Sobol (default) or Halton point, filling space evenlythe trial numberpromise 2 (stateless)
Tpethe point a learned density ratio prefersthe history it is shownsingle-worker + replay
Dehba differential-evolution child of a per-fidelity populationthe DE state it carriessingle-worker + replay
Nsga2a crossover-and-mutation child of a Pareto-ranked populationthe population it carriessingle-worker + replay
Nsga3an NSGA-II child, kept by reference-direction survivalthe population it carriessingle-worker + replay

Random, Grid and Qmc are stateless: their draw is a pure function of the trial number and the space, so they carry the strongest promise the determinism contract offers. Random never draws sequentially from one per-trial RNG — each parameter gets its own stream, derived with seed_for_name, so a value is stable when the search space gains, loses or reorders a parameter, and Sampler::sample_relative and Sampler::sample_independent agree by construction.

Tpe is history-dependent — it learns from completed and pending trials — so it deliberately does not get promise 2 under parallelism. It keeps no hidden mutable state (everything is recomputed from the StudyView each decision), which buys it single-worker determinism plus replayability instead; its own documentation states this precisely.

Dehb is the first genuinely stateful sampler: it carries DE populations, one per multi-fidelity budget, that cannot be recomputed from history — so it is the first real consumer of the sampler-state seam (state/restore_state), and a study reopened from storage continues with the exact populations it left. Like Tpe it is single-worker deterministic and parallel-replayable.

Nsga2 is the general multi-objective sampler: it carries a Pareto-ranked population, ranks it by non-domination and crowding distance (pareto), and answers the question StudyView::best deliberately refuses for a multi-objective study. Like Dehb it is stateful, single-worker deterministic and parallel-replayable.

Nsga3 is its many-objective counterpart: it breeds the same way but replaces crowding distance with survival along reference directions, which keeps a population spread where, beyond three objectives, nearly every solution is non-dominated. It carries the same promises as Nsga2.

Re-exports§

pub use dehb::DEFAULT_CROSSOVER_PROB;
pub use dehb::DEFAULT_MUTATION_FACTOR;
pub use dehb::Dehb;
pub use dehb::MAX_TOTAL_POP_SIZE;
pub use nsga2::DEFAULT_CROSSOVER_ETA;
pub use nsga2::DEFAULT_MUTATION_ETA;
pub use nsga2::DEFAULT_POPULATION_SIZE;
pub use nsga2::DEFAULT_SWAPPING_PROB;
pub use nsga2::MAX_POPULATION_SIZE;
pub use nsga2::MIN_POPULATION_SIZE;
pub use nsga2::Nsga2;
pub use nsga3::DEFAULT_DIVIDING_PARAMETER;
pub use nsga3::MAX_REFERENCE_POINTS;
pub use nsga3::Nsga3;

Modules§

dehb
DEHB — Differential-Evolution Hyperband, the low-budget black-box tuner for RL.
nsga2
NSGA-II — the elitist non-dominated sorting genetic algorithm, and atune’s multi-objective sampler.
nsga3
NSGA-III — the reference-point-based many-objective genetic algorithm.

Structs§

Grid
Walks every point of a finite space, once each, in a fixed order.
Qmc
A quasi-random Sobol or Halton sampler.
Random
Samples every parameter independently and uniformly over its support.
Tpe
A Tree-structured Parzen Estimator sampler.

Enums§

QmcSequence
Which low-discrepancy sequence a Qmc sampler draws. This enum may gain variants; downstream matches must handle unknown variants.

Constants§

HALTON_DIMENSIONS
The number of Halton dimensions this implementation covers directly — one prime base per dimension, the first 256 primes (2 ..= 1619).
SOBOL_DIMENSIONS
The number of Sobol dimensions this implementation covers directly.
SOBOL_POINTS
How many distinct points the sequence has: 2^BITS.

Traits§

Sampler
Chooses parameter values for a trial.

Type Aliases§

SamplerState
Sampler state as the framework persists it.