Skip to main content

QUBOVert

Travis-CI Documentation Status

Please see the Repository and Docs.

Convert common problems to QUBO form.

So far we have just implemented some of the formulations from [Lucas]. The goal of QUBOVert is to become a large collection of problems mapped to QUBO and Ising forms in order to aid the recent increase in study of these problems due to quantum optimization algorithms. I am hoping to have a lot of participation so that we can compile all these problems!

To participate, fork the repository, add your contributions, and submit a pull request. Add tests for any functionality that you add. Make sure you run python -m pytest, python -m pytest --codestyle --ignore=docs before committing anything (yes, even the tests need to pass codestyle checks), and python -m pydocstyle convention=numpy qubovert to ensure that the build passes. When you push changes to the master branch, Travis-CI will automatically check to see if all the tests pass. Note that all problems should be derived from the qubovert.utils.Problem class! Make sure all your docstrings follow the Numpydoc standard format.

Use Python’s help function! I have very descriptive doc strings on all the functions and classes.

Installation

pip install qubovert

To install from source:

git clone https://github.com/jiosue/qubovert.git
cd QUBOVert
pip install -e .

Then you can use it in Python with

import qubovert

# get info
help(qubovert)

# see all the problems specified
print(qubovert.__all__)
# or equivalently
print(qubovert.problems.__all__)

# see the utilities defined
help(qubovert.utils)
print(qubovert.utils.__all__)

# to see specifically the np problems:
help(qubovert.problems.np)
print(qubovert.problems.np.__all__)

# to see specifically the benchmarking problems:
help(qubovert.problems.benchmarking)
print(qubovert.problems.benchmarking.__all__)

# etc ...

See the following Set Cover example. All other problems can be used in a similar way.

from qubovert import SetCover
from any_module import qubo_solver
# or you can use my bruteforce solver...
# from qubovert.utils import solve_qubo_bruteforce as qubo_solver

U = {"a", "b", "c", "d"}
V = [{"a", "b"}, {"a", "c"}, {"c", "d"}]

problem = SetCover(U, V)
Q, offset = problem.to_qubo()

obj, sol = qubo_solver(Q)
obj += offset

solution = problem.convert_solution(sol)

print(solution) # will print {0, 2}
print(problem.is_solution_valid(solution)) # will print True, since V[0] + V[2] covers all of U
print(obj == len(solution)) # will print True

To use the Ising formulation instead:

from qubovert import SetCover
from any_module import ising_solver
# or you can use my bruteforce solver...
# from qubovert.utils import solve_ising_bruteforce as ising_solver

U = {"a", "b", "c", "d"}
V = [{"a", "b"}, {"a", "c"}, {"c", "d"}]

problem = SetCover(U, V)
h, J, offset = problem.to_ising()

obj, sol = ising_solver(h, J)
obj += offset

solution = problem.convert_solution(sol)

print(solution) # will print {0, 2}
print(problem.is_solution_valid(solution)) # will print True, since V[0] + V[2] covers all of U
print(obj == len(solution)) # will print True

To see problem specifics, run

help(qubovert.SetCover)
help(qubovert.VertexCover)
# etc

I have very descriptive doc strings that should explain everything you need to know to use each problem class.

Technical details on the conversions

For the log trick he mentions, we usually need a constraint like sum(x) >= 1. In order to enforce this constraint, we add a penalty to the QUBO of the form 1 - sum(x) + sum(x[i] x[j] for i in range(len(x)) for j in range(i+1, len(x))) (the idea comes from [Glover]).

References

[Lucas]

Andrew Lucas. Ising formulations of many np problems. Frontiers in Physics, 2:5, 2014.

[Glover]

Fred Glover, Gary Kochenberger, and Yu Du. A tutorial on formulating and using qubo models. arXiv:1811.11538v5, 2019.

Metadata

Release files for qubovert 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qubovert 0.0.1
File Size Uploaded Provenance Actions
qubovert-0.0.1.tar.gz 27.2 kB Without provenance Details for qubovert-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for qubovert 0.0.1
File Interpreter ABI Platform Actions
qubovert-0.0.1-py3-none-any.whl Python 3 none any Details for qubovert-0.0.1-py3-none-any.whl

Total release size: 79.8 kB

Release files / qubovert-0.0.1.tar.gz

Download URL qubovert-0.0.1.tar.gz
Size 27.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7ce026e62e8b309f166796aecd3bd1f81003f6f80d21f5900e9002dc79e7f413
BLAKE2b-256 checksum
How to use checksums
31f22ee503f8fdf4a16b18c1c33a92d30289436a05c0b901de9af69b2b96caf1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.2

Release files / qubovert-0.0.1-py3-none-any.whl

Download URL qubovert-0.0.1-py3-none-any.whl
Size 52.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8252ad692c4bb11b6b0f925093a26d6d263afc458fee0ff2fd002b3b8ec46fce
BLAKE2b-256 checksum
How to use checksums
9f31b4fd89a94ab67625ed13871bfa85e62d15fa0469e0bbca53dc8170a6a9e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.2

Security for qubovert 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page