1414
1515"""
1616A :ref:`dimod <index_dimod>` :term:`sampler` for D-Wave quantum computers.
17-
18- See :ref:`Ocean Glossary <index_concepts>`
19- for explanations of technical terms in descriptions of Ocean tools.
2017"""
2118
2219import copy
4138
4239
4340def qpu_graph (topology_type , topology_shape , nodelist , edgelist ):
44- """Converts node and edge lists to a dwave-networkx compatible graph.
41+ """Convert node and edge lists to a `` dwave-networkx`` graph.
4542
46- Creates a D-Wave Chimera, Pegasus or Zephyr graph compatible with
47- dwave-networkx libraries.
43+ Creates a QPU topology ( Chimera, Pegasus or Zephyr) graph compatible with
44+ Ocean software's :ref:`index_dnx`.
4845
4946 Args:
5047 topology_type (string):
51- The type of lattice. Valid strings are `chimera`, `pegasus`
52- and `zephyr`.
48+ Type of lattice. Valid strings are `chimera`, `pegasus` and
49+ `zephyr`.
5350 topology_shape(iterable of ints):
54- Specifies dimensions of the lattice.
51+ Dimensions of the lattice.
5552 nodelist (list of ints):
56- List of nodes in the graph. Node labeling is integer,
57- and compatible with the topology_type linear labeling scheme.
53+ List of nodes in the graph. Node labeling is integer and compatible
54+ with the linear labeling scheme for the specified ``topology_type`` .
5855 edgelist (list of Tuples):
59- List of edges in the graph, each edge consisting of a pair
60- of nodes.
56+ List of edges in the graph, with each edge consisting of a pair of
57+ nodes.
6158 """
62-
59+
6360 if topology_type == 'chimera' :
6461 if not (1 <= len (topology_shape ) <= 3 ):
6562 raise ValueError ('topology_shape is incompatible with a chimera lattice.' )
@@ -86,27 +83,30 @@ def qpu_graph(topology_type, topology_shape, nodelist, edgelist):
8683
8784
8885class DWaveSampler (dimod .Sampler , dimod .Structured ):
89- """A class for using D-Wave quantum computers as samplers for binary quadratic models.
90-
91- You can configure your :term:`solver` selection and usage by setting parameters,
92- hierarchically, in a configuration file, as environment variables, or
93- explicitly as input arguments. For more information, see the
94- :ref:`D-Wave Cloud Client <index_cloud>` package's
86+ r"""Submits binary quadratic models directly to D-Wave quantum computers.
87+
88+ Linear and quadratic terms of the :term:`binary quadratic model` (BQM) must
89+ map directly to qubit and coupler indices of the selected :term:`QPU`.
90+ Typically this mapping (:term:`minor-embedding`) is handled by software
91+ (e.g., the :class:`.EmbeddingComposite` class) but for small problems can be
92+ manual.
93+ You can configure your :term:`solver` selection and usage by setting
94+ parameters, hierarchically, in a configuration file, as environment
95+ variables, or explicitly as input arguments. For more information, see the
9596 :meth:`~dwave.cloud.client.Client.get_solvers` method. By default, online
96- D-Wave systems are returned ordered by highest number of qubits.
97+ QPUs are returned ordered by highest number of qubits.
9798
9899 Args:
99100 failover (bool, optional, default=False):
100- Signal a failover condition if a sampling error occurs. When ``True``,
101- raises :exc:`~dwave.system.exceptions.FailoverCondition` or
102- :exc:`~dwave.system.exceptions.RetryCondition` on sampleset resolve
103- to signal failover.
104-
105- Actual failover, i.e. selection of a new solver, has to be handled
106- by the user. A convenience method :meth:`.trigger_failover` is available
107- for this. Note that hardware graphs vary between QPUs, so triggering
108- failover results in regenerated :attr:`.nodelist`, :attr:`.edgelist`,
109- :attr:`.properties` and :attr:`.parameters`.
101+ Signal a failover condition if a sampling error occurs. When
102+ ``True``, raises :exc:`~dwave.system.exceptions.FailoverCondition`
103+ or :exc:`~dwave.system.exceptions.RetryCondition` on sampleset
104+ :meth:`~dimod.SampleSet.resolve` to signal failover.
105+ Actual failover (i.e., selection of a new solver) has to be handled
106+ by the user. A convenience method :meth:`.trigger_failover` is
107+ available for this. Note that hardware graphs vary between QPUs, so
108+ triggering failover results in regenerated :attr:`.nodelist`,
109+ :attr:`.edgelist`, :attr:`.properties` and :attr:`.parameters`.
110110
111111 .. versionchanged:: 1.16.0
112112
@@ -124,7 +124,8 @@ class DWaveSampler(dimod.Sampler, dimod.Structured):
124124 Ignored since 1.16.0. See note for ``failover`` parameter above.
125125
126126 **config:
127- Keyword arguments passed to :meth:`~dwave.cloud.client.Client.from_config`.
127+ Keyword arguments passed to
128+ :meth:`~dwave.cloud.client.Client.from_config`.
128129
129130 .. versionadded:: 1.29.0
130131 Support for context manager protocol.
@@ -151,16 +152,15 @@ class DWaveSampler(dimod.Sampler, dimod.Structured):
151152
152153 Examples:
153154 This example submits a two-variable Ising problem mapped directly to two
154- adjacent qubits on a D-Wave system . ``qubit_a`` is the first qubit in
155+ adjacent qubits on a :term:`QPU` . ``qubit_a`` is the first qubit in
155156 the QPU's indexed list of qubits and ``qubit_b`` is one of the qubits
156- coupled to it. Other required parameters for communication with the system, such
157- as its URL and an authentication token, are implicitly set in a configuration file
158- or as environment variables, as described in the
159- :ref:`ocean_sapi_access_basic` section.
160- Given sufficient reads (here 100), the quantum
161- computer should return the best solution, :math:`{1, -1}` on ``qubit_a`` and
162- ``qubit_b``, respectively, as its first sample (samples are ordered from
163- lowest energy).
157+ coupled to it. Other required parameters for communication with the
158+ system, such as its URL and an authentication token, are implicitly set
159+ in a configuration file or as environment variables, as described in the
160+ :ref:`ocean_sapi_access_basic` section. Given sufficient reads (here
161+ 100), the quantum computer should return the best solution,
162+ :math:`{1, -1}` on ``qubit_a`` and ``qubit_b``, respectively, as its
163+ first sample (samples are ordered from lowest energy).
164164
165165 >>> from dwave.system import DWaveSampler
166166 ...
@@ -173,9 +173,10 @@ class DWaveSampler(dimod.Sampler, dimod.Structured):
173173 ... print(sampleset.first.sample[qubit_a] == 1 and sampleset.first.sample[qubit_b] == -1)
174174 True
175175
176- See the :ref:`index_concepts` section
177- for explanations of technical terms in descriptions of Ocean tools.
178-
176+ See also:
177+ * :ref:`Beginner examples <qpu_index_examples_beginner>` of using
178+ :class:`.DWaveSampler`.
179+ * :ref:`qpu_basic_config`.
179180 """
180181 def __init__ (self , failover = False , retry_interval = - 1 , ** config ):
181182 # strongly prefer QPU solvers; requires kwarg-level override
@@ -212,7 +213,8 @@ def _get_solver(self, *, refresh: bool = False, penalty: Optional[Dict[str, int]
212213 """Get the least penalized solver from the list of solvers filtered and
213214 ordered according to user config.
214215
215- Note: we need to partially replicate :class:`dwave.cloud.Client.get_solver` logic.
216+ Note: we need to partially replicate
217+ :class:`dwave.cloud.Client.get_solver` logic.
216218 """
217219 if penalty is None :
218220 penalty = {}
@@ -232,31 +234,26 @@ def _get_solver(self, *, refresh: bool = False, penalty: Optional[Dict[str, int]
232234 raise SolverNotFoundError ("Solver with the requested features not available" )
233235
234236 warnings_default = WarningAction .IGNORE
235- """Defines the default behavior for :meth:`.sample_ising`'s and
236- :meth:`sample_qubo`'s `warnings` kwarg .
237+ """Defines the default behavior for ``warnings`` keyword arguments of the
238+ :meth:`.sample_ising` and :meth:`sample_qubo` methods .
237239 """
238240
239241 @property
240242 def properties (self ):
241- """dict: D-Wave solver properties as returned by a SAPI query.
243+ """dict: Solver properties as returned by a :term:` SAPI` query.
242244
243- Solver properties are dependent on the selected D-Wave solver and subject to change;
244- for example, new released features may add properties. The
245+ Solver properties are dependent on the selected solver and subject to
246+ change; for example, new features may add properties. The
245247 :ref:`qpu_index_solver_properties` and :ref:`qpu_solver_parameters`
246- sections describe the parameters and properties supported on the D-Wave system.
248+ sections describe the parameters and properties supported on D-Wave
249+ quantum computers.
247250
248251 Examples:
249252
250253 >>> from dwave.system import DWaveSampler
251- >>> with DWaveSampler() as sampler: # doctest: +SKIP
252- ... sampler.properties
253- {'anneal_offset_ranges': [[-0.2197463755538704, 0.03821687759418928],
254- [-0.2242514597680286, 0.01718456460967399],
255- [-0.20860153999435985, 0.05511969218508182],
256- # Snipped above response for brevity
257-
258- See the :ref:`Ocean Glossary <index_concepts>` section
259- for explanations of technical terms in descriptions of Ocean tools.
254+ >>> with DWaveSampler() as sampler:
255+ ... print(sampler.properties['category'])
256+ qpu
260257
261258 """
262259 try :
@@ -267,29 +264,25 @@ def properties(self):
267264
268265 @property
269266 def parameters (self ):
270- """dict[str, list]: D-Wave solver parameters in the form of a dict, where keys are
271- keyword parameters accepted by a SAPI query and values are lists of properties in
267+ """dict[str, list]: Solver parameters as returned by a :term:`SAPI`
268+ query.
269+
270+ Keys of the returned dict are keyword parameters accepted by a SAPI
271+ query and values are lists of properties in
272272 :attr:`~DWaveSampler.properties` for each key.
273273
274- Solver parameters are dependent on the selected D-Wave solver and subject to change;
275- for example, new released features may add parameters. The
274+ Solver parameters are dependent on the selected solver and subject to
275+ change; for example, new features may add parameters. The
276276 :ref:`qpu_index_solver_properties` and :ref:`qpu_solver_parameters`
277- sections describe the parameters and properties supported on the D-Wave system.
277+ sections describe the parameters and properties supported on D-Wave
278+ quantum computers.
278279
279280 Examples:
280281
281282 >>> from dwave.system import DWaveSampler
282- >>> with DWaveSampler() as sampler: # doctest: +SKIP
283- ... sampler.parameters
284- {'anneal_offsets': ['parameters'],
285- 'anneal_schedule': ['parameters'],
286- 'annealing_time': ['parameters'],
287- 'answer_mode': ['parameters'],
288- 'auto_scale': ['parameters'],
289- # Snipped above response for brevity
290-
291- See the :ref:`Ocean Glossary <index_concepts>` section
292- for explanations of technical terms in descriptions of Ocean tools.
283+ >>> with DWaveSampler() as sampler:
284+ ... 'auto_scale' in sampler.parameters
285+ True
293286
294287 """
295288 try :
@@ -304,18 +297,15 @@ def parameters(self):
304297
305298 @property
306299 def edgelist (self ):
307- """list: List of active couplers for the D-Wave solver.
300+ """list: List of active couplers for the solver.
308301
309302 Examples:
310- First 5 entries of the coupler list for one Advantage system.
303+ First coupler for a selected Advantage2 system.
311304
312305 >>> from dwave.system import DWaveSampler
313- >>> with DWaveSampler() as sampler: # doctest: +SKIP
314- ... sampler.edgelist[:5]
315- [(30, 31), (30, 45), (30, 2940), (30, 2955), (30, 2970)]
316-
317- See the :ref:`index_concepts` section
318- for explanations of technical terms in descriptions of Ocean tools.
306+ >>> with DWaveSampler(topology_type='zephyr') as sampler:
307+ ... sampler.edgelist[0]
308+ (0, 1)
319309
320310 """
321311 # Assumption: cloud client nodes are always integer-labelled
@@ -328,18 +318,15 @@ def edgelist(self):
328318
329319 @property
330320 def nodelist (self ):
331- """list: List of active qubits for the D-Wave solver.
321+ """list: List of active qubits for the solver.
332322
333323 Examples:
334- First 5 entries of the node list for one Advantage system.
324+ First three qubits for a selected Advantage2 system.
335325
336326 >>> from dwave.system import DWaveSampler
337- >>> with DWaveSampler() as sampler: # doctest: +SKIP
338- ... sampler.nodelist[:5]
339- [30, 31, 32, 33, 34]
340-
341- See the :ref:`index_concepts` section
342- for explanations of technical terms in descriptions of Ocean tools.
327+ >>> with DWaveSampler(topology_type='zephyr') as sampler:
328+ ... sampler.nodelist[:3]
329+ [0, 1, 2]
343330
344331 """
345332 # Assumption: cloud client nodes are always integer-labelled
@@ -381,11 +368,11 @@ def trigger_failover(self):
381368 pass
382369
383370 def sample (self , bqm , warnings = None , ** kwargs ):
384- """Sample from the specified binary quadratic model.
371+ """Sample from the specified :term:` binary quadratic model` .
385372
386373 Args:
387374 bqm (:class:`~dimod.BinaryQuadraticModel`):
388- The binary quadratic model. Must match
375+ The binary quadratic model. Must match
389376 :attr:`~DWaveSampler.nodelist` and :attr:`~DWaveSampler.edgelist`.
390377
391378 warnings (:class:`~dwave.system.warnings.WarningAction`, optional):
@@ -394,15 +381,16 @@ def sample(self, bqm, warnings=None, **kwargs):
394381 ignore warnings.
395382
396383 **kwargs:
397- Optional keyword arguments for the sampling method, specified per solver in
398- :attr:`.parameters`. The :ref:`qpu_index_solver_properties` and
384+ Optional keyword arguments for the sampling method, specified
385+ per solver in :attr:`.parameters`. The
386+ :ref:`qpu_index_solver_properties` and
399387 :ref:`qpu_solver_parameters` sections describe the parameters
400- and properties supported on the D-Wave system .
388+ and properties supported on D-Wave quantum computers .
401389
402390 Returns:
403- :class:`~dimod.SampleSet`: Sample set constructed from a (non-blocking)
404- :class:`~concurrent.futures.Future`-like object.
405- In it this sampler also provides timing information in the `info`
391+ :class:`~dimod.SampleSet`: Sample set constructed from a
392+ (non-blocking) :class:`~concurrent.futures.Future`-like object.
393+ In it this sampler also provides timing information in the `` info` `
406394 field as described in the :ref:`qpu_sapi_qpu_timing` section.
407395
408396 Examples:
0 commit comments