dwave.system.samplers.DWaveSampler.sample#

DWaveSampler.sample(bqm, warnings=None, **kwargs)[source]#

Sample from the specified binary quadratic model.

Parameters:
Returns:

Sample set constructed from a (non-blocking) Future-like object. In it this sampler also provides timing information in the info field as described in the SAPI Timing Fields section.

Return type:

SampleSet

Examples

This example submits a two-variable Ising problem mapped directly to two adjacent qubits on a D-Wave system. qubit_a is the first qubit in the QPU’s indexed list of qubits and qubit_b is one of the qubits coupled to it. Given sufficient reads (here 100), the quantum computer should return the best solution, \({1, -1}\) on qubit_a and qubit_b, respectively, as its first sample (samples are ordered from lowest energy).

>>> from dwave.system import DWaveSampler
...
>>> with DWaveSampler() as sampler:
...     qubit_a = sampler.nodelist[0]
...     qubit_b = next(iter(sampler.adjacency[qubit_a]))
...     sampleset = sampler.sample_ising({qubit_a: -1, qubit_b: 1},
...                                      {},
...                                      num_reads=100)
...     print(sampleset.first.sample[qubit_a] == 1 and sampleset.first.sample[qubit_b] == -1)
True