Logging

Logging.

class metatrain.utils.logging.MetricLogger(log_obj: Logger, dataset_info: ModelCapabilities | DatasetInfo, initial_metrics: Dict[str, float] | List[Dict[str, float]], names: str | List[str] = '', scales: Dict[str, float] | None = None)[source]

Bases: object

Simple interface to log training metrics logging instance.

Initialize the metric logger. The logger is initialized with the initial metrics and names relative to the metrics (e.g., “train”, “validation”).

In this way, and by assuming that these metrics never increase, the logger can align the output to make it easier to read.

Parameters:
log(metrics: Dict[str, float] | List[Dict[str, float]], epoch: int | None = None, rank: int | None = None)[source]

Log the metrics.

The metrics are automatically aligned to make them easier to read, based on the order of magnitude of each metric given to the class at initialization.

Parameters:
  • metrics (Dict[str, float] | List[Dict[str, float]]) – The current metrics to be printed.

  • epoch (int | None) – The current epoch (optional). If None, the epoch will not be printed, and the logging string will start with the first metric in the metrics dictionary.

  • rank (int | None) – The rank of the process, if the training is distributed. In that case, the logger will only print the metrics for the process with rank 0.

metatrain.utils.logging.setup_logging(log_obj: Logger, log_file: str | Path | None = None, level: int = 30)[source]

Create a logging environment for a given log_obj.

Extracted and adjusted from github.com/MDAnalysis/mdacli/blob/main/src/mdacli/logger.py

Parameters:
  • log_obj (Logger) – A logging instance

  • log_file (str | Path | None) – Name of the log file

  • level (int) – Set the root logger level to the specified level. If for example set to logging.DEBUG detailed debug logs including filename and function name are displayed. For logging.INFO only the message logged from errors, warnings and infos will be displayed.

metatrain.utils.logging.get_cli_input(argv: List[str] | None = None) str[source]

Proper formatted string of the command line input.

Parameters:

argv (List[str] | None) – List of strings to parse. If None taken from sys.argv.

Return type:

str