Composites#

dimod composites that provide layers of pre- and post-processing (e.g., minor-embedding) when using the D-Wave system:

Other Ocean packages provide additional composites; for example, dimod provides composites that operate on the problem (e.g., scaling values), track inputs and outputs for debugging, and other useful functionality relevant to generic samplers.

CutOffs#

Prunes the binary quadratic model (BQM) submitted to the child sampler by retaining only interactions with values commensurate with the sampler’s precision.

CutOffComposite#

class CutOffComposite(child_sampler, cutoff, cutoff_vartype=Vartype.SPIN, comparison=<built-in function lt>)[source]#

Composite to remove interactions below a specified cutoff value.

Prunes the binary quadratic model (BQM) submitted to the child sampler by retaining only interactions with values commensurate with the sampler’s precision as specified by the cutoff argument. Also removes variables isolated post- or pre-removal of these interactions from the BQM passed on to the child sampler, setting these variables to values that minimize the original BQM’s energy for the returned samples.

Parameters:
  • sampler (dimod.Sampler) – A dimod sampler.

  • cutoff (number) – Lower bound for absolute value of interactions. Interactions with absolute values lower than cutoff are removed. Isolated variables are also not passed on to the child sampler.

  • cutoff_vartype (Vartype/str/set, default=’SPIN’) –

    Variable space to execute the removal in. Accepted input values:

    • Vartype.SPIN, 'SPIN', {-1, 1}

    • Vartype.BINARY, 'BINARY', {0, 1}

  • comparison (function, optional) – A comparison operator for comparing interaction values to the cutoff value. Defaults to operator.lt().

Added in version 1.30.0: Support for context manager protocol with dimod.Scoped() implemented.

Examples

This example removes one interaction, 'ac': -0.7, before embedding on a D-Wave system. Note that the lowest-energy sample for the embedded problem is unchanged {'a': 1, 'b': -1, 'c': -1} and this solution is found. However, the sample is attributed the energy appropriate to the bqm without thresholding.

>>> import dimod
>>> sampler = DWaveSampler(solver={'qpu': True})
>>> bqm = dimod.BinaryQuadraticModel({'a': -1, 'b': 1, 'c': 1},
...                            {'ab': 0.8, 'ac': 0.7, 'bc': -1},
...                            0,
...                            dimod.SPIN)
>>> samples = CutOffComposite(
...     AutoEmbeddingComposite(sampler), 0.75).sample(bqm, num_reads=1000)
>>> print(samples.first.energy)
-5.5

Properties#

CutOffComposite.child

The child sampler.

CutOffComposite.children

List of child samplers that that are used by this composite.

CutOffComposite.parameters

A dict where keys are the keyword parameters accepted by the sampler methods and values are lists of the properties relevant to each parameter.

CutOffComposite.properties

A dict containing any additional information about the sampler.

Methods#

CutOffComposite.sample(bqm, **parameters)

Cut off interactions and sample from the provided binary quadratic model.

CutOffComposite.sample_ising(h, J, **parameters)

Sample from an Ising model using the implemented sample method.

CutOffComposite.sample_qubo(Q, **parameters)

Sample from a QUBO using the implemented sample method.

PolyCutOffComposite#

Prunes the polynomial submitted to the child sampler by retaining only interactions with values commensurate with the sampler’s precision.

class PolyCutOffComposite(child_sampler, cutoff, cutoff_vartype=Vartype.SPIN, comparison=<built-in function lt>)[source]#

Composite to remove polynomial interactions below a specified cutoff value.

Prunes the binary polynomial submitted to the child sampler by retaining only interactions with values commensurate with the sampler’s precision as specified by the cutoff argument. Also removes variables isolated post- or pre-removal of these interactions from the polynomial passed on to the child sampler, setting these variables to values that minimize the original polynomial’s energy for the returned samples.

