Esempio n. 1
0
#Lecture 21
from dwave.system.samplers import DWaveSampler

# In[6]:

# 1) Implement simple QUBO with two qubits in the Chimera graph: E(q0,q1)=(q0-q1)^2
# Set Q for the minor-embedded problem QUBO
qubit_biases = {(0, 0): 1, (4, 4): 1}
coupler_strengths = {(0, 4): -2}
Q = dict(qubit_biases)
Q.update(coupler_strengths)

# In[7]:

response = DWaveSampler().sample_qubo(Q, num_reads=1000)
for (sample, energy, num) in response.data():
    print(sample, "Energy: ", energy, "Occurrences: ", num)

# In[8]:

# As you can see, most of the time the QPU outputs values with qubits in the same state (00 or 11).
# 2) Minor-embedding to implement 3-bit 3-SAT
# We will now use "chaining" to lock q0 and q5 in the same state. This will allow the use of
# (q0, q4, q1, q5) to represent 3 qubits coupled to each other with the same coupling strengths.
# Entering the biases and coupler strengths as described in the notes:
qubit_biases = {(0, 0): 0.33, (1, 1): -0.33, (4, 4): -0.33, (5, 5): 0.33}
coupler_strengths = {(0, 4): 0.66, (1, 4): 0.66, (1, 5): 0.66, (0, 5): -1}
Q = dict(qubit_biases)
Q.update(coupler_strengths)

# In[9]:
Esempio n. 2
0
# Manual Minor-Embedding

from dwave.system.samplers import DWaveSampler
# Set Q for the minor-embedded problem QUBO
qubit_biases = {(0, 0): 0.3333, (1, 1): -0.333, (4, 4): -0.333, (5, 5): 0.333}
coupler_strengths = {(0, 4): 0.667, (0, 5): -1, (1, 4): 0.667, (1, 5): 0.667}
Q = dict(qubit_biases)
Q.update(coupler_strengths)
print(DWaveSampler().nodelist[0:8])
# Sample once on a D-Wave system and print the returned sample
response = DWaveSampler().sample_qubo(Q, num_reads=1)
print(next(response.samples()))

response = DWaveSampler().sample_qubo(Q, num_reads=100)
for rd in response.data():
    print(rd.sample, "Energy: ", rd.energy, "Occurrences: ",
          rd.num_occurrences)

import pdb
pdb.set_trace()  # debug

# Automatic

from dwave.system.samplers import DWaveSampler
from dwave.system.composites import EmbeddingComposite

# Set Q for the problem QUBO
# linear = {(0, 0): -1, (1, 1): -1, (2, 2): -1}
# quadratic = {(0, 1): 2, (0, 2): 2, (1, 2): 2}
linear = {('x0', 'x0'): -1, ('x1', 'x1'): -1, ('x2', 'x2'): -1}