smac.tae.execute_func

Classes

AbstractTAFunc(ta, stats[, ...])

Baseclass to execute target algorithms which are python functions.

ExecuteTAFuncArray(ta, stats[, ...])

Evaluate function for given configuration and resource limit.

ExecuteTAFuncDict(ta, stats[, ...])

Evaluate function for given configuration and resource limit.

class smac.tae.execute_func.AbstractTAFunc(ta, stats, multi_objectives=['cost'], run_obj='quality', memory_limit=None, par_factor=1, cost_for_crash=2147483647.0, abort_on_first_run_crash=False, use_pynisher=True)[source]

Bases: smac.tae.serial_runner.SerialRunner

Baseclass to execute target algorithms which are python functions.

Note:* Do not use directly

Parameters
  • ta (callable) – Function (target algorithm) to be optimized.

  • stats (Stats()) – stats object to collect statistics about runtime and so on

  • multi_objectives (List[str]) – names of the objectives, by default it is a single objective parameter “cost”

  • run_obj (str) – run objective of SMAC

  • memory_limit (int, optional) – Memory limit (in MB) that will be applied to the target algorithm.

  • par_factor (int) – penalization factor

  • cost_for_crash (float) – cost that is used in case of crashed runs (including runs that returned NaN or inf)

  • use_pynisher (bool) –

    use pynisher to limit resources; if disabled

    • TA func can use as many resources

    as it wants (time and memory) — use with caution * all runs will be returned as SUCCESS if returned value is not None

memory_limit
use_pynisher
run(config, instance=None, cutoff=None, seed=12345, budget=None, instance_specific='0')[source]

Runs target algorithm <self._ta> with configuration <config> for at most <cutoff> seconds, allowing it to use at most <memory_limit> RAM.

Whether the target algorithm is called with the <instance> and <seed> depends on the subclass implementing the actual call to the target algorithm.

Parameters
  • config (Configuration, dictionary (or similar)) – Dictionary param -> value

  • instance (str, optional) – Problem instance

  • cutoff (float, optional) – Wallclock time limit of the target algorithm. If no value is provided no limit will be enforced. It is casted to integer internally.

  • seed (int) – Random seed

  • budget (float, optional) – A positive, real-valued number representing an arbitrary limit to the target algorithm Handled by the target algorithm internally

  • instance_specific (str) – Instance specific information (e.g., domain file or solution)

Return type

Tuple[StatusType, float, float, Dict]

Returns

  • status (enum of StatusType (int)) – {SUCCESS, TIMEOUT, CRASHED, ABORT}

  • cost (np.ndarray) – cost/regret/quality/runtime (float) (None, if not returned by TA)

  • runtime (float) – runtime (None if not returned by TA)

  • additional_info (dict) – all further additional run information

class smac.tae.execute_func.ExecuteTAFuncArray(ta, stats, multi_objectives=['cost'], run_obj='quality', memory_limit=None, par_factor=1, cost_for_crash=2147483647.0, abort_on_first_run_crash=False, use_pynisher=True)[source]

Bases: smac.tae.execute_func.AbstractTAFunc

Evaluate function for given configuration and resource limit.

Passes the configuration as an array-like to the target algorithm. The target algorithm needs to implement one of the following signatures:

  • target_algorithm(config: np.ndarray) -> Union[float, Tuple[float, Any]]

  • target_algorithm(config: np.ndarray, seed: int) -> Union[float, Tuple[float, Any]]

  • target_algorithm(config: np.ndarray, seed: int, instance: str) -> Union[float, Tuple[float, Any]]

The target algorithm can either return a float (the loss), or a tuple with the first element being a float and the second being additional run information.

ExecuteTAFuncDict will use inspection to figure out the correct call to the target algorithm.

Parameters
  • ta (callable) – Function (target algorithm) to be optimized.

  • stats (smac.stats.stats.Stats, optional) – Stats object to collect statistics about runtime etc.

  • run_obj (str, optional) – Run objective (runtime or quality)

  • memory_limit (int, optional) – Memory limit (in MB) that will be applied to the target algorithm.

  • par_factor (int, optional) – Penalized average runtime factor. Only used when run_obj=’runtime’

class smac.tae.execute_func.ExecuteTAFuncDict(ta, stats, multi_objectives=['cost'], run_obj='quality', memory_limit=None, par_factor=1, cost_for_crash=2147483647.0, abort_on_first_run_crash=False, use_pynisher=True)[source]

Bases: smac.tae.execute_func.AbstractTAFunc

Evaluate function for given configuration and resource limit.

Passes the configuration as a dictionary to the target algorithm. The target algorithm needs to implement one of the following signatures:

  • target_algorithm(config: Configuration) -> Union[float, Tuple[float, Any]]

  • target_algorithm(config: Configuration, seed: int) -> Union[float, Tuple[float, Any]]

  • target_algorithm(config: Configuration, seed: int, instance: str) -> Union[float, Tuple[float, Any]]

The target algorithm can either return a float (the loss), or a tuple with the first element being a float and the second being additional run information.

ExecuteTAFuncDict will use inspection to figure out the correct call to the target algorithm.

Parameters
  • ta (callable) – Function (target algorithm) to be optimized.

  • stats (smac.stats.stats.Stats, optional) – Stats object to collect statistics about runtime etc.

  • run_obj (str, optional) – Run objective (runtime or quality)

  • memory_limit (int, optional) – Memory limit (in MB) that will be applied to the target algorithm.

  • par_factor (int, optional) – Penalized average runtime factor. Only used when run_obj=’runtime’

  • use_pynisher (bool, optional) – use pynisher to limit resources;