コード例 #1
0
 def get_major_versions(self, experiment_id, view='active_only'):
     view_type = ViewType.from_string(
         view) if view else ViewType.ACTIVE_ONLY
     runs = self.client.store.search_runs([experiment_id], None, view_type)
     major_versions_list = []
     for run in runs:
         tags = {k: v for k, v in run.data.tags.items()}
         parent_run_id = tags.get(mlflow_tags.MLFLOW_PARENT_RUN_ID, "")
         if parent_run_id == "":
             major_versions_list.append(run)
     return major_versions_list
コード例 #2
0
ファイル: handlers.py プロジェクト: tpartyka/mlflow
def _search_runs():
    request_message = _get_request_message(SearchRuns())
    response_message = SearchRuns.Response()
    run_view_type = ViewType.ACTIVE_ONLY
    if request_message.HasField('run_view_type'):
        run_view_type = ViewType.from_proto(request_message.run_view_type)
    run_entities = _get_store().search_runs(request_message.experiment_ids,
                                            SearchFilter(request_message),
                                            run_view_type)
    response_message.runs.extend([r.to_proto() for r in run_entities])
    response = Response(mimetype='application/json')
    response.set_data(message_to_json(response_message))
    return response
コード例 #3
0
ファイル: runs.py プロジェクト: zmoon111/mlflow
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], [], view_type)
    table = []
    for run in runs:
        tags = {t.key: t.value for t in run.data.tags}
        run_name = tags.get(MLFLOW_RUN_NAME, "")
        table.append([conv_longdate_to_str(run.info.start_time), run_name, run.info.run_uuid])
    print(tabulate(sorted(table, reverse=True), headers=["Date", "Name", "ID"]))
コード例 #4
0
def list_experiments(view):
    """
    List all experiments in the configured tracking server.
    """
    store = _get_store()
    view_type = ViewType.from_string(view) if view else ViewType.ACTIVE_ONLY
    experiments = store.list_experiments(view_type)
    table = [[
        exp.experiment_id, exp.name, exp.artifact_location if is_uri(
            exp.artifact_location) else os.path.abspath(exp.artifact_location)
    ] for exp in experiments]
    print(
        tabulate(sorted(table),
                 headers=["Experiment Id", "Name", "Artifact Location"]))
コード例 #5
0
ファイル: handlers.py プロジェクト: yuecong/mlflow
def _search_runs():
    request_message = _get_request_message(SearchRuns())
    response_message = SearchRuns.Response()
    run_view_type = ViewType.ACTIVE_ONLY
    if request_message.HasField('run_view_type'):
        run_view_type = ViewType.from_proto(request_message.run_view_type)
    sf = SearchFilter(anded_expressions=request_message.anded_expressions,
                      filter_string=request_message.filter)
    max_results = request_message.max_results
    experiment_ids = request_message.experiment_ids
    run_entities = _get_store().search_runs(experiment_ids, sf, run_view_type, max_results)
    response_message.runs.extend([r.to_proto() for r in run_entities])
    response = Response(mimetype='application/json')
    response.set_data(message_to_json(response_message))
    return response
コード例 #6
0
    def is_version_name_exist(self,
                              experiment_id,
                              version_name,
                              view='active_only'):
        view_type = ViewType.from_string(
            view) if view else ViewType.ACTIVE_ONLY
        runs = self.client.store.search_runs([experiment_id], None, view_type)
        for run in runs:
            tags = {k: v for k, v in run.data.tags.items()}
            run_name = tags.get(mlflow_tags.MLFLOW_RUN_NAME, "")

            if run_name == version_name:
                return True

        return False
コード例 #7
0
ファイル: rest_store.py プロジェクト: xudamao2015/mlflow
 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
コード例 #8
0
    def search_runs(self, experiment_ids, search_expressions, 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_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,
                                              run_view_type=ViewType.to_proto(run_view_type)))
        response_proto = self._call_endpoint(SearchRuns, req_body)
        return [Run.from_proto(proto_run) for proto_run in response_proto.runs]
コード例 #9
0
ファイル: rest_store.py プロジェクト: yusufazishty/mlflow
 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
コード例 #10
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]
コード例 #11
0
def _search_runs():
    request_message = _get_request_message(SearchRuns())
    response_message = SearchRuns.Response()
    run_view_type = ViewType.ACTIVE_ONLY
    if request_message.HasField('run_view_type'):
        run_view_type = ViewType.from_proto(request_message.run_view_type)
    filter_string = request_message.filter
    max_results = request_message.max_results
    experiment_ids = request_message.experiment_ids
    order_by = request_message.order_by
    page_token = request_message.page_token
    run_entities = _get_store().search_runs(experiment_ids, filter_string,
                                            run_view_type, max_results,
                                            order_by, page_token)
    response_message.runs.extend([r.to_proto() for r in run_entities])
    response = Response(mimetype='application/json')
    response.set_data(message_to_json(response_message))
    return response
コード例 #12
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]
コード例 #13
0
ファイル: test_rest_store.py プロジェクト: zuoxiaolei/mlflow
    def test_requestor(self, request):
        response = mock.MagicMock
        response.status_code = 200
        response.text = '{}'
        request.return_value = response

        creds = MlflowHostCreds('https://hello')
        store = RestStore(lambda: creds)

        user_name = "mock user"
        source_name = "rest test"

        source_name_patch = mock.patch(
            "mlflow.tracking.context.default_context._get_source_name",
            return_value=source_name)
        source_type_patch = mock.patch(
            "mlflow.tracking.context.default_context._get_source_type",
            return_value=SourceType.LOCAL)
        with mock.patch('mlflow.store.rest_store.http_request') as mock_http, \
                mock.patch('mlflow.tracking.utils._get_store', return_value=store), \
                mock.patch('mlflow.tracking.context.default_context._get_user',
                           return_value=user_name), \
                mock.patch('time.time', return_value=13579), \
                source_name_patch, source_type_patch:
            with mlflow.start_run(experiment_id="43"):
                cr_body = message_to_json(
                    CreateRun(experiment_id="43",
                              user_id=user_name,
                              start_time=13579000,
                              tags=[
                                  ProtoRunTag(key='mlflow.source.name',
                                              value=source_name),
                                  ProtoRunTag(key='mlflow.source.type',
                                              value='LOCAL'),
                                  ProtoRunTag(key='mlflow.user',
                                              value=user_name)
                              ]))
                expected_kwargs = self._args(creds, "runs/create", "POST",
                                             cr_body)

                assert mock_http.call_count == 1
                actual_kwargs = mock_http.call_args[1]

                # Test the passed tag values separately from the rest of the request
                # Tag order is inconsistent on Python 2 and 3, but the order does not matter
                expected_tags = expected_kwargs['json'].pop('tags')
                actual_tags = actual_kwargs['json'].pop('tags')
                assert (sorted(expected_tags,
                               key=lambda t: t['key']) == sorted(
                                   actual_tags, key=lambda t: t['key']))
                assert expected_kwargs == actual_kwargs

        with mock.patch('mlflow.store.rest_store.http_request') as mock_http:
            store.log_param("some_uuid", Param("k1", "v1"))
            body = message_to_json(
                LogParam(run_uuid="some_uuid",
                         run_id="some_uuid",
                         key="k1",
                         value="v1"))
            self._verify_requests(mock_http, creds, "runs/log-parameter",
                                  "POST", body)

        with mock.patch('mlflow.store.rest_store.http_request') as mock_http:
            store.set_tag("some_uuid", RunTag("t1", "abcd" * 1000))
            body = message_to_json(
                SetTag(run_uuid="some_uuid",
                       run_id="some_uuid",
                       key="t1",
                       value="abcd" * 1000))
            self._verify_requests(mock_http, creds, "runs/set-tag", "POST",
                                  body)

        with mock.patch('mlflow.store.rest_store.http_request') as mock_http:
            store.delete_tag("some_uuid", "t1")
            body = message_to_json(DeleteTag(run_id="some_uuid", key="t1"))
            self._verify_requests(mock_http, creds, "runs/delete-tag", "POST",
                                  body)

        with mock.patch('mlflow.store.rest_store.http_request') as mock_http:
            store.log_metric("u2", Metric("m1", 0.87, 12345, 3))
            body = message_to_json(
                LogMetric(run_uuid="u2",
                          run_id="u2",
                          key="m1",
                          value=0.87,
                          timestamp=12345,
                          step=3))
            self._verify_requests(mock_http, creds, "runs/log-metric", "POST",
                                  body)

        with mock.patch('mlflow.store.rest_store.http_request') as mock_http:
            metrics = [
                Metric("m1", 0.87, 12345, 0),
                Metric("m2", 0.49, 12345, -1),
                Metric("m3", 0.58, 12345, 2)
            ]
            params = [Param("p1", "p1val"), Param("p2", "p2val")]
            tags = [RunTag("t1", "t1val"), RunTag("t2", "t2val")]
            store.log_batch(run_id="u2",
                            metrics=metrics,
                            params=params,
                            tags=tags)
            metric_protos = [metric.to_proto() for metric in metrics]
            param_protos = [param.to_proto() for param in params]
            tag_protos = [tag.to_proto() for tag in tags]
            body = message_to_json(
                LogBatch(run_id="u2",
                         metrics=metric_protos,
                         params=param_protos,
                         tags=tag_protos))
            self._verify_requests(mock_http, creds, "runs/log-batch", "POST",
                                  body)

        with mock.patch('mlflow.store.rest_store.http_request') as mock_http:
            store.delete_run("u25")
            self._verify_requests(mock_http, creds, "runs/delete", "POST",
                                  message_to_json(DeleteRun(run_id="u25")))

        with mock.patch('mlflow.store.rest_store.http_request') as mock_http:
            store.restore_run("u76")
            self._verify_requests(mock_http, creds, "runs/restore", "POST",
                                  message_to_json(RestoreRun(run_id="u76")))

        with mock.patch('mlflow.store.rest_store.http_request') as mock_http:
            store.delete_experiment("0")
            self._verify_requests(
                mock_http, creds, "experiments/delete", "POST",
                message_to_json(DeleteExperiment(experiment_id="0")))

        with mock.patch('mlflow.store.rest_store.http_request') as mock_http:
            store.restore_experiment("0")
            self._verify_requests(
                mock_http, creds, "experiments/restore", "POST",
                message_to_json(RestoreExperiment(experiment_id="0")))

        with mock.patch('mlflow.store.rest_store.http_request') as mock_http:
            response = mock.MagicMock
            response.text = '{"runs": ["1a", "2b", "3c"], "next_page_token": "67890fghij"}'
            mock_http.return_value = response
            result = store.search_runs(["0", "1"],
                                       "params.p1 = 'a'",
                                       ViewType.ACTIVE_ONLY,
                                       max_results=10,
                                       order_by=["a"],
                                       page_token="12345abcde")

            expected_message = SearchRuns(experiment_ids=["0", "1"],
                                          filter="params.p1 = 'a'",
                                          run_view_type=ViewType.to_proto(
                                              ViewType.ACTIVE_ONLY),
                                          max_results=10,
                                          order_by=["a"],
                                          page_token="12345abcde")
            self._verify_requests(mock_http, creds, "runs/search", "POST",
                                  message_to_json(expected_message))
            assert result.token == "67890fghij"
コード例 #14
0
 def get_versions(self, experiment_id, view='active_only'):
     view_type = ViewType.from_string(view) if view else ViewType.ACTIVE_ONLY
     runs = self.client.store.search_runs([experiment_id], None, view_type)
     return runs
コード例 #15
0
def test_to_proto():
    assert ViewType.to_proto(ViewType.ACTIVE_ONLY) == service_pb2.ACTIVE_ONLY
    assert ViewType.to_proto(ViewType.DELETED_ONLY) == service_pb2.DELETED_ONLY
    assert ViewType.to_proto(ViewType.ALL) == service_pb2.ALL
コード例 #16
0
def test_from_proto():
    assert ViewType.from_proto(service_pb2.ACTIVE_ONLY) == ViewType.ACTIVE_ONLY
    assert ViewType.from_proto(
        service_pb2.DELETED_ONLY) == ViewType.DELETED_ONLY
    assert ViewType.from_proto(service_pb2.ALL) == ViewType.ALL