Skip to content

Commit ca956e1

Browse files
saitcakmakfacebook-github-bot
authored andcommitted
Unflakify TestOptimizeAcqfMixed.test_continuous_step (#2578)
Summary: Pull Request resolved: #2578 Due to randomized continuous & binary dimensions, the fixed continuous dimension would occasionally become part of the constraint and fail the test since the fixed value cannot satisfy the constraint. This diff updates the fixed dimension to ensure this cannot happen. Reviewed By: Balandat Differential Revision: D64475003 fbshipit-source-id: 03164639e462bc7583c0b1ba47cbeb9463085c4b
1 parent fb0c667 commit ca956e1

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

test/optim/test_optimize_acqf_mixed.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def test_continuous_step(self):
354354

355355
best_f = model(X)
356356
ei = ExpectedImprovement(model, best_f=best_f)
357-
X_clone, ei_val = continuous_step(
357+
X_new, ei_val = continuous_step(
358358
opt_inputs=_make_opt_inputs(
359359
acq_function=ei,
360360
bounds=bounds,
@@ -363,15 +363,18 @@ def test_continuous_step(self):
363363
discrete_dims=binary_dims,
364364
current_x=X.clone(),
365365
)
366-
self.assertAllClose(X_clone[cont_dims], root[cont_dims])
367-
self.assertAllClose(X_clone[binary_dims], X[binary_dims])
366+
self.assertAllClose(X_new[cont_dims], root[cont_dims])
367+
self.assertAllClose(X_new[binary_dims], X[binary_dims])
368368

369369
# Test with fixed features and constraints.
370370
fixed_binary = int(binary_dims[0])
371-
fixed_cont = int(cont_dims[0])
371+
# We don't want fixed cont to be one of the first two indices,
372+
# to avoid it being a part of the constraint. This ensures that.
373+
# The fixed value of 0.5 cannot satisfy the constraint.
374+
fixed_cont = int(cont_dims[:3].max())
372375
X_ = X.clone()
373376
X_[:2] = 1.0 # To satisfy the constraint.
374-
X_clone, ei_val = continuous_step(
377+
X_new, ei_val = continuous_step(
375378
opt_inputs=_make_opt_inputs(
376379
acq_function=ei,
377380
bounds=bounds,
@@ -390,11 +393,11 @@ def test_continuous_step(self):
390393
)
391394
self.assertTrue(
392395
torch.equal(
393-
X_clone[[fixed_binary, fixed_cont]],
396+
X_new[[fixed_binary, fixed_cont]],
394397
torch.tensor([1.0, 0.5], device=self.device),
395398
)
396399
)
397-
self.assertAllClose(X_clone[:2], X_[:2])
400+
self.assertAllClose(X_new[:2], X_[:2])
398401

399402
# test edge case when all parameters are binary
400403
root = torch.rand(d_bin)
@@ -422,7 +425,7 @@ def test_continuous_step(self):
422425
ValueError,
423426
"continuous_step requires current_x to be",
424427
):
425-
X_clone, ei_val = continuous_step(
428+
X_new, ei_val = continuous_step(
426429
opt_inputs=_make_opt_inputs(
427430
acq_function=ei,
428431
bounds=bounds,

0 commit comments

Comments
 (0)