mbl.analysis.run_searcher
1.2.1. mbl.analysis.run_searcher#
Classes
|
|
- class mbl.analysis.run_searcher.RunSearcher(tracking_uri, **kwargs)[source]#
Bases:
mlflow.tracking.client.MlflowClient
- Parameters
tracking_uri (str) – Address of local or remote tracking server. If not provided, defaults to the service set by
mlflow.tracking.set_tracking_uri
. See Where Runs Get Recorded for more info.registry_uri – Address of local or remote model registry server. If not provided, defaults to the service set by
mlflow.tracking.set_registry_uri
. If no such service was set, defaults to the tracking uri of the client.
- __init__(tracking_uri, **kwargs)[source]#
- Parameters
tracking_uri (str) –
Address of local or remote tracking server. If not provided, defaults to the service set by
mlflow.tracking.set_tracking_uri
. See Where Runs Get Recorded for more info.registry_uri – Address of local or remote model registry server. If not provided, defaults to the service set by
mlflow.tracking.set_registry_uri
. If no such service was set, defaults to the tracking uri of the client.
- static filter(n, h, penalty=0.0, s_target=0, seed=None, chi=None, offset=None, overall_const=None, relative_offset=None, method=None)[source]#
- Parameters
n (int) –
h (float) –
penalty (float) –
s_target (int) –
seed (Optional[int]) –
chi (Optional[int]) –
offset (Optional[float]) –
overall_const (Optional[float]) –
relative_offset (Optional[float]) –
method (Optional[str]) –
Returns:
Examples: Query string takes the form,
- query = (
“params.model = ‘CNN’ ” “and params.layers = ‘10’ ” “and metrics.`prediction accuracy` >= 0.945”
)
- query(experiment_id, filter_string=None, **kwargs)[source]#
- Parameters
experiment_id (int) –
filter_string (Optional[str]) –
- list_artifacts(experiment_id, filter_string, path=None, **kwargs)[source]#
List the artifacts for a run.
- Parameters
run_id – The run to list artifacts from.
path (Optional[str]) – The run’s relative artifact path to list from. By default it is set to None or the root artifact path.
experiment_id (int) –
filter_string (str) –
- Returns
List of
mlflow.entities.FileInfo
- Return type
List[mlflow.entities.file_info.FileInfo]
from mlflow import MlflowClient def print_artifact_info(artifact): print("artifact: {}".format(artifact.path)) print("is_dir: {}".format(artifact.is_dir)) print("size: {}".format(artifact.file_size)) features = "rooms zipcode, median_price, school_rating, transport" labels = "price" # Create a run under the default experiment (whose id is '0'). client = MlflowClient() experiment_id = "0" run = client.create_run(experiment_id) # Create some artifacts and log under the above run for file, content in [("features", features), ("labels", labels)]: with open("{}.txt".format(file), 'w') as f: f.write(content) client.log_artifact(run.info.run_id, "{}.txt".format(file)) # Fetch the logged artifacts artifacts = client.list_artifacts(run.info.run_id) for artifact in artifacts: print_artifact_info(artifact) client.set_terminated(run.info.run_id)
artifact: features.txt is_dir: False size: 53 artifact: labels.txt is_dir: False size: 5
- download_artifacts(experiment_id, filter_string, path=None, dst_path=None, **kwargs)[source]#
Warning
mlflow.tracking.client.MlflowClient.download_artifacts
is deprecated since 2.0. This method will be removed in a future release. Usemlflow.artifacts.download_artifacts
instead.Download an artifact file or directory from a run to a local directory if applicable, and return a local path for it.
- Parameters
run_id – The run to download artifacts from.
path (Optional[str]) – Relative source path to the desired artifact.
dst_path (Optional[str]) – Absolute path of the local filesystem destination directory to which to download the specified artifacts. This directory must already exist. If unspecified, the artifacts will either be downloaded to a new uniquely-named directory on the local filesystem or will be returned directly in the case of the LocalArtifactRepository.
experiment_id (int) –
filter_string (str) –
- Returns
Local path of desired artifact.
import os import mlflow from mlflow import MlflowClient features = "rooms, zipcode, median_price, school_rating, transport" with open("features.txt", 'w') as f: f.write(features) # Log artifacts with mlflow.start_run() as run: mlflow.log_artifact("features.txt", artifact_path="features") # Download artifacts client = MlflowClient() local_dir = "/tmp/artifact_downloads" if not os.path.exists(local_dir): os.mkdir(local_dir) local_path = client.download_artifacts(run.info.run_id, "features", local_dir) print("Artifacts downloaded in: {}".format(local_path)) print("Artifacts: {}".format(os.listdir(local_path)))
Artifacts downloaded in: /tmp/artifact_downloads/features Artifacts: ['features.txt']