Overview
Harbor’s metric system allows you to compute aggregate statistics across trial results. Metrics process lists of rewards and produce summary values like mean, max, min, or custom computations.MetricConfig
Configuration for a metric to be computed. Import:from harbor.models.metric.config import MetricConfig
Fields
MetricType
default:"MetricType.MEAN"
The type of metric to compute.
dict[str, Any]
default:"{}"
Additional keyword arguments passed to the metric constructor.
Example
MetricType
Enum defining available metric types. Import:from harbor.models.metric.type import MetricType
Values
str
Compute the mean (average) of rewards.
str
Compute the maximum reward value.
str
Compute the minimum reward value.
str
Compute the sum of all rewards.
str
Run a custom Python script to compute metrics.
Example
BaseMetric
Abstract base class for implementing custom metrics. Import:from harbor.metrics.base import BaseMetric
Type Parameters
TypeVar
The type of values the metric processes (typically
dict[str, float | int] for rewards).Abstract Methods
compute
list[T | None]
required
List of reward values. None values represent failed trials or missing rewards.
dict[str, float | int]
required
Dictionary of computed metric name-value pairs.
Example Implementation
Built-in Metrics
Harbor includes several built-in metrics:Mean
Max
Min
Sum
VerifierResult
Contains the verification results including rewards. Import:from harbor.models.verifier.result import VerifierResult
Fields
dict[str, float | int] | None
default:"None"
Dictionary mapping reward names to numeric values. None if verification failed or was disabled.
Example
Writing Custom Metrics
Simple Aggregation Metric
Metric with Parameters
Multi-Reward Analysis Metric
Using Metrics in Jobs
Related Types
- JobConfig - Configure metrics for a job
- JobResult - Access computed metrics
- TrialResult - Individual trial rewards