Skip to main content

Crate optimizer

Crate optimizer 

Source
Expand description

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

TypeRole
StudyDrive an optimization loop: create trials, record results, track the best.
TrialA single evaluation of the objective function, carrying suggested parameter values.
ParameterDefine the search space — FloatParam, IntParam, CategoricalParam, BoolParam, EnumParam.
SamplerStrategy for choosing the next point to evaluate (TPE, CMA-ES, random, etc.).
DirectionWhether the study minimizes or maximizes the objective value.

§Sampler Guide

§Single-objective samplers

SamplerAlgorithmBest forFeature flag
RandomSamplerUniform randomBaselines, high-dimensional
TpeSamplerTree-Parzen EstimatorGeneral-purpose Bayesian
GridSearchSamplerExhaustive gridSmall, discrete spaces
SobolSamplerSobol quasi-random sequenceSpace-filling, low dimensionssobol
CmaEsSamplerCMA-ESContinuous, moderate dimensionscma-es
GpSamplerGaussian Process + EIExpensive objectives, few trialsgp
DESamplerDifferential EvolutionNon-convex, population-based
BohbSamplerBOHB (TPE + HyperBand)Budget-aware early stopping

§Multi-objective samplers

SamplerAlgorithmBest forFeature flag
Nsga2SamplerNSGA-II2-3 objectives
Nsga3SamplerNSGA-III (reference-point)3+ objectives
MoeadSamplerMOEA/D (decomposition)Many objectives, structured fronts
MotpeSamplerMulti-Objective TPEBayesian multi-objective

§Feature Flags

FlagWhat it enablesDefault
asyncAsync/parallel optimization via tokio (Study::optimize_async, Study::optimize_parallel)off
derive#[derive(Categorical)] for enum parametersoff
serdeSerialize/Deserialize on public types, Study::save/Study::loadoff
journalJournalStorage — JSONL persistence with file locking (enables serde)off
sobolSobolSampler — quasi-random low-discrepancy sequencesoff
cma-esCmaEsSampler — Covariance Matrix Adaptation Evolution Strategyoff
gpGpSampler — Gaussian Process surrogate with Expected Improvementoff
tracingStructured log events via tracing at key optimization pointsoff

Re-exports§

pub use objective::Objective;

Modules§

distribution
Parameter distribution types.
multi_objective
Multi-objective optimization via a dedicated study type.
objective
The Objective trait defines what gets optimized.
param
Raw parameter value storage.
parameter
Parameter trait and five built-in parameter types.
pareto
Pareto front analysis utilities for multi-objective optimization.
prelude
Convenient wildcard import for the most common types.
pruner
Pruner trait and implementations for trial pruning.
sampler
Sampler trait and implementations for parameter sampling.
storage
Trial storage backends.

Structs§

FanovaConfig
Configuration for fANOVA analysis.
FanovaResult
Result of fANOVA analysis.
Study
A study manages the optimization process, tracking trials and their results.
StudyBuilder
A builder for constructing Study instances with a fluent API.
Trial
A single evaluation of the objective function.
TrialPruned
Convenience type for signalling a pruned trial from an objective function.

Enums§

AttrValue
A user attribute value that can be stored on a trial.
Direction
The direction of optimization.
Error
Errors returned by optimizer operations.
TrialState
The state of a trial in its lifecycle.

Functions§

generate_html_report
Generate an HTML report with interactive Plotly.js charts.

Type Aliases§

Result
A convenience alias for core::result::Result<T, Error>.