Skip to content

Commit ac3a7ec

Browse files
esantorellafacebook-github-bot
authored andcommitted
Don't test with a test stub when there's a function that does the same thing (#2735)
Summary: Pull Request resolved: #2735 Context: * There is a `get_sobol_benchmark_method` test stub, which is not needed when a Sobol benchmark method is provided, also called `get_sobol_benchmark_method`. It is better to test that function. * The latter `get_sobol_benchmark_method` requires an argument `distribute_replications`. (Making this mandatory was an intentional choice, because it is easy to forget it.) This diff: * Gets rid of the test stub and uses the non-stub version instead * Adds `distribute_replications` in a bunch of places. I chose `False` arbitrarily since the argument will have no effect here. Reviewed By: saitcakmak Differential Revision: D62157106 fbshipit-source-id: 9d6ef4e609502fc94d09be31aa31b1dd7325b111
1 parent 6b1b0a4 commit ac3a7ec

File tree

2 files changed

+13
-31
lines changed

2 files changed

+13
-31
lines changed

ax/benchmark/tests/test_benchmark.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from ax.benchmark.benchmark_problem import create_problem_from_botorch
2323
from ax.benchmark.benchmark_result import BenchmarkResult
2424
from ax.benchmark.methods.modular_botorch import get_sobol_botorch_modular_acquisition
25+
from ax.benchmark.methods.sobol import get_sobol_benchmark_method
2526
from ax.benchmark.problems.registry import get_problem
2627
from ax.modelbridge.generation_strategy import GenerationNode, GenerationStrategy
2728
from ax.modelbridge.model_spec import ModelSpec
@@ -35,7 +36,6 @@
3536
get_moo_surrogate,
3637
get_multi_objective_benchmark_problem,
3738
get_single_objective_benchmark_problem,
38-
get_sobol_benchmark_method,
3939
get_soo_surrogate,
4040
TestDataset,
4141
)
@@ -89,7 +89,9 @@ def test_batch(self) -> None:
8989
def test_storage(self) -> None:
9090
problem = get_single_objective_benchmark_problem()
9191
res = benchmark_replication(
92-
problem=problem, method=get_sobol_benchmark_method(), seed=0
92+
problem=problem,
93+
method=get_sobol_benchmark_method(distribute_replications=False),
94+
seed=0,
9395
)
9496
# Experiment is not in storage yet
9597
self.assertTrue(res.experiment is not None)
@@ -184,26 +186,20 @@ def test_create_benchmark_experiment(self) -> None:
184186
self.assertEqual(experiment.runner, problem.runner)
185187

186188
def test_replication_sobol_synthetic(self) -> None:
187-
method = get_sobol_benchmark_method()
189+
method = get_sobol_benchmark_method(distribute_replications=False)
188190
problems = [
189191
get_single_objective_benchmark_problem(),
190192
get_problem("jenatton", num_trials=6),
191193
]
192194
for problem in problems:
193195
res = benchmark_replication(problem=problem, method=method, seed=0)
194196

195-
self.assertEqual(
196-
min(
197-
problem.num_trials, not_none(method.scheduler_options.total_trials)
198-
),
199-
len(not_none(res.experiment).trials),
200-
)
201-
197+
self.assertEqual(problem.num_trials, len(not_none(res.experiment).trials))
202198
self.assertTrue(np.isfinite(res.score_trace).all())
203199
self.assertTrue(np.all(res.score_trace <= 100))
204200

205201
def test_replication_sobol_surrogate(self) -> None:
206-
method = get_sobol_benchmark_method()
202+
method = get_sobol_benchmark_method(distribute_replications=False)
207203

208204
# This is kind of a weird setup - these are "surrogates" that use a Branin
209205
# synthetic function. The idea here is to test the machinery around the
@@ -217,10 +213,7 @@ def test_replication_sobol_surrogate(self) -> None:
217213
res = benchmark_replication(problem=problem, method=method, seed=0)
218214

219215
self.assertEqual(
220-
min(
221-
problem.num_trials,
222-
not_none(method.scheduler_options.total_trials),
223-
),
216+
problem.num_trials,
224217
len(not_none(res.experiment).trials),
225218
)
226219

@@ -313,7 +306,9 @@ def test_replication_moo_sobol(self) -> None:
313306
problem = get_multi_objective_benchmark_problem()
314307

315308
res = benchmark_replication(
316-
problem=problem, method=get_sobol_benchmark_method(), seed=0
309+
problem=problem,
310+
method=get_sobol_benchmark_method(distribute_replications=False),
311+
seed=0,
317312
)
318313

319314
self.assertEqual(
@@ -331,7 +326,7 @@ def test_benchmark_one_method_problem(self) -> None:
331326
problem = get_single_objective_benchmark_problem()
332327
agg = benchmark_one_method_problem(
333328
problem=problem,
334-
method=get_sobol_benchmark_method(),
329+
method=get_sobol_benchmark_method(distribute_replications=False),
335330
seeds=(0, 1),
336331
)
337332

@@ -352,7 +347,7 @@ def test_benchmark_multiple_problems_methods(self) -> None:
352347
aggs = benchmark_multiple_problems_methods(
353348
problems=[get_single_objective_benchmark_problem(num_trials=6)],
354349
methods=[
355-
get_sobol_benchmark_method(),
350+
get_sobol_benchmark_method(distribute_replications=False),
356351
get_sobol_botorch_modular_acquisition(
357352
model_cls=SingleTaskGP,
358353
acquisition_cls=qLogNoisyExpectedImprovement,

ax/utils/testing/benchmark_stubs.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,6 @@ def get_multi_objective_benchmark_problem(
6868
)
6969

7070

71-
def get_sobol_benchmark_method() -> BenchmarkMethod:
72-
return BenchmarkMethod(
73-
name="SOBOL",
74-
generation_strategy=GenerationStrategy(
75-
steps=[GenerationStep(model=Models.SOBOL, num_trials=-1)],
76-
name="SOBOL",
77-
),
78-
scheduler_options=SchedulerOptions(
79-
total_trials=4, init_seconds_between_polls=0
80-
),
81-
)
82-
83-
8471
def get_soo_surrogate() -> SurrogateBenchmarkProblem:
8572
experiment = get_branin_experiment(with_completed_trial=True)
8673
surrogate = TorchModelBridge(

0 commit comments

Comments
 (0)