I think LeapHybridSampler().sample return incorrect energy value in some case.

I ran this code below.
But it failed.

I got energy value from 'LeapHybridSampler'.
Next I caluculated energy from sample and bqm.
But both aren't the same energy value.
On the other hand, in the case of some other bqm, that return the same energy.

I think that "LeapHybridSampler().sample" returned incorrect energy value.
Or is there something wrong with this code.

dwave-ocean-sdk==3.3.0

```
from dwave.system import LeapHybridSampler
import dimod

bqm_data = dimod.BinaryQuadraticModel(
{
0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0, 6: 0.0,
7: 0.0, 8: 1.0, 9: 1.0, 10: 1.0, 11: 1.0, 12: 1.0, 13: 1.0,
14: 1.0, 15: 3.0, 16: 3.0, 17: 3.0, 18: 3.0, 19: 3.0, 20: 3.0,
21: 3.0, 22: 1.0, 23: 1.0, 24: 1.0, 25: 1.0, 26: 1.0, 27: 1.0,
28: 1.0, 29: 0.0, 30: 2.0, 31: 0.0, 32: 0.0, 33: 0.0, 34: 0.0,
35: 0.0, 36: 0.0, 37: 1.0, 38: 1.0, 39: 1.0, 40: 1.0, 41: 1.0,
42: 1.0, 43: 1.0, 44: 2.0, 45: 3.0, 46: 3.0, 47: 2.0, 48: 1.0,
49: 1.0, 50: 1.0, 51: 1.0, 52: 2.0, 53: 3.0, 54: 3.0, 55: 2.0,
56: -1.0, 57: 0.0, 58: 4.0, 59: -1.0, 60: 0.0, 61: 4.0, 62: -1.0,
63: 0.0, 64: 4.0, 65: -1.0, 66: 0.0, 67: 4.0, 68: -1.0, 69: 0.0,
70: 4.0, 71: -1.0, 72: 0.0, 73: 4.0, 74: -1.0, 75: 1.0, 76: 4.0,
77: -1.0, 78: 1.0, 79: 4.0, 80: -1.0, 81: 1.0, 82: 4.0, 83: -1.0,
84: 1.0, 85: 4.0, 86: -1.0, 87: 1.0, 88: 4.0, 89: -1.0, 90: 1.0,
91: 4.0, 92: -1.0, 93: 1.0, 94: 4.0, 95: -1.0, 96: 1.0, 97: 4.0,
98: -1.0, 99: 1.0, 100: 4.0, 101: -1.0, 102: 1.0, 103: 4.0,
104: -1.0, 105: 1.0, 106: 4.0, 107: -1.0, 108: 1.0, 109: 4.0,
110: -1.0, 111: 1.0, 112: 4.0, 113: 9.0, 114: -1.0, 115: 1.0,
116: 4.0, 117: 9.0, 118: -1.0, 119: 1.0, 120: 4.0, 121: 9.0,
122: -1.0, 123: 1.0, 124: 4.0, 125: 9.0, 126: -1.0, 127: 1.0,
128: 4.0, 129: 9.0, 130: -1.0, 131: 1.0, 132: 4.0, 133: 9.0,
134: -1.0, 135: 1.0, 136: 4.0, 137: 9.0},
{
(0, 1): 2.0, (0, 8): 2.0, (0, 75): -2.0, (0, 76): -4.0,
(1, 75): -2.0, (1, 76): -4.0, (2, 3): 2.0, (2, 9): 2.0,
(2, 84): -2.0, (2, 85): -4.0, (3, 10): 2.0, (3, 84): -2.0,
(3, 85): -4.0, (4, 5): 2.0, (4, 11): 2.0, (4, 93): -2.0,
(4, 94): -4.0, (5, 12): 2.0, (5, 93): -2.0, (5, 94): -4.0,
(6, 7): 2.0, (6, 13): 2.0, (6, 102): -2.0, (6, 103): -4.0,
(7, 14): 2.0, (7, 102): -2.0, (7, 103): -4.0, (8, 15): 6.0,
(8, 22): 6.0, (8, 78): -2.0, (8, 79): -4.0, (8, 111): -2.0,
(8, 112): -4.0, (8, 113): -6.0, (9, 10): 2.0, (9, 16): 6.0,
(9, 17): 2.0, (9, 23): 6.0, (9, 24): 2.0, (9, 87): -2.0,
(9, 88): -4.0, (9, 115): -2.0, (9, 116): -4.0, (9, 117): -6.0,
(10, 16): 2.0, (10, 17): 6.0, (10, 23): 2.0, (10, 24): 6.0,
(10, 87): -2.0, (10, 88): -4.0, (10, 119): -2.0, (10, 120): -4.0,
(10, 121): -6.0, (11, 12): 2.0, (11, 18): 6.0, (11, 19): 2.0,
(11, 25): 6.0, (11, 26): 2.0, (11, 96): -2.0, (11, 97): -4.0,
(11, 123): -2.0, (11, 124): -4.0, (11, 125): -6.0,
(12, 18): 2.0, (12, 19): 6.0, (12, 25): 2.0, (12, 26): 6.0,
(12, 96): -2.0, (12, 97): -4.0, (12, 127): -2.0, (12, 128): -4.0,
(12, 129): -6.0, (13, 14): 2.0, (13, 20): 6.0, (13, 21): 2.0,
(13, 27): 6.0, (13, 28): 2.0, (13, 105): -2.0, (13, 106): -4.0,
(13, 131): -2.0, (13, 132): -4.0, (13, 133): -6.0, (14, 20): 2.0,
(14, 21): 6.0, (14, 27): 2.0, (14, 28): 6.0, (14, 105): -2.0,
(14, 106): -4.0, (14, 135): -2.0, (14, 136): -4.0,
(14, 137): -6.0, (15, 22): 6.0, (15, 78): -2.0, (15, 79): -4.0,
(15, 111): -2.0, (15, 112): -4.0, (15, 113): -6.0, (16, 17): 2.0,
(16, 23): 6.0, (16, 24): 2.0, (16, 87): -2.0, (16, 88): -4.0,
(16, 115): -2.0, (16, 116): -4.0, (16, 117): -6.0, (17, 23): 2.0,
(17, 24): 6.0, (17, 87): -2.0, (17, 88): -4.0, (17, 119): -2.0,
(17, 120): -4.0, (17, 121): -6.0, (18, 19): 2.0, (18, 25): 6.0,
(18, 26): 2.0, (18, 96): -2.0, (18, 97): -4.0, (18, 123): -2.0,
(18, 124): -4.0, (18, 125): -6.0, (19, 25): 2.0, (19, 26): 6.0,
(19, 96): -2.0, (19, 97): -4.0, (19, 127): -2.0, (19, 128): -4.0,
(19, 129): -6.0, (20, 21): 2.0, (20, 27): 6.0, (20, 28): 2.0,
(20, 105): -2.0, (20, 106): -4.0, (20, 131): -2.0,
(20, 132): -4.0, (20, 133): -6.0, (21, 27): 2.0, (21, 28): 6.0,
(21, 105): -2.0, (21, 106): -4.0, (21, 135): -2.0,
(21, 136): -4.0, (21, 137): -6.0, (22, 29): 2.0, (22, 78): -2.0,
(22, 79): -4.0, (22, 111): -2.0, (22, 112): -4.0, (22, 113): -6.0,
(23, 24): 2.0, (23, 31): 2.0, (23, 87): -2.0, (23, 88): -4.0,
(23, 115): -2.0, (23, 116): -4.0, (23, 117): -6.0, (24, 32): 2.0,
(24, 87): -2.0, (24, 88): -4.0, (24, 119): -2.0, (24, 120): -4.0,
(24, 121): -6.0, (25, 26): 2.0, (25, 33): 2.0, (25, 96): -2.0,
(25, 97): -4.0, (25, 123): -2.0, (25, 124): -4.0, (25, 125): -6.0,
(26, 34): 2.0, (26, 96): -2.0, (26, 97): -4.0, (26, 127): -2.0,
(26, 128): -4.0, (26, 129): -6.0, (27, 28): 2.0, (27, 35): 2.0,
(27, 105): -2.0, (27, 106): -4.0, (27, 131): -2.0, (27, 132): -4.0,
(27, 133): -6.0, (28, 36): 2.0, (28, 105): -2.0, (28, 106): -4.0,
(28, 135): -2.0, (28, 136): -4.0, (28, 137): -6.0, (29, 30): 2.0,
(29, 81): -2.0, (29, 82): -4.0, (30, 81): -2.0, (30, 82): -4.0,
(31, 32): 2.0, (31, 90): -2.0, (31, 91): -4.0, (32, 90): -2.0,
(32, 91): -4.0, (33, 34): 2.0, (33, 99): -2.0, (33, 100): -4.0,
(34, 99): -2.0, (34, 100): -4.0, (35, 36): 2.0, (35, 108): -2.0,
(35, 109): -4.0, (36, 108): -2.0, (36, 109): -4.0, (37, 111): -2.0,
(37, 112): -2.0, (37, 113): -2.0, (37, 110): 1.0, (38, 115): -2.0,
(38, 116): -2.0, (38, 117): -2.0, (38, 114): 1.0, (39, 119): -2.0,
(39, 120): -2.0, (39, 121): -2.0, (39, 118): 1.0, (40, 123): -2.0,
(40, 124): -2.0, (40, 125): -2.0, (40, 122): 1.0, (41, 127): -2.0,
(41, 128): -2.0, (41, 129): -2.0, (41, 126): 1.0, (42, 131): -2.0,
(42, 132): -2.0, (42, 133): -2.0, (42, 130): 1.0, (43, 135): -2.0,
(43, 136): -2.0, (43, 137): -2.0, (43, 134): 1.0, (44, 45): 2.0,
(44, 57): -2.0, (44, 58): -4.0, (44, 75): -2.0, (44, 76): -2.0,
(44, 74): 1.0, (45, 46): 2.0, (45, 57): -2.0, (45, 58): -4.0,
(45, 60): -2.0, (45, 61): -4.0, (45, 84): -2.0, (45, 85): -2.0,
(45, 83): 1.0, (46, 47): 2.0, (46, 60): -2.0, (46, 61): -4.0,
(46, 63): -2.0, (46, 64): -4.0, (46, 93): -2.0, (46, 94): -2.0,
(46, 92): 1.0, (47, 63): -2.0, (47, 64): -4.0, (47, 102): -2.0,
(47, 103): -2.0, (47, 101): 1.0, (48, 78): -2.0, (48, 79): -2.0,
(48, 77): 1.0, (49, 87): -2.0, (49, 88): -2.0, (49, 86): 1.0,
(50, 96): -2.0, (50, 97): -2.0, (50, 95): 1.0, (51, 105): -2.0,
(51, 106): -2.0, (51, 104): 1.0, (52, 53): 2.0, (52, 66): -2.0,
(52, 67): -4.0, (52, 81): -2.0, (52, 82): -2.0, (52, 80): 1.0,
(53, 54): 2.0, (53, 66): -2.0, (53, 67): -4.0, (53, 69): -2.0,
(53, 70): -4.0, (53, 90): -2.0, (53, 91): -2.0, (53, 89): 1.0,
(54, 55): 2.0, (54, 69): -2.0, (54, 70): -4.0, (54, 72): -2.0,
(54, 73): -4.0, (54, 99): -2.0, (54, 100): -2.0, (54, 98): 1.0,
(55, 72): -2.0, (55, 73): -4.0, (55, 108): -2.0, (55, 109): -2.0,
(55, 107): 1.0, (56, 57): 2.0, (56, 58): 2.0, (57, 58): 6.0,
(59, 60): 2.0, (59, 61): 2.0, (60, 61): 6.0, (62, 63): 2.0,
(62, 64): 2.0, (63, 64): 6.0, (65, 66): 2.0, (65, 67): 2.0,
(66, 67): 6.0, (68, 69): 2.0, (68, 70): 2.0, (69, 70): 6.0,
(71, 72): 2.0, (71, 73): 2.0, (72, 73): 6.0, (74, 75): 2.0,
(74, 76): 2.0, (75, 76): 8.0, (77, 78): 2.0, (77, 79): 2.0,
(78, 79): 8.0, (80, 81): 2.0, (80, 82): 2.0, (81, 82): 8.0,
(83, 84): 2.0, (83, 85): 2.0, (84, 85): 8.0, (86, 87): 2.0,
(86, 88): 2.0, (87, 88): 8.0, (89, 90): 2.0, (89, 91): 2.0,
(90, 91): 8.0, (92, 93): 2.0, (92, 94): 2.0, (93, 94): 8.0,
(95, 96): 2.0, (95, 97): 2.0, (96, 97): 8.0, (98, 99): 2.0,
(98, 100): 2.0, (99, 100): 8.0, (101, 102): 2.0, (101, 103): 2.0,
(102, 103): 8.0, (104, 105): 2.0, (104, 106): 2.0, (105, 106): 8.0,
(107, 108): 2.0, (107, 109): 2.0, (108, 109): 8.0, (110, 111): 2.0,
(110, 112): 2.0, (110, 113): 2.0, (111, 112): 8.0,
(111, 113): 10.0, (112, 113): 16.0, (114, 115): 2.0,
(114, 116): 2.0, (114, 117): 2.0, (115, 116): 8.0,
(115, 117): 10.0, (116, 117): 16.0, (118, 119): 2.0,
(118, 120): 2.0, (118, 121): 2.0, (119, 120): 8.0,
(119, 121): 10.0, (120, 121): 16.0, (122, 123): 2.0,
(122, 124): 2.0, (122, 125): 2.0, (123, 124): 8.0,
(123, 125): 10.0, (124, 125): 16.0, (126, 127): 2.0,
(126, 128): 2.0, (126, 129): 2.0, (127, 128): 8.0,
(127, 129): 10.0, (128, 129): 16.0, (130, 131): 2.0,
(130, 132): 2.0, (130, 133): 2.0, (131, 132): 8.0,
(131, 133): 10.0, (132, 133): 16.0, (134, 135): 2.0,
(134, 136): 2.0, (134, 137): 2.0, (135, 136): 8.0,
(135, 137): 10.0, (136, 137): 16.0}, 40.0, 'BINARY')


sampler_kwargs = {
'token': xxxxxxxxxxxxxxxxx
'endpoint': "https://cloud.dwavesys.com/sapi",
}

sampleset = LeapHybridSampler(**sampler_kwargs).sample(bqm_data)
calc_energy = []
for sample in sampleset.samples():
Q = bqm_data.to_qubo()
calc_energy.append(
dimod.qubo_energy(sample, Q[0], Q[1]))

assert calc_energy[0] == sampleset.record.energy[0]
```

