D-Wave QBSolv Behaving Unexpectedly [Example Code]
Hello all,
I'm relatively new to using D-wave's Ocean tools so I might be making a simple mistake, but I have encountered a problem with the QBSolv method.
For this example I will define two problems Q1 and Q2.
(Q1 has only two qubits in use)
Q1 = {(0, 0): 1, (1, 1): 1, (0, 1): 1}
(Q2 has 179 qubits in use with approximately 2000 cross terms, the full form has not been given).
Q2 = {(0, 0): 18412.0, (0, 1): 73600.0, (1, 1): 73624.0, (0, 2): 147200.0, (1, 2): 294400.0, (2, 2): 294448.0, ... (177, 178): 38587596.8, (178, 178): 38588976.8}
The rest of the code body looks like this:
-------------------------------------------------------------------------
from dwave_qbsolv import QBSolv
import neal
sampler = neal.SimulatedAnnealingSampler()
...
Q1 and Q2 definition
...
response = QBSolv().sample_qubo(Q1, solver=sampler, num_repeats = 10)
print("Q1 Run")
i=0
for sample, energy, num_occurrences in response.data():
print(sample, "Energy: ", energy, "Occurrences: ", num_occurrences)
i += 1
print("There are ", i, " Q1 results.")
response = QBSolv().sample_qubo(Q2, solver=sampler, num_repeats = 10)
print("Q2 Run")
i=0
for sample, energy, num_occurrences in response.data():
print(sample, "Energy: ", energy, "Occurrences: ", num_occurrences)
i += 1
print("There are ", i, " Q2 results.")
--------------------------------------------------------------------------
From the Q1 section of the code I receive this:
{0: 0, 1: 0} Energy: -0.0 Occurrences: 11
There are 1 distinct Q1 results.
From the Q2 section of the code I receive this:
{0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 1, 10: 0, 11: 0, 12: 0, 13: 0, 14: 0, 15: 0, 16: 0, 17: 0, 18: 0, 19: 0, 20: 0, 21: 0, 22: 0, 23: 0, 24: 1, 25: 0, 26: 0, 27: 0, 28: 0, 29: 0, 30: 0, 31: 0, 32: 1, 33: 1, 34: 0, 35: 0, 36: 1, 37: 0, 38: 0, 39: 0, 40: 0, 41: 0, 42: 0, 43: 1, 44: 1, 45: 0, 46: 0, 47: 0, 48: 0, 49: 0, 50: 0, 51: 1, 52: 0, 53: 0, 54: 0, 55: 0, 56: 0, 57: 0, 58: 1, 59: 0, 60: 1, 61: 0, 62: 0, 63: 0, 64: 0, 65: 0, 66: 1, 67: 1, 68: 0, 69: 0, 70: 0, 71: 1, 72: 1, 73: 1, 74: 1, 75: 0, 76: 0, 77: 0, 78: 0, 79: 1, 80: 1, 81: 1, 82: 1, 83: 0, 84: 0, 85: 0, 86: 0, 87: 0, 88: 0, 89: 0, 90: 0, 91: 0, 92: 0, 93: 0, 94: 0, 95: 0, 96: 1, 97: 1, 98: 0, 99: 0, 100: 0, 101: 0, 102: 0, 103: 0, 104: 0, 105: 0, 106: 0, 107: 0, 108: 0, 109: 0, 110: 0, 111: 1, 112: 0, 113: 0, 114: 0, 115: 0, 116: 0, 117: 0, 118: 1, 119: 0, 120: 0, 121: 0, 122: 0, 123: 0, 124: 0, 125: 0, 126: 0, 127: 0, 128: 0, 129: 0, 130: 0, 131: 0, 132: 1, 133: 0, 134: 0, 135: 0, 136: 0, 137: 0, 138: 0, 139: 0, 140: 0, 141: 0, 142: 0, 143: 0, 144: 0, 145: 0, 146: 0, 147: 1, 148: 1, 149: 0, 150: 0, 151: 0, 152: 0, 153: 0, 154: 0, 155: 1, 156: 1, 157: 0, 158: 0, 159: 0, 160: 0, 161: 0, 162: 0, 163: 0, 164: 0, 165: 0, 166: 0, 167: 0, 168: 0, 169: 0, 170: 0, 171: 0, 172: 0, 173: 0, 174: 0, 175: 0, 176: 0, 177: 0, 178: 0} Energy: -23000455.400000002 Occurrences: 1
.... (19 more results are suppressed for clarity)
There are 20 distinct Q2 results.
Clearly the Q2 solver is running for more than 11 repeats, and interestingly I find that even if I increase the number of repeats to very large numbers (10000+), I receive a response.data() object with no more than 20 distinct results stored within it.
I'm not sure how to interpret this behaviour or how to force QBSolv to run and record as many results as I explicitly specify. For completeness, I observe this behaviour both when using subqubo problems and when using the QBSolv method without simulated annealing.
Comments
Hi Peter,
Did you mean to do num_reads instead of num_repeats?
Hi Peter,
The results you are getting back are the top 20 unique results returned by running qbsolv.
The algorithm runs until the state returned is the same for a count num_repeats.
That said, the loop will run a minimum of num_repeats times (assuming it gets the same answer back num_repeats times right away).
It can run a very large number of times depending on the value num_repeats is set to, as it will have to produce the same result this many times.
The number 20 is a hard-coded value to limit the results to a manageable set:
https://github.com/dwavesystems/qbsolv/blob/master/python/dwave_qbsolv/qbsolv_binding.pyx#L90
It corresponds to the "algorithm" parameter in the sample() method.
For a number of reasons we have been encouraging users to move over to dwave-hybrid where possible, as it solves some problems existing in qbsolv and is under active development, while qbsolv is not.
Here is a community post about using dwave-hybrid:
https://support.dwavesys.com/hc/en-us/community/posts/360022231294-How-to-use-D-wave-with-qbsolv-command-
I hope this was all helpful.
Please let me know if anything is unclear or if you have more questions.
Tagging on to David's answer - here is a great paper that explains how qbsolv works:
https://github.com/dwavesystems/qbsolv/blob/master/qbsolv_techReport.pdf
It includes a section of pseudo-code which should help clarify how input parameters like num_repeats affects the algorithm.
Please sign in to leave a comment.