2026-01-30 18:08:13 +01:00
# optimizer
2026-01-30 17:33:33 +01:00
2026-02-12 08:33:23 +01:00
Bayesian and population-based optimization library with an Optuna-like API
for hyperparameter tuning and black-box optimization. Supports 12 samplers,
8 pruners, multi-objective optimization, async parallelism, and persistent storage.
2026-01-30 17:33:33 +01:00
2026-01-30 18:08:13 +01:00
[](https://docs.rs/optimizer)
[](https://crates.io/crates/optimizer)
[](https://codecov.io/gh/raimannma/rust-optimizer)
2026-01-30 17:33:33 +01:00
## Quick Start
```rust
2026-02-12 08:33:23 +01:00
use optimizer ::prelude ::* ;
2026-02-02 13:40:33 +01:00
2026-02-12 08:33:23 +01:00
let study : Study < f64 > = Study ::new ( Direction ::Minimize );
let x = FloatParam ::new ( - 10.0 , 10.0 ). name ( "x" );
2026-02-02 13:40:33 +01:00
2026-02-12 08:33:23 +01:00
study . optimize ( 50 , | trial | {
let val = x . suggest ( trial ) ? ;
Ok ::< _ , Error > (( val - 3.0 ). powi ( 2 ))
}). unwrap ();
2026-02-02 13:40:33 +01:00
2026-02-12 08:33:23 +01:00
let best = study . best_trial (). unwrap ();
println! ( "Best x = {:.4} , f(x) = {:.4} " , best . get ( & x ). unwrap (), best . value );
2026-02-02 13:40:33 +01:00
```
2026-02-12 08:33:23 +01:00
## Features at a Glance
2026-01-30 19:58:18 +01:00
2026-02-12 08:33:23 +01:00
- **[Samplers ](https://docs.rs/optimizer/latest/optimizer/sampler/ )** — Random, TPE, Multivariate TPE, Grid, Sobol, CMA-ES, Gaussian Process, Differential Evolution, BOHB, NSGA-II, NSGA-III, MOEA/D
- **[Pruners ](https://docs.rs/optimizer/latest/optimizer/pruner/ )** — Median, Percentile, Threshold, Patient, Hyperband, Successive Halving, Wilcoxon, Nop
- **[Parameters ](https://docs.rs/optimizer/latest/optimizer/parameter/ )** — Float, Int, Categorical, Bool, and Enum types with `.name()` labels and typed access
- **[Multi-objective ](https://docs.rs/optimizer/latest/optimizer/multi_objective/ )** — Pareto front extraction with NSGA-II/III and MOEA/D
- **[Async & parallel ](https://docs.rs/optimizer/latest/optimizer/struct.Study.html#method.optimize_parallel )** — Concurrent trial evaluation with Tokio
- **[Storage backends ](https://docs.rs/optimizer/latest/optimizer/storage/ )** — In-memory (default) or JSONL journal for persistence and resumption
2026-02-12 13:29:44 +01:00
- **[Visualization ](https://docs.rs/optimizer/latest/optimizer/fn.generate_html_report.html )** — HTML reports with optimization history and parameter importance
2026-02-12 08:33:23 +01:00
- **[Analysis ](https://docs.rs/optimizer/latest/optimizer/struct.Study.html#method.fanova )** — fANOVA and Spearman correlation for parameter importance
2026-01-30 19:58:18 +01:00
2026-01-30 17:33:33 +01:00
## Feature Flags
2026-02-12 08:33:23 +01:00
| Flag | Enables | Default |
|------|---------|---------|
| `async` | Async/parallel optimization (Tokio) | No |
| `derive` | `#[derive(Categorical)]` for enum parameters | No |
| `serde` | Serialization of trials and parameters | No |
| `journal` | JSONL storage backend (implies `serde` ) | No |
| `sobol` | Sobol quasi-random sampler | No |
| `cma-es` | CMA-ES sampler (requires `nalgebra` ) | No |
| `gp` | Gaussian Process sampler (requires `nalgebra` ) | No |
| `tracing` | Structured logging with `tracing` | No |
## Examples
```sh
2026-02-12 10:33:51 +01:00
cargo run --example basic_optimization # Minimize a quadratic — simplest possible usage
cargo run --example parameter_types --features derive # All 5 param types + #[derive(Categorical)]
cargo run --example sampler_comparison # Compare Random, TPE, and Grid on the same problem
cargo run --example pruning # Trial pruning with MedianPruner
cargo run --example early_stopping # Halt a study when a target is reached
cargo run --example async_parallel --features async # Evaluate trials concurrently with tokio
cargo run --example journal_storage --features journal # Persist trials to disk and resume later
cargo run --example ask_and_tell # Decouple sampling from evaluation
cargo run --example multi_objective # Optimize competing objectives + Pareto front
2026-02-12 08:33:23 +01:00
```
2026-01-30 17:33:33 +01:00
2026-02-12 08:33:23 +01:00
## Learn More
2026-01-30 17:33:33 +01:00
2026-02-12 08:33:23 +01:00
- [API documentation ](https://docs.rs/optimizer )
- [Changelog ](CHANGELOG.md )
- [GitHub Issues ](https://github.com/raimannma/rust-optimizer/issues )
2026-01-30 17:33:33 +01:00
## License
MIT