Package: pyqubo
PyQUBOPyQUBO allows you to create QUBOs or Ising models from flexible mathematical expressions easily.
Some of the features of PyQUBO arePython based (C++ backend).Fully integrated with Ocean SDK.(details)Automatic validation of constraints.(details)Placeholderfor parameter tuning. (details)For more details, seePyQUBO Documentation.Example UsageCreating QUBOThis example constructs a simple expression and compile it tomodel.
By callingmodel.to_qubo(), we get the resulting QUBO.
(This example solvesNumber Partitioning Problemwith 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 OceanPyQUBO can output theBinaryQuadraticModel(BQM)which is compatible withSamplerclass defined in D-Wave Ocean SDK.
In the example below, we solve the problem withSimulatedAnnealingSampler.>>> 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 thesamplerby aDWaveCliqueSamplerinstance, for example.For more examples, seeexample notebooks.BenchmarkingSince 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 inhere.Installationpipinstallpyquboorpython-mpipinstall.Supported Python VersionsPython 3.6, 3.7, 3.8, 3.9 and 3.10 are supported.Supported Operating SystemsLinux (32/64bit)OSX (x86_64(Intel)/arm64(Apple Silicon), 64bit, >=10.9)Win (64bit)TestRun all tests.exportUSE_TEST=1python-munittestdiscovertestShow coverage report.exportUSE_TEST=1coveragerun-munittestdiscovercoveragehtmlRun test with circleci CLI.circlecibuild--job$JOBNAMERun doctest.makedoctestDependencyThis repository contains the source code ofcimodwhich is licensed under the Apache License 2.0.cimodis the C++ header-only library for a binary quadratic model, developed byOpenJij.CitationIf 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}
}OrganizationRecruit Communications Co., Ltd.LicenceReleased under the Apache License 2.0.ContributionWe welcome contributions to this project. SeeCONTRIBUTING.We thank all contributors, especially @tail-island and @29rou.