dwavebinarycsp icon indicating copy to clipboard operation
dwavebinarycsp copied to clipboard

Non-zero minimum energy in BQM returned by stitch function

Open conquistador1492 opened this issue 6 years ago • 1 comments

stitch function returns BQM with non-zero energy of ground state for constraint with 1 or 2 variables. In 3 and more variables cases, everything is fine(below I give examples). I'm not sure it's a bug, but zero energy might be useful if somebody combines many different constraints. Then, they may be assured that the final state has zero energy.

csp0 = ConstraintSatisfactionProblem(BINARY)
csp0.add_constraint(lambda a: a, ['a'])

csp1 = ConstraintSatisfactionProblem(BINARY)
csp1.add_constraint(lambda a, b: a == b, ['a', 'b'])

csp2 = ConstraintSatisfactionProblem(BINARY)
csp2.add_constraint(lambda a, b: a & b, ['a', 'b'])

csp3 = ConstraintSatisfactionProblem(BINARY)
csp3.add_constraint(lambda a, b, c: a == b == c, ['a', 'b', 'c'])

csp4 = ConstraintSatisfactionProblem(BINARY)
csp4.add_constraint(lambda a, b, c: a == b == c, ['a', 'b', 'c'])

csp5 = ConstraintSatisfactionProblem(BINARY)
csp5.add_constraint(lambda a, b, c, d: (a & b) & c | d, ['a', 'b', 'c', 'd'])

for csp in [csp0, csp1, csp2, csp3, csp4, csp5]:
    bqm = stitch(csp)
    response = SimulatedAnnealingSampler().sample(bqm, num_reads=100)
    print(sorted(response.data(), key=lambda x: x.energy)[0].energy)

As a result, we get:

-1.0
-1.0
-2.0
0.0
0.0
-2.0000000011677344e-07

Environment

  • OS: Ubuntu 18.04.2 LTS
  • Python version: 3.6.7
  • dwavebinarycsp: 0.0.11

conquistador1492 avatar May 16 '19 01:05 conquistador1492

stitch(..) calls on dwavesystems/penaltymodel repo to help build the bqm. The penaltymodel is interested in making the gap between excited states and ground states as large as possible, but currently, it does not make the effort to shift the bqm so that the ground is always at 0.

Hence, this issue is not a bug, but it would be a great candidate for code enhancement.

m3ller avatar May 21 '19 23:05 m3ller