Parameters:
  • sampler (dimod.PolySampler) – A dimod binary polynomial sampler.

  • cutoff (number) – Lower bound for absolute value of interactions. Interactions with absolute values lower than cutoff are removed. Isolated variables are also not passed on to the child sampler.

  • cutoff_vartype (Vartype/str/set, default=’SPIN’) –

    Variable space to do the cutoff in. Accepted input values:

    • Vartype.SPIN, 'SPIN', {-1, 1}

    • Vartype.BINARY, 'BINARY', {0, 1}

  • comparison (function, optional) – A comparison operator for comparing the interaction value to the cutoff value. Defaults to operator.lt().

Added in version 1.30.0: Support for context manager protocol with dimod.Scoped() implemented.

Examples

This example removes one interaction, 'ac': 0.2, before submitting the polynomial to child sampler ExactSolver.

>>> import dimod
>>> sampler = dimod.HigherOrderComposite(dimod.ExactSolver())
>>> poly = dimod.BinaryPolynomial({'a': 3, 'abc':-4, 'ac': 0.2}, dimod.SPIN)
>>> samples = PolyCutOffComposite(sampler, 1).sample_poly(poly)
>>> print(samples.first.sample['a'])
-1

Properties#

PolyCutOffComposite.child

The child sampler.

PolyCutOffComposite.children

List of child samplers that that are used by this composite.

PolyCutOffComposite.parameters

A dict where keys are the keyword parameters accepted by the sampler methods and values are lists of the properties relevent to each parameter.

PolyCutOffComposite.properties

A dict containing any additional information about the sampler.

Methods#

PolyCutOffComposite.sample_poly(poly, **kwargs)

Cutoff and sample from the provided binary polynomial.

PolyCutOffComposite.sample_hising(h, J, **kwargs)

Sample from a higher-order Ising model.

PolyCutOffComposite.sample_hubo(H, **kwargs)

Sample from a higher-order unconstrained binary optimization problem.

Embedding#

Minor-embed a problem BQM into a D-Wave system.

Embedding composites for various types of problems and application. For example:

AutoEmbeddingComposite#

class AutoEmbeddingComposite(child_sampler, **kwargs)[source]#

Maps problems to a structured sampler, embedding if needed.

This composite first tries to submit the binary quadratic model directly to the child sampler and only embeds if a BinaryQuadraticModelStructureError exception is raised.

Parameters:
  • child_sampler (dimod.Sampler) – Structured dimod sampler, such as a DWaveSampler().

  • find_embedding (function, optional) – A function find_embedding(S, T, **kwargs) where S and T are edgelists. The function can accept additional keyword arguments. Defaults to minorminer.find_embedding().

  • kwargs – See the EmbeddingComposite class for additional keyword arguments.

Added in version 1.30.0: Support for context manager protocol with dimod.Scoped() implemented.

Properties#

AutoEmbeddingComposite.child

The child sampler.

AutoEmbeddingComposite.parameters

Parameters in the form of a dict.

AutoEmbeddingComposite.properties

Properties in the form of a dict.

Methods#

AutoEmbeddingComposite.sample(bqm, **parameters)

Sample from the provided binary quadratic model.

AutoEmbeddingComposite.sample_ising(h, J, ...)

Sample from an Ising model using the implemented sample method.

AutoEmbeddingComposite.sample_qubo(Q, ...)

Sample from a QUBO using the implemented sample method.

EmbeddingComposite#

class EmbeddingComposite(child_sampler, find_embedding=<function find_embedding>, embedding_parameters=None, scale_aware=False, child_structure_search=<function child_structure_dfs>)[source]#

Maps problems to a structured sampler.

Automatically minor-embeds a problem into a structured sampler such as a D-Wave quantum computer. A new minor-embedding is calculated each time one of its sampling methods is called.

