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

Fix a typo and make a test stronger #3215

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions ax/benchmark/benchmark_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def __init__(
self.lower_is_better: bool = lower_is_better
self.observe_noise_sd: bool = observe_noise_sd

def _class_specific_metdata_validation(
def _class_specific_metadata_validation(
self, metadata: BenchmarkTrialMetadata | None
) -> None:
return
Expand Down Expand Up @@ -164,7 +164,7 @@ def fetch_trial_data(self, trial: BaseTrial, **kwargs: Any) -> MetricFetchResult
)

metadata = trial.run_metadata["benchmark_metadata"]
self._class_specific_metdata_validation(metadata=metadata)
self._class_specific_metadata_validation(metadata=metadata)
backend_simulator = metadata.backend_simulator
df = metadata.dfs[self.name]

Expand Down
33 changes: 17 additions & 16 deletions ax/benchmark/tests/test_benchmark_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,25 @@

def _get_one_step_df(batch: bool, metric_name: str, step: int) -> pd.DataFrame:
if metric_name == "test_metric1":
return pd.DataFrame(
{
"arm_name": ["0_0", "0_1"] if batch else ["0_0"],
"metric_name": metric_name,
"mean": [1.0, 2.5] if batch else [1.0],
"sem": [0.1, 0.0] if batch else [0.1],
"trial_index": 0,
"step": step,
"virtual runtime": step,
}
)
return pd.DataFrame(
mean = [1.0, 2.5] if batch else [1.0]
sem = [0.1, 0.0] if batch else [0.1]
else:
mean = [0.5, 1.5] if batch else [0.5]
sem = [0.1, 0.0] if batch else [0.1]

df = pd.DataFrame(
{
"arm_name": ["0_0", "0_1"] if batch else ["0_0"],
"metric_name": metric_name,
"mean": [0.5, 1.5] if batch else [0.5],
"sem": [0.1, 0.0] if batch else [0.1],
"mean": mean,
"sem": sem,
"trial_index": 0,
"step": step,
"virtual runtime": step,
}
)
df["mean"] += step / 10
return df


def get_test_trial(
Expand Down Expand Up @@ -111,6 +108,7 @@ def get_test_trial(

class TestBenchmarkMetric(TestCase):
def setUp(self) -> None:
super().setUp()
self.outcome_names = ["test_metric1", "test_metric2"]
self.metrics = {
name: BenchmarkMetric(name=name, lower_is_better=True)
Expand Down Expand Up @@ -260,12 +258,15 @@ def _test_fetch_trial_multiple_time_steps_with_simulator(self, batch: bool) -> N
if not isinstance(metric, MapMetric):
drop_cols += ["step"]

step = 0 if has_simulator else 2
expected_df = _get_one_step_df(
batch=batch, metric_name=metric_name, step=0
batch=batch, metric_name=metric_name, step=step
).drop(columns=drop_cols)
if returns_full_data:
self.assertEqual(
df_or_map_df[df_or_map_df["step"] == 0].to_dict(),
df_or_map_df[df_or_map_df["step"] == step]
.reset_index(drop=True)
.to_dict(),
expected_df.to_dict(),
)
else:
Expand Down
Loading