Skip to content

[Bug] About Nonlinear inequality constraint and batch_limit #1783

@minsu77

Description

@minsu77

🐛 Bug

Hi, first of all, thank you for providing so much useful information in this community.

I am trying to use a nonlinear inequality constraint (parameter constraint) like the picture above. So I made a callable function that returns a negative number when inside an infeasible region.

Since there are two input parameters, "batch_initial_condition" is arbitrarily configured as [1, 2] shape tensor. (shape: [Num_restarts, Input dimension] )

And I also entered "batch_limit" as 1. But I get "call() missing 1 required positional argument: 'y'" error comes out.
There is no error when only the callable function is evaluated separately (e.g., NonlinCon(0.55, 1) -> return "-1")

How can i solve this error?

def initialize_model(train_X, train_Y):
    model = SingleTaskGP(train_X, train_Y, outcome_transform=Standardize(m=train_Y.shape[-1]))
    mll = ExactMarginalLogLikelihood(model.likelihood, model)
    return mll, model

BATCH_SIZE = 1 
NUM_RESTARTS = 1
RAW_SAMPLES = 1024
MC_SAMPLES = 512

class NonlinCon:
    def __call__(self, x, y):
        if x <= 3/4 and 2*x + y >=2:
            return -1
        elif x > 3/4 and y >= 1/2:
            return -1 #negative : infeasible
        else:
            return 1 #positive : feasible
        
NonlinCon = NonlinCon()

batch_init = torch.tensor([[[0.5, 0.5]]]) # [1, 1, 2] tensor
#[Num_restarts, q, input_dimension]

def optimize_acqf_and_get_observation(acq_func):
    candidates, _ = optimize_acqf(
        acq_function=acq_func,
        bounds=standard_bounds,
        q=1,
        num_restarts=NUM_RESTARTS,
        options={"batch_limit": 1, "maxiter": 200},
        raw_samples=RAW_SAMPLES,  # used for intialization heuristic
        nonlinear_inequality_constraints=[NonlinCon], # list of nonlinear constraints
        batch_initial_conditions=batch_init,
        sequential=True,
    )
    new_x = candidates.detach()
    return new_x

max_evals = 25
d = 2

standard_bounds = torch.zeros(2, d)
standard_bounds[1] = 1

mll, model = initialize_model(train_X, train_Y)
fit_gpytorch_model(mll, optimizer=fit_gpytorch_torch)
qmc_sampler = SobolQMCNormalSampler(num_samples=MC_SAMPLES)
qEI = qExpectedImprovement(
    model=model,
    best_f=train_Y.max(),
    sampler=qmc_sampler,
)
new_x = optimize_acqf_and_get_observation(qEI)
ValueError: __call__() missing 1 required positional argument: 'y'

Metadata

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