forked from facebook/Ax
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganize runner tests following previous class renaming (facebook#2991
) Summary: Pull Request resolved: facebook#2991 See D64969707 for context. This diff: * Moves the parts of `tests/runners/test_botorch_test_problem` that pertain to the runner into `tests/test_benchmark_runner.py` * Moves the parts that pertain to `BoTorchTestFunction` to `tests/benchmark_test_functions/test_botorch_test_function.py` * Moves `tests/runners/test_surrogate_runner.py` to `tests/benchmark_test_functions/test_surrogate_test_function.py` Differential Revision: D65090663
- Loading branch information
1 parent
405dfad
commit b03c935
Showing
4 changed files
with
83 additions
and
77 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
ax/benchmark/tests/benchmark_test_functions/test_botorch_test_function.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
# pyre-strict | ||
|
||
|
||
import torch | ||
from ax.benchmark.benchmark_test_functions.botorch_test import BoTorchTestFunction | ||
from ax.utils.common.testutils import TestCase | ||
from botorch.test_functions.multi_objective import BraninCurrin | ||
from botorch.test_functions.synthetic import ConstrainedHartmann, Hartmann | ||
|
||
|
||
class TestBoTorchTestFunction(TestCase): | ||
def setUp(self) -> None: | ||
super().setUp() | ||
botorch_base_test_functions = { | ||
"base Hartmann": Hartmann(dim=6), | ||
"negated Hartmann": Hartmann(dim=6, negate=True), | ||
"constrained Hartmann": ConstrainedHartmann(dim=6), | ||
"negated constrained Hartmann": ConstrainedHartmann(dim=6, negate=True), | ||
} | ||
self.botorch_test_problems = { | ||
k: BoTorchTestFunction(botorch_problem=v) | ||
for k, v in botorch_base_test_functions.items() | ||
} | ||
|
||
def test_negation(self) -> None: | ||
params = {f"x{i}": 0.5 for i in range(6)} | ||
evaluate_true_results = { | ||
k: v.evaluate_true(params) for k, v in self.botorch_test_problems.items() | ||
} | ||
self.assertEqual( | ||
evaluate_true_results["base Hartmann"], | ||
evaluate_true_results["constrained Hartmann"][0], | ||
) | ||
self.assertEqual( | ||
evaluate_true_results["base Hartmann"], | ||
-evaluate_true_results["negated Hartmann"], | ||
) | ||
self.assertEqual( | ||
evaluate_true_results["negated Hartmann"], | ||
evaluate_true_results["negated constrained Hartmann"][0], | ||
) | ||
self.assertEqual( | ||
evaluate_true_results["constrained Hartmann"][1], | ||
evaluate_true_results["negated constrained Hartmann"][1], | ||
) | ||
|
||
def test_raises_for_botorch_attrs(self) -> None: | ||
msg = "noise should be set on the `BenchmarkRunner`, not the test function." | ||
with self.assertRaisesRegex(ValueError, msg): | ||
BoTorchTestFunction(botorch_problem=Hartmann(dim=6, noise_std=0.1)) | ||
with self.assertRaisesRegex(ValueError, msg): | ||
BoTorchTestFunction( | ||
botorch_problem=ConstrainedHartmann(dim=6, constraint_noise_std=0.1) | ||
) | ||
|
||
def test_tensor_shapes(self) -> None: | ||
params = {f"x{i}": 0.5 for i in range(6)} | ||
evaluate_true_results = { | ||
k: v.evaluate_true(params) for k, v in self.botorch_test_problems.items() | ||
} | ||
evaluate_true_results["BraninCurrin"] = BoTorchTestFunction( | ||
botorch_problem=BraninCurrin() | ||
).evaluate_true(params) | ||
expected_len = { | ||
"base Hartmann": 1, | ||
"constrained Hartmann": 2, | ||
"negated Hartmann": 1, | ||
"negated constrained Hartmann": 2, | ||
"BraninCurrin": 2, | ||
} | ||
for name, result in evaluate_true_results.items(): | ||
with self.subTest(name=name): | ||
self.assertEqual(result.dtype, torch.double) | ||
self.assertEqual(result.shape, torch.Size([expected_len[name]])) |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters