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

Inconsistency for conflicting boundaries #1309

Open JoelPasvolsky opened 1 year ago

JoelPasvolsky commented 1 year ago

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

JoelPasvolsky commented 1 year ago

Just noticed something interesting: for order 1, if I then add an objective that uses variable j, the ValueError: conflicting upper bounds: 'i' error pops up, That's not good.