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_obj (Logger) – A logging instance
model_outputs – outputs of the model. Used to infer physical quantities and units
initial_metrics (Dict[str, float] | List[Dict[str, float]]) – initial training metrics
names (str | List[str]) – names of the metrics (e.g., “train”, “validation”)
dataset_info (ModelCapabilities | DatasetInfo)
- 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 themetrics
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
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. Forlogging.INFO
only the message logged from errors, warnings and infos will be displayed.