def get_run(self, run_id): """ Fetch the run from backend store :param run_id: Unique identifier for the run :return: A single Run object if it exists, otherwise raises an Exception """ req_body = message_to_json(GetRun(run_uuid=run_id, run_id=run_id)) response_proto = self._call_endpoint(GetRun, req_body) return Run.from_proto(response_proto.run)
def test_creation_and_hydration(self): run_data, metrics, params, tags = TestRunData._create() (run_info, run_id, experiment_id, user_id, status, start_time, end_time, lifecycle_stage, artifact_uri) = TestRunInfo._create() run1 = Run(run_info, run_data) self._check_run(run1, run_info, metrics, params, tags) expected_info_dict = { "run_uuid": run_id, "run_id": run_id, "experiment_id": experiment_id, "user_id": user_id, "status": status, "start_time": start_time, "end_time": end_time, "lifecycle_stage": lifecycle_stage, "artifact_uri": artifact_uri, } self.assertEqual( run1.to_dictionary(), { "info": expected_info_dict, "data": { "metrics": {m.key: m.value for m in metrics}, "params": {p.key: p.value for p in params}, "tags": {t.key: t.value for t in tags}, } }) proto = run1.to_proto() run2 = Run.from_proto(proto) self._check_run(run2, run_info, metrics, params, tags) run3 = Run(run_info, None) self.assertEqual(run3.to_dictionary(), { "info": expected_info_dict, })
def _search_runs(self, experiment_ids, filter_string, run_view_type, max_results, order_by, page_token): experiment_ids = [ str(experiment_id) for experiment_id in experiment_ids ] sr = SearchRuns(experiment_ids=experiment_ids, filter=filter_string, run_view_type=ViewType.to_proto(run_view_type), max_results=max_results, order_by=order_by, page_token=page_token) req_body = message_to_json(sr) response_proto = self._call_endpoint(SearchRuns, req_body) runs = [Run.from_proto(proto_run) for proto_run in response_proto.runs] # If next_page_token is not set, we will see it as "". We need to convert this to None. next_page_token = None if response_proto.next_page_token: next_page_token = response_proto.next_page_token return runs, next_page_token
def create_run(self, experiment_id, user_id, start_time, tags): """ Create a run under the specified experiment ID, setting the run's status to "RUNNING" and the start time to the current time. :param experiment_id: ID of the experiment for this run :param user_id: ID of the user launching this run :param source_type: Enum (integer) describing the source of the run :return: The created Run object """ tag_protos = [tag.to_proto() for tag in tags] req_body = message_to_json( CreateRun(experiment_id=str(experiment_id), user_id=user_id, start_time=start_time, tags=tag_protos)) response_proto = self._call_endpoint(CreateRun, req_body) run = Run.from_proto(response_proto.run) return run
def create_run(run_id="", exp_id="", uid="", start=0, end=0, metrics=None, params=None, tags=None, status=RunStatus.FINISHED, a_uri=None): return Run( RunInfo(run_uuid=run_id, run_id=run_id, experiment_id=exp_id, user_id=uid, status=status, start_time=start, end_time=end, lifecycle_stage=LifecycleStage.ACTIVE, artifact_uri=a_uri), RunData(metrics=metrics, params=params, tags=tags))
def to_mlflow_entity(self): """ Convert DB model to corresponding MLflow entity. :return: :py:class:`mlflow.entities.Run`. """ run_info = RunInfo(run_uuid=self.run_uuid, run_id=self.run_uuid, experiment_id=str(self.experiment_id), user_id=self.user_id, status=self.status, start_time=self.start_time, end_time=self.end_time, lifecycle_stage=self.lifecycle_stage, artifact_uri=self.artifact_uri) run_data = RunData( metrics=[m.to_mlflow_entity() for m in self.latest_metrics], params=[p.to_mlflow_entity() for p in self.params], tags=[t.to_mlflow_entity() for t in self.tags]) return Run(run_info=run_info, run_data=run_data)
def test_string_repr(self): run_info = RunInfo(run_uuid="hi", run_id="hi", experiment_id=0, user_id="user-id", status=RunStatus.FAILED, start_time=0, end_time=1, lifecycle_stage=LifecycleStage.ACTIVE) metrics = [ Metric(key="key-%s" % i, value=i, timestamp=0, step=i) for i in range(3) ] run_data = RunData(metrics=metrics, params=[], tags=[]) run1 = Run(run_info, run_data) expected = ( "<Run: data=<RunData: metrics={'key-0': 0, 'key-1': 1, 'key-2': 2}, " "params={}, tags={}>, info=<RunInfo: artifact_uri=None, end_time=1, " "experiment_id=0, " "lifecycle_stage='active', run_id='hi', run_uuid='hi', " "start_time=0, status=4, user_id='user-id'>>") assert str(run1) == expected
def _get_run_from_info(self, run_info): metrics = self._get_all_metrics(run_info) params = self._get_all_params(run_info) tags = self._get_all_tags(run_info) return Run(run_info, RunData(metrics, params, tags))
def __init__(self, run): Run.__init__(self, run.info, run.data)
def test_creating_run_with_absent_info_throws_exception(self): run_data = TestRunData._create()[0] with pytest.raises(MlflowException) as no_info_exc: Run(None, run_data) assert "run_info cannot be None" in str(no_info_exc)