Skip to content

fionahanington/dimod

 
 

Repository files navigation

dimod

https://travis-ci.org/dwavesystems/dimod.svg?branch=master https://ci.appveyor.com/api/projects/status/kfhg35q12fa0lux8?svg=true https://coveralls.io/repos/github/dwavesystems/dimod/badge.svg?branch=master

A shared API for QUBO/Ising samplers.

Included Samplers

dimod comes with a few samplers that are useful as reference implementations and for unit testing.

Basic Usage

>>> import dimod
>>> sampler = dimod.SimulatedAnnealingSampler()
>>> Q = {(0, 0): 1, (1, 1): 1, (0, 1): -1}
>>> response = sampler.sample_qubo(Q)
>>> h = {0: 1, 1 : 1}
>>> J = {(0, 1): -1}
>>> spin_response = sampler.sample_ising(h, J)

The response object returned has many ways to access the information

>>> list(response)  # your results might vary
[{0: 0.0, 1: 0.0}, {0: 0.0, 1: 0.0}, {0: 0.0, 1: 0.0}, {0: 0.0, 1: 0.0}, {0: 0.0, 1: 0.0}, {0: 1.0, 1: 0.0}, {0: 1.0, 1: 0.0}, {0: 0.0, 1: 1.0}, {0: 0.0, 1: 1.0}, {0: 1.0, 1: 1.0}]
>>> list(response.samples())
[{0: 0.0, 1: 0.0}, {0: 0.0, 1: 0.0}, {0: 0.0, 1: 0.0}, {0: 0.0, 1: 0.0}, {0: 0.0, 1: 0.0}, {0: 1.0, 1: 0.0}, {0: 1.0, 1: 0.0}, {0: 0.0, 1: 1.0}, {0: 0.0, 1: 1.0}, {0: 1.0, 1: 1.0}]
>>> list(response.energies())
[0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0]
>>> list(response.items())  # samples and energies
[({0: 0.0, 1: 0.0}, 0.0), ({0: 0.0, 1: 0.0}, 0.0), ({0: 0.0, 1: 0.0}, 0.0), ({0: 0.0, 1: 0.0}, 0.0), ({0: 0.0, 1: 0.0}, 0.0), ({0: 1.0, 1: 0.0}, 1.0), ({0: 1.0, 1: 0.0}, 1.0), ({0: 0.0, 1: 1.0}, 1.0), ({0: 0.0, 1: 1.0}, 1.0), ({0: 1.0, 1: 1.0}, 1.0)]

See documentation for more examples.

Install

Compatible with Python 2 and 3:

$ pip install dimod

To install with optional components:

$ pip install dimod[all]

To install from source:

$ python setup.py install

License

Released under the Apache License 2.0. See LICENSE.txt

About

A shared API for QUBO/Ising samplers.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 92.8%
  • PowerShell 4.9%
  • Batchfile 2.3%