# dwave.embedding.chain_breaks.MinimizeEnergy¶

class MinimizeEnergy(bqm, embedding)[source]

Unembed samples by minimizing local energy for broken chains.

Parameters: bqm (BinaryQuadraticModel) – Binary quadratic model associated with the source graph. 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.

Examples

This example embeds from a triangular graph to a square graph, chaining target-nodes 2 and 3 to represent source-node c, and unembeds minimizing the energy for the samples. The first two sample have unbroken chains, the second two have broken chains.

>>> import dimod
>>> import numpy as np
...
>>> h = {'a': 0, 'b': 0, 'c': 0}
>>> J = {('a', 'b'): 1, ('b', 'c'): 1, ('a', 'c'): 1}
>>> embedding = {'a': , 'b': , 'c': [2, 3]}
>>> cbm = dwave.embedding.MinimizeEnergy(bqm, embedding)
>>> samples = np.array([[+1, -1, +1, +1],
...                     [-1, -1, -1, -1],
...                     [-1, -1, +1, -1],
...                     [+1, +1, -1, +1]], dtype=np.int8)
>>> chains = [embedding['a'], embedding['b'], embedding['c']]
>>> unembedded, idx = cbm(samples, chains)
>>> unembedded
array([[ 1, -1,  1],
[-1, -1, -1],
[-1, -1,  1],
[ 1,  1, -1]], dtype=int8)
>>> idx
array([0, 1, 2, 3])

__call__(samples, chains)[source]
Parameters: samples (samples_like) – A collection of samples. samples_like is an extension of NumPy’s array_like. See dimod.as_samples(). chains (list[array_like]) – List of chains, where each chain is an array_like collection of the variables in the same order as their represention in the given samples. A 2-tuple containing: numpy.ndarray: Unembedded samples as an nS-by-nC array of dtype ‘int8’, where nC is the number of chains and nS the number of samples. Broken chains are resolved by greedy energy descent. numpy.ndarray: Indicies of the samples. Equivalent to np.arange(nS) because all samples are kept and none added. tuple