smac.main.smbo

Classes

SMBO(scenario, runner, runhistory, intensifier)

Implementation that contains the main Bayesian optimization loop.

Interfaces

class smac.main.smbo.SMBO(scenario, runner, runhistory, intensifier, overwrite=False)[source]

Bases: object

Implementation that contains the main Bayesian optimization loop.

Parameters:
  • scenario (Scenario) – The scenario object, holding all environmental information.

  • runner (AbstractRunner) – The runner (containing the target function) is called internally to judge a trial’s performance.

  • runhistory (Runhistory) – The runhistory stores all trials.

  • intensifier (AbstractIntensifier) – The intensifier decides which trial (combination of configuration, seed, budget and instance) should be run next.

  • overwrite (bool, defaults to False) – When True, overwrites the run results if a previous run is found that is inconsistent in the meta data with the current setup. If overwrite is set to False, the user is asked for the exact behaviour (overwrite completely, save old run, or use old results).

Warning

This model should be initialized by a facade only.

ask()[source]

Asks the intensifier for the next trial.

Returns:

info – Information about the trial (config, instance, seed, budget).

Return type:

TrialInfo

property budget_exhausted: bool

Checks whether the the remaining walltime, cputime or trials was exceeded.

exists(filename)[source]

Checks if the files associated with the run already exist. Checks all files that are created by the optimizer.

Parameters:

filename (str | Path) – The name of the folder of the SMAC run.

Return type:

bool

property intensifier: AbstractIntensifier

The run history, which is filled with all information during the optimization process.

load()[source]

Loads the optimizer, intensifier, and runhistory from the output directory specified in the scenario.

Return type:

None

optimize(*, data_to_scatter=None)[source]

Runs the Bayesian optimization loop.

Parameters:

data_to_scatter (dict[str, Any] | None) – When a user scatters data from their local process to the distributed network, this data is distributed in a round-robin fashion grouping by number of cores. Roughly speaking, we can keep this data in memory and then we do not have to (de-)serialize the data every time we would like to execute a target function with a big dataset. For example, when your target function has a big dataset shared across all the target function, this argument is very useful.

Returns:

incumbent – The best found configuration.

Return type:

Configuration

print_stats()[source]

Prints all statistics.

Return type:

None

register_callback(callback, index=None)[source]

Registers a callback to be called before, in between, and after the Bayesian optimization loop.

Callback is appended to the list by default.

Parameters:
  • callback (Callback) – The callback to be registered.

  • index (int, optional) – The index at which the callback should be registered. The default is None. If it is None, append the callback to the list.

Return type:

None

property remaining_cputime: float

Subtracts the target function running budget with the used time.

property remaining_trials: int

Subtract the target function runs in the scenario with the used ta runs.

property remaining_walltime: float

Subtracts the runtime configuration budget with the used wallclock time.

reset()[source]

Resets the internal variables of the optimizer, intensifier, and runhistory.

Return type:

None

property runhistory: RunHistory

The run history, which is filled with all information during the optimization process.

save()[source]

Saves the current stats, runhistory, and intensifier.

Return type:

None

tell(info, value, save=True)[source]

Adds the result of a trial to the runhistory and updates the stats object.

Parameters:
  • info (TrialInfo) – Describes the trial from which to process the results.

  • value (TrialValue) – Contains relevant information regarding the execution of a trial.

  • save (bool, optional to True) – Whether the runhistory should be saved.

Return type:

None

update_acquisition_function(acquisition_function)[source]

Updates the acquisition function including the associated model and the acquisition optimizer.

Return type:

None

update_model(model)[source]

Updates the model and updates the acquisition function.

Return type:

None

property used_target_function_walltime: float

Returns how much walltime the target function spend so far.

property used_walltime: float

Returns used wallclock time.

validate(config, *, seed=None)[source]

Validates a configuration on other seeds than the ones used in the optimization process and on the highest budget (if budget type is real-valued). Does not exceed the maximum number of config calls or seeds as defined in the scenario.

Parameters:
  • config (Configuration) – Configuration to validate In case that the budget type is real-valued budget, this argument is ignored.

  • seed (int | None, defaults to None) – If None, the seed from the scenario is used.

Returns:

cost – The averaged cost of the configuration. In case of multi-fidelity, the cost of each objective is averaged.

Return type:

float | ndarray[float]