Skip to content

Tensorboard eval

The tblogger module provides a simplified interface for logging to TensorBoard.

tblogger #

The tblogger class provides a simplified interface for logging to tensorboard.

ConfigWriter staticmethod #

ConfigWriter(
    *, write_summary_incumbent: bool = True
) -> SummaryWriter

Creates and returns a TensorBoard SummaryWriter configured to write logs to the appropriate directory for NePS.

PARAMETER DESCRIPTION
write_summary_incumbent

Determines whether to write summaries for the incumbent configurations. Defaults to True.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
SummaryWriter

An instance of TensorBoard SummaryWriter pointing to the designated NePS directory.

TYPE: SummaryWriter

Source code in neps\plot\tensorboard_eval.py
@staticmethod
def ConfigWriter(*, write_summary_incumbent: bool = True) -> SummaryWriter:  # noqa: N802
    """Creates and returns a TensorBoard SummaryWriter configured to write logs
    to the appropriate directory for NePS.

    Args:
        write_summary_incumbent (bool): Determines whether to write summaries
                                        for the incumbent configurations.
                                        Defaults to True.

    Returns:
        SummaryWriter: An instance of TensorBoard SummaryWriter pointing to the
                    designated NePS directory.
    """
    tblogger.write_incumbent = write_summary_incumbent
    tblogger._initiate_internal_configurations()
    # This code runs only once per config, to assign that config a config_writer.
    if (
        tblogger.config_previous_directory is None
        and tblogger.config_working_directory is not None
    ):
        # If no fidelities are there yet, define the writer via the config_id
        tblogger.config_id = str(tblogger.config_working_directory).rsplit(
            "/", maxsplit=1
        )[-1]
        tblogger.config_writer = SummaryWriter(
            tblogger.config_working_directory / "tbevents"
        )
        return tblogger.config_writer

    # Searching for the initial directory where tensorboard events are stored.
    if tblogger.config_working_directory is not None:
        init_dir = get_initial_directory(
            pipeline_directory=tblogger.config_working_directory
        )
        tblogger.config_id = str(init_dir).rsplit("/", maxsplit=1)[-1]
        if (init_dir / "tbevents").exists():
            tblogger.config_writer = SummaryWriter(init_dir / "tbevents")
            return tblogger.config_writer

        raise FileNotFoundError(
            "'tbevents' was not found in the initial directory of the configuration."
        )
    return None

WriteIncumbent staticmethod #

WriteIncumbent() -> None

Allows for writing the incumbent of the current search.

Source code in neps\plot\tensorboard_eval.py
@staticmethod
def WriteIncumbent() -> None:  # noqa: N802
    """Allows for writing the incumbent of the current search."""
    tblogger._initiate_internal_configurations()
    tblogger.write_incumbent = True

end_of_config staticmethod #

end_of_config(trial: Trial) -> None

Closes the writer.

Source code in neps\plot\tensorboard_eval.py
@staticmethod
def end_of_config(trial: Trial) -> None:  # noqa: ARG004
    """Closes the writer."""
    if tblogger.config_writer:
        # Close and reset previous config writers for consistent logging.
        # Prevent conflicts by reinitializing writers when logging ongoing.
        tblogger.config_writer.close()
        tblogger.config_writer = None

    if tblogger.write_incumbent:
        tblogger._tracking_incumbent_api()