feat: unify optimize and optimize_with via blanket Objective impl

- Add blanket `impl Objective<V> for Fn(&mut Trial) -> Result<V, E>`
  so closures work directly with `optimize`
- Rewrite optimize, optimize_async, optimize_parallel to accept
  `impl Objective<V>` with before_trial/after_trial hooks
- Remove optimize_with, optimize_with_async, optimize_with_parallel
- Remove max_retries and retry logic from Objective trait
- Add explicit closure type annotations for HRTB inference
- Convert FnMut test closures to Fn via RefCell/Cell
This commit is contained in:
Manuel Raimann
2026-02-12 13:09:14 +01:00
parent c20a53dfba
commit 47b5f9cec8
41 changed files with 316 additions and 793 deletions
+4 -4
View File
@@ -23,7 +23,7 @@ fn bench_tpe_sphere(c: &mut Criterion) {
b.iter(|| {
let study = Study::minimize(TpeSampler::builder().seed(42).build().unwrap());
study
.optimize(100, |trial| {
.optimize(100, |trial: &mut optimizer::Trial| {
let x: Vec<f64> = params
.iter()
.map(|p| p.suggest(trial))
@@ -48,7 +48,7 @@ fn bench_tpe_rosenbrock(c: &mut Criterion) {
b.iter(|| {
let study = Study::minimize(TpeSampler::builder().seed(42).build().unwrap());
study
.optimize(100, |trial| {
.optimize(100, |trial: &mut optimizer::Trial| {
let x: Vec<f64> = params
.iter()
.map(|p| p.suggest(trial))
@@ -72,7 +72,7 @@ fn bench_random_vs_tpe(c: &mut Criterion) {
b.iter(|| {
let study = Study::minimize(RandomSampler::with_seed(42));
study
.optimize(100, |trial| {
.optimize(100, |trial: &mut optimizer::Trial| {
let x: Vec<f64> = params
.iter()
.map(|p| p.suggest(trial))
@@ -88,7 +88,7 @@ fn bench_random_vs_tpe(c: &mut Criterion) {
b.iter(|| {
let study = Study::minimize(TpeSampler::builder().seed(42).build().unwrap());
study
.optimize(100, |trial| {
.optimize(100, |trial: &mut optimizer::Trial| {
let x: Vec<f64> = params
.iter()
.map(|p| p.suggest(trial))