def update_run_info(self, run_id, run_status, end_time): _validate_run_id(run_id) run_info = self._get_run_info(run_id) check_run_is_active(run_info) new_info = run_info._copy_with_overrides(run_status, end_time) self._overwrite_run_info(new_info) return new_info
def delete_run(self, run_id): run_info = self._get_run_info(run_id) if run_info is None: raise MlflowException( "Run '%s' metadata is in invalid state." % run_id, databricks_pb2.INVALID_STATE) check_run_is_active(run_info) new_info = run_info._copy_with_overrides( lifecycle_stage=LifecycleStage.DELETED) self._overwrite_run_info(new_info)
def log_batch(self, run_id, metrics, params, tags): _validate_run_id(run_id) _validate_batch_log_data(metrics, params, tags) _validate_batch_log_limits(metrics, params, tags) run_info = self._get_run_info(run_id) check_run_is_active(run_info) try: for param in params: self._log_run_param(run_info, param) for metric in metrics: self._log_run_metric(run_info, metric) for tag in tags: self._set_run_tag(run_info, tag) except Exception as e: raise MlflowException(e, INTERNAL_ERROR)
def delete_tag(self, run_id, key): """ Delete a tag from a run. This is irreversible. :param run_id: String ID of the run :param key: Name of the tag """ _validate_run_id(run_id) run_info = self._get_run_info(run_id) check_run_is_active(run_info) tag_path = self._get_tag_path(run_info.experiment_id, run_id, key) if not exists(tag_path): raise MlflowException( "No tag with name: {} in run with id {}".format(key, run_id), error_code=RESOURCE_DOES_NOT_EXIST) os.remove(tag_path)
def record_logged_model(self, run_id, mlflow_model): if not isinstance(mlflow_model, Model): raise TypeError( "Argument 'mlflow_model' should be mlflow.models.Model, got '{}'" .format(type(mlflow_model))) _validate_run_id(run_id) run_info = self._get_run_info(run_id) check_run_is_active(run_info) model_dict = mlflow_model.to_dict() run_info = self._get_run_info(run_id) path = self._get_tag_path(run_info.experiment_id, run_info.run_id, MLFLOW_LOGGED_MODELS) if os.path.exists(path): with open(path, "r") as f: model_list = json.loads(f.read()) else: model_list = [] tag = RunTag(MLFLOW_LOGGED_MODELS, json.dumps(model_list + [model_dict])) try: self._set_run_tag(run_info, tag) except Exception as e: raise MlflowException(e, INTERNAL_ERROR)
def set_tag(self, run_id, tag): _validate_run_id(run_id) _validate_tag_name(tag.key) run_info = self._get_run_info(run_id) check_run_is_active(run_info) self._set_run_tag(run_info, tag)
def log_param(self, run_id, param): _validate_run_id(run_id) _validate_param_name(param.key) run_info = self._get_run_info(run_id) check_run_is_active(run_info) self._log_run_param(run_info, param)
def log_metric(self, run_id, metric): _validate_run_id(run_id) _validate_metric_name(metric.key) run_info = self._get_run_info(run_id) check_run_is_active(run_info) self._log_run_metric(run_info, metric)