dimod.embedding.MinimizeEnergy

class MinimizeEnergy(linear=None, quadratic=None)[source]

Determine the sample values of broken chains by minimizing local energy.

Parameters:
  • linear (dict) – Linear biases of the source model as a dict of form {s: bias, …}, where s is a source-model variable and bias its associated linear bias.
  • quadratic (dict) – Quadratic biases of the source model as a dict of form {(u, v): bias, …}, where u, v are source-model variables and bias the associated quadratic bias.

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 using the MinimizeEnergy method four synthetic samples. The first two sample have unbroken chains, the second two have broken chains.

>>> import dimod
>>> h = {'a': 0, 'b': 0, 'c': 0}
>>> J = {('a', 'b'): 1, ('b', 'c'): 1, ('a', 'c'): 1}
>>> embedding = {'a': {0}, 'b': {1}, 'c': {2, 3}}
>>> method = dimod.embedding.MinimizeEnergy(h, J)
>>> samples = [{0: +1, 1: -1, 2: +1, 3: +1},
...            {0: -1, 1: -1, 2: -1, 3: -1},
...            {0: -1, 1: -1, 2: +1, 3: -1},
...            {0: +1, 1: +1, 2: -1, 3: +1}]
...
>>> for source_sample in dimod.iter_unembed(samples, embedding, chain_break_method=method):  
...     print(source_sample)
...
{'a': 1, 'c': 1, 'b': -1}
{'a': -1, 'c': -1, 'b': -1}
{'a': -1, 'c': 1, 'b': -1}
{'a': 1, 'c': -1, 'b': 1}
__call__(sample, embedding)[source]
Parameters:
  • sample (dict) – Sample as a dict of form {t: val, …}, where t is a target-graph variable and val its associated value as determined by a binary quadratic model sampler.
  • embedding (dict) – Mapping from source graph to target graph as a dict of form {s: {t, …}, …} where s is a source-graph node and t is a target-graph node.
Yields:

dict – The unembedded sample. When there is a chain break, the value is chosen to minimize the energy relative to its neighbors.