Logging

Logging.

class metatensor.models.utils.logging.MetricLogger(model_capabilities: ModelCapabilities, initial_metrics: Dict[str, float] | List[Dict[str, float]], names: str | List[str] = '')[source]

Bases: object

This class provides a simple interface to log training metrics to a file.

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)[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.

metatensor.models.utils.logging.setup_logging(logobj: Logger, logfile: str | Path | None = None, level: int = 30)[source]

Create a logging environment for a given logobj.

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

Parameters:
  • logobj (Logger) – A logging instance

  • logfile (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 inludcing filename and function name are displayed. For logging.INFO only the message logged from errors, warnings and infos will be displayed.