def sample_poly(self, poly, **kwargs):
        """Cutoff and sample from the provided binary polynomial.

        Removes interactions smaller than a given cutoff. Isolated
        variables (after the cutoff) are also removed.

        Note that if the problem had isolated variables before the cutoff, they
        will also be affected.

        Args:
            poly (:obj:`dimod.BinaryPolynomial`):
                Binary polynomial to be sampled from.

            **parameters:
                Parameters for the sampling method, specified by the child sampler.

        Returns:
            :obj:`dimod.SampleSet`

        """
        child = self.child
        cutoff = self._cutoff
        cutoff_vartype = self._cutoff_vartype
        comp = self._comparison

        if cutoff_vartype is dimod.SPIN:
            original = poly.to_spin(copy=False)
        else:
            original = poly.to_binary(copy=False)

        # remove all of the terms of order >= 2 that have a bias less than cutoff
        new = type(poly)(((term, bias) for term, bias in original.items()
                          if len(term) > 1 and not comp(abs(bias), cutoff)),
                         cutoff_vartype)

        # also include the linear biases for the variables in new
        for v in new.variables:
            term = v,
            if term in original:
                new[term] = original[term]

        # everything else is isolated
        isolated = list(original.variables.difference(new.variables))

        if isolated and len(new) == 0:
            # in this case all variables are isolated, so we just put one back
            # to serve as the basis
            term = isolated.pop(),
            new[term] = original[term]

        # get the samples from the child sampler and put them into the original vartype
        sampleset = child.sample_poly(new, **kwargs).change_vartype(poly.vartype, inplace=True)

        # we now need to add the isolated back in, in a way that minimizes
        # the energy. There are lots of ways to do this but for now we'll just
        # do one
        if isolated:
            samples, variables = _restore_isolated_higherorder(sampleset, poly, isolated)
        else:
            samples = sampleset.record.sample
            variables = sampleset.variables

        vectors = sampleset.data_vectors
        vectors.pop('energy')  # we're going to recalculate the energy anyway

        return dimod.SampleSet.from_samples_bqm((samples, variables), poly, **vectors)
def sample_poly ( self , poly , ** kwargs ) : child = self . child cutoff = self . _cutoff cutoff_vartype = self . _cutoff_vartype comp = self . _comparison if cutoff_vartype is dimod . SPIN : original = poly . to_spin ( copy = False ) else : original = poly . to_binary ( copy = False ) new = type ( poly ) ( ( ( term , bias ) for term , bias in original . items ( ) if len ( term ) > 1 and not comp ( abs ( bias ) , cutoff ) ) , cutoff_vartype ) for v in new . variables : term = v , if term in original : new [ term ] = original [ term ] isolated = list ( original . variables . difference ( new . variables ) ) if isolated and len ( new ) == 0 : term = isolated . pop ( ) , new [ term ] = original [ term ] sampleset = child . sample_poly ( new , ** kwargs ) . change_vartype ( poly . vartype , inplace = True ) if isolated : samples , variables = _restore_isolated_higherorder ( sampleset , poly , isolated ) else : samples = sampleset . record . sample variables = sampleset . variables vectors = sampleset . data_vectors vectors . pop ( 'energy' ) return dimod . SampleSet . from_samples_bqm ( ( samples , variables ) , poly , ** vectors )
Cutoff and sample from the provided binary polynomial.

        Removes interactions smaller than a given cutoff. Isolated
        variables (after the cutoff) are also removed.

        Note that if the problem had isolated variables before the cutoff, they
        will also be affected.

        Args:
            poly (:obj:`dimod.BinaryPolynomial`):
                Binary polynomial to be sampled from.

            **parameters:
                Parameters for the sampling method, specified by the child sampler.

        Returns:
            :obj:`dimod.SampleSet`