Skip to main content

PyQUBO allows you to create QUBOs or Ising models from mathematical expressions.

Project description

https://img.shields.io/pypi/v/pyqubo.svg https://codecov.io/gh/recruit-communications/pyqubo/branch/master/graph/badge.svg 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.

  • QUBO generation (compile) is fast.

  • Automatic validation of constraints. (details)

  • Placeholder for parameter tuning. (details)

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 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}

For more examples, see example notebooks.

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. See CONTRIBUTING.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyqubo-0.3.0.tar.gz (32.6 kB view details)

Uploaded Source

File details

Details for the file pyqubo-0.3.0.tar.gz.

File metadata

  • Download URL: pyqubo-0.3.0.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for pyqubo-0.3.0.tar.gz
Algorithm Hash digest
SHA256 9b57fdba4837b76176610664acde05291421a3f80222fd6d43ddd904778578fc
MD5 bc474be1458daa75b36d91b0e3d96d94
BLAKE2b-256 d12ab7ffc945602980a63aeffbb9f5e900388b96005e8b573e7f1b76993e5608

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page