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 system—and higher-order (non-quadratic) models.
reference examples of samplers and composed samplers.
abstract base classes for constructing new samplers and composed samplers.
(For explanations of the terminology, see the Ocean glossary.)
Example Usage#
Find all solutions to a two-variable BQM using dimod’s
ExactSolver
reference
sampler, a brute-force solver useful for testing code on small problems.
>>> 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]
Documentation#
- Date:
Dec 06, 2024
Note
This documentation is for the latest version of dimod. Documentation for the version currently installed by dwave-ocean-sdk is here: dimod.