Skip to contents

optimization_result() reports what compile() or optimize_grid() did to a program: the optimizer, the baseline and best scores, the winning parameters, every trial, and why the search stopped. All optimizers report the same core fields; optimizer-specific details live under extensions, keyed by the optimizer's name in snake case (for example extensions$gepa or extensions$better_together).

Usage

optimization_result(program)

# S3 method for class 'dsprrr_optimization_result'
print(x, ...)

Arguments

program

A module returned by compile() or modified by optimize_grid().

x

An optimization result.

...

Additional arguments, currently unused.

Value

A dsprrr_optimization_result list with fields:

  • version: result schema version.

  • optimizer: the optimizer's name.

  • status: "completed", or "partial" when a budget stopped the run.

  • baseline_score, best_score and best_trial: outcome measures, NA for optimizers that score nothing.

  • best_params: the winning parameter values.

  • trials: trial-level results as a tibble.

  • lineage: how the winning candidate was derived.

  • budget: the budget used, for optimizers run under optimizer_control().

  • stop_reason: why the optimizer stopped.

  • extensions: optimizer-specific details.

Returns NULL when program has not been optimized. print() shows a short summary and returns x invisibly.

Examples

classifier <- module(signature("text -> sentiment"))
trainset <- data.frame(
  text = c("I love it!", "Terrible experience", "It's okay"),
  sentiment = c("positive", "negative", "neutral")
)
compiled <- compile(classifier, LabeledFewShot(k = 2L), trainset)

result <- optimization_result(compiled)
result
#> <dsprrr_optimization_result>
#> Optimizer: LabeledFewShot
#> Status: completed
#> Trials: 0
#> Stopped: completed
result$best_params
#> $k
#> [1] 2
#> 
result$extensions$labeled_few_shot
#> $sample
#> [1] TRUE
#> 
#> $seed
#> [1] 123
#> 

# Not optimized
optimization_result(classifier)
#> NULL