Open tsphillips opened 5 years ago
Here is a sample that shows the difference in output:
$ python3 anneal-vs-neal.py
D-Wave anneal results:
{0: 0, 4: 1} Energy: -1.0 Occurrences: 5
{0: 1, 4: 0} Energy: -1.0 Occurrences: 3
Simulated anneal results:
{0: 1, 4: 0} Energy: -1.0 Occurrences: 1
{0: 0, 4: 1} Energy: -1.0 Occurrences: 1
{0: 1, 4: 0} Energy: -1.0 Occurrences: 1
{0: 1, 4: 0} Energy: -1.0 Occurrences: 1
{0: 1, 4: 0} Energy: -1.0 Occurrences: 1
{0: 1, 4: 1} Energy: 0.0 Occurrences: 1
{0: 0, 4: 0} Energy: 0.0 Occurrences: 1
{0: 0, 4: 0} Energy: 0.0 Occurrences: 1
$ cat anneal-vs-neal.py
from dwave.system.samplers import DWaveSampler
from neal import SimulatedAnnealingSampler
# This is a simple boolean NOT gate.
# true = (q0 NOT q4)
Q = {(0, 0): -1, (0, 4): 0, (4, 0): 2, (4, 4): -1}
# First we run a dwave anneal
dwave_sampler = DWaveSampler()
dwave_response = dwave_sampler.sample_qubo(Q, num_reads=8)
print('D-Wave anneal results:')
for sample, energy, num_occurrences in dwave_response.data():
print(sample, "Energy: ", energy, "Occurrences: ", num_occurrences)
# Second we run a simulated anneal
neal_sampler = SimulatedAnnealingSampler()
neal_response = neal_sampler.sample_qubo(Q, num_reads=8)
print('Simulated anneal results:')
for sample, energy, num_occurrences in neal_response.data():
print(sample, "Energy: ", energy, "Occurrences: ", num_occurrences)
Current Problem When I write code for DWaveSampler, I have to modify the code to use neal instead. For example, no matter which of these I write, the code that follows should never have to change.
Proposed Solution Have the inputs and outputs of neal match those of DWaveSampler. For example, the argument "anneal_schedule=" should be silently ignored. The output in response.data() should be aggregated like it is in DWaveSampler.
Alternatives Considered If I want the same code to work with both neal and DWaveSampler, then I would need to make my own wrapper around these. That is a layer of abstraction I would very much like to avoid.