示例#1
0
def _log_batch():
    _validate_batch_log_api_req(_get_request_json())
    request_message = _get_request_message(LogBatch())
    metrics = [Metric.from_proto(proto_metric) for proto_metric in request_message.metrics]
    params = [Param.from_proto(proto_param) for proto_param in request_message.params]
    tags = [RunTag.from_proto(proto_tag) for proto_tag in request_message.tags]
    _get_store().log_batch(run_id=request_message.run_id, metrics=metrics, params=params, tags=tags)
    response_message = LogBatch.Response()
    response = Response(mimetype='application/json')
    response.set_data(message_to_json(response_message))
    return response
    def get_metric_history(self, run_uuid, metric_key):
        """
        Returns all logged value for a given metric.

        :param run_uuid: Unique identifier for run
        :param metric_key: Metric name within the run

        :return: A list of float values logged for the give metric if logged, else empty list
        """
        req_body = _message_to_json(GetMetricHistory(run_uuid=run_uuid, metric_key=metric_key))
        response_proto = self._call_endpoint(GetMetricHistory, req_body)
        return [Metric.from_proto(metric).value for metric in response_proto.metrics]
    def get_metric(self, run_uuid, metric_key):
        """
        Returns the last logged value for a given metric.

        :param run_uuid: Unique identifier for run
        :param metric_key: Metric name within the run

        :return: A single float value for the give metric if logged, else None
        """
        req_body = _message_to_json(GetMetric(run_uuid=run_uuid, metric_key=metric_key))
        response_proto = self._call_endpoint(GetMetric, req_body)
        return Metric.from_proto(response_proto.metric)
示例#4
0
    def get_metric_history(self, run_uuid, metric_key):
        """
        Return all logged values for a given metric.

        :param run_uuid: Unique identifier for run
        :param metric_key: Metric name within the run

        :return: A list of :py:class:`mlflow.entities.Metric` entities if logged, else empty list
        """
        req_body = message_to_json(GetMetricHistory(run_uuid=run_uuid, metric_key=metric_key))
        response_proto = self._call_endpoint(GetMetricHistory, req_body)
        return [Metric.from_proto(metric) for metric in response_proto.metrics]
示例#5
0
    def test_creation_and_hydration(self):
        key = random_str()
        value = 10000
        ts = int(time.time())

        metric = Metric(key, value, ts)
        self._check(metric, key, value, ts)

        as_dict = {"key": key, "value": value, "timestamp": ts}
        self.assertEqual(dict(metric), as_dict)

        proto = metric.to_proto()
        metric2 = metric.from_proto(proto)
        self._check(metric2, key, value, ts)

        metric3 = Metric.from_dictionary(as_dict)
        self._check(metric3, key, value, ts)
示例#6
0
def test_creation_and_hydration():
    key = random_str()
    value = 10000
    ts = int(1000 * time.time())
    step = random_int()

    metric = Metric(key, value, ts, step)
    _check(metric, key, value, ts, step)

    as_dict = {"key": key, "value": value, "timestamp": ts, "step": step}
    assert dict(metric) == as_dict

    proto = metric.to_proto()
    metric2 = metric.from_proto(proto)
    _check(metric2, key, value, ts, step)

    metric3 = Metric.from_dictionary(as_dict)
    _check(metric3, key, value, ts, step)
示例#7
0
def test_parse_dict_int_as_string_backcompat():
    in_json = {"timestamp": "123"}
    message = ProtoMetric()
    parse_dict(in_json, message)
    experiment = Metric.from_proto(message)
    assert experiment.timestamp == 123