Constraints Example: Submitting to a QPU Solver#

This section shows how you submit a problem to a D-Wave quantum computer. It uses D-Wave’s open-source Ocean SDK to submit the exactly-one-true problem formulated in the previous chapters.

Before you can submit a problem to D-Wave solvers, you must have an account and an API token; visit Leap to sign up for an account and get your token.

Note

To run the following steps yourself requires prior configuration of some requisite information for problem submission through SAPI. If you have installed the Ocean SDK or are using a supported IDE, this is typically done as a first step.

For more information, including on Ocean SDK installation instructions and detailed examples, see the Ocean software documentation.

The Ocean software can heuristically find minor-embeddings for your QUBO or Ising objective functions, as shown here.

First, select a quantum computer. Ocean software provides feature-based solver selection, enabling you to select a quantum computer that meets your requirements on its number of qubits, topology, particular features, etc. This example, uses the default.

from dwave.system import DWaveSampler, EmbeddingComposite
sampler = EmbeddingComposite(DWaveSampler())

Set values of the QUBO and submit to the selected QPU.

linear = {('a', 'a'): -1, ('b', 'b'): -1, ('c', 'c'): -1}
quadratic = {('a', 'b'): 2, ('b', 'c'): 2, ('a', 'c'): 2}
Q = {**linear, **quadratic}

sampleset = sampler.sample_qubo(Q, num_reads=5000)

Below are results from running this problem on a Advantage system:

>>> print(sampleset)                        
   a  b  c energy num_oc. chain_b.
0  0  0  1   -1.0    1591     0.0
1  1  0  0   -1.0    2040     0.0
2  0  1  0   -1.0    1365     0.0
3  1  0  1    0.0       2     0.0
4  1  1  0    0.0       1     0.0
5  0  1  1    0.0       1     0.0
['BINARY', 6 rows, 5000 samples, 3 variables]

In the results of 5000 reads, you see that the lowest energy occurs for the three valid solutions to the problem.