def gc(backend_store_uri, run_ids): """ Permanently delete runs in the `deleted` lifecycle stage from the specified backend store. This command deletes all artifacts and metadata associated with the specified runs. """ backend_store = _get_store(backend_store_uri, None) if not hasattr(backend_store, '_hard_delete_run'): raise MlflowException( "This cli can only be used with a backend that allows hard-deleting runs" ) if not run_ids: run_ids = backend_store._get_deleted_runs() else: run_ids = run_ids.split(',') for run_id in run_ids: run = backend_store.get_run(run_id) if run.info.lifecycle_stage != LifecycleStage.DELETED: raise MlflowException( 'Run {} is not in `deleted` lifecycle stage. Only runs in ' '`deleted` lifecycle stage can be deleted.'.format(run_id)) artifact_repo = get_artifact_repository(run.info.artifact_uri) artifact_repo.delete_artifacts() backend_store._hard_delete_run(run_id) print("Run with ID %s has been permanently deleted." % str(run_id))
def describe_run(run_id): """ All of run details will print to the stdout as JSON format. """ store = _get_store() run = store.get_run(run_id) json_run = json.dumps(run.to_dictionary(), indent=4) print(json_run)
def restore_run(run_id): """ Restore a deleted run. Returns an error if the run is active or has been permanently deleted. """ store = _get_store() store.restore_run(run_id) print("Run with id %s has been restored." % str(run_id))
def delete_run(run_id): """ Mark a run for deletion. Return an error if the run does not exist or is already marked. You can restore a marked run with ``restore_run``, or permanently delete a run in the backend store. """ store = _get_store() store.delete_run(run_id) print("Run with ID %s has been deleted." % str(run_id))
def list_artifacts(run_id, artifact_path): """ Return all the artifacts directly under run's root artifact directory, or a sub-directory. The output is a JSON-formatted list. """ artifact_path = artifact_path if artifact_path is not None else "" store = _get_store() artifact_uri = store.get_run(run_id).info.artifact_uri artifact_repo = get_artifact_repository(artifact_uri) file_infos = artifact_repo.list_artifacts(artifact_path) print(_file_infos_to_json(file_infos))
def log_artifacts(local_dir, run_id, artifact_path): """ Log the files within a local directory as an artifact of a run, optionally within a run-specific artifact path. Run artifacts can be organized into directories, so you can place the artifact in a directory this way. """ store = _get_store() artifact_uri = store.get_run(run_id).info.artifact_uri artifact_repo = get_artifact_repository(artifact_uri) artifact_repo.log_artifacts(local_dir, artifact_path) _logger.info("Logged artifact from local dir %s to artifact_path=%s", local_dir, artifact_path)
def list_run(experiment_id, view): """ List all runs of the specified experiment in the configured tracking server. """ store = _get_store() view_type = ViewType.from_string(view) if view else ViewType.ACTIVE_ONLY runs = store.search_runs([experiment_id], None, view_type) table = [] for run in runs: tags = {k: v for k, v in run.data.tags.items()} run_name = tags.get(MLFLOW_RUN_NAME, "") table.append([conv_longdate_to_str(run.info.start_time), run_name, run.info.run_id]) print(tabulate(sorted(table, reverse=True), headers=["Date", "Name", "ID"]))
def download_artifacts(run_id, artifact_path, artifact_uri): """ Download an artifact file or directory to a local directory. The output is the name of the file or directory on the local disk. Either ``--run-id`` or ``--artifact-uri`` must be provided. """ if run_id is None and artifact_uri is None: _logger.error( "Either ``--run-id`` or ``--artifact-uri`` must be provided.") sys.exit(1) if artifact_uri is not None: print(_download_artifact_from_uri(artifact_uri)) return artifact_path = artifact_path if artifact_path is not None else "" store = _get_store() artifact_uri = store.get_run(run_id).info.artifact_uri artifact_repo = get_artifact_repository(artifact_uri) artifact_location = artifact_repo.download_artifacts(artifact_path) print(artifact_location)