Submitting a Problem to the D-Wave System

This section shows what it looks like to use the Ocean software to submit an exactly-one-true problem and output the states returned. It assumes that you have already defined a problem that can be expressed on the working graph; see the preceding sections to see how to get to this point.

Note

The example that follows assumes that the requisite information for problem submission through SAPI has been configured. This is typically done as a first step when you install the Ocean SDK. For more information, including Ocean SDK installation instructions and detailed examples, see the Ocean software documentation at https://docs.ocean.dwavesys.com.

Submit the Problem

When you submit a problem, you can either minor-embed it onto the Chimera topology manually, or use the Ocean tools to determine a minor-embedding automatically for you.

Manual Minor-Embedding

Because we previously worked out an embedding for a system with the necessary qubits present, we can directly set qubits on the QPU. In the Automated Minor-Embedding section, we use an Ocean software tool to automate the minor-embedding so we can submit the problem using the original QUBO variables.

>>> 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)
>>> # Sample once on a D-Wave system and print the returned sample
>>> response = DWaveSampler().sample_qubo(Q, num_reads=1)
>>> print(next(response.samples()))
{0: 1, 1: 0, 4: 0, 5: 1}              

Note

Because the yield of a working graph is typically less than the total number of qubits and couplers that are fabricated and physically present in a QPU, we must first verify that the qubits we selected are active. For example, to check the qubits in the first unit cell:

>>> print(DWaveSampler().nodelist[0:8])        
[0, 1, 2, 3, 4, 5, 6, 7]

Likewise for the selected couplers. If any are inactive, we can use a different unit cell.

Automated Minor-Embedding

The Ocean software can accept problems defined with the QUBO or Ising variables by heuristically finding a minor-embedding.

>>> from dwave.system.samplers import DWaveSampler
>>> from dwave.system.composites import EmbeddingComposite
>>> # Set Q for the problem QUBO
>>> linear = {('x0', 'x0'): -1, ('x1', 'x1'): -1, ('x2', 'x2'): -1}
>>> quadratic = {('x0', 'x1'): 2, ('x0', 'x2'): 2, ('x1', 'x2'): 2}
>>> Q = dict(linear)
>>> Q.update(quadratic)
>>> # Minor-embed and sample 1000 times on a default D-Wave system
>>> response = EmbeddingComposite(DWaveSampler()).sample_qubo(Q, num_reads=1000)
>>> for sample, energy, num_occurrences in response.data():
...    print(sample, "Energy: ", energy, "Occurrences: ", num_occurrences)
{'x0': 0, 'x1': 0, 'x2': 1} Energy:  -1.0 Occurrences:  254
{'x0': 0, 'x1': 1, 'x2': 0} Energy:  -1.0 Occurrences:  408
{'x0': 1, 'x1': 0, 'x2': 0} Energy:  -1.0 Occurrences:  337
{'x0': 1, 'x1': 1, 'x2': 0} Energy:  0.0 Occurrences:  1

Again in the results of 10000 reads, we see that the lowest energy occurs for the 3 valid states for our problem. Although 4 unique states are returned, the lowest energy occurs for the 3 valid states, which are the most frequent solution.

Check the Solution

Let’s take a look at the solution, mapping it back to the variables in our original problem. We have a valid solution to the exactly-one-true problem: \(a\) and \(c\) are FALSE; \(b\) is TRUE. Both of the chained qubits, 0 and 5, return the same value.

Variables b c a b
Qubit 0 1 4 5
Returned Values 1 0 0 1

Increase the Number of Reads

Here, we increase the number of reads to 10000. Increasing the number of reads usually returns more variation in the returned solutions.

>>> response = DWaveSampler().sample_qubo(Q, num_reads=1000)
>>> for (sample, energy, num) in response.data():
...     print(sample, "Energy: ", energy, "Occurrences: ", num)
{0: 1, 1: 0, 4: 0, 5: 1} -0.33370000000000005 322
{0: 0, 1: 0, 4: 1, 5: 0} -0.33300000000000013 340
{0: 0, 1: 1, 4: 0, 5: 0} -0.333 335
{0: 0, 1: 0, 4: 1, 5: 1} 0.0 1
{0: 1, 1: 1, 4: 0, 5: 1} 0.00030000000000002247 1
{0: 0, 1: 1, 4: 1, 5: 0} 0.0010000000000000009 1

In the results of 10000 reads, we can see that the lowest energy occurs for the 3 valid states for our problem. Although there are only 3 valid answers to our 3-variable exactly-one-true problem, 6 unique states are returned. The lowest energy occurs for the 3 valid states, which are by far the most frequent solution. Returning a range of solutions is useful for sampling problems.