dwave.embedding.chain_breaks.discard

discard(samples, chains)[source]

Discard broken chains.

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.

Returns

A 2-tuple containing:

numpy.ndarray: Unembedded samples as an array of dtype ‘int8’. Broken chains are discarded.

numpy.ndarray: Indicies of rows with unbroken chains.

Return type

tuple

Examples

This example unembeds two samples that chains nodes 0 and 1 to represent a single source node. The first sample has an unbroken chain, the second a broken chain.

>>> import dimod
>>> import numpy as np
...
>>> chains = [(0, 1), (2,)]
>>> samples = np.array([[1, 1, 0], [1, 0, 0]], dtype=np.int8)
>>> unembedded, idx = dwave.embedding.discard(samples, chains)
>>> unembedded
array([[1, 0]], dtype=int8)
>>> print(idx)
[0]