Ejemplo n.º 1
0
    def _log_metric(self, key, value, timestamp=None, source=None, is_json=False):
        # type: (str, Any, Optional[datetime], Optional[MetricSource], Optional[bool]) -> None
        if is_json:
            metric = Metric(key=key, timestamp=timestamp or utcnow(), value_json=value)
        else:
            metric = Metric(key=key, timestamp=timestamp or utcnow(), value=value)

        self.tracking_store.log_metric(
            task_run=self.task_run, metric=metric, source=source
        )
Ejemplo n.º 2
0
 def _log_param(self, run_id, param):
     # type: (str, mlflow.entities.Param) -> None
     # Temporarly log params as metrics
     dbnd_metric = Metric(key=param.key,
                          value=param.value,
                          timestamp=utcnow())
     self.dbnd_store.log_metric(self._get_current_task_run(), dbnd_metric)
     logger.info("Param {}".format(param))
Ejemplo n.º 3
0
 def get_metric_history(self, key, source=None):
     metric_target = self.meta.get_metric_target(key, source=source)
     if not metric_target.exists():
         raise DatabandError("Metric '%s' not found" % key)
     metric_data = metric_target.readlines()
     rsl = []
     for pair in metric_data:
         ts, val = pair.strip().split(" ")
         rsl.append(Metric(key, float(val), datetime.fromtimestamp(int(ts))))
     return rsl
Ejemplo n.º 4
0
 def _log_metric(self, run_id, metric):
     # type: (str, mlflow.entities.Metric) -> None
     dbnd_metric = Metric(
         key=metric.key,
         value=metric.value,
         # mlflow.entities.Metric.timestamp is `int(time.time() * 1000)`
         timestamp=datetime.fromtimestamp(metric.timestamp / 1000),
     )
     self.dbnd_store.log_metric(self._get_current_task_run(), dbnd_metric)
     logger.info("Metric {}".format(metric))
Ejemplo n.º 5
0
    def get_metric(self, key, source=None):
        metric_target = self.meta.get_metric_target(key, source=source)
        if not metric_target.exists():
            raise DatabandRuntimeError("Metric '%s' not found" % key)
        metric_data = metric_target.readlines()
        if len(metric_data) == 0:
            raise DatabandRuntimeError(
                "Metric '%s' is malformed. No data found." % key)
        first_line = metric_data[0]

        metric_parsed = _METRICS_RE.match(first_line)
        if not metric_parsed:
            raise DatabandRuntimeError(
                "Metric '%s' is malformed. Expected format: 'TS VALUE', got='%s'"
                % (key, first_line))

        timestamp, val = metric_parsed.groups()

        return Metric(
            key=key,
            value=_parse_metric(val),
            timestamp=datetime.fromtimestamp(int(timestamp)),
        )
Ejemplo n.º 6
0
    def make_object(self, data, **kwargs):
        from dbnd._core.tracking.metrics import Metric

        return Metric(**data)
Ejemplo n.º 7
0
    def _log_metric(self, key, value, timestamp=None, source=None):
        metric = Metric(key=key, timestamp=timestamp or utcnow(), value=value)

        self.tracking_store.log_metric(
            task_run=self.task_run, metric=metric, source=source
        )