Skip to content

optimizer

diapason.learning.optimize.optimizer

OptimizationEngine -- orchestrates the optimize loop.

Ties together the LLM optimizer, trial runner, and persistence store into a single propose -> evaluate -> analyze -> repeat loop.

OptimizationEngine

Orchestrates the optimize loop: propose -> evaluate -> analyze -> repeat.

export_best_recipe(run, path)

Export the best trial's config as a TOML recipe file.

Parameters:

Name Type Description Default
run OptimizationRun

A completed :class:OptimizationRun.

required
path Path

Destination path for the TOML file.

required

Returns:

Type Description
Path

The path written to.

Raises:

Type Description
ValueError

If there is no best trial in the run.

run(progress_callback=None)

Execute the full optimization loop.

  1. Generate a run_id via uuid.
  2. llm_optimizer.propose_initial() -> first config.
  3. Loop up to max_trials: a. trial_runner.run_trial(config) -> TrialResult b. llm_optimizer.analyze_trial(config, summary, traces) c. Update TrialResult with analysis text d. Append to history e. If store, store.save_trial(result) f. Update best_trial if accuracy improved g. Check early stopping (no improvement for patience trials) h. If not stopped, llm_optimizer.propose_next(history)
  4. Set run status to "completed".
  5. If store, store.save_run(optimization_run).
  6. Return the :class:OptimizationRun.

Parameters:

Name Type Description Default
progress_callback Optional[Callable[[int, int], None]]

Optional (trial_num, max_trials) -> None called after each trial completes.

None

compute_pareto_frontier(trials, objectives)

Compute the Pareto frontier: trials not dominated by any other.

A trial A dominates trial B if A is >= B on all objectives and > B on at least one (direction-aware: maximize flips the comparison).