smac.tae.execute_func module

class smac.tae.execute_func.AbstractTAFunc(ta, stats=None, runhistory=None, run_obj: str = 'quality', memory_limit: int = None, par_factor: int = 1, cost_for_crash: float = 2147483647.0, use_pynisher: bool = True)[source]

Bases: smac.tae.execute_ta_run.ExecuteTARun

Baseclass to execute target algorithms which are python functions.

Note:* Do not use directly

memory_limit
use_pynisher
run(config, instance=None, cutoff=None, seed=12345, 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 (dictionary (or similar)) – Dictionary param -> value
  • instance (str) – Problem instance
  • cutoff (int, optional) – Wallclock time limit of the target algorithm. If no value is provided no limit will be enforced.
  • memory_limit (int, optional) – Memory limit in MB enforced on the target algorithm If no value is provided no limit will be enforced.
  • seed (int) – Random seed
  • instance_specific (str) – Instance specific information (e.g., domain file or solution)
Returns:

  • status (enum of StatusType (int)) – {SUCCESS, TIMEOUT, CRASHED, ABORT}
  • cost (float) – 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

start(config: ConfigSpace.configuration_space.Configuration, instance: str, cutoff: float = None, seed: int = 12345, instance_specific: str = '0', capped: bool = False)

Wrapper function for ExecuteTARun.run() to check configuration budget before the runs and to update stats after run

Parameters:
  • config (Configuration) – Mainly a dictionary param -> value
  • instance (string) – Problem instance
  • cutoff (float) – Runtime cutoff
  • seed (int) – Random seed
  • instance_specific (str) – Instance specific information (e.g., domain file or solution)
  • capped (bool) – If true and status is StatusType.TIMEOUT, uses StatusType.CAPPED
Returns:

  • status (enum of StatusType (int)) – {SUCCESS, TIMEOUT, CRASHED, ABORT}
  • cost (float) – cost/regret/quality (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=None, runhistory=None, run_obj: str = 'quality', memory_limit: int = None, par_factor: int = 1, cost_for_crash: float = 2147483647.0, use_pynisher: bool = 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)
  • runhistory (RunHistory, optional) – runhistory to keep track of all runs; only used if set
  • 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’
run(config, instance=None, cutoff=None, seed=12345, instance_specific='0')

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 (dictionary (or similar)) – Dictionary param -> value
  • instance (str) – Problem instance
  • cutoff (int, optional) – Wallclock time limit of the target algorithm. If no value is provided no limit will be enforced.
  • memory_limit (int, optional) – Memory limit in MB enforced on the target algorithm If no value is provided no limit will be enforced.
  • seed (int) – Random seed
  • instance_specific (str) – Instance specific information (e.g., domain file or solution)
Returns:

  • status (enum of StatusType (int)) – {SUCCESS, TIMEOUT, CRASHED, ABORT}
  • cost (float) – 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

start(config: ConfigSpace.configuration_space.Configuration, instance: str, cutoff: float = None, seed: int = 12345, instance_specific: str = '0', capped: bool = False)

Wrapper function for ExecuteTARun.run() to check configuration budget before the runs and to update stats after run

Parameters:
  • config (Configuration) – Mainly a dictionary param -> value
  • instance (string) – Problem instance
  • cutoff (float) – Runtime cutoff
  • seed (int) – Random seed
  • instance_specific (str) – Instance specific information (e.g., domain file or solution)
  • capped (bool) – If true and status is StatusType.TIMEOUT, uses StatusType.CAPPED
Returns:

  • status (enum of StatusType (int)) – {SUCCESS, TIMEOUT, CRASHED, ABORT}
  • cost (float) – cost/regret/quality (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.ExecuteTAFuncDict(ta, stats=None, runhistory=None, run_obj: str = 'quality', memory_limit: int = None, par_factor: int = 1, cost_for_crash: float = 2147483647.0, use_pynisher: bool = 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)
  • runhistory (RunHistory, optional) – runhistory to keep track of all runs; only used if set
  • 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’
run(config, instance=None, cutoff=None, seed=12345, instance_specific='0')

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 (dictionary (or similar)) – Dictionary param -> value
  • instance (str) – Problem instance
  • cutoff (int, optional) – Wallclock time limit of the target algorithm. If no value is provided no limit will be enforced.
  • memory_limit (int, optional) – Memory limit in MB enforced on the target algorithm If no value is provided no limit will be enforced.
  • seed (int) – Random seed
  • instance_specific (str) – Instance specific information (e.g., domain file or solution)
Returns:

  • status (enum of StatusType (int)) – {SUCCESS, TIMEOUT, CRASHED, ABORT}
  • cost (float) – 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

start(config: ConfigSpace.configuration_space.Configuration, instance: str, cutoff: float = None, seed: int = 12345, instance_specific: str = '0', capped: bool = False)

Wrapper function for ExecuteTARun.run() to check configuration budget before the runs and to update stats after run

Parameters:
  • config (Configuration) – Mainly a dictionary param -> value
  • instance (string) – Problem instance
  • cutoff (float) – Runtime cutoff
  • seed (int) – Random seed
  • instance_specific (str) – Instance specific information (e.g., domain file or solution)
  • capped (bool) – If true and status is StatusType.TIMEOUT, uses StatusType.CAPPED
Returns:

  • status (enum of StatusType (int)) – {SUCCESS, TIMEOUT, CRASHED, ABORT}
  • cost (float) – cost/regret/quality (float) (None, if not returned by TA)
  • runtime (float) – runtime (None if not returned by TA)
  • additional_info (dict) – all further additional run information