Logging module

class mbrl.util.logger.Logger(log_dir: Union[str, pathlib.Path], enable_back_compatible: bool = False)

Bases: object

Light-weight csv logger.

This logger is based on pytorch_sac’s logger with some modifications and some of its features removed.

To use this logger you must register logging groups using register_group(). Each group will save data to a separate csv file, at log_dir/<group_name>.csv, and will output to console using its own dedicated tabular format.

Parameters
  • log_dir (str or pathlib.Path) – the directory where to save the logs.

  • enable_back_compatible (bool, optional) – if True, this logger can be used in the methods in the pytorch_sac library. Defaults to False.

log_data(group_name: str, data: Mapping[str, Union[int, float, torch.Tensor]])

Logs the data contained in a given dictionary to the given logging group.

Parameters
  • group_name (str) – the name of the logging group to use. It must have been registered already, otherwise an exception will be thrown.

  • data (mapping str->(int/float/torch.Tensor)) – the dictionary with the data. Each keyword must be a variable name in the log format passed when creating this group.

register_group(group_name: str, log_format: List[Tuple[str, str, str]], dump_frequency: int = 1, color: str = 'yellow')

Register a logging group.

Parameters
  • group_name (str) – the name assigned to the logging group.

  • log_format (list of 3-tuples) – each tuple contains 3 strings, representing (variable_name, shortcut, type), for a variable that the logger should keep track of in this group. The variable name will be used as a header in the csv file for the entries of this variable. The shortcut will be used as a header for the console output tabular format. The type should be one of “int”, “float”, “time”.

  • dump_frequency (int) – how often (measured in calls to log_data()) should the logger dump the data collected since the last call. If dump_frequency > 1, then the data collected between calls is averaged.

  • color (str) – a color to use for this group in the console.