Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Have semantics of neal match DWaveSampler #36

Open
tsphillips opened this issue Sep 27, 2018 · 1 comment
Open

Feature: Have semantics of neal match DWaveSampler #36

tsphillips opened this issue Sep 27, 2018 · 1 comment

Comments

@tsphillips
Copy link

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.

sampler = DWaveSampler()
sampler = neal.SimulatedAnnealingSampler()

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.

@tsphillips
Copy link
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants