dwave.embedding.embed_bqm

embed_bqm(source_bqm, embedding, target_adjacency, chain_strength=1.0, smear_vartype=None)[source]

Embed a binary quadratic model onto a target graph.

Parameters:
  • source_bqm (BinaryQuadraticModel) – Binary quadratic model to embed.
  • embedding (dict) – Mapping from source graph to target graph as a dict of form {s: {t, …}, …}, where s is a source-model variable and t is a target-model variable.
  • target_adjacency (dict/networkx.Graph) – Adjacency of the target graph as a dict of form {t: Nt, …}, where t is a variable in the target graph and Nt is its set of neighbours.
  • chain_strength (float, optional) – Magnitude of the quadratic bias (in SPIN-space) applied between variables to create chains, with the energy penalty of chain breaks set to 2 * chain_strength.
  • smear_vartype (Vartype, optional, default=None) – Determines whether the linear bias of embedded variables is smeared (the specified value is evenly divided as biases of a chain in the target graph) in SPIN or BINARY space. Defaults to the Vartype of source_bqm.
Returns:

Target binary quadratic model.

Return type:

BinaryQuadraticModel

Examples

This example embeds a triangular binary quadratic model representing a \(K_3\) clique into a square target graph by mapping variable c in the source to nodes 2 and 3 in the target.

>>> import networkx as nx
...
>>> target = nx.cycle_graph(4)
>>> # Binary quadratic model for a triangular source graph
>>> h = {'a': 0, 'b': 0, 'c': 0}
>>> J = {('a', 'b'): 1, ('b', 'c'): 1, ('a', 'c'): 1}
>>> bqm = dimod.BinaryQuadraticModel.from_ising(h, J)
>>> # Variable c is a chain
>>> embedding = {'a': {0}, 'b': {1}, 'c': {2, 3}}
>>> # Embed and show the chain strength
>>> target_bqm = dwave.embedding.embed_bqm(bqm, embedding, target)
>>> target_bqm.quadratic[(2, 3)]
-1.0
>>> print(target_bqm.quadratic)  # doctest: +SKIP
{(0, 1): 1.0, (0, 3): 1.0, (1, 2): 1.0, (2, 3): -1.0}