emdgroup/baybe

operator in ContinuousLinearConstraint

Closed this issue · 5 comments

I met a problem from my previous code, the error is "ContinuousLinearConstraint.init() got an unexpected keyword argument 'operator'"

I checked the code, it seems the operator default is removed 3 days ago, but their is no updates on documentations, may I ask the alternative method to make a constraint when it searches for next recommendations?

you are right, the operator has no default anymore and needs to be provided always for ContinuousLinearConstraint

This is not mentioned in the changelog because the version without default was never published

Not sure why you want to use an alternative, why not simply add the operator for the constraint type you want to model
? Perhaps you are using it in a way I dont fully grasp, so some example code could be helpful.

Hi, many thanks for your quick response. Indeed, i am really a beginner of this package. So follow is my code in constraint part:

constraints = [
    ContinuousLinearConstraint(
        parameters=["x1", "x2", "x3"],  # these parameters must exist in the search space
        operator = "=",
        coefficients=[1.0, 1.0, 1.0],
        rhs=100,
    ),
    ContinuousLinearConstraint(
        parameters=["x1", "x2"],
        operator = "<=",
        coefficients=[1.0, 1.0],
        rhs=20,
    )
]

# initialise the search space and campaign
searchspace = SearchSpace.from_product(parameters=parameters,constraints=constraints)
campaign = Campaign(searchspace, objective)

I only slightly revised the example which was given by documentation. However, it output an error said : ContinuousLinearConstraint.init() got an unexpected keyword argument 'operator'

I am thinking if the operator hyperparameter is removed, so I print the argument it accepted as:

print(ContinuousLinearConstraint.__init__.__annotations__)

it print a list as : {'return': None, 'parameters': 'list[str]', 'coefficients': 'list[float]', 'rhs': 'float'}

When I removed operator in ContinuousLinearConstraint method, then my code is running fine, but the constraint not taking its function.

Sorry maybe the question is quite basic, as a beginner...

One thing that might be a bit tricky is that the class ContinuousLinearConstraint existed before the latest update, but was an abstract base class not to be used by users. I suspect that there is something funny with your baybe installation.

Indeed your code works fine for me and I get

{'return': None, 'parameters': list[str], 'operator': 'str', 'coefficients': 'list[float]'}

as annotation output.

Please reinstall baybe and verify you have a verison of at least 0.11.1 via

import baybe
print(baybe.__version__)

It's fairly interesting, I checked my version was 0.11.0, and I reinstall it before I asked the question, it still show 0.11.0, but after I restart my computer, now everything is running okay!

That was really a weird problem I asked...Thanks a lot for your help, have a good weekend!

hmm perhaps some old verison or so was still in your memory / kernel, can happen when working with jupyter notebooks

make sure you have a version >= 0.11.1

thank you for confirming

closing as resolved

consider leaving a github star 🌟 :)

have a good weekend