>>> E assert 0.0 == -40.0

 

0

Comments

4 comments
  • Hi Masato,

    Thank you for bringing this to our notice. The behavior you noted is because of a bug in LeapHybridSampler(). The energy returned by LeapHybridSampler() does not include the constant offset (which is 40 in your problem). The bug has been filed and we are working to resolve it.

    In the meantime, you might want to manually add the constant offset to the energy returned by LeapHybridSampler().

    Please let us know if you have any further questions.

    0
    Comment actions Permalink
  • Hi Masato,

    This bug has been resolved on Feb 10, 2021.

    Please let us know if you have any further questions.

    0
    Comment actions Permalink
  • Hi Tanvi,

    There is no problem now.

    Thank you.

    0
    Comment actions Permalink
  • It seems to me that LeapHybridSampler still returns inaccurate values for large BQMs.

    Below is a sample code.

    energy_first and every_computed are equal for small n and m.

    However, for large n and m, they may not be the same.

    This sample code returns the following output.

    energy_first=-5370732932
    energy_comp.=-5370732888
    energy_diff.=44

    ---------------

    from dwave.system import LeapHybridSampler
    import dimod
    import tqdm
    import random

    n = 10000
    m = 5000000
    time_limit = 40

    random.seed(0)
    Q = {}
    for _ in tqdm.tqdm(range(m)):
        x = random.randint(0, n-1)
        y = random.randint(0, n-1)
        w = random.randint(-100000, 100000)
        if x <= y:
            Q[(x, y)] = w
        else:
            Q[(y, x)] = w

    bqm = dimod.BQM.from_qubo(Q)
    result = LeapHybridSampler().sample(bqm, time_limit=time_limit)

    solution = [int(i) for i in result.first.sample.values()]
    energy_first = int(result.first.energy)
    print(f'energy_first={energy_first}')
    energy_computed= sum([solution[x]*solution[y]*Q[(x, y)] for x, y in Q.keys()])
    print(f'energy_comp.={energy_computed}')
    print(f'energy_diff.={energy_computed-energy_first}')

    0
    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post