mlos_core.optimizers.bayesian_optimizers.smac_optimizer

Contains the wrapper class for the SmacOptimizer.

Notes

See the SMAC3 Documentation for more details.

Classes

SmacOptimizer

Wrapper class for SMAC based Bayesian optimization.

Module Contents

class mlos_core.optimizers.bayesian_optimizers.smac_optimizer.SmacOptimizer(*, parameter_space: ConfigSpace.ConfigurationSpace, optimization_targets: List[str], objective_weights: List[float] | None = None, space_adapter: mlos_core.spaces.adapters.adapter.BaseSpaceAdapter | None = None, seed: int | None = 0, run_name: str | None = None, output_directory: str | None = None, max_trials: int = 100, n_random_init: int | None = None, max_ratio: float | None = None, use_default_config: bool = False, n_random_probability: float = 0.1)[source]

Bases: mlos_core.optimizers.bayesian_optimizers.bayesian_optimizer.BaseBayesianOptimizer

Wrapper class for SMAC based Bayesian optimization.

Instantiate a new SMAC optimizer wrapper.

Parameters:
  • parameter_space (ConfigSpace.ConfigurationSpace) – The parameter space to optimize.

  • optimization_targets (List[str]) – The names of the optimization targets to minimize.

  • objective_weights (Optional[List[float]]) – Optional list of weights of optimization targets.

  • space_adapter (BaseSpaceAdapter) – The space adapter class to employ for parameter space transformations.

  • seed (Optional[int]) – By default SMAC uses a known seed (0) to keep results reproducible. However, if a None seed is explicitly provided, we let a random seed be produced by SMAC.

  • run_name (Optional[str]) – Name of this run. This is used to easily distinguish across different runs. If set to None (default), SMAC will generate a hash from metadata.

  • output_directory (Optional[str]) – The directory where SMAC output will saved. If set to None (default), a temporary dir will be used.

  • max_trials (int) – Maximum number of trials (i.e., function evaluations) to be run. Defaults to 100. Note that modifying this value directly affects the value of n_random_init, if latter is set to None.

  • n_random_init (Optional[int]) – Number of points evaluated at start to bootstrap the optimizer. Default depends on max_trials and number of parameters and max_ratio. Note: it can sometimes be useful to set this to 1 when pre-warming the optimizer from historical data. See Also: mlos_bench.optimizers.base_optimizer.Optimizer.bulk_register()

  • max_ratio (Optional[int]) – Maximum ratio of max_trials to be random configs to be evaluated at start to bootstrap the optimizer. Useful if you want to explicitly control the number of random configs evaluated at start.

  • use_default_config (bool) – Whether to use the default config for the first trial after random initialization.

  • n_random_probability (float) – Probability of choosing to evaluate a random configuration during optimization. Defaults to 0.1. Setting this to a higher value favors exploration over exploitation.

__del__() None[source]
Return type:

None

acquisition_function(suggestion: mlos_core.data_classes.Suggestion) numpy.typing.NDArray[source]

Invokes the acquisition function from this Bayesian optimizer for the given configuration.

Parameters:

suggestion (Suggestion) – The suggestion containing the configuration(s) to evaluate.

Return type:

numpy.typing.NDArray

cleanup() None[source]

Remove temp files, release resources, etc.

after use. Default is no-op. Redefine this method in optimizers that require cleanup.

Return type:

None

abstract register_pending(pending: mlos_core.data_classes.Suggestion) None[source]

Registers the given suggestion as “pending”. That is it say, it has been suggested by the optimizer, and an experiment trial has been started. This can be useful for executing multiple trials in parallel, retry logic, etc.

Parameters:

pending (Suggestion) – The pending suggestion to register.

Return type:

None

surrogate_predict(suggestion: mlos_core.data_classes.Suggestion) numpy.typing.NDArray[source]

Obtain a prediction from this Bayesian optimizer’s surrogate model for the given configuration(s).

Parameters:

suggestion (Suggestion) – The suggestion containing the configuration(s) to predict.

Return type:

numpy.typing.NDArray

base_optimizer[source]
property max_ratio: float | None[source]

Gets the max_ratio parameter used in py:meth:constructor <.__init__> of this SmacOptimizer.

Return type:

float

property n_random_init: int[source]

Gets the number of random samples to use to initialize the optimizer’s search space sampling.

Note: This may not be equal to the value passed to the initializer, due to logic present in the SMAC.

See also

max_ratio

Returns:

The number of random samples used to initialize the optimizer’s search space sampling.

Return type:

int

trial_info_map: Dict[ConfigSpace.Configuration, smac.runhistory.TrialInfo][source]