Giter Club home page Giter Club logo

dwave-greedy's Introduction

Linux/MacOS/Windows build status Code coverage Documentation status Latest version on PyPI PyPI - Python Version

dwave-greedy

An implementation of a steepest descent solver for binary quadratic models.

Steepest descent is the discrete analogue of gradient descent, but the best move is computed using a local minimization rather rather than computing a gradient. At each step, we determine the dimension along which to descend based on the highest energy drop caused by a variable flip.

>>> import greedy
...
>>> solver = greedy.SteepestDescentSolver()
>>> sampleset = solver.sample_ising({0: 2, 1: 2}, {(0, 1): -1})
...
>>> print(sampleset)
    0  1 energy num_oc.
0 -1 -1   -5.0       1
['SPIN', 1 rows, 1 samples, 2 variables]

Installation

Install from a package on PyPI:

pip install dwave-greedy

or install from source:

pip install git+https://github.com/dwavesystems/dwave-greedy.git#egg=dwave-greeedy

Note: installation from source involves a "cythonization" step. To install project requirements automatically, make sure to use a PEP-517 compliant pip, e.g. pip>=10.0.

To build from source:

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

Examples

Simple frustrated Ising triangle:

import dimod
import greedy

# Construct a simple problem
bqm = dimod.BQM.from_qubo({'ab': 1, 'bc': 1, 'ca': 1})

# Instantiate the sampler
sampler = greedy.SteepestDescentSampler()

# Solve the problem
result = sampler.sample(bqm)

Large RAN1 sparse problem (requires NetworkX package):

import dimod
import greedy
import networkx

# Generate random Erdős-Rényi sparse graph with 10% density
graph = networkx.fast_gnp_random_graph(n=1000, p=0.1)

# Generate RAN1 problem on the sparse graph
bqm = dimod.generators.random.ran_r(r=1, graph=graph)

# Instantiate the sampler
sampler = greedy.SteepestDescentSampler()

# Run steepest descent for 100 times, each time from a random state
sampleset = sampler.sample(bqm, num_reads=100)

# Print the best energy
print(min(sampleset.record.energy))

License

Released under the Apache License 2.0. See LICENSE file.

Contributing

Ocean's contributing guide has guidelines for contributing to Ocean packages.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.