hydraflow.core.context
source module hydraflow.core.context
Provide context managers to log parameters and manage the MLflow run context.
Functions
-
log_run — Log the parameters from the given configuration object.
-
start_run — Start an MLflow run and log parameters using the provided configuration object.
-
chdir_artifact — Change the current working directory to the artifact directory of the given run.
source log_run(config: object | None, *, synchronous: bool | None = None) → Iterator[None]
Log the parameters from the given configuration object.
This context manager logs the parameters from the provided configuration object using MLflow. It also manages the MLflow run context, ensuring that artifacts are logged and the run is properly closed.
Parameters
-
config : object — The configuration object to log the parameters from.
-
synchronous : bool | None — Whether to log the parameters synchronously. Defaults to None.
Yields
-
None — None
Example
with log_run(config):
# Perform operations within the MLflow run context
pass
source start_run(config: object, *, chdir: bool = False, run_id: str | None = None, experiment_id: str | None = None, run_name: str | None = None, nested: bool = False, parent_run_id: str | None = None, tags: dict[str, str] | None = None, description: str | None = None, log_system_metrics: bool | None = None, synchronous: bool | None = None) → Iterator[Run]
Start an MLflow run and log parameters using the provided configuration object.
This context manager starts an MLflow run and logs parameters using the specified configuration object. It ensures that the run is properly closed after completion.
Parameters
-
config : object — The configuration object to log parameters from.
-
chdir : bool — Whether to change the current working directory to the artifact directory of the current run. Defaults to False.
-
run_id : str | None — The existing run ID. Defaults to None.
-
experiment_id : str | None — The experiment ID. Defaults to None.
-
run_name : str | None — The name of the run. Defaults to None.
-
nested : bool — Whether to allow nested runs. Defaults to False.
-
parent_run_id : str | None — The parent run ID. Defaults to None.
-
tags : dict[str, str] | None — Tags to associate with the run. Defaults to None.
-
description : str | None — A description of the run. Defaults to None.
-
log_system_metrics : bool | None — Whether to log system metrics. Defaults to None.
-
synchronous : bool | None — Whether to log parameters synchronously. Defaults to None.
Yields
-
Run — An MLflow Run object representing the started run.
source chdir_artifact(run: Run | None = None) → Iterator[Path]
Change the current working directory to the artifact directory of the given run.
This context manager changes the current working directory to the artifact directory of the given run. It ensures that the directory is changed back to the original directory after the context is exited.
Parameters
-
run : Run | None — The run to get the artifact directory from.