Bayesian and population-based optimization library with an Optuna-like API
for hyperparameter tuning and black-box optimization. It ships 12 samplers
(from random search to CMA-ES and NSGA-III), 8 pruners, async/parallel
evaluation, and optional journal-based persistence — all with zero required
feature flags for the common case.
§Getting Started
Minimize a function in five lines — no feature flags needed:
use optimizer::prelude::*;
let study: Study<f64> = Study::new(Direction::Minimize);
let x = FloatParam::new(-10.0, 10.0).name("x");
study
.optimize(50, |trial: &mut optimizer::Trial| {
let v = x.suggest(trial)?;
Ok::<_, Error>((v - 3.0).powi(2))
})
.unwrap();
let best = study.best_trial().unwrap();
println!("x = {:.4}, f(x) = {:.4}", best.get(&x).unwrap(), best.value);
§Core Concepts
| Type | Role |
Study | Drive an optimization loop: create trials, record results, track the best. |
Trial | A single evaluation of the objective function, carrying suggested parameter values. |
Parameter | Define the search space — FloatParam, IntParam, CategoricalParam, BoolParam, EnumParam. |
Sampler | Strategy for choosing the next point to evaluate (TPE, CMA-ES, random, etc.). |
Direction | Whether the study minimizes or maximizes the objective value. |
§Sampler Guide
§Single-objective samplers
| Sampler | Algorithm | Best for | Feature flag |
RandomSampler | Uniform random | Baselines, high-dimensional | — |
TpeSampler | Tree-Parzen Estimator | General-purpose Bayesian | — |
GridSearchSampler | Exhaustive grid | Small, discrete spaces | — |
SobolSampler | Sobol quasi-random sequence | Space-filling, low dimensions | sobol |
CmaEsSampler | CMA-ES | Continuous, moderate dimensions | cma-es |
GpSampler | Gaussian Process + EI | Expensive objectives, few trials | gp |
DESampler | Differential Evolution | Non-convex, population-based | — |
BohbSampler | BOHB (TPE + HyperBand) | Budget-aware early stopping | — |
§Multi-objective samplers
| Sampler | Algorithm | Best for | Feature flag |
Nsga2Sampler | NSGA-II | 2-3 objectives | — |
Nsga3Sampler | NSGA-III (reference-point) | 3+ objectives | — |
MoeadSampler | MOEA/D (decomposition) | Many objectives, structured fronts | — |
MotpeSampler | Multi-Objective TPE | Bayesian multi-objective | — |
§Feature Flags
| Flag | What it enables | Default |
async | Async/parallel optimization via tokio (Study::optimize_async, Study::optimize_parallel) | off |
derive | #[derive(Categorical)] for enum parameters | off |
serde | Serialize/Deserialize on public types, Study::save/Study::load | off |
journal | JournalStorage — JSONL persistence with file locking (enables serde) | off |
sobol | SobolSampler — quasi-random low-discrepancy sequences | off |
cma-es | CmaEsSampler — Covariance Matrix Adaptation Evolution Strategy | off |
gp | GpSampler — Gaussian Process surrogate with Expected Improvement | off |
tracing | Structured log events via tracing at key optimization points | off |