dwavesystems / dwavesystems/dimod

Inconsistency for conflicting boundaries

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

Description

**Description**
I can first add a constraint that acts as an upper bound and then set an upper bound on the variable but I am not allowed to do the same thing in reverse order:

1)
```
>>> cqm = dimod.ConstrainedQuadraticModel()
>>> cqm.add_constraint(j <= 3, "Max j")
>>> cqm.set_upper_bound('j', 5)
>>> print(cqm)
Constrained quadratic model: 1 variables, 1 constraints, 1 biases

Objective
0

Constraints
Max j: Integer('j') <= 3.0

Bounds
0.0 <= Integer('j') <= 5.0
```

2)
```
>>> cqm = dimod.ConstrainedQuadraticModel()
>>> cqm.add_variable('INTEGER', 'j', upper_bound=10)
>>> cqm.add_constraint(j <= 3, "Max j")
ValueError: conflicting upper bounds: 'j'
```

The first makes sense to me despite the redundant bounds in practice, it might be easier for users to set both generic upper bounds on variables and then to have some constraints that tighten those bounds.

**Steps To Reproduce**
See above

**Expected Behavior**
I don't like getting a conflicting bounds error when I chose to set a constraint on a single variable.

**Environment**
- OS: WIN10
- Python version: 3.10

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.