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) Tuple[pandas.DataFrame, pandas.DataFrame, pandas.DataFrame | None][source]

Get the N best observations so far as a triplet of DataFrames (config, score, context). 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 triplet of best (config, score, context) DataFrames of best observations.

Return type:

Tuple[pandas.DataFrame, pandas.DataFrame, Optional[pandas.DataFrame]]

get_observations() Tuple[pandas.DataFrame, pandas.DataFrame, pandas.DataFrame | None][source]

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

Returns:

observations – A triplet of (config, score, context) DataFrames of observations.

Return type:

Tuple[pandas.DataFrame, pandas.DataFrame, Optional[pandas.DataFrame]]

register(*, configs: pandas.DataFrame, scores: pandas.DataFrame, context: pandas.DataFrame | None = None, metadata: pandas.DataFrame | None = None) None[source]

Wrapper method, which employs the space adapter (if any), before registering the configs and scores.

Parameters:
  • configs (pandas.DataFrame) – Dataframe of configs / parameters. The columns are parameter names and the rows are the configs.

  • scores (pandas.DataFrame) – Scores from running the configs. The index is the same as the index of the configs.

  • context (pandas.DataFrame) – Not Yet Implemented.

  • metadata (Optional[pandas.DataFrame]) – Metadata returned by the backend optimizer’s suggest method.

Return type:

None

abstract register_pending(*, configs: pandas.DataFrame, context: pandas.DataFrame | None = None, metadata: pandas.DataFrame | None = None) None[source]

Registers the given configs 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:
  • configs (pandas.DataFrame) – Dataframe of configs / parameters. The columns are parameter names and the rows are the configs.

  • context (pandas.DataFrame) – Not Yet Implemented.

  • metadata (Optional[pandas.DataFrame]) – Metadata returned by the backend optimizer’s suggest method.

Return type:

None

suggest(*, context: pandas.DataFrame | None = None, defaults: bool = False) Tuple[pandas.DataFrame, pandas.DataFrame | None][source]

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

Parameters:
  • context (pandas.DataFrame) – 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:

  • configuration (pandas.DataFrame) – Pandas dataframe with a single row. Column names are the parameter names.

  • metadata (Optional[pandas.DataFrame]) – The metadata associated with the given configuration used for evaluations. Backend optimizer specific.

Return type:

Tuple[pandas.DataFrame, Optional[pandas.DataFrame]]

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]