Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix output tensor dimension in degenerate optimize_acqf call #2743

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions botorch/optim/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ def _optimize_acqf_all_features_fixed(
X = X.expand(q, *X.shape)
with torch.no_grad():
acq_value = acq_function(X)
if acq_value.ndim == 1:
acq_value = acq_value[0]
return X, acq_value


Expand Down
19 changes: 19 additions & 0 deletions test/optim/test_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

import numpy as np
import torch

from botorch.acquisition.acquisition import (
AcquisitionFunction,
OneShotAcquisitionFunction,
)
from botorch.acquisition.analytic import LogExpectedImprovement
from botorch.acquisition.knowledge_gradient import qKnowledgeGradient
from botorch.acquisition.monte_carlo import qExpectedImprovement
from botorch.acquisition.multi_objective.hypervolume_knowledge_gradient import (
Expand Down Expand Up @@ -1147,6 +1149,23 @@ def nlc(x):
),
)

def test_optimize_acqf_all_fixed_features(self):
train_X = torch.rand(3, 2)
train_Y = torch.rand(3, 1)
gp = SingleTaskGP(train_X=train_X, train_Y=train_Y)
gp.eval()
logEI = LogExpectedImprovement(model=gp, best_f=train_Y.max())
bounds = torch.stack([torch.zeros(2), torch.ones(2)])
_, acqf_value = optimize_acqf(
logEI,
bounds,
q=1,
num_restarts=1,
raw_samples=1,
fixed_features={0: 0, 1: 0},
)
self.assertEqual(acqf_value.ndim, 0)

def test_constraint_caching(self):
def nlc(x):
return 4 - x.sum(dim=-1)
Expand Down