Skip to content

Commit

Permalink
Merge pull request #491 from JoelPasvolsky/newer_qpus
Browse files Browse the repository at this point in the history
Update examples to use newer QPUs
  • Loading branch information
randomir authored May 12, 2023
2 parents ab6c4d1 + 40aab7f commit 168eda4
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 91 deletions.
41 changes: 21 additions & 20 deletions dwave/system/composites/tiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
multiple times to a structured sampler.
The :class:`.TilingComposite` class takes a problem that can fit on a small
:term:`Chimera` graph and replicates it across a larger Pegasus or
Chimera graph to obtain samples from multiple areas of the solver in one call.
For example, a 2x2 Chimera lattice could be tiled 64 times (8x8) on a
fully-yielded D-Wave 2000Q system (16x16).
:term:`Chimera` graph and replicates it across the larger working graph of
a quantum processing unit (QPU) to obtain samples from multiple areas of
the QPU in one call.
For example, a single Chimera unit cell could be tiled over 600 times on a
fully-yielded Advantage system.
See `Ocean Glossary <https://docs.ocean.dwavesys.com/en/stable/concepts/index.html>`_
for explanations of technical terms in descriptions of Ocean tools.
Expand All @@ -46,12 +47,6 @@ class TilingComposite(dimod.Sampler, dimod.Composite, dimod.Structured):
graph of dimensions ``sub_m``, ``sub_n``, ``t``, or minor-embeddable to
such a graph.
Notation *CN* refers to a Chimera graph consisting of an NxN grid of unit
cells, where each unit cell is a bipartite graph with shores of size t.
The D-Wave 2000Q QPU supports a C16 Chimera graph: its 2048 qubits are
logically mapped into a 16x16 matrix of unit cells of 8 qubits (t=4).
See also the :func:`dwave_networkx.chimera_graph` function.
Notation *PN* referes to a Pegasus graph consisting of a 3x(N-1)x(N-1) grid
of cells, where each unit cell is a bipartite graph with shore of size t,
supplemented with odd couplers (see ``nice_coordinate`` definition in
Expand All @@ -61,10 +56,18 @@ class TilingComposite(dimod.Sampler, dimod.Composite, dimod.Structured):
Chimera-structured problems, with an option of additional odd-couplers,
onto Pegasus. See also the :func:`dwave_networkx.pegasus_graph` function.
Notation *CN* refers to a Chimera graph consisting of an NxN grid of unit
cells, where each unit cell is a bipartite graph with shores of size t.
(An earlier quantum computer, the D-Wave 2000Q, supported a C16 Chimera
graph: its 2048 qubits were logically mapped into a 16x16 matrix of unit
cells of 8 qubits (t=4). See also the :func:`dwave_networkx.chimera_graph`
function.)
A problem that can be minor-embedded in a single chimera unit cell, for
example, can therefore be tiled across the unit cells of a D-Wave 2000Q as
16x16 duplicates (or Advantage as 3x15x15 duplicates), subject to solver
yield. This enables up to 256 (625) parallel samples per read.
example, can therefore be tiled as 3x15x15 duplicates across an Advantage
QPU (or, previously, over the unit cells of a D-Wave 2000Q as 16x16
duplicates), subject to solver yield. This enables over 600 (256 for the
D-Wave 2000Q) parallel samples per read.
Args:
sampler (:class:`dimod.Sampler`): Structured dimod sampler such as a
Expand All @@ -87,8 +90,7 @@ class TilingComposite(dimod.Sampler, dimod.Composite, dimod.Structured):
>>> from dwave.system import DWaveSampler, EmbeddingComposite
>>> from dwave.system import TilingComposite
...
>>> qpu_2000q = DWaveSampler(solver={'topology__type': 'chimera'})
>>> sampler = EmbeddingComposite(TilingComposite(qpu_2000q, 1, 1, 4))
>>> sampler = EmbeddingComposite(TilingComposite(DWaveSampler(), 1, 1, 4))
>>> Q = {(1, 1): -1, (1, 2): 2, (2, 1): 0, (2, 2): -1}
>>> sampleset = sampler.sample_qubo(Q)
>>> len(sampleset)> 1
Expand Down Expand Up @@ -281,11 +283,10 @@ def sample(self, bqm, **kwargs):
>>> from dwave.system import DWaveSampler, EmbeddingComposite
>>> from dwave.system import TilingComposite
...
>>> qpu_2000q = DWaveSampler(solver={'topology__type': 'chimera'})
>>> sampler = EmbeddingComposite(TilingComposite(qpu_2000q, 1, 1, 4))
>>> response = sampler.sample_ising({},{('a', 'b'): 1})
>>> len(response) # doctest: +SKIP
246
>>> sampler = EmbeddingComposite(TilingComposite(DWaveSampler(), 1, 1, 4))
>>> sampleset = sampler.sample_ising({},{('a', 'b'): 1})
>>> len(sampleset) > 1
True
See `Ocean Glossary <https://docs.ocean.dwavesys.com/en/stable/concepts/index.html>`_
for explanations of technical terms in descriptions of Ocean tools.
Expand Down
90 changes: 32 additions & 58 deletions dwave/system/composites/virtual_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,38 +76,40 @@ class VirtualGraphComposite(FixedEmbeddingComposite):
be considered valid.
.. attention::
D-Wave's *virtual graphs* feature can require many seconds of D-Wave system time to calibrate
qubits to compensate for the effects of biases. If your account has limited
D-Wave system access, consider using :class:`.FixedEmbeddingComposite` instead.
D-Wave's *virtual graphs* feature can require many seconds of D-Wave system time to calibrate
qubits to compensate for the effects of biases. If your account has limited
D-Wave system access, consider using :class:`.FixedEmbeddingComposite` instead.
Examples:
This example uses :class:`.VirtualGraphComposite` to instantiate a composed sampler
that submits a QUBO problem to a D-Wave solver.
The problem represents a logical
AND gate using penalty function :math:`P = xy - 2(x+y)z +3z`, where variables x and y
are the gate's inputs and z the output. This simple three-variable problem is manually
minor-embedded to a single :std:doc:`Chimera <oceandocs:docs_system/intro>` unit cell:
variables x and y are represented by qubits 1 and 5, respectively, and z by a
two-qubit chain consisting of qubits 0 and 4.
The chain strength is set to the maximum allowed found from querying the solver's extended
J range. In this example, the ten returned samples all represent valid states of
the AND gate.
>>> from dwave.system import DWaveSampler, VirtualGraphComposite
>>> embedding = {'x': {1}, 'y': {5}, 'z': {0, 4}}
>>> qpu_2000q = DWaveSampler(solver={'topology__type': 'chimera'})
>>> qpu_2000q.properties['extended_j_range']
[-2.0, 1.0]
>>> sampler = VirtualGraphComposite(qpu_2000q, embedding, chain_strength=2) # doctest: +SKIP
>>> Q = {('x', 'y'): 1, ('x', 'z'): -2, ('y', 'z'): -2, ('z', 'z'): 3}
>>> sampleset = sampler.sample_qubo(Q, num_reads=10) # doctest: +SKIP
>>> print(sampleset) # doctest: +SKIP
x y z energy num_oc. chain_.
0 1 0 0 0.0 2 0.0
1 0 1 0 0.0 3 0.0
2 1 1 1 0.0 3 0.0
3 0 0 0 0.0 2 0.0
['BINARY', 4 rows, 10 samples, 3 variables]
This example uses :class:`.VirtualGraphComposite` to instantiate a
composed sampler that submits an Ising problem to a D-Wave solver.
This simple three-variable problem is manually minor-embedded such that
variables ``a`` and ``b`` are represented by single qubits while variable
``c`` is represented by a four-qubit chain. The chain strength is set to
the maximum allowed found from querying the solver's extended J range.
The minor embedding shown below was for an execution of this example on a
particular Advantage system; select a suitable embedding for the QPU you
use.
>>> from dwave.system import DWaveSampler, VirtualGraphComposite
...
>>> h = {'a': 1, 'b': -1}
>>> J = {('b', 'c'): -1, ('a', 'c'): -1}
...
>>> qpu = DWaveSampler()
>>> embedding = {'a': [2656], 'c': [2641, 2642, 2643, 2644], 'b': [2659]}
>>> qpu.properties['extended_j_range']
[-2.0, 1.0]
>>> # Sample using VirtualGraphComposite
>>> sampler = VirtualGraphComposite(qpu, embedding, chain_strength=2) # doctest: +SKIP
>>> sampleset = sampler.sample_ising(h, J, num_reads=100) # doctest: +SKIP
>>> print(sampleset) # doctest: +SKIP
a b c energy num_oc. chain_.
0 +1 +1 +1 -2.0 21 0.0
1 -1 +1 +1 -2.0 66 0.0
2 -1 -1 -1 -2.0 8 0.0
3 -1 +1 -1 -2.0 5 0.0
['SPIN', 4 rows, 100 samples, 3 variables]
See `Ocean Glossary <https://docs.ocean.dwavesys.com/en/stable/concepts/index.html>`_
for explanations of technical terms in descriptions of Ocean tools.
Expand Down Expand Up @@ -163,34 +165,6 @@ def sample(self, bqm, apply_flux_bias_offsets=True, **kwargs):
**kwargs:
Optional keyword arguments for the sampling method, specified per solver.
Examples:
This example uses :class:`.VirtualGraphComposite` to instantiate a composed sampler
that submits an Ising problem to a D-Wave solver.
The problem represents a logical
NOT gate using penalty function :math:`P = xy`, where variable x is the gate's input
and y the output. This simple two-variable problem is manually minor-embedded
to a single :std:doc:`Chimera <oceandocs:docs_system/intro>` unit cell: each variable
is represented by a chain of half the cell's qubits, x as qubits 0, 1, 4, 5,
and y as qubits 2, 3, 6, 7.
The chain strength is set to half the maximum allowed found from querying the solver's extended
J range. In this example, the ten returned samples all represent valid states of
the NOT gate.
>>> from dwave.system import DWaveSampler, VirtualGraphComposite
>>> embedding = {'x': {0, 4, 1, 5}, 'y': {2, 6, 3, 7}}
>>> qpu_2000q = DWaveSampler(solver={'topology__type': 'chimera'})
>>> qpu_2000q.properties['extended_j_range']
[-2.0, 1.0]
>>> sampler = VirtualGraphComposite(qpu_2000q, embedding, chain_strength=1) # doctest: +SKIP
>>> h = {}
>>> J = {('x', 'y'): 1}
>>> sampleset = sampler.sample_ising(h, J, num_reads=10) # doctest: +SKIP
>>> print(sampleset) # doctest: +SKIP
x y energy num_oc. chain_.
0 -1 +1 -1.0 6 0.0
1 +1 -1 -1.0 4 0.0
['SPIN', 2 rows, 10 samples, 2 variables]
See `Ocean Glossary <https://docs.ocean.dwavesys.com/en/stable/concepts/index.html>`_
for explanations of technical terms in descriptions of Ocean tools.
Expand Down
16 changes: 8 additions & 8 deletions dwave/system/samplers/dwave_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,12 @@ def edgelist(self):
"""list: List of active couplers for the D-Wave solver.
Examples:
Coupler list for one D-Wave 2000Q system (output snipped for brevity).
First 5 entries of the coupler list for one Advantage system.
>>> from dwave.system import DWaveSampler
>>> sampler = DWaveSampler()
>>> sampler.edgelist
[(0, 4), (0, 5), (0, 6), (0, 7), ...
>>> sampler.edgelist[:5] # doctest: +SKIP
[(30, 31), (30, 45), (30, 2940), (30, 2955), (30, 2970)]
See `Ocean Glossary <https://docs.ocean.dwavesys.com/en/stable/concepts/index.html>`_
for explanations of technical terms in descriptions of Ocean tools.
Expand All @@ -307,12 +307,12 @@ def nodelist(self):
"""list: List of active qubits for the D-Wave solver.
Examples:
Node list for one D-Wave 2000Q system (output snipped for brevity).
First 5 entries of the node list for one Advantage system.
>>> from dwave.system import DWaveSampler
>>> sampler = DWaveSampler()
>>> sampler.nodelist
[0, 1, 2, ...
>>> sampler.nodelist[:5] # doctest: +SKIP
[30, 31, 32, 33, 34]
See `Ocean Glossary <https://docs.ocean.dwavesys.com/en/stable/concepts/index.html>`_
for explanations of technical terms in descriptions of Ocean tools.
Expand Down Expand Up @@ -586,13 +586,13 @@ def to_networkx_graph(self):
Examples:
This example converts a selected D-Wave system solver to a graph
and verifies it has over 2000 nodes.
and verifies it has over 5000 nodes.
>>> from dwave.system import DWaveSampler
...
>>> sampler = DWaveSampler()
>>> g = sampler.to_networkx_graph() # doctest: +SKIP
>>> len(g.nodes) > 2000 # doctest: +SKIP
>>> len(g.nodes) > 5000 # doctest: +SKIP
True
"""
return qpu_graph(self.properties['topology']['type'],
Expand Down
10 changes: 5 additions & 5 deletions dwave/system/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ def common_working_graph(graph0, graph1):
Examples:
This example creates a graph that represents a quarter (4 by 4 Chimera tiles)
of a particular D-Wave system's working graph.
This example creates a graph that represents a part of a particular
Advantage quantum computer's working graph.
>>> import dwave_networkx as dnx
>>> from dwave.system import DWaveSampler, common_working_graph
...
>>> sampler = DWaveSampler()
>>> C4 = dnx.chimera_graph(4) # a 4x4 lattice of Chimera tiles
>>> c4_working_graph = common_working_graph(C4, sampler.adjacency)
>>> sampler = DWaveSampler(solver={'topology__type': 'pegasus'})
>>> P3 = dnx.pegasus_graph(3)
>>> p3_working_graph = common_working_graph(P3, sampler.adjacency)
"""

Expand Down

0 comments on commit 168eda4

Please sign in to comment.