dwavesystems/dimod

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

elham-azd opened this issue · 2 comments

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

  • OS: macOS 12.5.1
  • Python version: Python 3.10.7

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

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).