|
5 | 5 | # LICENSE file in the root directory of this source tree.
|
6 | 6 |
|
7 | 7 | import itertools
|
| 8 | +import warnings |
| 9 | +from contextlib import ExitStack |
8 | 10 | from unittest import mock
|
9 | 11 |
|
10 | 12 | import torch
|
| 13 | +from botorch import settings |
11 | 14 | from botorch.acquisition import monte_carlo
|
12 | 15 | from botorch.acquisition.objective import GenericMCObjective, MCAcquisitionObjective
|
13 | 16 | from botorch.acquisition.utils import (
|
|
17 | 20 | project_to_target_fidelity,
|
18 | 21 | prune_inferior_points,
|
19 | 22 | )
|
20 |
| -from botorch.exceptions import UnsupportedError |
| 23 | +from botorch.exceptions.errors import UnsupportedError |
| 24 | +from botorch.exceptions.warnings import SamplingWarning |
21 | 25 | from botorch.sampling.samplers import IIDNormalSampler, SobolQMCNormalSampler
|
22 | 26 | from botorch.utils.testing import BotorchTestCase, MockModel, MockPosterior
|
23 | 27 | from torch import Tensor
|
@@ -351,6 +355,22 @@ def test_prune_inferior_points(self):
|
351 | 355 | mm = MockModel(MockPosterior(samples=samples))
|
352 | 356 | X_pruned = prune_inferior_points(model=mm, X=X)
|
353 | 357 | self.assertTrue(torch.equal(X_pruned, X[:2]))
|
| 358 | + # test high-dim sampling |
| 359 | + with ExitStack() as es: |
| 360 | + mock_event_shape = es.enter_context( |
| 361 | + mock.patch( |
| 362 | + "botorch.utils.testing.MockPosterior.event_shape", |
| 363 | + new_callable=mock.PropertyMock, |
| 364 | + ) |
| 365 | + ) |
| 366 | + mock_event_shape.return_value = torch.Size([1, 1, 1112]) |
| 367 | + es.enter_context( |
| 368 | + mock.patch.object(MockPosterior, "rsample", return_value=samples) |
| 369 | + ) |
| 370 | + mm = MockModel(MockPosterior(samples=samples)) |
| 371 | + with warnings.catch_warnings(record=True) as ws, settings.debug(True): |
| 372 | + prune_inferior_points(model=mm, X=X) |
| 373 | + self.assertTrue(issubclass(ws[-1].category, SamplingWarning)) |
354 | 374 |
|
355 | 375 |
|
356 | 376 | class TestFidelityUtils(BotorchTestCase):
|
|
0 commit comments