Skip to content

Run Handler

Exitare edited this page Aug 14, 2022 · 7 revisions

The run handler is designed to extend to already existing mlflow api with convenience functions.
Like the experiment handler, the constructor supports parameters for an already created client or an url to connect to a mlflow server instance.

from mlflow_wrapper.run_handler import RunHandler

run_handler: RunHandler = RunHandler()

Get Run by Id

This function is included for completeness. Mlflows api offers this function as well.

run:Run = run_handler.get_run_by_id(experiment_id: str, run_id: str)

Returns a run if found, else returns None

Get Run Id By Name

Returns the run id for a run with the given name.
As multiple runs can have the same names, the first run with this name will be returned.
If the parent run id is provided, only a run that matches the name inside the parent run will be returned.

run_id: str = run_handler.get_run_id_by_name(self, experiment_id: str, run_name: str, parent_run_id: str = None)

Get Run by Name

Returns a run by name. Similar to other functions this returns only the first occurrence of the run with the name. If a parent run id is provided, only children runs will be checked and if found returned

run: Run = run_handler.get_run_by_name(self, experiment_id: str, run_name: str, parent_run_id: str = None)

Get parent and child run

Returns a list of runs, containing both parent run and all related child runs. If no run is found, returns an empty list

get_run(self, experiment_id: str, run_name: str, include_children: bool = True) -> List:

runs: List = run_handler.get_run(self, experiment_id: str, run_name: str)

Get run by metrics

Supports 3 modes. Min, Max, and None. Min: Returns the given run where the metric is minimal. If no runs with the particular metric exist, None will be returned. Max: Returns the given run where the metric is at its maximum.f no runs with the particular metric exist, None will be returned. None: Returns the first run that is encountered with the specified metric. If none is found, returns None

get_run_by_metric(self, experiment_id: str, metric: str, mode: str = None) -> Optional[Run]

metric_run: Run = run_handler.get_run_by_metric(experiment_id=experiment_id, metric="Test Metric", mode=mode)

Delete parent and child runs

Mlflow allows to delete runs. However, if the parent run is deleted, the children runs are not deleted. This function offers the ability to delete all runs for a given parent run.

delete_run(self, experiment_id: str, run_name: str, delete_children: bool = True)


run_handler.delete_run(self, experiment_id: str, run_name: str)

Download artifacts

Mlflow allows to download artifacts. However, this can be sometimes tedious when a lot of files should be downloaded. The function can download all artifacts by either one run or a list of runs.

run_handler.download_artifacts(self, save_path: Union[Path, str], run: Run = None, runs: [] = None,
                           mlflow_folder: str = None)