Skip to content

Commit e9bd020

Browse files
generatedunixname89002005232357facebook-github-bot
authored andcommitted
Revert D60472381 (facebook#2627)
Summary: Pull Request resolved: facebook#2627 This diff reverts D60472381 Failure in OSS CI (T197664383), which will block other diffs in this repo. I plan to forward-fix by tomorrow or so, which is too slow. Reviewed By: esantorella Differential Revision: D60602573 fbshipit-source-id: 8da100be62a315582d14327bac396eba8c38b274
1 parent 7e60844 commit e9bd020

File tree

2 files changed

+23
-153
lines changed

2 files changed

+23
-153
lines changed

ax/benchmark/tests/test_benchmark.py

Lines changed: 1 addition & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
# pyre-strict
77

88
import tempfile
9-
from typing import List
109
from unittest.mock import patch
1110

1211
import numpy as np
13-
import torch
1412
from ax.benchmark.benchmark import (
1513
_create_benchmark_experiment,
1614
benchmark_multiple_problems_methods,
@@ -23,10 +21,7 @@
2321
BenchmarkMethod,
2422
get_benchmark_scheduler_options,
2523
)
26-
from ax.benchmark.benchmark_problem import (
27-
BenchmarkProblem,
28-
create_single_objective_problem_from_botorch,
29-
)
24+
from ax.benchmark.benchmark_problem import create_single_objective_problem_from_botorch
3025
from ax.benchmark.benchmark_result import BenchmarkResult
3126
from ax.benchmark.methods.modular_botorch import get_sobol_botorch_modular_acquisition
3227
from ax.benchmark.metrics.base import GroundTruthMetricMixin
@@ -58,13 +53,6 @@
5853
from botorch.models.gp_regression import SingleTaskGP
5954
from botorch.optim.optimize import optimize_acqf
6055
from botorch.test_functions.synthetic import Branin
61-
from pyre_extensions import none_throws
62-
63-
64-
# Branin is subclassed here for convenience.
65-
class ThreeProblem(Branin):
66-
def evaluate_true(self, X: torch.Tensor) -> torch.Tensor:
67-
return torch.tensor(3.0, dtype=torch.float64)
6856

6957

7058
class TestBenchmark(TestCase):
@@ -102,84 +90,6 @@ def test_batch(self) -> None:
10290
)
10391
self.assertEqual(mock_optimize_acqf.call_args.kwargs["q"], batch_size)
10492