Parameters:
  • child_sampler (dimod.Sampler) – A dimod sampler, such as a DWaveSampler, that accepts only binary quadratic models of a particular structure.

  • find_embedding (function, optional) – A function find_embedding(S, T, **kwargs) where S and T are edgelists. The function can accept additional keyword arguments. Defaults to minorminer.find_embedding().

  • embedding_parameters (dict, optional) – If provided, parameters are passed to the embedding method as keyword arguments.

  • scale_aware (bool, optional, default=False) – Pass chain interactions to child samplers that accept an ignored_interactions parameter.

  • child_structure_search (function, optional) – A function that accepts a sampler and returns the structure attribute. Defaults to dimod.child_structure_dfs().

Added in version 1.30.0: Support for context manager protocol with dimod.Scoped() implemented.

Examples

>>> from dwave.system import DWaveSampler, EmbeddingComposite
...
>>> with EmbeddingComposite(DWaveSampler()) as sampler:
...     h = {'a': -1., 'b': 2}
...     J = {('a', 'b'): 1.5}
...     sampleset = sampler.sample_ising(h, J, num_reads=100)
...     print(sampleset.first.energy)
-4.5

Properties#

EmbeddingComposite.child

The child sampler.

EmbeddingComposite.parameters

Parameters in the form of a dict.

EmbeddingComposite.properties

Properties in the form of a dict.

EmbeddingComposite.return_embedding_default

Defines the default behavior for returning embeddings.

EmbeddingComposite.warnings_default

Defines the default behavior for warnings.

Methods#

EmbeddingComposite.sample(bqm[, ...])

Sample from the provided binary quadratic model.

EmbeddingComposite.sample_ising(h, J, ...)

Sample from an Ising model using the implemented sample method.

EmbeddingComposite.sample_qubo(Q, **parameters)

Sample from a QUBO using the implemented sample method.

FixedEmbeddingComposite#

class FixedEmbeddingComposite(child_sampler, embedding=None, source_adjacency=None, **kwargs)[source]#

Bases: LazyFixedEmbeddingComposite

Maps problems to a structured sampler with the specified minor-embedding.

Parameters:
  • child_sampler (dimod.Sampler) – Structured dimod sampler such as a D-Wave quantum computer.

  • embedding (dict[hashable, iterable], optional) – Mapping from a source graph to the specified sampler’s graph (the target graph).

  • source_adjacency (dict[hashable, iterable]) – Deprecated. Dictionary to describe source graph as {node: {node neighbours}}.

  • kwargs – See the EmbeddingComposite class for additional keyword arguments. Note that find_embedding and embedding_parameters keyword arguments are ignored.

Added in version 1.30.0: Support for context manager protocol with dimod.Scoped() implemented.

Examples

To embed a triangular problem (a problem with a three-node complete graph, or clique) in the Chimera topology, you need to chain two qubits. This example maps triangular problems to a composed sampler (based on the unstructured ExactSolver) with a Chimera unit-cell structure.

>>> import dimod
>>> import dwave_networkx as dnx
>>> from dwave.system import FixedEmbeddingComposite
...
>>> c1 = dnx.chimera_graph(1)
>>> embedding = {'a': [0, 4], 'b': [1], 'c': [5]}
>>> structured_sampler = dimod.StructureComposite(dimod.ExactSolver(),
...                                               c1.nodes, c1.edges)
>>> sampler = FixedEmbeddingComposite(structured_sampler, embedding)
>>> sampler.edgelist
[('a', 'b'), ('a', 'c'), ('b', 'c')]

Properties#

FixedEmbeddingComposite.adjacency

Adjacency structure for the composed sampler.

FixedEmbeddingComposite.child

The child sampler.

FixedEmbeddingComposite.children

List containing the structured sampler.

FixedEmbeddingComposite.edgelist

Edges available to the composed sampler.

FixedEmbeddingComposite.nodelist

Nodes available to the composed sampler.

FixedEmbeddingComposite.parameters

Parameters in the form of a dict.

FixedEmbeddingComposite.properties

Properties in the form of a dict.

FixedEmbeddingComposite.structure

Structure of the structured sampler formatted as a namedtuple() where the 3-tuple values are the nodelist, edgelist and adjacency attributes.

Methods#

FixedEmbeddingComposite.sample(bqm, **parameters)

Sample the binary quadratic model.

FixedEmbeddingComposite.sample_ising(h, J, ...)

Sample from an Ising model using the implemented sample method.

FixedEmbeddingComposite.sample_qubo(Q, ...)

Sample from a QUBO using the implemented sample method.

LazyFixedEmbeddingComposite#

class LazyFixedEmbeddingComposite(child_sampler, find_embedding=<function find_embedding>, embedding_parameters=None, scale_aware=False, child_structure_search=<function child_structure_dfs>)[source]#

Maps problems to the structure of its first given problem.

This composite reuses the minor-embedding found for its first given problem without recalculating a new minor-embedding for subsequent calls of its sampling methods.

Parameters:
  • child_sampler (dimod.Sampler) – Structured dimod sampler.

  • find_embedding (function, default=:func:minorminer.find_embedding) – A function find_embedding(S, T, **kwargs) where S and T are edgelists. The function can accept additional keyword arguments. The function is used to find the embedding for the first problem solved.

  • embedding_parameters (dict, optional) – If provided, parameters are passed to the embedding method as keyword arguments.

Added in version 1.30.0: Support for context manager protocol with dimod.Scoped() implemented.

Examples

>>> from dwave.system import LazyFixedEmbeddingComposite, DWaveSampler
...
>>> sampler = LazyFixedEmbeddingComposite(DWaveSampler())
>>> sampler.nodelist is None  # no structure prior to first sampling
True
>>> __ = sampler.sample_ising({}, {('a', 'b'): -1})
>>> sampler.nodelist  # has structure based on given problem
['a', 'b']

Properties#

LazyFixedEmbeddingComposite.adjacency

Adjacency structure for the composed sampler.

LazyFixedEmbeddingComposite.edgelist

Edges available to the composed sampler.

LazyFixedEmbeddingComposite.nodelist

Nodes available to the composed sampler.

LazyFixedEmbeddingComposite.parameters

Parameters in the form of a dict.

LazyFixedEmbeddingComposite.properties

Properties in the form of a dict.

LazyFixedEmbeddingComposite.structure

Structure of the structured sampler formatted as a namedtuple() where the 3-tuple values are the nodelist, edgelist and adjacency attributes.

Methods#

LazyFixedEmbeddingComposite.sample(bqm, ...)

Sample the binary quadratic model.

LazyFixedEmbeddingComposite.sample_ising(h, ...)

Sample from an Ising model using the implemented sample method.

LazyFixedEmbeddingComposite.sample_qubo(Q, ...)

Sample from a QUBO using the implemented sample method.

ParallelEmbeddingComposite#

class ParallelEmbeddingComposite(child_sampler, *, embeddings=None, source=None, embedder=None, embedder_kwargs=None, one_to_iterable=False, child_structure_search=<function child_structure_dfs>)[source]#

Composite to parallelize sampling of a small problem on a structured sampler

Enables parallel sampling on a (target) sampler by use of multiple disjoint embeddings. If a list of embeddings is not provided, the function find_multiple_embeddings() is called by default to attempt a maximum number of embeddings. If the target and source graph match processor architecture on a Chimera, Pegasus or Zephyr then tiling of a known embedding in a regular pattern may be a useful embedding strategy and find_sublattice_embeddings can be considered. See parallel_embeddings documentation for customizable options including specification of the time_out and maximum number of embeddings. See tests/test_parallel_embeddings.py for use cases beyond the examples provided.

Embeddings, particularly for large subgraphs of large target graphs can be difficult to obtain. Relying on the defaults of this routine may result in slow embedding, see parallel_embeddings for methods. Note that parallelization of job submissions can mitigate for network latency, programming time and readout time in the case of QPU samplers, subject to additional complexity in the embedding process.

Parameters:
  • child_sampler (Sampler) – dimod sampler such as a DWaveSampler.

  • embeddings (list, optional) – A list of embeddings. Each embedding is assumed to be a dictionary with source-graph nodes as keys and iterables on target-graph nodes to as values. The embeddings can include keys not required by the source graph. Note that one_to_iterable is ignored (assumed True).

  • source (nx.Graph, optional) – A source graph must be provided if embeddings are not specified. The source graph nodes should be supported by every embedding.

  • embedder (Callable, optional) – A function that returns embeddings when it is not provided. The first two arguments are assumed to be the source and target graph.

  • embedder_kwargs (dict, optional) – keyword arguments for the embedder function. The default is an empty dictionary.

  • one_to_iterable (bool, default=False) – This parameter should be fixed to match the value type returned by embedder. If False the values in every dictionary are target nodes (defining a subgraph embedding), these are transformed to tuples for compatibility with embed_bqm and unembed_sampleset. If True, the values are iterables over target nodes and no transformation is required.

  • child_structure_search (function, optional) – A function that accepts a sampler and returns the structure attribute. Defaults to dimod.child_structure_dfs().

Raises:

ValueError – If the child_sampler is not structured, and the structure cannot be inferred from child_structure_search. If neither embeddings, nor a source graph, are provided. If the embeddings provided are an empty list, or no embeddings are found. If embeddings and source graph nodes are inconsistent. If embeddings and target graph nodes are inconsistent.

Examples

This example submits a simple Ising problem of just two variables on a D-Wave system. We use the default subgraph embedder finding a maximum number of embeddings. Note that searching for O(1000) of embeddings takes several seconds.

>>> from dwave.system import DWaveSampler
>>> from dwave.system import ParallelEmbeddingComposite
>>> from networkx import from_edgelist
>>> embedder_kwargs = {'max_num_emb': None}  # Without this, only 1 embedding will be sought
>>> source = from_edgelist([('a', 'b')])
>>> qpu = DWaveSampler()
>>> sampler = ParallelEmbeddingComposite(qpu, source=source, embedder_kwargs=embedder_kwargs)
>>> sampleset = sampler.sample_ising({},{('a', 'b'): 1}, num_reads=1)
>>> len(sampleset) > 1  # Equal to the number of parallel embeddings
True

If an embedding can be found for a Chimera tile, we can try many dispacements on a target QPU graph (tiling). If all variables on the Chimera tile are used, and the target graph is defect free, this allows an optimal parallelization. Note that find_sublattice_embeddings should only be preferred to the default find_multiple_embeddings where the source and target graph have a special lattice relationship. Finding a large set of disjoint chimera cells within a typical processor graph can take several seconds. See tests/ for other examples.

>>> from dwave.system import DWaveSampler
>>> from dwave.system import ParallelEmbeddingComposite
>>> from dwave_networkx import chimera_graph
>>> from minorminer.utils.parallel_embeddings import find_sublattice_embeddings
>>> source = tile = chimera_graph(1, 1, 4)  # A 1:1 mapping assumed
>>> qpu = DWaveSampler()
>>> embedder = find_sublattice_embeddings
>>> embedder_kwargs = {'max_num_emb': None, 'tile': tile}
>>> sampler = ParallelEmbeddingComposite(qpu, source=source, embedder=embedder, embedder_kwargs=embedder_kwargs)
>>> J = {e: -1 for e in tile.edges}  # A ferromagnet on the Chimera tile.
>>> sampleset = sampler.sample_ising({}, J, num_reads=1)
>>> len(sampleset) > 1  # Equal to the number of parallel embeddings
True

Consider use of draw_parallel_embeddings() for visualization of the embeddings found (embeddings=sampler.embeddings over target=qpu.to_networkx_graph()).

See the Concepts section for explanations of technical terms in descriptions of Ocean tools.

TilingComposite#

class TilingComposite(sampler, sub_m, sub_n, t=4)[source]#

Composite to tile a small problem across a structured sampler.

Enables parallel sampling on Chimera or Pegasus structured samplers of small problems. The small problem should be defined on a Chimera graph of dimensions sub_m, sub_n, t, or minor-embeddable to such a graph.

Deprecated since version 1.32.0: Tiling is generalized in ParallelEmbeddingComposite to handle bigger and non-Chimera source graphs on any structured graph supported by DWaveSampler (including Zephyr). TilingComposite will be removed in dwave-system 2.0.

Notation PN referes to a Pegasus graph consisting of a 3x(N-1)x(N-1) grid of cells, where each unit cell is a bipartite graph with shore of size t, supplemented with odd couplers (see nice_coordinate definition in the pegasus_graph() function). The Advantage QPU supports a P16 Pegasus graph: its qubits may be mapped to a 3x15x15 matrix of unit cells, each of 8 qubits. This code supports tiling of Chimera-structured problems, with an option of additional odd-couplers, onto Pegasus. See also the pegasus_graph() function.

Notation CN refers to a Chimera graph consisting of an NxN grid of unit cells, where each unit cell is a bipartite graph with shores of size t. (An earlier quantum computer, the D-Wave 2000Q, supported a C16 Chimera graph: its 2048 qubits were logically mapped into a 16x16 matrix of unit cells of 8 qubits (t=4). See also the chimera_graph() function.)

A problem that can be minor-embedded in a single chimera unit cell, for example, can therefore be tiled as 3x15x15 duplicates across an Advantage QPU (or, previously, over the unit cells of a D-Wave 2000Q as 16x16 duplicates), subject to solver yield. This enables over 600 (256 for the D-Wave 2000Q) parallel samples per read.

Parameters:
  • sampler (Sampler) – Structured dimod sampler such as a DWaveSampler.

  • sub_m (int) – Minimum number of Chimera unit cell rows required for minor-embedding a single instance of the problem.

  • sub_n (int) – Minimum number of Chimera unit cell columns required for minor-embedding a single instance of the problem.

  • t (int, optional, default=4) – Size of the shore within each Chimera unit cell.

Added in version 1.30.0: Support for context manager protocol with dimod.Scoped() implemented.

Examples

This example submits a two-variable QUBO problem representing a logical NOT gate to a D-Wave system. The QUBO—two nodes with biases of -1 that are coupled with strength 2—needs only any two coupled qubits and so is easily minor-embedded in a single unit cell. Composite TilingComposite tiles it multiple times for parallel solution: the two nodes should typically have opposite values.

>>> from dwave.system import DWaveSampler, EmbeddingComposite
>>> from dwave.system import TilingComposite
...
>>> sampler = EmbeddingComposite(TilingComposite(DWaveSampler(), 1, 1, 4))
>>> Q = {(1, 1): -1, (1, 2): 2, (2, 1): 0, (2, 2): -1}
>>> sampleset = sampler.sample_qubo(Q)
>>> len(sampleset)> 1
True

See the Concepts section for explanations of technical terms in descriptions of Ocean tools.

Properties#

TilingComposite.adjacency

Adjacency structure formatted as a dict, where keys are the nodes of the structured sampler and values are sets of all adjacent nodes for each key node.

TilingComposite.child

The child sampler.

TilingComposite.children

The single wrapped structured sampler.

TilingComposite.edgelist

List of active couplers for the structured solver.

TilingComposite.embeddings

Embeddings into each available tile on the structured solver.

TilingComposite.nodelist

List of active qubits for the structured solver.

TilingComposite.num_tiles

Number of tiles available for replicating the problem.

TilingComposite.parameters

Parameters in the form of a dict.

TilingComposite.properties

Properties in the form of a dict.

TilingComposite.structure

Structure of the structured sampler formatted as a namedtuple() where the 3-tuple values are the nodelist, edgelist and adjacency attributes.

Methods#

TilingComposite.sample(bqm, **kwargs)

Sample from the specified binary quadratic model.

TilingComposite.sample_ising(h, J, **parameters)

Sample from an Ising model using the implemented sample method.

TilingComposite.sample_qubo(Q, **parameters)

Sample from a QUBO using the implemented sample method.

VirtualGraphComposite#

