pub trait Sampler: Send + Sync {
// Required methods
fn sample(
&mut self,
space: &SearchSpace,
trial_index: usize,
) -> Result<Option<HashMap<String, Value>>>;
fn n_trials(&self) -> Option<usize>;
// Provided methods
fn prepare(&mut self, _space: &SearchSpace) { ... }
fn record_result(&mut self, _params: &HashMap<String, Value>, _value: f64) { ... }
}Expand description
A sampler produces hyperparameter configurations from a search space.
The contract is ask/tell: the runner calls prepare
once before the loop, sample to ask for the next
configuration, and record_result to tell
the sampler each completed trial’s objective value — the feedback
that model-based samplers (TPE, future BO backends) require.
Required Methods§
Provided Methods§
Sourcefn prepare(&mut self, _space: &SearchSpace)
fn prepare(&mut self, _space: &SearchSpace)
Called once before the trial loop with the resolved search
space. Lets samplers precompute state — e.g. GridSampler
resolves its dimension grid here so n_trials is correct
before the first sample.