mdecandia / dimod

A shared API for QUBO/Ising samplers.

Home Page:http://dimod.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

https://ci.appveyor.com/api/projects/status/2oc8vrxxh15ecgo1?svg=true https://readthedocs.org/projects/dimod/badge/?version=latest https://circleci.com/gh/dwavesystems/dimod.svg?style=svg

dimod

dimod is a shared API for binary quadratic samplers. It provides a binary quadratic model (BQM) class that contains Ising and quadratic unconstrained binary optimization (QUBO) models used by samplers such as the D-Wave system. It also provides utilities for constructing new samplers and composed samplers and for minor-embedding. Its reference examples include several samplers and composed samplers.

Learn more about dimod on Read the Docs.

Example Usage

This example constructs a simple QUBO and converts it to Ising format.

>>> import dimod
>>> bqm = dimod.BinaryQuadraticModel({0: -1, 1: -1}, {(0, 1): 2}, 0.0, dimod.BINARY)  # QUBO
>>> bqm_ising = bqm.change_vartype(dimod.SPIN, inplace=False)  # Ising

This example uses one of dimod's test samplers, ExactSampler, a solver that calculates the energies of all possible samples.

>>> import dimod
>>> h = {0: 0.0, 1: 0.0}
>>> J = {(0, 1): -1.0}
>>> bqm = dimod.BinaryQuadraticModel.from_ising(h, J)
>>> response = dimod.ExactSolver().sample(bqm)
>>> response.samples_matrix
matrix([[-1, -1],
        [ 1, -1],
        [ 1,  1],
        [-1,  1]])

See the documentation for more examples.

Installation

Compatible with Python 2 and 3:

pip install dimod

To install with optional components:

pip install dimod[all]

To install from source:

pip install -r requirements.txt
python setup.py install

License

Released under the Apache License 2.0. See LICENSE file.

Contribution

See CONTRIBUTING.rst file.

About

A shared API for QUBO/Ising samplers.

http://dimod.readthedocs.io/en/latest/

License:Apache License 2.0


Languages

Language:Python 100.0%