Quantum Solvers#

Ocean’s dwave-system package enables you to use a D-Wave quantum computer as a sampler. In addition to DWaveSampler, the package provides an EmbeddingComposite composite that maps unstructured problems to the graph structure of the selected sampler, a process known as minor-embedding.

Solver Identity and Selection#

Optimization problems submitted to quantum computers in the Leap service, as either stand-alone problems small enough to fit onto a QPU or subproblems generated by a hybrid solver from a large problem, are sent to a QPU solver selected by default or explicitly. The Example: Simple QPU Usage example uses the QPU selected by default by Ocean software’s DWaveSampler class. For research, however, you may prefer to explicitly select a QPU solver.

QPU solvers are uniquely referenced by an identity dictionary.[1] This identity includes a name (e.g., Advantage2_system1.6) and a graph identifier that tracks any changes to the solver’s working graph. Ocean software enables solver selection by identity (name alone or with a particular graph ID), topology type, qubit count, and other characteristics, as described in the get_solvers() method. The Example: Problem on the Native Graph example ensures that the selected QPU solver has a Zephyr topology and saves the graph_id of its current working graph for reference.

Example: Simple QPU Usage#

Note

The Configuring Access to the Leap Service (Basic) steps you through configuring access to D-Wave quantum computers.

For a binary quadratic model (BQM) representing a Boolean AND gate (see the Formulation Example: BQM for a Boolean Circuit section for more details) the problem is defined on alphanumeric variables \(in1, in2, out\) that must be mapped to the QPU’s numerically indexed qubits.

>>> from dimod.generators import and_gate
>>> bqm = and_gate('in1', 'in2', 'out')

Because of the sampler’s probabilistic nature, you typically request multiple samples for a problem; this example sets the num_reads solver parameter to 1000.

>>> from dwave.system import DWaveSampler, EmbeddingComposite
>>> sampler = EmbeddingComposite(DWaveSampler())
>>> sampleset = sampler.sample(bqm, num_reads=1000)
>>> print(sampleset)   
  in1 in2 out energy num_oc. chain_.
0   1   0   0    0.0     321     0.0
1   1   1   1    0.0      97     0.0
2   0   0   0    0.0     375     0.0
3   0   1   0    0.0     206     0.0
4   1   0   1    2.0       1 0.33333
['BINARY', 5 rows, 1000 samples, 3 variables]

Note that the first four samples are the valid states of the AND gate and have lower energy than invalid state \(in1=1, in2=0, out=1\).

For additional beginner examples of submitting problems to D-Wave quantum computers, see the Basic QPU Examples section.

Example: Problem on the Native Graph#

This example creates a RAN7 problem (see ran_r()) on a graph of 1000 nodes structured in a Zephyr topology, which can embed directly onto 1000 qubits of an Advantage2 QPU.

For reproducibility, it saves the working graph identifier of the selected QPU.

>>> from dwave.system import DWaveSampler
...
>>> sampler = DWaveSampler(topology__type="zephyr")
>>> qpu_identity = sampler.solver.identity   
>>> print(sampler.solver.identity.dict())  
{'name': 'Advantage2_system1.6', 'version': {'graph_id': '010e7a62e5'}}

In any future experiments, the researcher can explicitly select that QPU with the requirement that the current working graph is unchanged:

>>> sampler = DWaveSampler(solver=dict(identity=qpu_identity))        
>>> print(sampler.solver.version)      
{'graph_id': '010e7a62e5'}

Run the problem on the first 1000 qubits of the working graph:

>>> from dimod.generators import ran_r
>>> qpu_graph = sampler.to_networkx_graph()
>>> problem_graph = qpu_graph.subgraph(list(qpu_graph.nodes)[:1000])  
>>> bqm = ran_r(7, problem_graph)  
>>> sampleset = sampler.sample(bqm, num_reads=1000, label="Zephyr RAN7")