class VirtualGraphComposite(sampler, embedding, chain_strength=None, **kwargs)[source]#

Removed. Used to provide access to the D-Wave virtual graph feature for minor-embedding, but now is just a thin wrapper around the FixedEmbeddingComposite.

Deprecated since version 1.25.0: This class is deprecated due to improved calibration of newer QPUs and will be removed in 1.27.0; to calibrate chains for residual biases, follow the instructions in the shimming tutorial.

Removed in version 1.28.0: This class is now only a pass-through wrapper around the FixedEmbeddingComposite.

It will be completely removed in dwave-system 2.0.

For removal reasons and alternatives, see the deprecation note above.

Properties#

VirtualGraphComposite.adjacency

Adjacency structure for the composed sampler.

VirtualGraphComposite.child

The child sampler.

VirtualGraphComposite.children

List containing the structured sampler.

VirtualGraphComposite.edgelist

Edges available to the composed sampler.

VirtualGraphComposite.nodelist

Nodes available to the composed sampler.

VirtualGraphComposite.parameters

Parameters in the form of a dict.

VirtualGraphComposite.properties

Properties in the form of a dict.

VirtualGraphComposite.structure

Structure of the structured sampler formatted as a namedtuple() where the 3-tuple values are the nodelist, edgelist and adjacency attributes.

Methods#

VirtualGraphComposite.sample(bqm[, ...])

Sample the binary quadratic model.

VirtualGraphComposite.sample_ising(h, J, ...)

Sample from an Ising model using the implemented sample method.

VirtualGraphComposite.sample_qubo(Q, ...)

Sample from a QUBO using the implemented sample method.

Linear Bias#

Composite for using auxiliary qubits to bias problem qubits.

LinearAncillaComposite#

class LinearAncillaComposite(child_sampler: Sampler)[source]#

Implements linear biases as ancilla qubits polarized with strong flux biases.

Linear bias \(h_i\) of qubit \(i\) is implemented through a coupling \(J_{ij}\) between the qubit and a neighboring qubit \(j\) that has a large flux-bias offset.

Parameters:

child_sampler (dimod.Sampler) – A dimod sampler, such as a DWaveSampler(), that has flux bias controls.

Added in version 1.30.0: Support for context manager protocol with dimod.Scoped() implemented.

Examples

This example submits a two-qubit problem consisting of linear biases with opposed signs and anti-ferromagnetic coupling. A D-Wave quantum computer solves it with the fast-anneal protocol using ancilla qubits to represent the linear biases.

>>> from dwave.system import DWaveSampler, EmbeddingComposite, LinearAncillaComposite
...
>>> with EmbeddingComposite(LinearAncillaComposite(DWaveSampler())) as sampler:   
...     sampleset = sampler.sample_ising({0:1, 1:-1}, {(0, 1): 1}, fast_anneal=True)
...     sampleset.first.energy
-3

Properties#

LinearAncillaComposite.child

The child sampler.

LinearAncillaComposite.children

List containing the structured sampler.

LinearAncillaComposite.parameters

Parameters in the form of a dict.

LinearAncillaComposite.properties

Properties in the form of a dict.

Methods#

LinearAncillaComposite.sample(bqm, *[, ...])

Sample from the provided binary quadratic model.

LinearAncillaComposite.sample_ising(h, J, ...)

Sample from an Ising model using the implemented sample method.

LinearAncillaComposite.sample_qubo(Q, ...)

Sample from a QUBO using the implemented sample method.

Reverse Anneal#

Composites that do batch operations for reverse annealing based on sets of initial states or anneal schedules.

ReverseBatchStatesComposite#

class ReverseBatchStatesComposite(child_sampler)[source]#

Composite that reverse anneals from multiple initial samples.

Each submission is independent from one another.

Parameters:

sampler (Sampler) – A dimod sampler.

Added in version 1.30.0: Support for context manager protocol with dimod.Scoped() implemented.

Examples

