Skip to content

Commit

Permalink
Replace usage of exp_to_df with Experiment.to_df
Browse files Browse the repository at this point in the history
Summary: Updates some use cases of `exp_to_df` to utilize `Experiment.to_df`. This diff handles most usage that doesn't rely on the kwargs exposed on `exp_to_df`. The remaining usage will be updated after adding the necessary options to `Experiment.to_df`.

Differential Revision: D68774600
  • Loading branch information
saitcakmak authored and facebook-github-bot committed Jan 28, 2025
1 parent c1888e9 commit 4b13714
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
5 changes: 2 additions & 3 deletions ax/modelbridge/tests/test_torch_moo_modelbridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
infer_objective_thresholds,
pareto_frontier_evaluator,
)
from ax.service.utils.report_utils import exp_to_df
from ax.utils.common.random import set_rng_seed
from ax.utils.common.testutils import TestCase
from ax.utils.testing.core_stubs import (
Expand Down Expand Up @@ -546,7 +545,7 @@ def test_infer_objective_thresholds(self, _, cuda: bool = False) -> None:
self.assertEqual(obj_thresholds[1].op, ComparisonOp.LEQ)
self.assertFalse(obj_thresholds[0].relative)
self.assertFalse(obj_thresholds[1].relative)
df = exp_to_df(exp)
df = exp.to_df()
Y = np.stack([df.branin_a.values, df.branin_b.values]).T
Y = torch.from_numpy(Y)
Y[:, 0] *= -1
Expand Down Expand Up @@ -616,7 +615,7 @@ def test_infer_objective_thresholds(self, _, cuda: bool = False) -> None:
self.assertEqual(obj_thresholds[1].op, ComparisonOp.LEQ)
self.assertFalse(obj_thresholds[0].relative)
self.assertFalse(obj_thresholds[1].relative)
df = exp_to_df(exp)
df = exp.to_df()
trial_mask = df.trial_index == 1
Y = np.stack([df.branin_a.values[trial_mask], df.branin_b.values[trial_mask]]).T
Y = torch.from_numpy(Y)
Expand Down
3 changes: 1 addition & 2 deletions ax/service/ax_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
InstantiationBase,
ObjectiveProperties,
)
from ax.service.utils.report_utils import exp_to_df
from ax.service.utils.with_db_settings_base import DBSettings
from ax.storage.json_store.decoder import (
generation_strategy_from_json,
Expand Down Expand Up @@ -920,7 +919,7 @@ def get_trials_data_frame(self) -> pd.DataFrame:
one-arm trials, which is the case in base ``AxClient``; will correspond
to arms in trials in the batch-trial case).
"""
return exp_to_df(exp=self.experiment)
return self.experiment.to_df()

def get_max_parallelism(self) -> list[tuple[int, int]]:
"""Retrieves maximum number of trials that can be scheduled in parallel
Expand Down
22 changes: 11 additions & 11 deletions ax/service/tests/test_report_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def test_compare_to_baseline(self) -> None:
}

with patch(
"ax.service.utils.report_utils.exp_to_df",
"ax.core.Experiment.to_df",
return_value=arms_df,
), patch.object(
Experiment,
Expand Down Expand Up @@ -694,7 +694,7 @@ def test_compare_to_baseline_pass_in_opt(self) -> None:
}

with patch(
"ax.service.utils.report_utils.exp_to_df",
"ax.core.Experiment.to_df",
return_value=arms_df,
), patch.object(
Experiment,
Expand Down Expand Up @@ -769,7 +769,7 @@ def test_compare_to_baseline_minimize(self) -> None:
}

with patch(
"ax.service.utils.report_utils.exp_to_df",
"ax.core.Experiment.to_df",
return_value=arms_df,
), patch.object(
Experiment,
Expand Down Expand Up @@ -857,7 +857,7 @@ def test_compare_to_baseline_edge_case(self) -> None:
}

with patch(
"ax.service.utils.report_utils.exp_to_df",
"ax.core.Experiment.to_df",
return_value=arms_df,
), patch.object(
Experiment,
Expand Down Expand Up @@ -889,7 +889,7 @@ def test_compare_to_baseline_edge_case(self) -> None:

# no best arm names
with patch(
"ax.service.utils.report_utils.exp_to_df",
"ax.core.Experiment.to_df",
return_value=arms_df,
):
with self.assertLogs("ax", level=INFO) as log:
Expand All @@ -916,7 +916,7 @@ def test_compare_to_baseline_edge_case(self) -> None:

# no optimization config
with patch(
"ax.service.utils.report_utils.exp_to_df",
"ax.core.Experiment.to_df",
return_value=arms_df,
):
with self.assertLogs("ax", level=INFO) as log:
Expand Down Expand Up @@ -973,7 +973,7 @@ def test_compare_to_baseline_arms_not_found(self) -> None:

# no arms df
with patch(
"ax.service.utils.report_utils.exp_to_df",
"ax.core.Experiment.to_df",
return_value=None,
):
with self.assertLogs("ax", level=INFO) as log:
Expand All @@ -996,7 +996,7 @@ def test_compare_to_baseline_arms_not_found(self) -> None:

# best arms df is none
with patch(
"ax.service.utils.report_utils.exp_to_df",
"ax.core.Experiment.to_df",
return_value=arms_df,
):
with self.assertLogs("ax", level=INFO) as log:
Expand All @@ -1021,7 +1021,7 @@ def test_compare_to_baseline_arms_not_found(self) -> None:

# baseline not found in arms_df
with patch(
"ax.service.utils.report_utils.exp_to_df",
"ax.core.Experiment.to_df",
return_value=arms_df,
):
experiment_with_status_quo = experiment
Expand Down Expand Up @@ -1099,7 +1099,7 @@ def test_compare_to_baseline_moo(self) -> None:
}

with patch(
"ax.service.utils.report_utils.exp_to_df",
"ax.core.Experiment.to_df",
return_value=arms_df,
), patch.object(
Experiment,
Expand Down Expand Up @@ -1216,7 +1216,7 @@ def test_compare_to_baseline_equal(self) -> None:
comparison_arm_names = ["equal"]

with patch(
"ax.service.utils.report_utils.exp_to_df",
"ax.core.Experiment.to_df",
return_value=arms_df,
):
result = compare_to_baseline(
Expand Down

0 comments on commit 4b13714

Please sign in to comment.