Skip to content

Commit

Permalink
Raise ValueError when m<2 in qNoisyExpectedHypervolumeImprovement (#1881
Browse files Browse the repository at this point in the history
)

Summary:
Raise more informative message when qNoistyExpectedHypervolumeImprovement cannot handle single objective input as discussed in #1880

Pull Request resolved: #1881

Reviewed By: saitcakmak

Differential Revision: D46648504

Pulled By: esantorella

fbshipit-source-id: 08cdd2aa15f76ad79b75bcbf95407a1522fe6213
  • Loading branch information
kstoneriv3 authored and facebook-github-bot committed Jun 13, 2023
1 parent 28befdb commit e7b1994
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions botorch/acquisition/multi_objective/monte_carlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,11 @@ def __init__(
cache_root: A boolean indicating whether to cache the root
decomposition over `X_baseline` and use low-rank updates.
"""
if len(ref_point) < 2:
raise ValueError(
"qNoisyExpectedHypervolumeImprovement supports m>=2 outcomes "
f"but ref_point has length {len(ref_point)}, which is smaller than 2."
)
ref_point = torch.as_tensor(
ref_point, dtype=X_baseline.dtype, device=X_baseline.device
)
Expand Down
18 changes: 17 additions & 1 deletion test/acquisition/multi_objective/test_monte_carlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ def test_q_noisy_expected_hypervolume_improvement(self):
tkwargs = {"device": self.device}
for dtype, m in product(
(torch.float, torch.double),
(2, 3),
(1, 2, 3),
):
tkwargs["dtype"] = dtype
ref_point = self.ref_point[:m]
Expand All @@ -641,6 +641,22 @@ def test_q_noisy_expected_hypervolume_improvement(self):
X = torch.zeros(1, 1, **tkwargs)
# basic test
sampler = IIDNormalSampler(sample_shape=torch.Size([1]))

# test error is raised if m == 1
if m == 1:
with self.assertRaisesRegex(
ValueError,
"qNoisyExpectedHypervolumeImprovement supports m>=2 outcomes ",
):
acqf = qNoisyExpectedHypervolumeImprovement(
model=mm,
ref_point=ref_point,
X_baseline=X_baseline,
sampler=sampler,
cache_root=False,
)
continue

acqf = qNoisyExpectedHypervolumeImprovement(
model=mm,
ref_point=ref_point,
Expand Down

0 comments on commit e7b1994

Please sign in to comment.