This example runs three reverse anneals from two configured and one randomly generated initial states on a problem constructed by setting random \(\pm 1\) values on a clique (complete graph) of 15 nodes, minor-embedded on a D-Wave system using the DWaveCliqueSampler sampler.

>>> import dimod
>>> from dwave.system import DWaveCliqueSampler, ReverseBatchStatesComposite
...
>>> sampler = DWaveCliqueSampler()      
>>> sampler_reverse = ReverseBatchStatesComposite(sampler)    
>>> schedule = [[0.0, 1.0], [10.0, 0.5], [20, 1.0]]
...
>>> bqm = dimod.generators.ran_r(1, 15)
>>> init_samples = [{i: -1 for i in range(15)}, {i: 1 for i in range(15)}]
>>> sampleset = sampler_reverse.sample(bqm,
...                                    anneal_schedule=schedule,
...                                    initial_states=init_samples,
...                                    num_reads=3,
...                                    reinitialize_state=True)   

Properties#

ReverseBatchStatesComposite.child

The child sampler.

ReverseBatchStatesComposite.children

List of child samplers that that are used by this composite.

ReverseBatchStatesComposite.parameters

Parameters as a dict, where keys are keyword parameters accepted by the sampler methods and values are lists of the properties relevent to each parameter.

ReverseBatchStatesComposite.properties

Properties as a dict containing any additional information about the sampler.

Methods#

ReverseBatchStatesComposite.sample(bqm[, ...])

Sample the binary quadratic model using reverse annealing from multiple initial states.

ReverseBatchStatesComposite.sample_ising(h, ...)

Sample from an Ising model using the implemented sample method.

ReverseBatchStatesComposite.sample_qubo(Q, ...)

Sample from a QUBO using the implemented sample method.

ReverseAdvanceComposite#

class ReverseAdvanceComposite(child_sampler)[source]#

Composite that reverse anneals an initial sample through a sequence of anneal schedules.

If you do not specify an initial sample, a random sample is used for the first submission. By default, each subsequent submission selects the most-found lowest-energy sample as its initial state. If you set reinitialize_state to False, which makes each submission behave like a random walk, the subsequent submission selects the last returned sample as its initial state.

Parameters:

sampler (dimod.Sampler) – A dimod sampler.

Added in version 1.30.0: Support for context manager protocol with dimod.Scoped() implemented.

Examples

This example runs 100 reverse anneals each for three schedules on a problem constructed by setting random \(\pm 1\) values on a clique (complete graph) of 15 nodes, minor-embedded on a D-Wave system using the DWaveCliqueSampler sampler.

>>> import dimod
>>> from dwave.system import DWaveCliqueSampler, ReverseAdvanceComposite
...
>>> sampler = DWaveCliqueSampler()     
>>> sampler_reverse = ReverseAdvanceComposite(sampler)    
>>> schedule = [[[0.0, 1.0], [t, 0.5], [20, 1.0]] for t in (5, 10, 15)]
...
>>> bqm = dimod.generators.ran_r(1, 15)
>>> init_samples = {i: -1 for i in range(15)}
>>> sampleset = sampler_reverse.sample(bqm,
...                                    anneal_schedules=schedule,
...                                    initial_state=init_samples,
...                                    num_reads=100,
...                                    reinitialize_state=True)     

Properties#

ReverseAdvanceComposite.child

The child sampler.

ReverseAdvanceComposite.children

List of child samplers that that are used by this composite.

ReverseAdvanceComposite.parameters

Parameters as a dict, where keys are keyword parameters accepted by the sampler methods and values are lists of the properties relevent to each parameter.

ReverseAdvanceComposite.properties

Properties as a dict containing any additional information about the sampler.

Methods#

ReverseAdvanceComposite.sample(bqm[, ...])

Sample the binary quadratic model using reverse annealing along a given set of anneal schedules.

ReverseAdvanceComposite.sample_ising(h, J, ...)

Sample from an Ising model using the implemented sample method.

ReverseAdvanceComposite.sample_qubo(Q, ...)

Sample from a QUBO using the implemented sample method.