facebookresearch / nevergrad

A Python toolbox for performing gradient-free optimization
https://facebookresearch.github.io/nevergrad/
MIT License
3.89k stars 349 forks source link

tell Method Does Not Accept constraint_violation Parameter #1616

Closed xyyylll closed 1 week ago

xyyylll commented 1 week ago

I'm encountering an issue with the tell method in Nevergrad's Optimizer class where the method signature appears to support a constraint_violation parameter, but it doesn't accept it when called.

Example code snippet:

import nevergrad as ng

def objective_function(x):
    return sum((x - 2) ** 2)

def constraint_total_budget(x):
    return sum(x) - 1000

optimizer = ng.optimizers.NGOpt(parametrization=ng.p.Array(shape=(10,)), budget=100)

candidate = optimizer.ask()
objective_value = objective_function(candidate.value)
constraint_violations = [constraint_total_budget(candidate.value)]

try:
    optimizer.tell(candidate, objective_value, constraint_violations)
except TypeError as e:
    print("Error:", e)

Observed Behavior Calling optimizer.tell(candidate, objective_value, constraint_violations) results in the following error:

TypeError: tell() takes 3 positional arguments but 4 were given