dwave.embedding.unembed_sampleset

unembed_sampleset(target_sampleset, embedding, source_bqm, chain_break_method=None, chain_break_fraction=False, return_embedding=False)[source]

Unembed a samples set.

Given samples from a target binary quadratic model (BQM), construct a sample set for a source BQM by unembedding.

Parameters:
  • target_sampleset (dimod.SampleSet) – Sample set from the target BQM.
  • embedding (dict) – Mapping from source graph to target graph as a dict of form {s: {t, …}, …}, where s is a source variable and t is a target variable.
  • source_bqm (dimod.BinaryQuadraticModel) – Source BQM.
  • chain_break_method (function/list, optional) – Method or methods used to resolve chain breaks. If multiple methods are given, the results are concatenated and a new field called “chain_break_method” specifying the index of the method is appended to the sample set. Defaults to majority_vote(). See dwave.embedding.chain_breaks.
  • chain_break_fraction (bool, optional, default=False) – Add a chain_break_fraction field to the unembedded dimod.SampleSet with the fraction of chains broken before unembedding.
  • return_embedding (bool, optional, default=False) – If True, the embedding is added to dimod.SampleSet.info of the returned sample set. Note that if an embedding key already exists in the sample set then it is overwritten.
Returns:

Sample set in the source BQM.

Return type:

SampleSet

Examples

This example unembeds from a square target graph samples of a triangular source BQM.

>>> # Triangular binary quadratic model and an embedding
>>> J = {('a', 'b'): -1, ('b', 'c'): -1, ('a', 'c'): -1}
>>> bqm = dimod.BinaryQuadraticModel.from_ising({}, J)
>>> embedding = {'a': [0, 1], 'b': [2], 'c': [3]}
>>> # Samples from the embedded binary quadratic model
>>> samples = [{0: -1, 1: -1, 2: -1, 3: -1},  # [0, 1] is unbroken
...            {0: -1, 1: +1, 2: +1, 3: +1}]  # [0, 1] is broken
>>> energies = [-3, 1]
>>> embedded = dimod.SampleSet.from_samples(samples, dimod.SPIN, energies)
>>> # Unembed
>>> samples = dwave.embedding.unembed_sampleset(embedded, embedding, bqm)
>>> samples.record.sample   # doctest: +SKIP
array([[-1, -1, -1],
       [ 1,  1,  1]], dtype=int8)