Skip to content

CometLogger

CometLogger

Bases: Logger

Comet Logger.

Handles the logging for the Comet service. Inherits from Logger.

Source code in sequel/utils/loggers/comet_logger.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class CometLogger(Logger):
    """[Comet](https://www.comet.com/docs/v2/) Logger.

    Handles the logging for the Comet service. Inherits from Logger.
    """

    def __init__(self, config: omegaconf.OmegaConf, api_key: Optional[str] = None):
        """Inits the CometLogger class.

        Args:
            config (omegaconf.OmegaConf): The experiment config file. It is automatically logged to Comet.
            api_key (Optional[str], optional): The COMET api key. If None, the API is inferred via the environment
                variables. Defaults to None.

        Raises:
            KeyError: If the `api_key` is None and the `COMET_API_KEY` environment variable is not set.
        """
        super().__init__()

        self.config = config
        if api_key is None:
            if os.environ.get("COMET_API_KEY") is None:
                raise KeyError(
                    "The COMET_API_KEY has not been set up as an environment variable. In order to add the "
                    "COMET_API_KEY to the environment variables, run in your terminal: "
                    "export COMET_API_KEY='YOUR_API_TOKEN'."
                )
            else:
                api_key = os.environ.get("COMET_API_KEY")

        self.experiment = Experiment(
            api_key=api_key,
            project_name="rot-mnist-20",
            display_summary_level=0,
        )

        self.log_parameters(config)
        self.log_code()

    def log(self, item, step=None, epoch=None):
        self.experiment.log_metrics(item, step=step, epoch=epoch)

    def log_figure(self, figure, name, step=None, epoch=None):
        self.experiment.log_image(figure, name=name, step=step)

    def log_code(self):
        self.experiment.log_code(folder=get_original_source_code_root_dir())

    def log_parameters(self, config: dict):
        self.experiment.log_parameters(convert_omegaconf_to_flat_dict(config))

    def terminate(self):
        pass

__init__(config, api_key=None)

Inits the CometLogger class.

Parameters:

Name Type Description Default
config omegaconf.OmegaConf

The experiment config file. It is automatically logged to Comet.

required
api_key Optional[str]

The COMET api key. If None, the API is inferred via the environment variables. Defaults to None.

None

Raises:

Type Description
KeyError

If the api_key is None and the COMET_API_KEY environment variable is not set.

Source code in sequel/utils/loggers/comet_logger.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def __init__(self, config: omegaconf.OmegaConf, api_key: Optional[str] = None):
    """Inits the CometLogger class.

    Args:
        config (omegaconf.OmegaConf): The experiment config file. It is automatically logged to Comet.
        api_key (Optional[str], optional): The COMET api key. If None, the API is inferred via the environment
            variables. Defaults to None.

    Raises:
        KeyError: If the `api_key` is None and the `COMET_API_KEY` environment variable is not set.
    """
    super().__init__()

    self.config = config
    if api_key is None:
        if os.environ.get("COMET_API_KEY") is None:
            raise KeyError(
                "The COMET_API_KEY has not been set up as an environment variable. In order to add the "
                "COMET_API_KEY to the environment variables, run in your terminal: "
                "export COMET_API_KEY='YOUR_API_TOKEN'."
            )
        else:
            api_key = os.environ.get("COMET_API_KEY")

    self.experiment = Experiment(
        api_key=api_key,
        project_name="rot-mnist-20",
        display_summary_level=0,
    )

    self.log_parameters(config)
    self.log_code()