Skip to content

[Bug]: Inconsistent output dimensions #2740

Open
@AdrianSosic

Description

What happened?

Not sure if this is intentional, but it seems like a bug to me. When fixing all features in optimize_acqf, the returned acquisition value changes from a float to a 1-D tensor. Haven't checked what happens for the other optimize_* functions.

Of course, this is a degenerate case since calling the optimization routing with zero degrees of freedom is sort of meaningless, but it can still be useful when invoking BoTorch procedurally from wrappers as in my case.

Please provide a minimal, reproducible example of the unexpected behavior.

Here a minimal example adjusted from the landing page code:

import torch
from botorch.acquisition import LogExpectedImprovement
from botorch.fit import fit_gpytorch_mll
from botorch.models import SingleTaskGP
from botorch.models.transforms import Normalize, Standardize
from botorch.optim import optimize_acqf
from gpytorch.mlls import ExactMarginalLogLikelihood

def run(fixed_features):

    train_X = torch.rand(10, 2, dtype=torch.double) * 2
    Y = 1 - torch.linalg.norm(train_X - 0.5, dim=-1, keepdim=True)
    Y = Y + 0.1 * torch.randn_like(Y)

    gp = SingleTaskGP(
        train_X=train_X,
        train_Y=Y,
        input_transform=Normalize(d=2),
        outcome_transform=Standardize(m=1),
    )
    mll = ExactMarginalLogLikelihood(gp.likelihood, gp)
    fit_gpytorch_mll(mll)
    logEI = LogExpectedImprovement(model=gp, best_f=Y.max())
    bounds = torch.stack([torch.zeros(2), torch.ones(2)]).to(torch.double)
    candidate, acq_value = optimize_acqf(
        logEI,
        bounds=bounds,
        q=1,
        num_restarts=5,
        raw_samples=20,
        fixed_features=fixed_features,
    )
    print(acq_value)

run({0: 0})  
run({0: 0, 1: 0})

Please paste any relevant traceback/logs produced by the example provided.

tensor(-4.7173, dtype=torch.float64)
tensor([-8.1727], dtype=torch.float64)

BoTorch Version

0.13.0

Python Version

3.10

Operating System

macOS

Code of Conduct

  • I agree to follow BoTorch's Code of Conduct

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions