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 (C++ backend).

  • Fully integrated with Ocean SDK. (details)

  • Automatic validation of constraints. (details)

  • Placeholder for parameter tuning. (details)

For more details, see PyQUBO Documentation.

Example Usage

Creating QUBO

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,
('s2', 's2'): -96.0,
('s3', 's1'): 224.0,
('s3', 's2'): 112.0,
('s3', 's3'): -196.0,
('s4', 's1'): 32.0,
('s4', 's2'): 16.0,
('s4', 's3'): 56.0,
('s4', 's4'): -52.0}

Integration with D-Wave Ocean

PyQUBO can output the BinaryQuadraticModel(BQM) which is compatible with Sampler class defined in D-Wave Ocean SDK. In the example below, we solve the problem with SimulatedAnnealingSampler.

>>> import neal
>>> sampler = neal.SimulatedAnnealingSampler()
>>> bqm = model.to_bqm()
>>> sampleset = sampler.sample(bqm, num_reads=10)
>>> decoded_samples = model.decode_sampleset(sampleset)
>>> best_sample = min(decoded_samples, key=lambda x: x.energy)
>>> best_sample.sample # doctest: +SKIP
{'s1': 0, 's2': 0, 's3': 1, 's4': 0}

If you want to solve the problem by actual D-Wave machines, just replace the sampler by a DWaveCliqueSampler instance, for example.

For more examples, see example notebooks.

Installation

pip install pyqubo

or

python setup.py install

Supported Python Versions

Python 3.5, 3.6, 3.7 and 3.8 are supported.

Supported Operating Systems

  • Linux (32/64bit)

  • OSX (64bit, >=10.9)

  • Win (64bit)

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

Citation

If you use PyQUBO in your research, please cite this paper.

@article{tanahashi2019application,
  title={Application of Ising Machines and a Software Development for Ising Machines},
  author={Tanahashi, Kotaro and Takayanagi, Shinichi and Motohashi, Tomomitsu and Tanaka, Shu},
  journal={Journal of the Physical Society of Japan},
  volume={88},
  number={6},
  pages={061010},
  year={2019},
  publisher={The Physical Society of Japan}
}

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-1.0.0.tar.gz (18.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyqubo-1.0.0-py3.8-macosx-10.9-x86_64.egg (244.2 kB view details)

Uploaded Egg

pyqubo-1.0.0-py3.7-macosx-10.9-x86_64.egg (240.8 kB view details)

Uploaded Egg

pyqubo-1.0.0-py3.6-macosx-10.9-x86_64.egg (240.7 kB view details)

Uploaded Egg

pyqubo-1.0.0-py3.5-macosx-10.9-x86_64.egg (241.1 kB view details)

Uploaded Egg

pyqubo-1.0.0-cp38-cp38-win_amd64.whl (205.8 kB view details)

Uploaded CPython 3.8Windows x86-64

pyqubo-1.0.0-cp38-cp38-manylinux1_x86_64.whl (241.6 kB view details)

Uploaded CPython 3.8

pyqubo-1.0.0-cp38-cp38-macosx_10_9_x86_64.whl (224.7 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

pyqubo-1.0.0-cp37-cp37m-win_amd64.whl (203.6 kB view details)

Uploaded CPython 3.7mWindows x86-64

pyqubo-1.0.0-cp37-cp37m-manylinux1_x86_64.whl (247.8 kB view details)

Uploaded CPython 3.7m

pyqubo-1.0.0-cp37-cp37m-macosx_10_9_x86_64.whl (221.3 kB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

pyqubo-1.0.0-cp36-cp36m-win_amd64.whl (203.6 kB view details)

Uploaded CPython 3.6mWindows x86-64

pyqubo-1.0.0-cp36-cp36m-manylinux1_x86_64.whl (246.7 kB view details)

Uploaded CPython 3.6m

pyqubo-1.0.0-cp36-cp36m-macosx_10_9_x86_64.whl (221.2 kB view details)

Uploaded CPython 3.6mmacOS 10.9+ x86-64

pyqubo-1.0.0-cp35-cp35m-win_amd64.whl (203.6 kB view details)

Uploaded CPython 3.5mWindows x86-64

pyqubo-1.0.0-cp35-cp35m-manylinux1_x86_64.whl (246.7 kB view details)

Uploaded CPython 3.5m

pyqubo-1.0.0-cp35-cp35m-macosx_10_9_x86_64.whl (221.2 kB view details)

Uploaded CPython 3.5mmacOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: pyqubo-1.0.0.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.6.11

File hashes

Hashes for pyqubo-1.0.0.tar.gz
Algorithm Hash digest
SHA256 79c22e987267bc778a35a3d1cdb855d22a1ae9bd9cd4dcc411e4e3bfd41ca999
MD5 9877f7c9d251c675f5d30c81e044869e
BLAKE2b-256 635bddbcd1e43bb7e6f12e761ead81b95026a7497587b5d8d1a7b460d00e8241

See more details on using hashes here.

File details

Details for the file pyqubo-1.0.0-py3.8-macosx-10.9-x86_64.egg.

File metadata

  • Download URL: pyqubo-1.0.0-py3.8-macosx-10.9-x86_64.egg
  • Upload date:
  • Size: 244.2 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.0

File hashes

Hashes for pyqubo-1.0.0-py3.8-macosx-10.9-x86_64.egg
Algorithm Hash digest
SHA256 a430d9ca678c2c64609fa5706460c49e8867a74922b4ecb73825db7ec21af98b
MD5 6451ab383db4610a6de2fe299d7d9524
BLAKE2b-256 636ea264c6f6e706b9504d5c5dc3d948094a357a26e05df5cbe8334a1de5063b

See more details on using hashes here.

File details

Details for the file pyqubo-1.0.0-py3.7-macosx-10.9-x86_64.egg.

File metadata

  • Download URL: pyqubo-1.0.0-py3.7-macosx-10.9-x86_64.egg
  • Upload date:
  • Size: 240.8 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.7.5

File hashes

Hashes for pyqubo-1.0.0-py3.7-macosx-10.9-x86_64.egg
Algorithm Hash digest
SHA256 921bdb4a3c44bb09101b699da4280e916b0417117b7e73a8da5c61e0132375ab
MD5 529cd5a44dc0713bec08e5711e3ec1a4
BLAKE2b-256 adc903409e3ec0878cbd6436621062eccb4b0d9d8550c9af5df7c1217f55d222

See more details on using hashes here.

File details

Details for the file pyqubo-1.0.0-py3.6-macosx-10.9-x86_64.egg.

File metadata

  • Download URL: pyqubo-1.0.0-py3.6-macosx-10.9-x86_64.egg
  • Upload date:
  • Size: 240.7 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.6.5

File hashes

Hashes for pyqubo-1.0.0-py3.6-macosx-10.9-x86_64.egg
Algorithm Hash digest
SHA256 604fcbb1843e96b468ef7eb11dfb697889492fe4f3add3fef5e24144d2589757
MD5 1d856cc64ca58b4704268595d1e0bbb0
BLAKE2b-256 3e26536c756c2eb7236531fa8ec1ce45ef7604702b5f4b1513427a77586aef2a

See more details on using hashes here.

File details

Details for the file pyqubo-1.0.0-py3.5-macosx-10.9-x86_64.egg.

File metadata

  • Download URL: pyqubo-1.0.0-py3.5-macosx-10.9-x86_64.egg
  • Upload date:
  • Size: 241.1 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.5.8

File hashes

Hashes for pyqubo-1.0.0-py3.5-macosx-10.9-x86_64.egg
Algorithm Hash digest
SHA256 3ae125d03b1e84986d02ee12e1964293e5910fd495971e1425813b9e5a0ba506
MD5 8036e72a5de6ce5524121d002f1ebc65
BLAKE2b-256 569df572bcfc278c663e153be0b9c0441facc4699157502f933adc94782fe760

See more details on using hashes here.

File details

Details for the file pyqubo-1.0.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pyqubo-1.0.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 205.8 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.5

File hashes

Hashes for pyqubo-1.0.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 5278f87f06699c400faed29db97cdde8816e817a0703a00843ca882c4aa52887
MD5 23b50f3e1a79fa64e1f9062dd5a071e2
BLAKE2b-256 67f7189ee3b21e1862122011970a7404b06c70c643173011f16cb59783d00b0e

See more details on using hashes here.

File details

Details for the file pyqubo-1.0.0-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: pyqubo-1.0.0-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 241.6 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.6.11

File hashes

Hashes for pyqubo-1.0.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 5b8581f8eee2adc773703cd60df590c7f80c98da95fc7f9f4eb58d6bb1ff9e47
MD5 2a6d546cb62676ccf2f24af13ebc2d0c
BLAKE2b-256 5c9d5984d10b57f05cfe48b083ccaa1281e8d6f4babd07f38480d9566444243b

See more details on using hashes here.

File details

Details for the file pyqubo-1.0.0-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pyqubo-1.0.0-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 224.7 kB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.0

File hashes

Hashes for pyqubo-1.0.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6761dd56411db7ecc66f0857216633448f27c52885eba5c4f15c57820676cf18
MD5 e304fa6e31e5e2282cf1302a663b3a01
BLAKE2b-256 b37628d4c6bf463ccf0ef74fec4c1ff2bfb24995b9dc074a033c6173e801cbb5

See more details on using hashes here.

File details

Details for the file pyqubo-1.0.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: pyqubo-1.0.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 203.6 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.7.3

File hashes

Hashes for pyqubo-1.0.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 9c7fa037f2a990f89ee08c3bcce1a3f8163c3246ca25bc9e0047ca86b0892ebf
MD5 3f1a9898498631e0ba6623fbe2817337
BLAKE2b-256 db77e81856af424a1bcca0ffe94c62622faf07031857f0c2dac086db79496555

See more details on using hashes here.

File details

Details for the file pyqubo-1.0.0-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pyqubo-1.0.0-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 247.8 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.6.11

File hashes

Hashes for pyqubo-1.0.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e45e41535f82ef484bebe7ef6a80de95af8bf07eac03b803c5e7936d97b0f06b
MD5 c6451c5fe12a4165628671f9011882d4
BLAKE2b-256 0356a62bac3f032c46d3b5577a3d42caee00e4ffacb1291cf385759dbdd6f7de

See more details on using hashes here.

File details

Details for the file pyqubo-1.0.0-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pyqubo-1.0.0-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 221.3 kB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.7.5

File hashes

Hashes for pyqubo-1.0.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e1c66c9c23c5418f13c8cae3f5cbb01c3347b08b44d6f44c30f078c263e65921
MD5 967ab547ba8d0981acde8a0d8c9d97fd
BLAKE2b-256 4816fff53db3406c23ee98b1370b44437cf05608b82a277b8eb1c8f5ea1e3803

See more details on using hashes here.

File details

Details for the file pyqubo-1.0.0-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: pyqubo-1.0.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 203.6 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.6.5

File hashes

Hashes for pyqubo-1.0.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 32ebe5a5b26b9bb5f6b9da63b09cd28808e5acaa3375a498b0192f3fbc36a302
MD5 c91f9f05fe378368270a56dc8c875f54
BLAKE2b-256 2ea6577abed5ab3aa685ca74dfd071082bebefb93d4ee897778120977b3282c9

See more details on using hashes here.

File details

Details for the file pyqubo-1.0.0-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pyqubo-1.0.0-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 246.7 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.6.11

File hashes

Hashes for pyqubo-1.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7aa7619a565ab8ab76b52d587e7de2cf860a6f557c242eeee0f930762a2aba22
MD5 8719475ff5565366544447b1889ed067
BLAKE2b-256 d758707a1d165380a73f9a20b2ff74d5d5fc9cfe864020fcf8dc8f19a902f833

See more details on using hashes here.

File details

Details for the file pyqubo-1.0.0-cp36-cp36m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pyqubo-1.0.0-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 221.2 kB
  • Tags: CPython 3.6m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.6.5

File hashes

Hashes for pyqubo-1.0.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 23ddeba5b1117e18855da79c53debc6b2963d7906429e72f1ef69dfc053cd1c9
MD5 694eedefe3d36b5754ddbce97cbfe237
BLAKE2b-256 932d33a0643d862c91b0d4bcb5665ef9d6e67b0072f31d6b37c370552cf0d8bc

See more details on using hashes here.

File details

Details for the file pyqubo-1.0.0-cp35-cp35m-win_amd64.whl.

File metadata

  • Download URL: pyqubo-1.0.0-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 203.6 kB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.5.4

File hashes

Hashes for pyqubo-1.0.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 a55df75f2be4813824087014f906a7be963cec109a554cff8dabb30fc7c52f3c
MD5 862bb6181202fbb1d205052178d1efaa
BLAKE2b-256 a9bece319b84ee4a202f5c4b1c6e444195191eb5d9f47f97c167ec3113415627

See more details on using hashes here.

File details

Details for the file pyqubo-1.0.0-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pyqubo-1.0.0-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 246.7 kB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.6.11

File hashes

Hashes for pyqubo-1.0.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 db11be3a7b850fe05796f2bc13018b80bd0d2dc8b3820ff1dd1c39ea8005724e
MD5 851e0802eb199f5be1fc509eff123b8a
BLAKE2b-256 0be349fc09ef878434f6d6859b58a868c2ea31708704b512fcee4d86d0f75d79

See more details on using hashes here.

File details

Details for the file pyqubo-1.0.0-cp35-cp35m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pyqubo-1.0.0-cp35-cp35m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 221.2 kB
  • Tags: CPython 3.5m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.5.8

File hashes

Hashes for pyqubo-1.0.0-cp35-cp35m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 22d628e3e07cbf4c9e968ecf327820fd972b2e31d5defb00a72dd5306e76c93e
MD5 221c0761af8b8cebd1a1200ec26876c6
BLAKE2b-256 8570e1b43fd8a42f07f80ef99aa237762854bbaf742ea9d34701f10312f34932

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