GithubHelp home page GithubHelp logo

jberwald / pyqubo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from recruit-communications/pyqubo

1.0 2.0 0.0 262 KB

Python DSL for constructing QUBOs from mathematical expressions.

License: Apache License 2.0

Makefile 0.39% Jupyter Notebook 29.95% Python 69.66%

pyqubo's Introduction

https://readthedocs.org/projects/pyqubo/badge/?version=latest https://circleci.com/gh/recruit-communications/pyqubo.svg?style=svg

PyQUBO

PyQUBO allows you to create QUBOs or Ising models from flexible mathematical expressions easily. Some of the features of PyQUBO are

  • Python-based (the entire code is written in Python).
  • QUBO generation (compile) is fast (due to the JIT like compile mechanism).
  • Comes with plenty of useful expressions such as binary integer variables, logical constraints, or matrix/vector variables.

For more details, see PyQUBO Documentation.

Example Usage

This example constructs a simple expression and compile it to model. By calling model.to_qubo(), we get the resulting QUBO. (This example solves a number partitioning problem with a set S = {4, 2, 7, 1})

>>> from pyqubo import Spin
>>> s1, s2, s3, s4 = Spin("s1"), Spin("s2"), Spin("s3"), Spin("s4")
>>> H = (4*s1 + 2*s2 + 7*s3 + s4)**2
>>> model = H.compile()
>>> qubo, offset = model.to_qubo()
>>> pprint(qubo)
{('s1', 's1'): -160.0,
 ('s1', 's2'): 64.0,
 ('s1', 's3'): 224.0,
 ('s1', 's4'): 32.0,
 ('s2', 's2'): -96.0,
 ('s2', 's3'): 112.0,
 ('s2', 's4'): 16.0,
 ('s3', 's3'): -196.0,
 ('s3', 's4'): 56.0,
 ('s4', 's4'): -52.0}

Installation

pip install pyqubo

or

python setup.py install

Supported Python Versions

Python 2.7, 3.4, 3.5, 3.6 and 3.7 are supported.

Test

Run all tests.

python -m unittest discover test

Show coverage report.

coverage run -m unittest discover
coverage html

Run test with circleci CLI.

circleci build --job $JOBNAME

Run doctest.

make doctest

Organization

Recruit Communications Co., Ltd.

Licence

Released under the Apache License 2.0.

Contribution

We welcome contributions to this project.

pyqubo's People

Contributors

kotarotanahashi avatar

Stargazers

 avatar

Watchers

James Cloos avatar Jesse Berwald avatar

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.