105-
def test_noisy_property_test(self) -> None:
106-
problem = create_single_objective_problem_from_botorch(
107-
test_problem_class=ThreeProblem,
108-
test_problem_kwargs={"noise_std": 1.0},
109-
lower_is_better=True,
110-
num_trials=5,
111-
)
112-
113-
res = benchmark_replication(
114-
problem=problem,
115-
method=get_sobol_benchmark_method(),
116-
seed=0,
117-
)
118-
self.assertTrue((res.optimization_trace == 3).all())
119-
df = none_throws(res.experiment).fetch_data().df
120-
self.assertTrue(
121-
(df.loc[df["metric_name"] == "ThreeProblem", "mean"] != 3).all()
122-
)
123-
124-
def test_characterization_noisy_soo(self) -> None:
125-
soo_problem = get_single_objective_benchmark_problem(
126-
test_problem_kwargs={"noise_std": 1.0}
127-
)
128-
expected = [
129-
104.36542659448965,
130-
90.20076516036951,
131-
56.18382601460175,
132-
7.5867050504430775,
133-
]
134-
self._noisy_characterization_test(problem=soo_problem, expected_result=expected)
135-
136-
def test_characterization_noisy_moo(self) -> None:
137-
moo_problem = get_multi_objective_benchmark_problem(
138-
test_problem_kwargs={"noise_std": 1.0}
139-
)
140-
expected = [0.0, 0.0, 6.952682254445629, 6.952682254445629]
141-
self._noisy_characterization_test(problem=moo_problem, expected_result=expected)
142-
143-
def test_characterization_noisy_soo_surrogate(self) -> None:
144-
# Surrogate construction shouldn't be random
145-
torch.manual_seed(0)
146-
soo_surrogate_problem = get_soo_surrogate(noise_stds=1.0)
147-
expected = [
148-
104.36542659448779,
149-
104.36542659448779,
150-
104.36542659448779,
151-
104.36542659448779,
152-
]
153-
self._noisy_characterization_test(
154-
problem=soo_surrogate_problem,
155-
expected_result=expected,
156-
)
157-
158-
def test_characterization_noisy_moo_surrogate(self) -> None:
159-
# Surrogate construction shouldn't be random
160-
torch.manual_seed(0)
161-
moo_surrogate_problem = get_moo_surrogate(noise_stds=1.0)
162-
expected = [
163-
24.999999999997655,
164-
24.999999999997655,
165-
24.999999999997655,
166-
24.999999999997655,
167-
]
168-
self._noisy_characterization_test(
169-
problem=moo_surrogate_problem,
170-
expected_result=expected,
171-
)
172-
173-
def _noisy_characterization_test(
174-
self, problem: BenchmarkProblem, expected_result: List[float]
175-
) -> None:
176-
res = benchmark_replication(
177-
problem=problem,
178-
method=get_sobol_benchmark_method(),
179-
seed=0,
180-
)
181-
self.assertTrue((res.optimization_trace == expected_result).all())
182-
18393
def test_storage(self) -> None:
18494
problem = get_single_objective_benchmark_problem()
18595
res = benchmark_replication(

ax/utils/testing/benchmark_stubs.py

Lines changed: 22 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,24 @@
1717
MultiObjectiveBenchmarkProblem,
1818
)
1919
from ax.benchmark.benchmark_result import AggregatedBenchmarkResult, BenchmarkResult
20-
from ax.benchmark.metrics.benchmark import BenchmarkMetric
2120
from ax.benchmark.problems.surrogate import (
2221
MOOSurrogateBenchmarkProblem,
2322
SOOSurrogateBenchmarkProblem,
2423
)
2524
from ax.benchmark.runners.surrogate import SurrogateRunner
2625
from ax.core.experiment import Experiment
27-
from ax.core.objective import MultiObjective, Objective
2826
from ax.core.optimization_config import (
2927
MultiObjectiveOptimizationConfig,
3028
OptimizationConfig,
3129
)
32-
from ax.core.outcome_constraint import ObjectiveThreshold
3330
from ax.modelbridge.generation_strategy import GenerationStep, GenerationStrategy
3431
from ax.modelbridge.registry import Models
3532
from ax.modelbridge.torch import TorchModelBridge
3633
from ax.models.torch.botorch_modular.model import BoTorchModel
3734
from ax.models.torch.botorch_modular.surrogate import Surrogate
3835
from ax.service.scheduler import SchedulerOptions
3936
from ax.utils.common.constants import Keys
37+
from ax.utils.common.typeutils import checked_cast
4038
from ax.utils.testing.core_stubs import (
4139
get_branin_experiment,
4240
get_branin_experiment_with_multi_objective,
@@ -62,13 +60,11 @@ def get_single_objective_benchmark_problem(
6260

6361

6462
def get_multi_objective_benchmark_problem(
65-
observe_noise_sd: bool = False,
66-
num_trials: int = 4,
67-
test_problem_kwargs: Optional[Dict[str, Any]] = None,
63+
observe_noise_sd: bool = False, num_trials: int = 4
6864
) -> MultiObjectiveBenchmarkProblem:
6965
return create_multi_objective_problem_from_botorch(
7066
test_problem_class=BraninCurrin,
71-
test_problem_kwargs={} if test_problem_kwargs is None else test_problem_kwargs,
67+
test_problem_kwargs={},
7268
num_trials=num_trials,
7369
observe_noise_sd=observe_noise_sd,
7470
)
@@ -98,97 +94,61 @@ def get_sobol_benchmark_method() -> BenchmarkMethod:
9894
)
9995

10096

101-
def get_soo_surrogate(noise_stds: float = 0.0) -> SOOSurrogateBenchmarkProblem:
102-
outcome_name = "branin"
103-
observe_noise_stds = True
97+
def get_soo_surrogate() -> SOOSurrogateBenchmarkProblem:
10498
experiment = get_branin_experiment(with_completed_trial=True)
105-
106-
optimization_config = OptimizationConfig(
107-
objective=Objective(
108-
metric=BenchmarkMetric(
109-
name=outcome_name,
110-
lower_is_better=False,
111-
observe_noise_sd=observe_noise_stds,
112-
),
113-
minimize=False,
114-
)
115-
)
116-
surrogate = Surrogate(botorch_model_class=SingleTaskGP)
117-
model_bridge = TorchModelBridge(
99+
surrogate = TorchModelBridge(
118100
experiment=experiment,
119101
search_space=experiment.search_space,
120-
model=BoTorchModel(surrogate=surrogate),
102+
model=BoTorchModel(surrogate=Surrogate(botorch_model_class=SingleTaskGP)),
121103
data=experiment.lookup_data(),
122104
transforms=[],
123105
)
124-
datasets = surrogate.training_data
125106
runner = SurrogateRunner(
126-
name=outcome_name,
107+
name="test",
127108
search_space=experiment.search_space,
128-
outcome_names=[outcome_name],
129-
get_surrogate_and_datasets=lambda: (model_bridge, datasets),
130-
noise_stds=noise_stds,
109+
outcome_names=["branin"],
110+
get_surrogate_and_datasets=lambda: (surrogate, []),
131111
)
132112
return SOOSurrogateBenchmarkProblem(
133113
name="test",
134114
search_space=experiment.search_space,
135-
optimization_config=optimization_config,
115+
optimization_config=checked_cast(
116+
OptimizationConfig, experiment.optimization_config
117+
),
136118
num_trials=6,
137-
observe_noise_stds=observe_noise_stds,
119+
observe_noise_stds=True,
138120
optimal_value=0.0,
139121
runner=runner,
140122
is_noiseless=runner.is_noiseless,
141123
)
142124

143125

144-
def get_moo_surrogate(noise_stds: float = 0.0) -> MOOSurrogateBenchmarkProblem:
145-
observe_noise_stds = True
146-
outcome_names = ["branin_a", "branin_b"]
147-
# set this to be easy to beat, so hypervolume computations aren't all zero
148-
ref_point = [10.0, 10.0]
149-
surrogate = Surrogate(botorch_model_class=SingleTaskGP)
126+
def get_moo_surrogate() -> MOOSurrogateBenchmarkProblem:
150127
experiment = get_branin_experiment_with_multi_objective(with_completed_trial=True)
151-
model_bridge = TorchModelBridge(
128+
surrogate = TorchModelBridge(
152129
experiment=experiment,
153130
search_space=experiment.search_space,
154-
model=BoTorchModel(surrogate=surrogate),
131+
model=BoTorchModel(surrogate=Surrogate(botorch_model_class=SingleTaskGP)),
155132
data=experiment.lookup_data(),
156133
transforms=[],
157134
)
158135

159136
runner = SurrogateRunner(
160137
name="test",
161138
search_space=experiment.search_space,
162-
outcome_names=outcome_names,
163-
get_surrogate_and_datasets=lambda: (model_bridge, surrogate.training_data),
164-
noise_stds=noise_stds,
139+
outcome_names=["branin_a", "branin_b"],
140+
get_surrogate_and_datasets=lambda: (surrogate, []),
165141
)
166-
metrics = [
167-
BenchmarkMetric(
168-
name=name,
169-
lower_is_better=True,
170-
observe_noise_sd=observe_noise_stds,
171-
)
172-
for name in outcome_names
173-
]
174-
objectives = [Objective(metric=metric) for metric in metrics]
175-
objective_thresholds = [
176-
ObjectiveThreshold(metric=metric, bound=ref_p, relative=False)
177-
for metric, ref_p in zip(metrics, ref_point)
178-
]
179-
optimization_config = MultiObjectiveOptimizationConfig(
180-
objective=MultiObjective(objectives=objectives),
181-
objective_thresholds=objective_thresholds,
182-
)
183-
184142
return MOOSurrogateBenchmarkProblem(
185143
name="test",
186144
search_space=experiment.search_space,
187-
optimization_config=optimization_config,
145+
optimization_config=checked_cast(
146+
MultiObjectiveOptimizationConfig, experiment.optimization_config
147+
),
188148
num_trials=10,
189149
observe_noise_stds=True,
190150
optimal_value=1.0,
191-
reference_point=ref_point,
151+
reference_point=[],
192152
runner=runner,
193153
is_noiseless=runner.is_noiseless,
194154
)

0 commit comments

Comments
 (0)