dwave.embedding.embed_bqm#
- embed_bqm(source_bqm, embedding=None, target_adjacency=None, chain_strength=None, smear_vartype=None)[source]#
Embed a binary quadratic model onto a target graph.
- Parameters:
source_bqm (
BinaryQuadraticModel) – Binary quadratic model (BQM) to embed.embedding (dict/
EmbeddedStructure) – Mapping from source graph to target graph as a dict of form{s: {t, ...}, ...}, wheresis a source-model variable andtis a target-model variable. Alternately, anEmbeddedStructureobject produced by, for example,EmbeddedStructure(target_adjacency.edges(), embedding). Ifembeddingis a dict,target_adjacencymust be provided.target_adjacency (dict/
networkx.Graph, optional) – Adjacency of the target graph as a dict of form{t: Nt, ...}, wheretis a variable in the target graph andNtis its set of neighbors. Omit if and only ifembeddingis anEmbeddedStructureobject.chain_strength (float/mapping/callable, optional) – Sets the coupling strength between qubits representing variables that form a chain. Mappings should specify the required chain strength for each variable. Callables should accept the BQM and embedding and return a float or mapping. By default,
chain_strengthis calculated withuniform_torque_compensation().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 theVartypeofsource_bqm.
- Returns:
Target binary quadratic model.
- Return type:
Examples
This example embeds a triangular binary quadratic model representing a \(K_3\) clique into a square target graph by mapping variable
cin the source to nodes 2 and 3 in the target.>>> import dimod >>> import networkx as nx >>> from dwave.embedding import embed_bqm ... >>> 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 = embed_bqm(bqm, embedding, target) >>> print(target_bqm.quadratic[(2, 3)]) -1.9996979771955565
See also