目标函数运行器
smac.runner.target_function_runner #
TargetFunctionRunner #
TargetFunctionRunner(
scenario: Scenario,
target_function: Callable,
required_arguments: list[str] = None,
)
基类: 抽象串行运行器
用于执行作为 Python 函数的目标函数的类。为给定配置和资源限制评估函数。
目标函数可以返回一个浮点数(损失),或者一个元组,其中第一个元素是浮点数,第二个元素是额外的运行信息。在多目标设置中,浮点数会被一个浮点数列表取代。
参数#
target_function : Callable 目标函数。 scenario : Scenario required_arguments : list[str], defaults to [] 需要传递给目标函数的一系列必要参数。
源代码位于 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]
)
调用算法,算法在 run
方法中处理。
源代码位于 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
]
如果设置了算法墙钟时间限制或内存限制,则使用 pynisher 调用目标函数。否则,直接调用该函数。
参数#
config : Configuration 要传递给目标函数的配置。 instance : str | None, defaults to None 问题实例。 budget : float | None, defaults to None 一个正的实数值,表示目标函数内部处理的任意限制。 seed : int, defaults to None dask_data_to_scatter: dict[str, Any] 当不使用 Dask 时,此 kwargs 必须为空!() 当用户将数据从其本地进程分散到分布式网络时,这些数据会以轮询方式按核心数分组分布。粗略地说,我们可以将这些数据保存在内存中,这样每次要执行带有大数据集的目标函数时,就不必(反)序列化数据。例如,当您的目标函数具有跨所有目标函数共享的大数据集时,此参数非常有用。
返回值#
status : StatusType 试验状态。 cost : float | list[float] 试验的成本。 runtime : float 目标函数运行所需的时间。 cpu_time : float 目标函数在硬件上运行所需的时间。 additional_info : dict 所有其他额外的试验信息。
源代码位于 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]
围绕 run() 方法的包装器,用于执行和检查给定配置的执行。此函数封装了常见的处理逻辑,从而简化了 run() 的实现。
参数#
trial_info : RunInfo 包含足够信息以独立执行配置运行的对象。 dask_data_to_scatter: dict[str, Any] 当用户将数据从其本地进程分散到分布式网络时,这些数据会以轮询方式按核心数分组分布。粗略地说,我们可以将这些数据保存在内存中,这样每次要执行带有大数据集的目标函数时,就不必(反)序列化数据。例如,当您的目标函数具有跨所有目标函数共享的大数据集时,此参数非常有用。
返回值#
info : TrialInfo 包含已启动配置的对象。 value : TrialValue 包含关于配置状态/性能的信息。
源代码位于 smac/runner/abstract_runner.py
submit_trial #
submit_trial(trial_info: TrialInfo) -> None
此函数以串行方式提交 trial_info 对象。由于此任务只有一个工作线程,此接口可被视为 run
方法的包装器。
结果/异常都可以在此步骤中完全确定,因此两个列表都被正确填充。
参数#
trial_info : TrialInfo 包含已启动配置的对象。
源代码位于 smac/runner/abstract_serial_runner.py
wait #
SMBO/强化器可能需要等待试验完成才能做出决策。对于串行运行器,结果立即可用,因此无需等待。