bencher.optuna_conversions

Attributes

logger

_EXPECTED_PLOT_FAILURES

Functions

optuna_grid_search(→ optuna.Study)

use optuna to perform a grid search

param_importance(→ panel.Column)

summarise_trial(→ list[str])

Given a trial produce a string summary of the best results

sweep_var_to_optuna_dist(...)

Convert a sweep var to an optuna distribution

sweep_var_to_suggest(→ object)

Converts from a sweep var to an optuna

cfg_from_optuna_trial(...)

Build a worker config from an optuna trial's suggested values.

_plot_failure_pane(plot_fn, exc, *[, unexpected])

Build the error pane that replaces a plot that failed to render.

_append_safe(row, plot_fn, *args, **kwargs)

Append a plot to row, surfacing any exception instead of propagating.

_append_safe_sized(row, plot_fn, width, *args, **kwargs)

Like _append_safe but sets a consistent width on the resulting plotly figure.

Module Contents

bencher.optuna_conversions.logger

use optuna to perform a grid search

Parameters:
  • bench_cfg (BenchCfg) – setting for grid search

  • trial_vars (list | None) – If provided, use these variables for the search space. Otherwise, filter bench_cfg.all_vars by optimize=True.

Returns:

results of grid search

Return type:

optuna.Study

bencher.optuna_conversions.param_importance(bench_cfg: bencher.bench_cfg.BenchCfg, study: optuna.Study, plot_width: int | None = None) panel.Column
bencher.optuna_conversions.summarise_trial(trial: optuna.trial, bench_cfg: bencher.bench_cfg.BenchCfg) list[str]

Given a trial produce a string summary of the best results

Parameters:
  • trial (optuna.trial) – trial to summarise

  • bench_cfg (BenchCfg) – info about the trial

Returns:

Summary of trial

Return type:

list[str]

bencher.optuna_conversions.sweep_var_to_optuna_dist(var: param.Parameter) optuna.distributions.BaseDistribution

Convert a sweep var to an optuna distribution

Parameters:

var (param.Parameter) – A sweep var

Raises:

ValueError – Unsupported var type

Returns:

Optuna representation of a sweep var

Return type:

optuna.distributions.BaseDistribution

bencher.optuna_conversions.sweep_var_to_suggest(iv: bencher.variables.parametrised_sweep.ParametrizedSweep, trial: optuna.trial) object

Converts from a sweep var to an optuna

Parameters:
  • iv (ParametrizedSweep) – A parametrized sweep input variable

  • trial (optuna.trial) – Optuna trial used to define the sample

Raises:

ValueError – Unsupported var type

Returns:

A sampled variable (can be any type)

Return type:

Any

bencher.optuna_conversions.cfg_from_optuna_trial(trial: optuna.trial, bench_cfg: bencher.bench_cfg.BenchCfg, cfg_type: type[bencher.variables.parametrised_sweep.ParametrizedSweep]) bencher.variables.parametrised_sweep.ParametrizedSweep

Build a worker config from an optuna trial’s suggested values.

cfg_type is the worker class, not an instance – it is called here to construct one. Annotating it ParametrizedSweep makes a checker resolve cfg_type() through Parameterized.__call__ and infer a dict.

bencher.optuna_conversions._EXPECTED_PLOT_FAILURES
bencher.optuna_conversions._plot_failure_pane(plot_fn, exc: Exception, *, unexpected: bool = False)

Build the error pane that replaces a plot that failed to render.

unexpected marks an exception outside _EXPECTED_PLOT_FAILURES; it gets an extra ERROR log naming the type, because an unanticipated type here is a signal that the expected-failure tuple has fallen out of date.

bencher.optuna_conversions._append_safe(row, plot_fn, *args, **kwargs)

Append a plot to row, surfacing any exception instead of propagating.

Nothing is ever re-raised: this runs while the report is being built, after the sweep has already paid for every sample, so a crash here would throw away the whole run’s results to report one missing plot. A visible error pane costs nothing and keeps the rest of the report.

bencher.optuna_conversions._append_safe_sized(row, plot_fn, width, *args, **kwargs)

Like _append_safe but sets a consistent width on the resulting plotly figure.