Skip to main content

QuantumUQ

QuantumUQ logo

PyPI Python Tests Documentation DOI License Downloads

QuantumUQ -- Uncertainty Quantification for Quantum Machine Learning

Measure shot noise, epistemic uncertainty, calibration, and noise sensitivity in PennyLane and Qiskit models.

pip install quantumuq

Predictive entropy falling as shot count increases, measured identically across both backends via the same Predictor interface:

Uncertainty vs shots

Installation

pip install quantumuq
# With optional Qiskit Aer support:
pip install "quantumuq[aer]"

Quick examples

PennyLane:

from quantumuq import wrap_qnode, ShotBootstrap
import pennylane as qml
import numpy as np

dev = qml.device("default.qubit", wires=2, shots=1000)

@qml.qnode(dev)
def circuit(x, params):
    qml.AngleEmbedding(x, wires=[0, 1])
    qml.StronglyEntanglingLayers(params, wires=[0, 1])
    return qml.probs(wires=[0, 1])

# 2 qubits -> 4 outcomes (|00>,|01>,|10>,|11>); collapse to 2 classes.
def probs_4_to_2(p):
    p = np.asarray(p)
    if p.ndim == 1:
        return np.array([p[0] + p[1], p[2] + p[3]])
    return np.stack([p[:, 0] + p[:, 1], p[:, 2] + p[:, 3]], axis=-1)

params = 0.1 * np.random.default_rng(0).standard_normal((1, 2, 3))
predictor = wrap_qnode(
    circuit, task="classification", n_classes=2, params=params, postprocess=probs_4_to_2
)
uq = ShotBootstrap(n_samples=16, shots=1000, seed=0)
uq_model = predictor.with_uq(uq)
dist = uq_model.predict_dist(np.random.randn(4, 2))
print(dist.mean.shape, dist.std.shape)

Qiskit:

from quantumuq import wrap_qiskit_sampler, ShotBootstrap
from qiskit.circuit import Parameter, QuantumCircuit
from qiskit.primitives import StatevectorSampler
import numpy as np

theta = Parameter("theta")
qc = QuantumCircuit(1)
qc.ry(theta, 0)
qc.measure_all()

def feature_map(X: np.ndarray):
    return [[float(x[0])] for x in np.atleast_2d(X)]

# A Generator instance (not a plain int) makes the sampler's RNG state
# advance across calls, so repeated ShotBootstrap draws actually differ.
sampler = StatevectorSampler(seed=np.random.default_rng(0))
predictor = wrap_qiskit_sampler(
    sampler,
    circuit=qc,
    task="classification",
    n_classes=2,
    feature_map=feature_map,
)
uq = ShotBootstrap(n_samples=8, shots=1000, seed=0)
uq_model = predictor.with_uq(uq)
dist = uq_model.predict_dist(np.random.randn(4, 1))
print(dist.mean.shape, dist.std.shape)

Methods & metrics

  • Uncertainty methods: ShotBootstrap, DeepEnsemble, NoiseProfile
  • Metrics (classification): nll, brier, ece, predictive_entropy
  • Metrics (regression): rmse, gaussian_nll
  • Persistence: UQModel.save() / UQModel.load() checkpoint a fitted model's trained parameters and method config for both PennyLane and Qiskit predictors

Benchmark suite

quantumuq.benchmarks trains a small reference variational classifier and sweeps shot count, reporting accuracy and calibration metrics reproducibly -- so a paper can cite a fixed benchmark rather than "we used a Python package."

pip install "quantumuq[benchmarks]"  # adds scikit-learn, for iris/breast_cancer
quantumuq-benchmark --backend pennylane --dataset moons --shots 100,500,1000,10000
  • Datasets: moons (no extra dependency), iris (binary subset), breast_cancer -- all reduced to 2 features so the same small reference circuit applies to each; iris/breast_cancer require scikit-learn.
  • Backends: pennylane (gradient-trained) and qiskit (SPSA-trained, since Qiskit circuits aren't differentiable through this library).
  • Metrics per shot count: accuracy, nll, ece, brier, predictive_entropy, and mean ShotBootstrap uncertainty.
  • --output results.csv saves the full table. The same functionality is available from Python via quantumuq.benchmarks.run_benchmark(...).

This is a lightweight harness, not a rigorous ML pipeline -- see quantumuq.benchmarks.run_benchmark's docstring for the exact simplifications (fixed single train/test split, dataset subsampling for consistent runtime, a shared 2-feature/2-qubit circuit architecture). Quantum kernel classifiers and hybrid QNN models, and depolarizing/readout noise sweeps, are natural extensions not yet implemented.

Examples

Runnable notebooks live in examples/notebooks/:

Roadmap

  • Richer model adapters (more flexible outputs, calibration hooks)
  • Additional metrics and visualization utilities
  • Optional integrations with experiment tracking tools
  • Benchmark suite: quantum kernel classifiers and hybrid QNN models, depolarizing/readout noise sweeps (currently shot-count only)

License

MIT License. See LICENSE for details.

Code of Conduct

This project adheres to the Qiskit Code of Conduct. See CODE_OF_CONDUCT.md.

Citation

If you use QuantumUQ in academic work, please cite (also available via GitHub's "Cite this repository" button, backed by CITATION.cff):

@article{Catak_2026,
  title={QuantumUQ: A Library for Uncertainty Quantification in Quantum Machine Learning},
  url={http://dx.doi.org/10.36227/techrxiv.177205048.88644983/v1},
  DOI={10.36227/techrxiv.177205048.88644983/v1},
  publisher={Institute of Electrical and Electronics Engineers (IEEE)},
  author={Catak, Ferhat Ozgur},
  year={2026},
  month=feb 
}

Metadata

Release files for quantumuq 0.4.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 quantumuq 0.4.1
File Size Uploaded
quantumuq-0.4.1.tar.gz 761.4 kB Details

Built distribution (wheel)

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

Total release size: 789.7 kB

Release files / quantumuq-0.4.1.tar.gz

Download URL quantumuq-0.4.1.tar.gz
Size 761.4 kB
Tags Source
SHA-256 checksum
How to use checksums
cf23e8e8c53c8c4fba262892d1e88bc87662ba80c03e142ce68bdaa5f5bddad9
BLAKE2b-256 checksum
How to use checksums
0eb5d0ef8e01bd54594ad9d5d53f6bc612e8fb216b09753369306f86db5b6d98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 28, 2026.

Transparency log

Release files / quantumuq-0.4.1-py3-none-any.whl

Download URL quantumuq-0.4.1-py3-none-any.whl
Size 28.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9fe1cfe1632146c508dcf8710b7dac429476efa8bcfdf4a325aa3eb5fe58b546
BLAKE2b-256 checksum
How to use checksums
1a3800529d6815c6dde10372e510064d64ae1f4e8cfc798e7bbfd7a6db2560f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 28, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

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