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.
-
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
anddimod.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 dimoddimod.Sampler
. Typically aDWaveSampler
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.
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'] [-2.0, 1.0] >>> sampler = VirtualGraphComposite(DWaveSampler(), embedding, chain_strength=2) >>> Q = {('x', 'y'): 1, ('x', 'z'): -2, ('y', 'z'): -2, ('z', 'z'): 3} >>> response = sampler.sample_qubo(Q, num_reads=10) >>> for sample in response.samples(): ... 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}
- sampler (
Sampler Properties¶
VirtualGraphComposite.properties |
dict – Properties in the form of a dict. |
VirtualGraphComposite.parameters |
dict[str, list] – Parameters in the form of a dict. |
Composite Properties¶
VirtualGraphComposite.children |
list – List containing the FixedEmbeddingComposite-wrapped sampler. |
VirtualGraphComposite.child |
First child in children . |
Structured Sampler Properties¶
VirtualGraphComposite.nodelist |
list – Nodes available to the composed sampler. |
VirtualGraphComposite.edgelist |
list – Edges available to the composed sampler. |
VirtualGraphComposite.adjacency |
dict[variable, set] – 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, **kwargs) |
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. |