# 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.samplers import DWaveSampler
>>> from dwave.system.composites import VirtualGraphComposite
>>> embedding = {'x': {0, 4, 1, 5}, 'y': {2, 6, 3, 7}}
>>> DWaveSampler().properties['extended_j_range']   # doctest: +SKIP
[-2.0, 1.0]
>>> sampler = VirtualGraphComposite(DWaveSampler(), embedding, chain_strength=1) # doctest: +SKIP
>>> h = {}
>>> J = {('x', 'y'): 1}
>>> response = sampler.sample_ising(h, J, num_reads=10) # doctest: +SKIP
>>> for sample in response.samples():    # doctest: +SKIP
...     print(sample)
...
{'y': -1, 'x': 1}
{'y': 1, 'x': -1}
{'y': -1, 'x': 1}
{'y': -1, 'x': 1}
{'y': -1, 'x': 1}
{'y': 1, 'x': -1}
{'y': 1, 'x': -1}
{'y': 1, 'x': -1}
{'y': -1, 'x': 1}
{'y': 1, 'x': -1}


See Ocean Glossary for explanations of technical terms in descriptions of Ocean tools.