Target function runner
smac.runner.target_function_runner
#
TargetFunctionRunner
#
TargetFunctionRunner(
scenario: Scenario,
target_function: Callable,
required_arguments: list[str] = None,
)
Bases: AbstractSerialRunner
Class to execute target functions which are python functions. Evaluates function for given configuration and resource limit.
The target function can either return a float (the loss), or a tuple with the first element being a float and the second being additional run information. In a multi-objective setting, the float value is replaced by a list of floats.
Parameters#
target_function : Callable The target function. scenario : Scenario required_arguments : list[str], defaults to [] A list of required arguments, which are passed to the target function.
Source code in smac/runner/target_function_runner.py
__call__
#
__call__(
config: Configuration,
algorithm: Callable,
algorithm_kwargs: dict[str, Any],
) -> (
float
| list[float]
| dict[str, float]
| tuple[float, dict]
| tuple[list[float], dict]
| tuple[dict[str, float], dict]
)
Calls the algorithm, which is processed in the run
method.
Source code in smac/runner/target_function_runner.py
run
#
run(
config: Configuration,
instance: str | None = None,
budget: float | None = None,
seed: int | None = None,
**dask_data_to_scatter: dict[str, Any]
) -> tuple[
StatusType, float | list[float], float, float, dict
]
Calls the target function with pynisher if algorithm wall time limit or memory limit is set. Otherwise, the function is called directly.
Parameters#
config : Configuration Configuration to be passed to the target function. instance : str | None, defaults to None The Problem instance. budget : float | None, defaults to None A positive, real-valued number representing an arbitrary limit to the target function handled by the target function internally. seed : int, defaults to None dask_data_to_scatter: dict[str, Any] This kwargs must be empty when we do not use dask! () 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#
status : StatusType Status of the trial. cost : float | list[float] Resulting cost(s) of the trial. runtime : float The time the target function took to run. cpu_time : float The time the target function took on the hardware to run. additional_info : dict All further additional trial information.
Source code in smac/runner/target_function_runner.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
run_wrapper
#
run_wrapper(
trial_info: TrialInfo,
**dask_data_to_scatter: dict[str, Any]
) -> tuple[TrialInfo, TrialValue]
Wrapper around run() to execute and check the execution of a given config. This function encapsulates common handling/processing, so that run() implementation is simplified.
Parameters#
trial_info : RunInfo Object that contains enough information to execute a configuration run in isolation. dask_data_to_scatter: dict[str, Any] 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#
info : TrialInfo An object containing the configuration launched. value : TrialValue Contains information about the status/performance of config.
Source code in smac/runner/abstract_runner.py
submit_trial
#
submit_trial(trial_info: TrialInfo) -> None
This function submits a trial_info object in a serial fashion. As there is a single
worker for this task, this interface can be considered a wrapper over the run
method.
Both result/exceptions can be completely determined in this step so both lists are properly filled.
Parameters#
trial_info : TrialInfo An object containing the configuration launched.
Source code in smac/runner/abstract_serial_runner.py
wait
#
The SMBO/intensifier might need to wait for trials to finish before making a decision. For serial runners, no wait is needed as the result is immediately available.