Skip to content

Experiment logger

fyt.utils.experiment_logger

BaseExperimentLogger

Bases: ABC, Generic[T_Context]

Abstract base class for experiment logging.

All tracker-specific calls (MLflow, W&B, etc.) must live in concrete subclasses. Core pipeline components depend only on this interface.

run_id property

The ID of the current (or most recent) run.

run_name property

The configured run name, or a freshly generated one per access.

Generated names are intentionally NOT cached: multi-seed executions start several runs from one logger instance, and each must get its own name. An explicitly configured name stays stable.

__enter__() abstractmethod

Enter the context manager for the experiment logger.

__exit__(exc_type, exc_value, traceback) abstractmethod

Exit the context manager for the experiment logger.

log_artifact(local_path, artifact_path=None) abstractmethod

Log a local file as an artifact.

Parameters:

Name Type Description Default
local_path str | Path

Path to the file to log.

required
artifact_path str | None

Subdirectory within the run's artifact store.

None

log_dict(data) abstractmethod

Log a dictionary to the experiment tracking system.

log_experiment_data(data_paths) abstractmethod

Logs experiment data.

log_input(input_path) abstractmethod

Log the input dataset to the experiment tracking system.

log_metrics(metrics) abstractmethod

Log multiple metrics at once.

Parameters:

Name Type Description Default
metrics dict[str, float | int]

Dictionary of metric names and values.

required

log_model(model, artifact_path='model') abstractmethod

Log a trained model.

Parameters:

Name Type Description Default
model Any

The trained model to log.

required
artifact_path str

Path within the artifact directory to save the model.

'model'

log_params(params) abstractmethod

Log multiple parameters at once.

Parameters:

Name Type Description Default
params Mapping[str, object]

Dictionary of parameter names and values.

required

resume_run(run_id) abstractmethod

Re-open a previously completed run to log additional data.

Parameters:

Name Type Description Default
run_id str

The ID of the run to resume.

required

Returns:

Type Description
AbstractContextManager[T_Context]

A context manager wrapping the resumed run.

set_tag(key, value) abstractmethod

Set a tag on the current run.

Parameters:

Name Type Description Default
key str

Tag name.

required
value object

Tag value.

required

start_nested_run(run_name) abstractmethod

Start a nested run (e.g. for Optuna trials).

Parameters:

Name Type Description Default
run_name str

Name for the nested run.

required

Returns:

Type Description
AbstractContextManager[T_Context]

A context manager wrapping the nested run.

MlflowLogger

Bases: BaseExperimentLogger[ActiveRun]

log_dict(data)

Log a dictionary to MLflow as parameters or metrics.

log_experiment_data(data_paths)

Logs experiment data files as MLflow artifacts and, if applicable, as tables.

For each path in data_paths, this method: - Checks if the file exists; if not, logs a warning and skips it. - Logs the file as an MLflow artifact under a subdirectory named after its parent folder. - If the file is JSON, attempts to read it into a DataFrame and logs it as a table. - If the JSON file contains a single record, logs its contents as a dictionary. - Logs an info message upon successful artifact logging.

Parameters:

Name Type Description Default
data_paths list[Path]

List of file paths to be logged as experiment artifacts.

required
Notes
  • If reading a JSON file fails, the exception is silently ignored.
  • Requires mlflow and a configured logger.

log_input(input_path)

Logs the input dataset to MLflow after loading it from the specified file path.

Supports loading data from JSON, CSV, and Parquet files. The loaded data is converted into an MLflow pandas dataset and logged as an input artifact.

Parameters:

Name Type Description Default
input_path Path

The path to the input data file.

required

Raises:

Type Description
FileNotFoundError

If the specified input path does not exist.

ValueError

If the file format is not one of .json, .csv, or .parquet.

MlflowLoggerConfig

Bases: BaseExperimentLoggerConfig

Configuration for the MLflow logger implementation.

from_section(section) classmethod

Build a full config from a run-config experiment_logger section.

Fields missing from the section are filled from DEFAULT_CONFIG_PATH when that file exists; section values always win over file defaults.

Parameters:

Name Type Description Default
section BaseExperimentLoggerConfig

The (possibly sparse) logger section of a command config.

required

Returns:

Type Description
'MlflowLoggerConfig'

The fully validated MLflow logger config.

NoOpExperimentLogger

Bases: BaseExperimentLogger[None]

Null-object experiment logger that satisfies the interface but does nothing.

Use this as a default when no real experiment tracking is configured, eliminating if logger is not None checks throughout the codebase.