Beispiel #1
0
    def get_metric_type_and_properties(
            self, metric: Metric) -> Tuple[int, Dict[str, Any]]:
        """Given an Ax Metric, convert its type into a member of MetricType enum,
        and construct a dictionary to be stored in the database `properties`
        json blob.
        """
        metric_type = METRIC_REGISTRY.get(type(metric))
        if metric_type is None:
            raise SQAEncodeError(
                "Cannot encode metric to SQLAlchemy because metric's "
                "subclass is invalid.")  # pragma: no cover

        # name and lower_is_better are stored directly on the metric,
        # so we don't need to include these in the properties blob
        properties = get_object_properties(
            object=metric, exclude_fields=["name", "lower_is_better"])

        return metric_type, properties
Beispiel #2
0
    def get_metric_type_and_properties(
            self, metric: Metric) -> Tuple[int, Dict[str, Any]]:
        """Given an Ax Metric, convert its type into a member of MetricType enum,
        and construct a dictionary to be stored in the database `properties`
        json blob.
        """
        metric_class = type(metric)
        metric_type = METRIC_REGISTRY.get(metric_class)
        if metric_type is None:
            raise SQAEncodeError(
                "Cannot encode metric to SQLAlchemy because metric's "
                f"subclass ({metric_class}) is missing from the registry. "
                "The metric registry currently contains the following: "
                f"{','.join(map(str, METRIC_REGISTRY.keys()))}"
            )  # pragma: no cover

        properties = metric_class.serialize_init_args(metric=metric)
        return metric_type, properties