dwavesystems / dwavesystems/dimod

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

Open
#1,299 2 comments 0 reactions 0 assignees View on GitHub
bug enhancement
Dominant language
Python
Stars
143
Forks
91
Avg merge
1h 24m
Merged PRs (30d)
3

Description

**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

Contributor guide

Open the contributing guide

Research direction

Start by running the reported Python reproduction with dimod.ConstrainedQuadraticModel.add_constraint and inspect how chained comparisons are interpreted. Add a regression test covering 5 <= v0 <= 100 and compare it with two separate constraints. Done means both bounds remain as constraints rather than the lower bound being discarded.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.