dimod.embedding.discard¶
-
discard(sample, embedding)[source]¶ Discard the sample if a chain is broken.
Parameters: - sample (Mapping) – Sample as a dict of form {t: val, …}, where t is a variable in the target graph 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-model variable and t is a target-model variable.
Yields: dict – The unembedded sample if no chains were broken.
Examples
This example unembeds a sample from a target graph that chains nodes 0 and 1 to represent source node a. The first sample has an unbroken chain, the second a broken chain.
>>> import dimod >>> embedding = {'a': {0, 1}, 'b': {2}} >>> samples = {0: 1, 1: 1, 2: 0} >>> next(dimod.embedding.discard(samples, embedding), 'No sample') {'a': 1, 'b': 0} >>> samples = {0: 1, 1: 0, 2: 0} >>> next(dimod.embedding.discard(samples, embedding), 'No sample') 'No sample'