VirtualGraphComposite

Class

A dimod composite that uses the D-Wave virtual graph feature for improved minor-embedding.

D-Wave virtual graphs simplify the process of minor-embedding by enabling you to more easily create, optimize, use, and reuse an embedding for a given working graph. When you submit an embedding and specify a chain strength using these tools, they automatically calibrate the qubits in a chain to compensate for the effects of biases that may be introduced as a result of strong couplings.

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

class VirtualGraphComposite(sampler, embedding, chain_strength=None, flux_biases=None, flux_bias_num_reads=1000, flux_bias_max_age=3600)[source]

Composite to use the D-Wave virtual graph feature for minor-embedding.

Inherits from dimod.ComposedSampler and dimod.Structured.

Calibrates qubits in chains to compensate for the effects of biases and enables easy creation, optimization, use, and reuse of an embedding for a given working graph.

Parameters:
  • sampler (DWaveSampler) – A dimod dimod.Sampler. Typically a DWaveSampler or derived composite sampler; other samplers may not work or make sense with this composite layer.
  • embedding (dict[hashable, iterable]) – Mapping from a source graph to the specified sampler’s graph (the target graph).
  • chain_strength (float, optional, default=None) – Desired chain coupling strength. This is the magnitude of couplings between qubits in a chain. If None, uses the maximum available as returned by a SAPI query to the D-Wave solver.
  • flux_biases (list/False/None, optional, default=None) – Per-qubit flux bias offsets in the form of a list of lists, where each sublist is of length 2 and specifies a variable and the flux bias offset associated with that variable. Qubits in a chain with strong negative J values experience a J-induced bias; this parameter compensates by recalibrating to remove that bias. If False, no flux bias is applied or calculated. If None, flux biases are pulled from the database or calculated empirically.
  • flux_bias_num_reads (int, optional, default=1000) – Number of samples to collect per flux bias value.
  • flux_bias_max_age (int, optional, default=3600) – Maximum age (in seconds) allowed for a previously calculated flux bias offset to 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 FixedEmbeddingComposite() instead.

Examples

This example uses VirtualGraphComposite to instantiate a composed sampler that submits a QUBO problem to a D-Wave solver selected by the user’s default D-Wave Cloud Client configuration file. The problem represents a logical AND gate using penalty function \(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 Chimera 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.samplers import DWaveSampler
>>> from dwave.system.composites import VirtualGraphComposite
>>> embedding = {'x': {1}, 'y': {5}, 'z': {0, 4}}
>>> DWaveSampler().properties['extended_j_range']   # doctest: +SKIP
[-2.0, 1.0]
>>> sampler = VirtualGraphComposite(DWaveSampler(), embedding, chain_strength=2) # doctest: +SKIP
>>> Q = {('x', 'y'): 1, ('x', 'z'): -2, ('y', 'z'): -2, ('z', 'z'): 3}
>>> response = sampler.sample_qubo(Q, num_reads=10) # doctest: +SKIP
>>> for sample in response.samples():    # doctest: +SKIP
...     print(sample)
...
{'y': 0, 'x': 1, 'z': 0}
{'y': 1, 'x': 0, 'z': 0}
{'y': 1, 'x': 0, 'z': 0}
{'y': 1, 'x': 1, 'z': 1}
{'y': 0, 'x': 1, 'z': 0}
{'y': 1, 'x': 0, 'z': 0}
{'y': 0, 'x': 1, 'z': 0}
{'y': 0, 'x': 1, 'z': 0}
{'y': 0, 'x': 0, 'z': 0}
{'y': 1, 'x': 0, 'z': 0}

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

Sampler Properties

VirtualGraphComposite.properties Properties in the form of a dict.
VirtualGraphComposite.parameters Parameters in the form of a dict.

Composite Properties

VirtualGraphComposite.children List containing the FixedEmbeddingComposite-wrapped sampler.
VirtualGraphComposite.child First child in children.

Structured Sampler Properties

VirtualGraphComposite.nodelist Nodes available to the composed sampler.
VirtualGraphComposite.edgelist Edges available to the composed sampler.
VirtualGraphComposite.adjacency Adjacency structure for the composed sampler.
VirtualGraphComposite.structure Structure of the structured sampler formatted as a namedtuple Structure(nodelist, edgelist, adjacency), where the 3-tuple values are the nodelist and edgelist properties and adjacency() method.

Methods

VirtualGraphComposite.sample(bqm[, …]) Sample from the given Ising model.
VirtualGraphComposite.sample_ising(h, J, …) Samples from an Ising model using an implemented sample method.
VirtualGraphComposite.sample_qubo(Q, …) Samples from a QUBO using an implemented sample method.