mlos_core.optimizers.optimizer

Contains the BaseOptimizer abstract class.

Classes

BaseOptimizer

Optimizer abstract base class defining the basic interface:

Module Contents

class mlos_core.optimizers.optimizer.BaseOptimizer(*, parameter_space: ConfigSpace.ConfigurationSpace, optimization_targets: List[str], objective_weights: List[float] | None = None, space_adapter: mlos_core.spaces.adapters.adapter.BaseSpaceAdapter | None = None)[source]

Optimizer abstract base class defining the basic interface: suggest(), register(),

Create a new instance of the base optimizer.

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

  • optimization_targets (List[str]) – The names of the optimization targets to minimize. To maximize a target, use the negative of the target when registering scores.

  • 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.

__repr__() str[source]
Return type:

str

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

get_best_observations(n_max: int = 1) mlos_core.data_classes.Observations[source]

Get the N best observations so far as a filtered version of Observations. Default is N=1. The columns are ordered in ASCENDING order of the optimization targets. The function uses pandas.DataFrame.nsmallest(…, keep=”first”) method under the hood.

Parameters:

n_max (int) – Maximum number of best observations to return. Default is 1.

Returns:

observations – A filtered version of Observations with the best N observations.

Return type:

Observations

get_observations() mlos_core.data_classes.Observations[source]

Returns the observations as a triplet of DataFrames (config, score, context).

Returns:

observations – All the observations registered so far.

Return type:

Observations

register(observations: mlos_core.data_classes.Observation | mlos_core.data_classes.Observations) None[source]

Register all observations at once. Exactly one of observations or observation must be provided.

Parameters:

observations (Optional[Union[Observation, Observations]]) – The observations to register.

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

suggest(*, context: pandas.Series | None = None, defaults: bool = False) mlos_core.data_classes.Suggestion[source]

Wrapper method, which employs the space adapter (if any), after suggesting a new configuration.

Parameters:
  • context (pandas.Series) – Not Yet Implemented.

  • defaults (bool) – Whether or not to return the default config instead of an optimizer guided one. By default, use the one from the optimizer.

Returns:

suggestion – The suggested point to evaluate.

Return type:

Suggestion

optimizer_parameter_space: ConfigSpace.ConfigurationSpace[source]

The parameter space actually used by the optimizer.

(in case a SpaceAdapter is used)

parameter_space: ConfigSpace.ConfigurationSpace[source]

The parameter space to optimize.

property space_adapter: mlos_core.spaces.adapters.adapter.BaseSpaceAdapter | None[source]

Get the space adapter instance (if any).

Return type:

Optional[mlos_core.spaces.adapters.adapter.BaseSpaceAdapter]