smac.scenario

Classes

Scenario(configspace[, name, ...])

The scenario manages environment variables and therefore gives context in which frame the optimization is performed.

Interfaces

class smac.scenario.Scenario(configspace, name=None, output_directory=PosixPath('smac3_output'), deterministic=False, objectives='cost', crash_cost=inf, termination_cost_threshold=inf, walltime_limit=inf, cputime_limit=inf, trial_walltime_limit=None, trial_memory_limit=None, n_trials=100, instances=None, instance_features=None, min_budget=None, max_budget=None, seed=0, n_workers=1)[source]

Bases: object

The scenario manages environment variables and therefore gives context in which frame the optimization is performed.

Parameters:
  • configspace (ConfigSpace) – The configuration space from which to sample the configurations.

  • name (str | None, defaults to None) – The name of the run. If no name is passed, SMAC generates a hash from the meta data. Specify this argument to identify your run easily.

  • output_directory (Path, defaults to Path("smac3_output")) – The directory in which to save the output. The files are saved in ./output_directory/name/seed.

  • deterministic (bool, defaults to False) – If deterministic is set to true, only one seed is passed to the target function. Otherwise, multiple seeds (if n_seeds of the intensifier is greater than 1) are passed to the target function to ensure generalization.

  • objective (str | list[str] | None, defaults to "cost") – The objective(s) to optimize. This argument is required for multi-objective optimization.

  • crash_cost (float | list[float], defaults to np.inf) – Defines the cost for a failed trial. In case of multi-objective, each objective can be associated with a different cost.

  • termination_cost_threshold (float | list[float], defaults to np.inf) – Defines a cost threshold when the optimization should stop. In case of multi-objective, each objective must be associated with a cost. The optimization stops when all objectives crossed the threshold.

  • walltime_limit (float, defaults to np.inf) – The maximum time in seconds that SMAC is allowed to run.

  • cputime_limit (float, defaults to np.inf) – The maximum CPU time in seconds that SMAC is allowed to run.

  • trial_walltime_limit (float | None, defaults to None) – The maximum time in seconds that a trial is allowed to run. If not specified, no constraints are enforced. Otherwise, the process will be spawned by pynisher.

  • trial_memory_limit (int | None, defaults to None) – The maximum memory in MB that a trial is allowed to use. If not specified, no constraints are enforced. Otherwise, the process will be spawned by pynisher.

  • n_trials (int, defaults to 100) – The maximum number of trials (combination of configuration, seed, budget, and instance, depending on the task) to run.

  • instances (list[str] | None, defaults to None) – Names of the instances to use. If None, no instances are used. Instances could be dataset names, seeds, subsets, etc.

  • instance_features (dict[str, list[float]] | None, defaults to None) – Instances can be associated with features. For example, meta data of the dataset (mean, var, …) can be incorporated which are then further used to expand the training data of the surrogate model.

  • instance_order (str | None, defaults to "shuffle_once") – How to order the instances. Possible values are “shuffle” and “shuffle_once”. You can disable this feature by setting the argument to None.

  • min_budget (float | None, defaults to None) – The minimum budget (epochs, subset size, number of instances, …) that is used for the optimization. Use this argument if you use multi-fidelity or instance optimization.

  • max_budget (float | None, defaults to None) – The maximum budget (epochs, subset size, number of instances, …) that is used for the optimization. Use this argument if you use multi-fidelity or instance optimization.

  • seed (int, defaults to 0) – The seed is used to make results reproducible. If seed is -1, SMAC will generate a random seed.

  • n_workers (int, defaults to 1) – The number of workers to use for parallelization. If n_workers is greather than 1, SMAC will use Dask to parallelize the optimization.

__post_init__()[source]

Checks whether the config is valid.

Return type:

None

count_instance_features()[source]

Counts the number of instance features.

Return type:

int

count_objectives()[source]

Counts the number of objectives.

Return type:

int

static load(path)[source]

Loads a scenario and the configuration space from a file.

Return type:

Scenario

static make_serializable(scenario)[source]

Makes the scenario serializable.

Return type:

dict[str, Any]

property meta: dict[str, Any]

Returns the meta data of the SMAC run.

Note

Meta data are set when the facade is initialized.

Return type:

dict[str, Any]

save()[source]

Saves internal variables and the configuration space to a file.

Return type:

None