Beispiel #1
0
    def create_run(self, experiment_id, user_id, run_name, source_type,
                   source_name, entry_point_name, start_time, source_version,
                   tags, parent_run_id):
        """
        Creates 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=experiment_id,
                      user_id=user_id,
                      run_name="",
                      source_type=source_type,
                      source_name=source_name,
                      entry_point_name=entry_point_name,
                      start_time=start_time,
                      source_version=source_version,
                      tags=tag_protos,
                      parent_run_id=parent_run_id))
        response_proto = self._call_endpoint(CreateRun, req_body)
        run = Run.from_proto(response_proto.run)
        if run_name:
            self.set_tag(run.info.run_uuid,
                         RunTag(key=MLFLOW_RUN_NAME, value=run_name))
        return run
Beispiel #2
0
    def test_creation_and_hydration(self):
        run_data, metrics, params, tags = TestRunData._create()
        (run_info, run_uuid, experiment_id, name, source_type, source_name, entry_point_name,
         user_id, status, start_time, end_time, source_version, lifecycle_stage,
         artifact_uri) = TestRunInfo._create()

        run1 = Run(run_info, run_data)

        self._check_run(run1, run_info, metrics, params, tags)

        as_dict = {"info": {"run_uuid": run_uuid,
                            "experiment_id": experiment_id,
                            "name": name,
                            "source_type": source_type,
                            "source_name": source_name,
                            "entry_point_name": entry_point_name,
                            "user_id": user_id,
                            "status": status,
                            "start_time": start_time,
                            "end_time": end_time,
                            "source_version": source_version,
                            "lifecycle_stage": lifecycle_stage,
                            "artifact_uri": artifact_uri,
                            },
                   "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}}
                   }
        self.assertEqual(run1.to_dictionary(), as_dict)

        proto = run1.to_proto()
        run2 = Run.from_proto(proto)
        self._check_run(run2, run_info, metrics, params, tags)
Beispiel #3
0
    def search_runs(self,
                    experiment_ids,
                    search_filter,
                    run_view_type,
                    max_results=SEARCH_MAX_RESULTS_THRESHOLD):
        """
        Return runs that match the given list of search expressions within the experiments.
        Given multiple search expressions, all these expressions are ANDed together for search.

        :param experiment_ids: List of experiment ids to scope the search
        :param search_filter: :py:class`mlflow.utils.search_utils.SearchFilter` object to encode
            search expression or filter string.
        :param run_view_type: ACTIVE, DELETED, or ALL runs.
        :param max_results: Maximum number of runs desired.

        :return: A list of Run objects that satisfy the search expressions
        """
        experiment_ids = [
            str(experiment_id) for experiment_id in experiment_ids
        ]
        sr = SearchRuns(
            experiment_ids=experiment_ids,
            filter=search_filter.filter_string if search_filter else None,
            run_view_type=ViewType.to_proto(run_view_type),
            max_results=max_results)
        req_body = message_to_json(sr)
        response_proto = self._call_endpoint(SearchRuns, req_body)
        return [Run.from_proto(proto_run) for proto_run in response_proto.runs]
Beispiel #4
0
    def get_run(self, run_uuid):
        """
        Fetches the run from backend store

        :param run_uuid: 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_uuid))
        response_proto = self._call_endpoint(GetRun, req_body)
        return Run.from_proto(response_proto.run)
Beispiel #5
0
    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, search_expressions):
        """
        Returns runs that match the given list of search expressions within the experiments.
        Given multiple search expressions, all these expressions are ANDed together for search.

        :param experiment_ids: List of experiment ids to scope the search
        :param search_expression: list of search expressions

        :return: A list of Run objects that satisfy the search expressions
        """
        search_expressions_protos = [expr.to_proto() for expr in search_expressions]
        req_body = _message_to_json(SearchRuns(experiment_ids=experiment_ids,
                                               anded_expressions=search_expressions_protos))
        response_proto = self._call_endpoint(SearchRuns, req_body)
        return [Run.from_proto(proto_run) for proto_run in response_proto.runs]
Beispiel #7
0
 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]
     return runs, response_proto.next_page_token
Beispiel #8
0
 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
Beispiel #9
0
 def search_runs(self,
                 experiment_ids,
                 filter_string,
                 run_view_type,
                 max_results=SEARCH_MAX_RESULTS_THRESHOLD,
                 order_by=None):
     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)
     req_body = message_to_json(sr)
     response_proto = self._call_endpoint(SearchRuns, req_body)
     return [Run.from_proto(proto_run) for proto_run in response_proto.runs]
Beispiel #10
0
    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
Beispiel #11
0
    def search_runs(self, experiment_ids, search_filter, run_view_type):
        """
        Returns runs that match the given list of search expressions within the experiments.
        Given multiple search expressions, all these expressions are ANDed together for search.

        :param experiment_ids: List of experiment ids to scope the search
        :param search_filter: :py:class`mlflow.utils.search_utils.SearchFilter` object to encode
            search expression or filter string.
        :param run_view_type: ACTIVE, DELETED, or ALL runs.

        :return: A list of Run objects that satisfy the search expressions
        """
        sr = SearchRuns(experiment_ids=experiment_ids,
                        anded_expressions=search_filter.search_expressions if search_filter else [],
                        filter=search_filter.filter_string if search_filter else None,
                        run_view_type=ViewType.to_proto(run_view_type))
        req_body = message_to_json(sr)
        response_proto = self._call_endpoint(SearchRuns, req_body)
        return [Run.from_proto(proto_run) for proto_run in response_proto.runs]
Beispiel #12
0
    def test_creation_and_hydration(self):
        run_data, metrics, params, tags = TestRunData._create()
        (run_info, run_uuid, experiment_id, name, source_type, source_name,
         entry_point_name, user_id, status, start_time, end_time,
         source_version, artifact_uri) = TestRunInfo._create()

        run1 = Run(run_info, run_data)

        self._check_run(run1, run_info, run_data)

        as_dict = {
            "info": {
                "run_uuid": run_uuid,
                "experiment_id": experiment_id,
                "name": name,
                "source_type": source_type,
                "source_name": source_name,
                "entry_point_name": entry_point_name,
                "user_id": user_id,
                "status": status,
                "start_time": start_time,
                "end_time": end_time,
                "source_version": source_version,
                "artifact_uri": artifact_uri,
            },
            "data": {
                "metrics": metrics,
                "params": params,
                "tags": tags
            }
        }
        self.assertEqual(run1.to_dictionary(), as_dict)

        proto = run1.to_proto()
        run2 = Run.from_proto(proto)
        self._check_run(run2, run_info, run_data)

        run3 = Run.from_dictionary(as_dict)
        self._check_run(run3, run_info, run_data)