botorch
botorch copied to clipboard
[Bug] optimize_acqf_cyclic fails due to batch_initial_conditions shape when used on a problem with inequality constraints.
🐛 Bug
I'm running optimize_acqf_cyclic on a problem with inequality constraints and it seems to be failing in _make_linear_constraints. It seems that the batch_initial_conditions=candidates[i].unsqueeze(0) (line 301) is of shape 1 x dims, but _make_linear_constraints is expecting something of shape b x q x d.
candidates[i].unsqueeze(0).unsqueeze(0) seems to work.
** Stack trace/error message **
File "C:\Anaconda3\envs\ai-engine-updated\lib\site-packages\botorch\optim\optimize.py", line 309, in optimize_acqf_cyclic
candidate_i, acq_val_i = optimize_acqf(
File "C:\Anaconda3\envs\ai-engine-updated\lib\site-packages\botorch\optim\optimize.py", line 184, in optimize_acqf
batch_candidates_curr, batch_acq_values_curr = gen_candidates_scipy(
File "C:\Anaconda3\envs\ai-engine-updated\lib\site-packages\botorch\generation\gen.py", line 132, in gen_candidates_scipy
constraints = make_scipy_linear_constraints(
File "C:\Anaconda3\envs\ai-engine-updated\lib\site-packages\botorch\optim\parameter_constraints.py", line 119, in make_scipy_linear_constraints
constraints += _make_linear_constraints(
File "C:\Anaconda3\envs\ai-engine-updated\lib\site-packages\botorch\optim\parameter_constraints.py", line 223, in _make_linear_constraints
raise UnsupportedError("shapeX
must be b x q x d
")
botorch.exceptions.errors.UnsupportedError: shapeX
must be b x q x d
Expected Behavior
I'm expecting to be able to use optimize_acqf_cyclic on a problem with inequality constraints.
System information
Please complete the following information:
0.5.1.dev14+g951483dc 1.5.0 1.9.0+cu111 Windows 10
Additional context
Add any other context about the problem here.
@sdaulton could you take a look at this one, please?
@alantan-SQ40 could you please provide a full repro so we can debug? Thanks!
OK. Here's an example:
from botorch.utils.testing import MockAcquisitionFunction
from botorch.optim.optimize import optimize_acqf_cyclic
from torch import tensor
bounds = tensor([[0., 0., 0., 0., 0., 0., 0., 0.],
[1., 1., 1., 1., 1., 1., 1., 1.]], device='cuda:0',
dtype=torch.float64)
ineq_constraints = [
(tensor([0, 1], device='cuda:0'), tensor([ 1., -1.], device='cuda:0', dtype=torch.float64), tensor(-0., device='cuda:0', dtype=torch.float64))
]
optimize_acqf_cyclic(acq_function=MockAcquisitionFunction(),
bounds=bounds,
q=3,
inequality_constraints=ineq_constraints,
fixed_features=None,
post_processing_func=None,
num_restarts=2,
raw_samples=10,
cyclic_options={'maxiter':2}
)
It results in:
[INFO 09-20 12:20:32] botorch: Generated candidate batch 1 of 1.
[INFO 09-20 12:20:32] botorch: Generated sequential candidate 1 of 3
[INFO 09-20 12:20:33] botorch: Generated candidate batch 1 of 1.
[INFO 09-20 12:20:33] botorch: Generated sequential candidate 2 of 3
[INFO 09-20 12:20:34] botorch: Generated candidate batch 1 of 1.
[INFO 09-20 12:20:34] botorch: Generated sequential candidate 3 of 3
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2021.1.1\plugins\python\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
exec(exp, global_vars, local_vars)
File "<string>", line 10, in <module>
File "C:\Anaconda3\envs\ai-engine-updated\lib\site-packages\botorch\optim\optimize.py", line 309, in optimize_acqf_cyclic
candidate_i, acq_val_i = optimize_acqf(
File "C:\Anaconda3\envs\ai-engine-updated\lib\site-packages\botorch\optim\optimize.py", line 184, in optimize_acqf
batch_candidates_curr, batch_acq_values_curr = gen_candidates_scipy(
File "C:\Anaconda3\envs\ai-engine-updated\lib\site-packages\botorch\generation\gen.py", line 132, in gen_candidates_scipy
constraints = make_scipy_linear_constraints(
File "C:\Anaconda3\envs\ai-engine-updated\lib\site-packages\botorch\optim\parameter_constraints.py", line 119, in make_scipy_linear_constraints
constraints += _make_linear_constraints(
File "C:\Anaconda3\envs\ai-engine-updated\lib\site-packages\botorch\optim\parameter_constraints.py", line 223, in _make_linear_constraints
raise UnsupportedError("`shapeX` must be `b x q x d`")
botorch.exceptions.errors.UnsupportedError: `shapeX` must be `b x q x d`
Tested on BoTorch version 0.5.1. Does that help?