Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several minor benchmarking changes #3196

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 37 additions & 10 deletions ax/benchmark/benchmark_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
Metrics vary on two dimensions: Whether they are `MapMetric`s or not, and
whether they are available while running or not.

There are two Metric classes:
- `BenchmarkMetric`: For when outputs should be `Data` (not `MapData`) and data
There are four Metric classes:
- `BenchmarkMetric`: A non-Map metric
is not available while running.
- `BenchmarkMapMetric`: For when outputs should be `MapData` (not `Data`) and
data is available while running.

There are further benchmark classes that are not yet implemented:
- `BenchmarkTimeVaryingMetric`: For when outputs should be `Data` and the metric
is available while running.
- `BenchmarkMapUnavailableWhileRunningMetric`: For when outputs should be
Expand Down Expand Up @@ -200,7 +198,7 @@ def fetch_trial_data(self, trial: BaseTrial, **kwargs: Any) -> MetricFetchResult
available_data = df[df["virtual runtime"] <= max_t]

if not self.observe_noise_sd:
available_data["sem"] = None
available_data.loc[:, "sem"] = None
return self._df_to_result(df=available_data.drop(columns=["virtual runtime"]))

@abstractmethod
Expand All @@ -214,8 +212,10 @@ def _df_to_result(self, df: DataFrame) -> MetricFetchResult:

class BenchmarkMetric(BenchmarkMetricBase):
"""
Metric for benchmarking that produces `Data` and is not available while
running.
Non-map Metric for benchmarking that is not available while running.

It cannot process data with multiple time steps, as it would only return one
value -- the value it has at completion time -- regardless.
"""

def _class_specific_metdata_validation(
Expand All @@ -234,12 +234,27 @@ def _df_to_result(self, df: DataFrame) -> MetricFetchResult:
return Ok(value=Data(df=df.drop(columns=["step"])))


class BenchmarkMapMetric(MapMetric, BenchmarkMetricBase):
class BenchmarkTimeVaryingMetric(BenchmarkMetricBase):
"""
Metric for benchmarking that produces `Data` and is available while
running.
Non-Map Metric for benchmarking that is available while running.

It can produce different values at different times depending on when it is
called, using the `time` on a `BackendSimulator`.
"""

@classmethod
def is_available_while_running(cls) -> bool:
return True

def _df_to_result(self, df: DataFrame) -> MetricFetchResult:
return Ok(
value=Data(df=df[df["step"] == df["step"].max()].drop(columns=["step"]))
)


class BenchmarkMapMetric(MapMetric, BenchmarkMetricBase):
"""MapMetric for benchmarking. It is available while running."""

# pyre-fixme: Inconsistent override [15]: `map_key_info` overrides attribute
# defined in `MapMetric` inconsistently. Type `MapKeyInfo[int]` is not a
# subtype of the overridden attribute `MapKeyInfo[float]`
Expand All @@ -253,3 +268,15 @@ def _df_to_result(self, df: DataFrame) -> MetricFetchResult:
# Just in case the key was renamed by a subclass
df = df.rename(columns={"step": self.map_key_info.key})
return Ok(value=MapData(df=df, map_key_infos=[self.map_key_info]))


class BenchmarkMapUnavailableWhileRunningMetric(MapMetric, BenchmarkMetricBase):
# pyre-fixme: Inconsistent override [15]: `map_key_info` overrides attribute
# defined in `MapMetric` inconsistently. Type `MapKeyInfo[int]` is not a
# subtype of the overridden attribute `MapKeyInfo[float]`
map_key_info: MapKeyInfo[int] = MapKeyInfo(key="step", default_value=0)

def _df_to_result(self, df: DataFrame) -> MetricFetchResult:
# Just in case the key was renamed by a subclass
df = df.rename(columns={"step": self.map_key_info.key})
return Ok(value=MapData(df=df, map_key_infos=[self.map_key_info]))
2 changes: 1 addition & 1 deletion ax/benchmark/benchmark_trial_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BenchmarkTrialMetadata:

Args:
df: A dict mapping each metric name to a Pandas DataFrame with columns
["metric_name", "arm_name", "mean", "sem", and "t"]. The "sem" is
["metric_name", "arm_name", "mean", "sem", and "step"]. The "sem" is
always present in this df even if noise levels are unobserved;
``BenchmarkMetric`` and ``BenchmarkMapMetric`` hide that data if it
should not be observed, and ``BenchmarkMapMetric``s drop data from
Expand Down
Loading
Loading