palma.components.logger#

Module Contents#

Classes#

Logger

Logger is an abstract class that defines a common

DummyLogger

Logger is an abstract class that defines a common

FileSystemLogger

A logger for saving artifacts and metadata to the file system.

MLFlowLogger

MLFlowLogger class for logging experiments using MLflow.

_Logger

Attributes#

mlflow

_logger

logger

set_logger

palma.components.logger.mlflow#
palma.components.logger._logger#
class palma.components.logger.Logger(uri: str, **kwargs)#

Logger is an abstract class that defines a common interface for a set of Logger-subclasses.

It provides common methods for all possible subclasses, making it possible for a user to create a custom subclass compatible with the rest of the components.

property uri#
abstract log_project(project: palma.base.project.Project) None#
abstract log_metrics(metrics: dict, path: str) None#
abstract log_params(**kwargs) None#
abstract log_artifact(**kwargs) None#
class palma.components.logger.DummyLogger(uri: str, **kwargs)#

Bases: Logger

Logger is an abstract class that defines a common interface for a set of Logger-subclasses.

It provides common methods for all possible subclasses, making it possible for a user to create a custom subclass compatible with the rest of the components.

log_project(project: palma.base.project.Project) None#
log_metrics(metrics: dict, path: str) None#
log_params(parameters: dict, path: str) None#
log_artifact(obj, path: str) None#
class palma.components.logger.FileSystemLogger(uri: str = tempfile.gettempdir(), **kwargs)#

Bases: Logger

A logger for saving artifacts and metadata to the file system.

Parameters:
uristr, optional

The root path or directory where artifacts and metadata will be saved. Defaults to the system temporary directory.

**kwargsdict

Additional keyword arguments to pass to the base logger.

Attributes:
path_projectstr

The path to the project directory.

path_studystr

The path to the study directory within the project.

Methods

log_project(project: Project) -> None

Performs the first level of backup by creating folders and saving an instance of Project.

log_metrics(metrics: dict, path: str) -> None

Saves metrics in JSON format at the specified path.

log_artifact(obj, path: str) -> None

Saves an artifact at the specified path, handling different types of objects.

log_params(parameters: dict, path: str) -> None

Saves model parameters in JSON format at the specified path.

log_project(project: palma.base.project.Project) None#

log_project performs the first level of backup as described in the object description.

This method creates the needed folders and saves an instance of Project.

Parameters:
project: :class:`~palma.Project`

an instance of Project

log_metrics(metrics: dict, path: str) None#

Logs metrics to a JSON file.

Parameters:
metricsdict

The metrics to be logged.

pathstr

The relative path (from the study directory) where the metrics JSON file will be saved.

log_artifact(obj, path: str) None#

Logs an artifact, handling different types of objects.

Parameters:
objany

The artifact to be logged.

pathstr

The relative path (from the study directory) where the artifact will be saved.

log_params(parameters: dict, path: str) None#

Logs model parameters to a JSON file.

Parameters:
parametersdict

The model parameters to be logged.

pathstr

The relative path (from the study directory) where the parameters JSON file will be saved.

__create_directories()#

Creates the study directory if it doesn’t exist.

If the study directory does not exist, it is created along with any necessary parent directories.

class palma.components.logger.MLFlowLogger(uri: str, artifact_location: str = '.mlruns')#

Bases: Logger

MLFlowLogger class for logging experiments using MLflow.

Parameters:
uristr

The URI for the MLflow tracking server.

artifact_locationstr

The place to save artifact on file system logger

Raises:
ImportError: If mlflow is not installed.
Attributes:
tmp_logger(FileSystemLogger)

Temporary logger for local logging before MLflow logging.

Methods

log_project(project: ‘Project’) -> None:

Logs the project information to MLflow, including project name and parameters.

log_metrics(metrics: dict[str, typing.Any]) -> None:

Logs metrics to MLflow.

log_artifact(artifact: dict, path) -> None:

Logs artifacts to MLflow using the temporary logger.

log_params(params: dict) -> None:

Logs parameters to MLflow.

log_model(model, path) -> None:

Logs the model to MLflow using the temporary logger.

log_project(project: palma.base.project.Project) None#
log_metrics(metrics: dict[str, Any], path=None) None#
log_artifact(artifact: dict, path) None#
log_params(params: dict) None#
class palma.components.logger._Logger(dummy)#
property logger: Logger#
property uri#
__set__(_logger) None#
Parameters:
_logger: Logger

Define the logger to use.

>>> from palma import logger, set_logger
>>> from palma.components import FileSystemLogger
>>> from palma.components import MLFlowLogger
>>> set_logger(MLFlowLogger(uri="."))
>>> set_logger(FileSystemLogger(uri="."))
palma.components.logger.logger#
palma.components.logger.set_logger#