Higher-Order Samplers#

The dimod package includes the following example higher-order samplers.

Exact Polynomial Solver#

A simple exact solver for testing and debugging code using your local CPU.

Note:

This sampler is designed for use in testing. Because it calculates the energy for every possible sample, it is very slow.

Class#

class ExactPolySolver[source]#

A simple exact polynomial solver for testing/debugging code on your CPU.

Notes

This solver becomes slow for problems with 18 or more variables.

Examples

This example solves a three-variable hising model.

>>> h = {'a': -0.5, 'b': 1.0, 'c': 0.}
>>> J = {('a', 'b'): -1.5, ('a', 'b', 'c'): -1.0}
>>> sampleset = dimod.ExactPolySolver().sample_hising(h, J)
>>> print(sampleset)                                
   a  b  c energy num_oc.
1 -1 -1 +1   -3.0       1
5 +1 +1 +1   -2.0       1
0 -1 -1 -1   -1.0       1
3 +1 -1 -1   -1.0       1
4 +1 +1 -1    0.0       1
2 +1 -1 +1    1.0       1
7 -1 +1 -1    2.0       1
6 -1 +1 +1    4.0       1
['SPIN', 8 rows, 8 samples, 3 variables]

This example solves a three-variable binary polynomial

>>> poly = dimod.BinaryPolynomial({('a',): 1.5, ('a', 'b'): -1, ('a', 'b', 'c'): 0.5}, 'SPIN')
>>> sampleset = dimod.ExactPolySolver().sample_poly(poly)
>>> sampleset.first.sample
{'a': -1, 'b': -1, 'c': -1}

Methods#

ExactPolySolver.sample_hising(h, J, **kwargs)

Sample from a higher-order Ising model.

ExactPolySolver.sample_hubo(H, **kwargs)

Sample from a higher-order unconstrained binary optimization problem.

ExactPolySolver.sample_poly(polynomial, **kwargs)

Sample from a binary polynomial.