dwave.system.composites.VirtualGraphComposite.sample¶
- VirtualGraphComposite.sample(bqm, apply_flux_bias_offsets=True, **kwargs)[source]¶
Sample from the given Ising model.
- Parameters
h (list/dict) – Linear biases of the Ising model. If a list, the list’s indices are used as variable labels.
J (dict of (int, int) – float): Quadratic biases of the Ising model.
apply_flux_bias_offsets (bool, optional) – If True, use the calculated flux_bias offsets (if available).
**kwargs – Optional keyword arguments for the sampling method, specified per solver.
Examples
This example uses
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 \(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 Chimera 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) >>> h = {} >>> J = {('x', 'y'): 1} >>> sampleset = sampler.sample_ising(h, J, num_reads=10) >>> print(sampleset) 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 for explanations of technical terms in descriptions of Ocean tools.