dimod#

Reference documentation for dimod:

About dimod#

dimod is a shared API for samplers. It provides:

  • Classes for quadratic models—such as the binary quadratic model (BQM) class that contains Ising and QUBO models used by samplers such as the D-Wave quantum computer—and higher-order (non-quadratic) models.

  • Reference examples of samplers and composed samplers.

  • Abstract base classes for constructing new samplers and composed samplers.

>>> import dimod
...
>>> # Construct a problem
>>> bqm = dimod.BinaryQuadraticModel({0: -1, 1: 1}, {(0, 1): 2}, 0.0, dimod.BINARY)
...
>>> # Use dimod's brute force solver to solve the problem
>>> sampleset = dimod.ExactSolver().sample(bqm)
>>> print(sampleset)
   0  1 energy num_oc.
1  1  0   -1.0       1
0  0  0    0.0       1
3  0  1    1.0       1
2  1  1    2.0       1
['BINARY', 4 rows, 4 samples, 2 variables]

For explanations of the terminology, see the Concepts section.

Usage Information#

Data Structure#

Quadratic models are implemented with an adjacency structure in which each variable tracks its own linear bias and its neighborhood. The figure below shows the graph and adjacency representations for an example BQM,

\[E(x) = .5 x_0 - 3 x_1 - x_0 x_1 + x_0 x_2 + 2 x_0 x_3 + x_2 x_3\]
Adjacency Structure

Fig. 203 Adjacency structure of a 4-variable binary quadratic model.#