跳到内容

元数据回调

smac.callback.metadata_callback #

MetadataCallback #

MetadataCallback(**kwargs: str | int | float | dict | list)

继承自: Callback

源代码位于 smac/callback/metadata_callback.py
def __init__(self, **kwargs: str | int | float | dict | list) -> None:
    # Arguments must be json serializable
    self.kwargs = kwargs

on_ask_end #

on_ask_end(smbo: SMBO, info: TrialInfo) -> None

在强化器被要求进行下一次试验后调用。

源代码位于 smac/callback/callback.py
def on_ask_end(self, smbo: smac.main.smbo.SMBO, info: TrialInfo) -> None:
    """Called after the intensifier is asked for the next trial."""
    pass

on_ask_start #

on_ask_start(smbo: SMBO) -> None

在强化器被要求进行下一次试验前调用。

源代码位于 smac/callback/callback.py
def on_ask_start(self, smbo: smac.main.smbo.SMBO) -> None:
    """Called before the intensifier is asked for the next trial."""
    pass

on_end #

on_end(smbo: SMBO) -> None

在优化完成后调用。

源代码位于 smac/callback/callback.py
def on_end(self, smbo: smac.main.smbo.SMBO) -> None:
    """Called after the optimization finished."""
    pass

on_iteration_end #

on_iteration_end(smbo: SMBO) -> None

在迭代结束后调用。

源代码位于 smac/callback/callback.py
def on_iteration_end(self, smbo: smac.main.smbo.SMBO) -> None:
    """Called after an iteration ended."""
    pass

on_iteration_start #

on_iteration_start(smbo: SMBO) -> None

在采样下一个运行前调用。

源代码位于 smac/callback/callback.py
def on_iteration_start(self, smbo: smac.main.smbo.SMBO) -> None:
    """Called before the next run is sampled."""
    pass

on_next_configurations_end #

on_next_configurations_end(
    config_selector: ConfigSelector, config: Configuration
) -> None

在强化器要求新的配置后调用。实质上,此回调在训练代理模型和调用采集函数之前被调用。

源代码位于 smac/callback/callback.py
def on_next_configurations_end(
    self, config_selector: smac.main.config_selector.ConfigSelector, config: Configuration
) -> None:
    """Called after the intensification asks for new configurations. Essentially, this callback is called
    before the surrogate model is trained and before the acquisition function is called.
    """
    pass

on_next_configurations_start #

on_next_configurations_start(
    config_selector: ConfigSelector,
) -> None

在强化器要求新的配置前调用。实质上,此回调在训练代理模型和调用采集函数之前被调用。

源代码位于 smac/callback/callback.py
def on_next_configurations_start(self, config_selector: smac.main.config_selector.ConfigSelector) -> None:
    """Called before the intensification asks for new configurations. Essentially, this callback is called
    before the surrogate model is trained and before the acquisition function is called.
    """
    pass

on_start #

on_start(smbo: SMBO) -> None

在优化开始前调用。

源代码位于 smac/callback/metadata_callback.py
def on_start(self, smbo: SMBO) -> None:
    """Called before the optimization starts."""
    path = smbo._scenario.output_directory
    meta_dict = {
        "utc_time": str(datetime.utcnow()),
        "os": platform.platform(),
        "smac_version": getattr(smac, "version"),
    }
    for key, value in self.kwargs.items():
        meta_dict[key] = value

    path.mkdir(parents=True, exist_ok=True)

    with open(path / "metadata.json", "w") as fp:
        json.dump(meta_dict, fp, indent=2, cls=NumpyEncoder)

on_tell_end #

on_tell_end(
    smbo: SMBO, info: TrialInfo, value: TrialValue
) -> bool | None

在统计数据更新并将试验添加到运行历史后调用。可选地,返回 false 以优雅地停止优化。

源代码位于 smac/callback/callback.py
def on_tell_end(self, smbo: smac.main.smbo.SMBO, info: TrialInfo, value: TrialValue) -> bool | None:
    """Called after the stats are updated and the trial is added to the runhistory. Optionally, returns false
    to gracefully stop the optimization.
    """
    pass

on_tell_start #

on_tell_start(
    smbo: SMBO, info: TrialInfo, value: TrialValue
) -> bool | None

在统计数据更新并将试验添加到运行历史之前调用。可选地,返回 false 以优雅地停止优化。

源代码位于 smac/callback/callback.py
def on_tell_start(self, smbo: smac.main.smbo.SMBO, info: TrialInfo, value: TrialValue) -> bool | None:
    """Called before the stats are updated and the trial is added to the runhistory. Optionally, returns false
    to gracefully stop the optimization.
    """
    pass