Skip to content

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 instance.

  • start_run Start an MLflow run and log parameters using the provided configuration instance.

  • chdir_artifact Change the current working directory to the artifact directory of the given run.

source log_run(run: Run)Iterator[None]

Log the parameters from the given configuration instance.

This context manager logs the parameters from the provided configuration instance using MLflow. It also manages the MLflow run context, ensuring that artifacts are logged and the run is properly closed.

Parameters

  • run : Run The run instance.

Yields

  • None None

source start_run(*, 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)Iterator[Run]

Start an MLflow run and log parameters using the provided configuration instance.

This context manager starts an MLflow run and logs parameters using the specified configuration instance. It ensures that the run is properly closed after completion.

Parameters

  • config : object The configuration instance 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 instance representing the started run.

source chdir_artifact(run: Run)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.