dwavesystems / dimod

A shared API for QUBO/Ising samplers.
https://docs.ocean.dwavesys.com/en/stable/docs_dimod/
Apache License 2.0
121 stars 80 forks source link

dimod dismisses part of the expression when both lower bound and higher bound are defined in a single line #1299

Open elham-azd opened 1 year ago

elham-azd commented 1 year ago

Description dimod does not parse constraints correctly when we define both lower bound and higher bound in a single line. It dismisses the first part of the expression.

Steps To Reproduce

import dimod

v0, v1 = dimod.Integers('xy')

cqm = dimod.ConstrainedQuadraticModel()
cqm.set_objective(v0 + v1)
cqm.add_constraint(5 <= v0 <= 100)

print(cqm.constraints)

Output: {'c08e0e6': Le(ConstraintView({'x': 1.0}, {}, 0.0, {'x': 'INTEGER'}), 100.0)}

Expected Behavior The above expression should give the same output as:

import dimod

v0, v1 = dimod.Integers('xy')

cqm = dimod.ConstrainedQuadraticModel()
cqm.set_objective(v0 + v1)
cqm.add_constraint(v0 >= 5)
cqm.add_constraint(v0 <= 100)

print(cqm.constraints)

Output: {'cb82aca': Ge(ConstraintView({'x': 1.0}, {}, 0.0, {'x': 'INTEGER'}), 5.0), 'cdcf213': Le(ConstraintView({'x': 1.0}, {}, 0.0, {'x': 'INTEGER'}), 100.0)}

Environment

arcondello commented 1 year ago

Right. We don't currently support bounding on both sides, should either raise an error or support this feature.

arcondello commented 1 year ago

I am inclined to go with raising an error, because we would treat this as two constraints under the hood, and the API expects only one (e.g. it returns a single variable label etc).