PyQUBO allows you to create QUBOs or Ising models from mathematical expressions.
Project description
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) # doctest: +SKIP {('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}
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.
Benchmarking
Since the core logic of the new PyQUBO (>=1.0.0) is written in C++ and the logic itself is also optimized, the execution time to produce QUBO has become shorter. We benchmarked the execution time to produce QUBOs of TSP with the new PyQUBO (1.0.0) and the previous PyQUBO (0.4.0). The result shows the new PyQUBO runs 1000 times faster as the problem size increases.
Execution time includes building Hamiltonian, compilation, and producing QUBOs. The code to produce the above result is found in here.
Installation
pip install pyqubo
or
python -m pip install .
Supported Python Versions
Python 3.6, 3.7, 3.8, 3.9 and 3.10 are supported.
Supported Operating Systems
Linux (32/64bit)
OSX (x86_64(Intel)/arm64(Apple Silicon), 64bit, >=10.9)
Win (64bit)
Test
Run all tests.
export USE_TEST=1
python -m unittest discover test
Show coverage report.
export USE_TEST=1
coverage run -m unittest discover
coverage html
Run test with circleci CLI.
circleci build --job $JOBNAME
Run doctest.
make doctest
Dependency
This repository contains the source code of cimod which is licensed under the Apache License 2.0. cimod is the C++ header-only library for a binary quadratic model, developed by OpenJij.
Citation
If you use PyQUBO in your research, please cite the following papers ([M. Zaman, et al., 2021], [K. Tanahashi, et al., 2019]).
@article{zaman2021pyqubo, title={PyQUBO: Python Library for QUBO Creation}, author={Zaman, Mashiyat and Tanahashi, Kotaro and Tanaka, Shu}, journal={IEEE Transactions on Computers}, year={2021}, publisher={IEEE} } @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.
We thank all contributors, especially @tail-island and @29rou.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for pyqubo-1.4.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cba42ae56f7e7a2624b44df59886dd7f838c63fb0097944f2260d9d4220216c |
|
MD5 | 40543b53c4897dd9eec8c3fc5bdf3a5b |
|
BLAKE2b-256 | 69ca5937388183b80ba0dede3b3e837616cdef4d04b46a8e3b2a9541739e75b1 |
Hashes for pyqubo-1.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b638247c65163d7f958479b967722bd7f294a76fff540d0f66a75c3268a994a7 |
|
MD5 | 693d9daa96d9a08446c9006a645d4ed5 |
|
BLAKE2b-256 | 31ce1c8d9c55a7dc083584baf99f6dbd5e493efb833ff1c03907c3a690824d20 |
Hashes for pyqubo-1.4.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7eec1fdcf57fb24cfedb36a2744b350f8e992d223c053c39711225a8a4ad154c |
|
MD5 | 16775262355cc0b440f4f29bc313ad3f |
|
BLAKE2b-256 | f8b23c067ff6fd772c3eefb7c5e990a65aa3f2c3df7ba5c6d103d005ee904f93 |
Hashes for pyqubo-1.4.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 610b8860e82d1bf0e3dcf35f6fff3621968fd208392092d9f582b82e759999e2 |
|
MD5 | ae133a1ea068f3b87549baa9fac151c8 |
|
BLAKE2b-256 | 62816b6eb270a5ed050bf48667d2cf027c5ba389f6f35cbfb9e54eb569bc91af |
Hashes for pyqubo-1.4.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c502ad9dd2cc125e21e9df7e3a7cb9ae4b6e2538bf9890f35d19ca8c5c9c8f3b |
|
MD5 | 6841361f3544a0f51c966bd81c78833d |
|
BLAKE2b-256 | a3f8fa98efbecdf94e3d39f348aa1637f84dbdb021ca326b888b4aff8e775211 |
Hashes for pyqubo-1.4.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c13335d6cf89b1e6581aa595d2593c86996687abb04cc934508ac676566e3bd8 |
|
MD5 | 592d0e522e3464362337f0f30f14d6bc |
|
BLAKE2b-256 | b1141dc1677ed9d7675ccdd75f7f054bd47c05bfa567f1e0d54342a53ba0113e |
Hashes for pyqubo-1.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a3e69633f060c2a8c7cce949e5476e4a295820c842f0be79bd716fb013521e8 |
|
MD5 | c7a3f16f938a78233106cbb61087e315 |
|
BLAKE2b-256 | d4f1621fb9973c5435083dffd726c3d2639559d6688f30a49060fd5e1b36d955 |
Hashes for pyqubo-1.4.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae7c55b57787ba1b599ca6aba80a9f3daf7b1e48fc1cb4602af8d482fb456c9b |
|
MD5 | e397132043ed80f93642c70bccc8fa21 |
|
BLAKE2b-256 | 375465e7b5847aa15fb8ee0a9be92bc896aef2d75855e93f3f481d141f49a2d8 |
Hashes for pyqubo-1.4.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4e5e4168b4b88b999070caa9b9b20750538699412b3da3a204ed2155b4b274e |
|
MD5 | b3564ca6bb2658d9a4b461605fcb6765 |
|
BLAKE2b-256 | b2b845b7a9fd1374f1688c3b02513a46dd440c557a24a5b0016e36037ee78f93 |
Hashes for pyqubo-1.4.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6edad1930710ec1203c475285f521522c84f09b6b9ad2ddf37b5fbdcbe1962c |
|
MD5 | f0a57e5f84a1e59613c89bdcfdfdc1da |
|
BLAKE2b-256 | 3dc43cd7be45613c96d50d8a53f56b68da23d0fc4b2d4c4445ccfc57277eee9d |
Hashes for pyqubo-1.4.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 060f8426b8429cfceee597ab1831dca8e9119920a699e0bbaf874b4d6eb51383 |
|
MD5 | ed409f13f9e521378a3791c20a6edf63 |
|
BLAKE2b-256 | 080fb6e3eeabe5e6efe84d240490c1dd283d638b1e92ad3210164af62e5e34e7 |
Hashes for pyqubo-1.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03d0eedef5367508a378a79e3b8094903c95818e60c33a435b98e0b0c07c35ec |
|
MD5 | 55124f6882149428a62059ee835aec3b |
|
BLAKE2b-256 | 40c562bb20420f47431dacb68e8c7e8266c2ee8138d69acf0cdfa1abfe23255a |
Hashes for pyqubo-1.4.0-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e8d6d88ae764d1143b2e8c123b7272908ef23c23e0ce6433c56ce9ffe7aa47a |
|
MD5 | 744ff47557b85fcfb2bbd20806e12cf6 |
|
BLAKE2b-256 | 55181e2f6a6955dea59bab4dd60788292b37e8588de455090dc56c63194a503d |
Hashes for pyqubo-1.4.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e081591eb5bf7ee22fba219e89419d77368e5fd3c8c06bc1f5d777ff3083145 |
|
MD5 | 025bfc0c2e131f84258d2e8acc4cecbe |
|
BLAKE2b-256 | 3f90711b0356c26d1d7176c9caf19c45fa41bd312a068ac64a9b01c5ed5b5d13 |
Hashes for pyqubo-1.4.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e7d26dafd3d60d5a4ef55ee4219a1e922c875c43dda049acea325f0cfca57c9 |
|
MD5 | b6e1614c6a5cf85ecee44c19780dfdb8 |
|
BLAKE2b-256 | dba78543948fa4cfb21829cdfbb67343b6f6b7048cc8ebab22b519df5babac45 |
Hashes for pyqubo-1.4.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31ec4ac13f446d3a684e2d8fb62e64329c4c08e4bfa61a3498114226480c6105 |
|
MD5 | f0757b3ed63fbbc174add52fbbf58f33 |
|
BLAKE2b-256 | f752715829e70a122681e797e91737d21d7359298a0716bba921d2ad62a563b4 |
Hashes for pyqubo-1.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ff1d6e7f00c78ece85092885b0179347e3ce1657b98720e12008ad51c493338 |
|
MD5 | 8e00b2282079ada80e375427c27c059f |
|
BLAKE2b-256 | 656c2ec073a1c70331e8229f569a06e2c7a0e944472b4855ebbf5c1c50a72110 |
Hashes for pyqubo-1.4.0-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd0ac2d7c191ad771b7a316f81b32ada5a5ba08b8ec0bf71caf1ec8543e94646 |
|
MD5 | e9aefc456d5f669f232f8cde859e4003 |
|
BLAKE2b-256 | 9584210f03ab0ba966f472c60928cad0b0dd7a204c4fe403affe80a799f73b66 |
Hashes for pyqubo-1.4.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f8ac4e896c7db52c694eb0851cedd3c05b455c6e135c1f1a942718562be4621 |
|
MD5 | 25de0f813e975895824262f726e80a77 |
|
BLAKE2b-256 | 490c0e18c342b944d2e3ce8967ab84bf32a686705d7221ff0a5b8a87903ef13a |
Hashes for pyqubo-1.4.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8af6023ddc00a265db7a7e53502b08e750a82362c482755b10bc8af034a3410 |
|
MD5 | a21121dec30b200aef3349dcae05fe56 |
|
BLAKE2b-256 | 045fd22b571248dbdc31c0294d386baa6752a1daa414f9ed2fec5f7cd08f63d0 |
Hashes for pyqubo-1.4.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec247064b43eae2e2785ffa80320c2b58664ab25e545158a3cad5ffd9b056be7 |
|
MD5 | 02f70dfc37c8220eae494cdd1bdd08eb |
|
BLAKE2b-256 | 2d0317997c71196d4807cf0de0e4330b869ceb762ce5ffd8861adc8800e720df |
Hashes for pyqubo-1.4.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a67394e9005edcd871488aea317ff93b497190075532ce3448bb965e1ee8c79 |
|
MD5 | aa8295d3bbed10b2e79043526b3e68f5 |
|
BLAKE2b-256 | 5c9407d08cbb302e33d94351489bededc46d8a608b012aa5ec3c5ed8e1c830a1 |
Hashes for pyqubo-1.4.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7866f6bf15ffff3570e5c7c296d57a1721decf9188caa3bfe77ab0781a88fdf0 |
|
MD5 | 5fc99dc4316fd30f193c77a26347efac |
|
BLAKE2b-256 | f20442bafd13d82efa2faab2cfa4265f26803eedf1b08c7a49c24a365a31a7e8 |
Hashes for pyqubo-1.4.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3da3222ed1f2039301ba0863436c4ad5ccfd5ae7a5c0d13f873dddd19bbcc762 |
|
MD5 | 073713db0dcc1faf23813636d6e57677 |
|
BLAKE2b-256 | ef73e747c9da710fae7d5fc38489565087f9282d35ae5785651daabdd9f6aa6b |
Hashes for pyqubo-1.4.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f70fdb69dbc64ae4d6df7a4511d66179b4c9c945317cf693b3b1c5abecf6e717 |
|
MD5 | b4c295d5ac2a93dca860ac0713f5541a |
|
BLAKE2b-256 | 2d146f04a498e66ab680b78da0ac1be92ba24c51ca4a4b955bdab602430b9e7e |
Hashes for pyqubo-1.4.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0baec96e7a1e03084568a356810975e7c787e0bf106608ec5eaf2b7216aebe8 |
|
MD5 | d0bf9df9e0238d059467224a61dadec0 |
|
BLAKE2b-256 | ed4dbe0705e59d6c78481caf4a0decd15da28fc579bd760327f213fe2c5dcc7a |
Hashes for pyqubo-1.4.0-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d8f17ec63291b3ef7c1a97c58b4877be3f41a56e0359d953830aa1e4287b645 |
|
MD5 | fe1949cdcabd262b38d8345775441d1d |
|
BLAKE2b-256 | 3e28e4b1871c1406fc068988973e64027944ff8e12c0e5d960c9f58215dee9ac |
Hashes for pyqubo-1.4.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a8e74d383b701b850bb6ba28806f54a7ac6b7e0e41086969b38e368c7d971ef |
|
MD5 | 29c3de17793989ec4896aaf618799969 |
|
BLAKE2b-256 | c5b3469c05b362f7e91e8160ea62572f325203302babc72254733fbd551bc6a9 |