pqblocks-qubo
Unified mathematical representation and converter library for Quadratic Unconstrained Binary Optimization (QUBO) and Ising formulations.
Overview
pqblocks-qubo is a foundational mathematical model and compilation engine for Quadratic Unconstrained Binary Optimization (QUBO) and Ising spin-glass problems.
It provides a unified BinaryQuadraticModel (BQM) abstraction supporting both binary variables ($x_i \in {0, 1}$) and spin variables ($s_i \in {-1, +1}$), with seamless $O(1)$ bidirectional conversions, linear constraint compilation (equality, inequality, one-hot), and canonical problem generators (MaxCut, TSP, Graph Coloring, 0/1 Knapsack, Portfolio Optimization).
Key Highlights
- BQM Abstraction: Represents quadratic energy functions with linear terms, symmetric quadratic couplings, and constant energy offsets.
- Spin/Binary Duality: Instant mathematical conversion between Ising and QUBO representations without loss of precision.
- Constraint Compilers: Automatic translation of linear equality and inequality constraints into quadratic penalty terms.
- Problem Formulations: Built-in loaders for NP-hard combinatorial optimization challenges.
Installation
pip install pqblocks-qubo
Dependencies
Requires Python 3.11+, numpy>=1.20.0, and networkx.
Quickstart
import networkx as nx
from pqblocks_qubo import load_maxcut, to_qubo
# 1. Build a graph and construct native Ising model for MaxCut
G = nx.cycle_graph(4)
bqm_ising = load_maxcut(G)
# 2. Convert transparently to QUBO
bqm_qubo = to_qubo(bqm_ising)
# 3. Evaluate state energy (deterministic evaluation)
sample = {0: 0, 1: 1, 2: 0, 3: 1}
print(f"QUBO Energy: {bqm_qubo.energy(sample)}")
Combinatorial Problem Modeling
Traveling Salesperson Problem (TSP)
import numpy as np
from pqblocks_qubo import load_tsp
dist_matrix = np.array([
[0.0, 10.0, 15.0, 20.0],
[10.0, 0.0, 35.0, 25.0],
[15.0, 35.0, 0.0, 30.0],
[20.0, 25.0, 30.0, 0.0],
])
tsp_bqm, var_map = load_tsp(dist_matrix)
print(f"TSP BQM variables: {tsp_bqm.num_variables}")
0/1 Knapsack Problem
from pqblocks_qubo import load_knapsack
values = [10, 20, 30]
weights = [1, 2, 3]
capacity = 4
knapsack_bqm = load_knapsack(values, weights, capacity)
print(f"Knapsack BQM variables: {knapsack_bqm.num_variables}")
Documentation
- BENCHMARKS.md - Energy evaluation and conversion microbenchmarks.
- TESTING.md - Test harness details and 93% statement coverage.
- EVIDENCE.md - Theoretical formulations, Hamiltonian definitions, and literature citations.
- VERIFICATION_REPORT.md - Multi-python validation log.
- USE_CASES.md - Practical combinatorial modeling workflows.
- SECURITY_NOTES.md - Scope classification and safe evaluation.
- AGENTS.md - Automated verification instructions.
- CHANGELOG.md - Release history.
License
Metadata
Release files for pqblocks-qubo 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pqblocks_qubo-0.1.0.tar.gz | 38.3 kB | Without provenance | Details for pqblocks_qubo-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pqblocks_qubo-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pqblocks_qubo-0.1.0-py3-none-any.whl |
Total release size: 68.3 kB
Release files / pqblocks_qubo-0.1.0.tar.gz
| Download URL | pqblocks_qubo-0.1.0.tar.gz |
|---|---|
| Size | 38.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
736716cddb8e50533135f54a15d2dabbafecdbb4835305e5d3ee688aa422e7ec
|
|
BLAKE2b-256 checksum How to use checksums |
518f11c065b61371c24eff92b1a5bf6da8c679c527f611b671ed7cbf6ddd2724
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pqblocks_qubo-0.1.0-py3-none-any.whl
| Download URL | pqblocks_qubo-0.1.0-py3-none-any.whl |
|---|---|
| Size | 30.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
32b6b365f41ffaed67c1d3443b10147b0bc0e12be527cef958e3be0bcd7b505f
|
|
BLAKE2b-256 checksum How to use checksums |
2ecb9f5b5db0da2f0cd252c4b0859cfb7858a2d81af0694032499268385a5482
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for pqblocks-qubo 0.1.0
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.