Skip to content

Metadata callback

smac.callback.metadata_callback #

MetadataCallback #

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

Bases: Callback

Source code in 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

Called after the intensifier is asked for the next trial.

Source code in 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

Called before the intensifier is asked for the next trial.

Source code in 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

Called after the optimization finished.

Source code in 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

Called after an iteration ended.

Source code in 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

Called before the next run is sampled.

Source code in 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

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.

Source code in 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

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.

Source code in 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

Called before the optimization starts.

Source code in 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

Called after the stats are updated and the trial is added to the runhistory. Optionally, returns false to gracefully stop the optimization.

Source code in 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

Called before the stats are updated and the trial is added to the runhistory. Optionally, returns false to gracefully stop the optimization.

Source code in 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