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
+2 -2
View File
@@ -8,7 +8,7 @@ fn test_summary_with_completed_trials() {
let x = FloatParam::new(0.0, 10.0).name("x");
study
.optimize(5, |trial| {
.optimize(5, |trial: &mut optimizer::Trial| {
let val = x.suggest(trial)?;
Ok::<_, Error>(val * val)
})
@@ -61,7 +61,7 @@ fn test_display_matches_summary() {
let x = FloatParam::new(0.0, 10.0).name("x");
study
.optimize(3, |trial| {
.optimize(3, |trial: &mut optimizer::Trial| {
let val = x.suggest(trial)?;
Ok::<_, Error>(val)
})