Skip to main content

Paper Paper DOI Zenodo DOI

PyPI version Python Version License

GitHub last commit codecov

PyPI Downloads Docker Pulls Ask DeepWiki

QuPRS: Quantum Path-sum Reduction and Solver

QuPRS("kyu-parse") is a tool for Quantum Circuit tool integrate Path-sum Reduction and Solver.

In quantum computing, verifying whether an optimized or compiled quantum circuit is functionally equivalent to the original circuit is a crucial task. QuPRS aims to solve this problem, and its features include:

  • Novel verification method: Based on pathsum, which is a circuit representation method different from traditional matrix products.
  • Multiple verification strategies:
    1. Hybrid mode (RR + WMC): Combines the efficiency of reduction rules and the completeness of weighted model counting.
    2. Reduction rules only (RR): Extremely fast, suitable for circuits that can be simplified by local rules.
    3. WMC only: A powerful SAT-based method for more complex circuit structures.
  • Seamless integration with Qiskit ecosystem: Circuits can be directly loaded from Qiskit QuantumCircuit objects or QASM files.

Contents

Installation

It is recommended to install QuPRS in a virtual environment.

  1. Create and activate a Conda virtual environment:

    conda create --name QuPRS python=3.12 # Or your preferred Python version
    conda activate QuPRS
    
  2. Install QuPRS using pip:

    pip install QuPRS
    

Platform Support

QuPRS provides pre-built wheels for the following operating systems and architectures:

OS Architecture Status Note
Linux x86_64 ✅ Supported Tested on Ubuntu
Linux ARM64 (aarch64) ✅ Supported Tested on Ubuntu
macOS Intel (x86_64) ✅ Supported macOS 15+
macOS Apple Silicon (M1/M2/M3) ✅ Supported macOS 15+
Windows x86_64 / ARM64 ⚠️ WSL2 Only Please use WSL2

The published macOS wheels for QuPRS v0.13.2 are tagged macosx_15_0_* and require macOS 15+. On macOS 14, pip cannot use these prebuilt wheels but can attempt to build the source distribution (sdist). A macOS 14.8.9 / Apple Silicon / Python 3.12.10 smoke test successfully installed v0.13.2 from sdist with Homebrew build dependencies and ran a basic Ganak-backed equivalence check. This is limited source-install evidence, not a guarantee for every macOS 14 configuration, Python version, or solver feature.

For the tested macOS 14 ARM64 source-build path (rather than a prebuilt wheel):

brew install cmake gmp mpfr zlib
python -m pip install --no-binary=quprs 'QuPRS==0.13.2'

For the supported prebuilt-wheel installation path, use macOS 15 or later.

Using QuPRS

This tool can build quantum circuit using path-sum formulation.

First, import the necessary components from the QuPRS library.

from QuPRS.pathsum import PathSum

Create pathsum Circuit

Create a pathsum Circuit You can create a PathSum.QuantumCircuit object directly:

qubit_num = 2
circuit = PathSum.QuantumCircuit(qubit_num)
circuit = circuit.h(0) # Apply Hadamard gate to qubit 0
circuit = circuit.h(0) # Apply Hadamard gate to qubit 0 again (H*H = I)
# Add more gates as needed
# e.g., circuit = circuit.cx(0, 1)

Import From qasm

pathsum supports importing circuits from QASM files or strings.

From a QASM file:

filename = "my_circuit.qasm"
# Ensure my_circuit.qasm exists and contains valid QASM code
# Example my_circuit.qasm:
# OPENQASM 2.0;
# include "qelib1.inc";
# qreg q[2];
# h q[0];
# cx q[0],q[1];

circuit = PathSum.load_from_qasm_file(filename)

Or

qasm_str = """
OPENQASM 2.0;
include "qelib1.inc";
qreg q[2];
h q[0];
cx q[0],q[1];
"""
circuit = PathSum.load_from_qasm_str(qasm_str)

Equivalence Checking

QuPRS provides tools for checking the equivalence of two quantum circuits, potentially imported from Qiskit or QASM files.

Importing Circuits for Equivalence Checking You can load circuits from QASM files or define them directly using Qiskit for comparison.

Circuit Prepare

  • Load from QASM files
    # Assuming circuit1.qasm and circuit2.qasm exist
    from QuPRS.interface.load_qiskit import load_circuit
    
    circuit1 = load_circuit("circuit1.qasm")
    circuit2 = load_circuit("circuit2.qasm")
    
  • Direct import from Qiskit QuantumCircuit objects:
    from qiskit import QuantumCircuit 
    
    # Define circuit1 using Qiskit
    circuit1 = QuantumCircuit(2)
    circuit1.h(1)
    circuit1.cx(0, 1)
    circuit1.h(1)
    
    # Define circuit2 using Qiskit
    circuit2 = QuantumCircuit(2)
    circuit2.cz(0, 1)
    

Run Equivalence Checking

  • Hybrid: Reduction Rules (RR) and Weighted Model Counting (WMC)

    This method combines RR with WMC for equivalence checking.

    from QuPRS import check_equivalence
    
    result = check_equivalence(circuit1, circuit2, method = "hybrid",)
    
  • Using Reduction Rules (RR)

    from QuPRS import check_equivalence
    
    result = check_equivalence(circuit1, circuit2, method = "reduction_rules",)
    
  • WMC only (without RR)

    To perform equivalence checking using only WMC, you need to disable the Reduction Rules switch.

    from QuPRS import check_equivalence
    
    result = check_equivalence(circuit1, circuit2, method = "wmc_only",)
    

Solver subprocess reliability and timeout limits

On Linux and macOS, both backends supervise each invocation of the selected external weighted model counter (Ganak or GPMC). The solver gets the remaining monotonic time budget; Ganak's --version provenance check has its own shorter cap within that budget. When the budget is exhausted, the supervisor terminates the solver's POSIX process group, waits for the directly owned child, and closes captured output. Children that deliberately detach into a different session/process group are not covered by this guarantee. A terminated grandchild may temporarily appear as a zombie while its adoptive process reaps it; it is no longer executing. Native Windows is not supported; use WSL2.

Each subprocess has a 1 MiB per-stream diagnostic output limit. Both Python and Rust capture streams in private temporary files; files can briefly grow past the threshold between checks, but returned diagnostic buffers are limited to 1 MiB each. Unlike pipe readers, this design does not wait on inherited pipe descriptors held by detached descendants. Temporary circuit-CNF files are removed on success and failure by default. Rust can explicitly retain a failed CNF for diagnosis with QUPRS_KEEP_FAILED_CNF=1; such files may contain sensitive circuit details.

Important: timeout is not currently a strict wall-clock limit for every part of check_equivalence(). Rust's in-process circuit construction/Reduction and CNF encoding are not forcibly interrupted by the solver subprocess supervisor. On POSIX, Python uses SIGALRM for a cooperative request-level limit only on the main thread; the same alarm cannot protect non-main-thread calls, and a Python strategy safe_mode worker timeout does not supervise later work by itself. A solver invocation is bounded by its own remaining-budget deadline; long-running in-process work can still exceed the requested overall time. Do not rely on this API as a hard end-to-end kill switch.

The result status equivalent / equivalent* is a verified equivalence classification; not_equivalent is an actual negative result; unknown means reduction alone was inconclusive; Timeout means a deadline expired. Solver launch failures, output overflow, nonzero exits, malformed counts and other solver errors raise an exception rather than returning not_equivalent or silently switching to another solver. QuPRS-managed solver dispatch currently uses one process-wide lock because the Rust FFI resolves executable overrides via environment variables; this prioritizes correctness over concurrent WMC throughput. Waiting for this lock consumes the request's remaining monotonic budget; an expired request does not launch a solver. The Rust FFI currently accepts integer-second timeouts, so the remaining duration is rounded down. Unrelated threads that modify these environment variables directly remain outside this guarantee. Python does not replace an embedding application's active SIGALRM timer or handler; when such a timer already exists, QuPRS relies on subprocess deadlines and does not install its own in-process strategy alarm. The public API requires a positive integer timeout in seconds (zero is invalid).

The Python backend exposes solver-related Python exceptions directly; the Rust FFI currently wraps external solver failures as a Python ValueError prefixed Verification Engine Failed. Use distinct handling for exceptions, timeouts and mathematical results.

Cite

If you use QuPRS in your research, please cite our paper:

Paper Paper DOI

Equivalence Checking of Quantum Circuits via Path-Sum and Weighted Model Counting
Wei-Jia Huang, Christophe Chareton, Yu-Fang Chen, Kai-Min Chung, Min-Hsiu Hsieh, Alfons Laarman, and Jingyi Mei.
In Tools and Algorithms for the Construction and Analysis of Systems (TACAS 2026), Lecture Notes in Computer Science, vol. 15668, pp. 419–439. Springer, 2026.
DOI: 10.1007/978-3-032-22749-2_21

@inproceedings{huang2026equivalence,
  author    = {Huang, Wei-Jia and Chareton, Christophe and Chen, Yu-Fang and Chung, Kai-Min and Hsieh, Min-Hsiu and Laarman, Alfons and Mei, Jingyi},
  title     = {Equivalence Checking of Quantum Circuits via Path-Sum and Weighted Model Counting},
  booktitle = {Tools and Algorithms for the Construction and Analysis of Systems (TACAS 2026)},
  series    = {Lecture Notes in Computer Science},
  pages     = {419--439},
  year      = {2026},
  publisher = {Springer Nature Switzerland},
  doi       = {10.1007/978-3-032-22749-2_21},
  url       = {https://doi.org/10.1007/978-3-032-22749-2_21}
}

You can also cite this software repository via Zenodo:

DOI

Floating weighted counts

Ganak 2.8.0 uses --mode=6; GPMC uses -mode=1. Both operate on floating-point encodings of the path sum. Ganak mode 6 prints rounded complex counts (nine significant digits in the pinned release). Neither solver is an exact-arithmetic certificate for the original circuit. Ganak's pinned version, archive/executable SHA256 and architecture checks still apply.

Count fixtures compare against hand-computed complex sums and the other solver using relative error 1e-8 and absolute error 1e-12; individual Rust solver-integration fixtures use a documented 2e-9 absolute budget. These are fixture budgets, not universal error bounds under cancellation. Rust serializes both solver inputs with 17 significant decimal digits in scientific notation (enough to round-trip binary64 weights). Python evaluates symbolic weights at 113 bits where supported and writes their decimal form without an arbitrary nine-decimal quantization. Input precision cannot exceed the information in the original circuit parameters or the numerical type used upstream.

Both Python and Rust WMC backends classify the unrounded, normalized complex count using 1e-6 magnitude and phase thresholds. Python exposes these as config.WMC_MAGNITUDE_TOLERANCE and config.WMC_PHASE_TOLERANCE; config.TOLERANCE remains the independent symbolic-reduction tolerance (default 1e-10). Nonzero global phase gives equivalent* when the count magnitude passes the threshold. Python uses a scaled log-magnitude and signed atan2, avoiding overflow, zero-count division, and negative phases wrapping to nearly 2*pi. Results closer to a decision boundary than encoding or printed-count error should be checked independently; agreement between two solvers alone does not establish exact equivalence. Nonzero exits, crashes, missing results and malformed/non-finite counts are failures, without cross-solver fallback.

Python WMC precision profiling

Use the deterministic microbenchmark to compare 53-bit and 113-bit phase weight evaluation on the same machine:

python scripts/profile_wmc_weight_precision.py --samples 96 --repeats 5 --warmups 2 --json-file python_wmc_precision_profile.json

Its JSON report includes distinct and repeated phases, normalized timing, and platform metadata. Cache timings are experimental only, not enabled in production. The PR benchmark workflow records the report as an artifact. Absolute timings across different CI runners are not directly comparable. This profile is observational and does not introduce a new release gate.

License Information

  • The original source code of this project is licensed under the MIT License.

  • This project utilizes and depends on several third-party components and libraries, which are governed by their own licenses. For detailed copyright notices and the full license texts of these components, please see the NOTICE.md file.

Acknowledgements

This project utilizes gpmc, a binary component developed by Kenji Hashimoto, for parts of its Weighted Model Counting functionality.

Metadata

Release files for QuPRS 0.13.3

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

Source distribution (sdist)

Source distribution for QuPRS 0.13.3
File Size Uploaded Provenance Actions
quprs-0.13.3.tar.gz 1.5 MB With provenance Details for quprs-0.13.3.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for QuPRS 0.13.3
File Actions
quprs-0.13.3-cp38-abi3-manylinux_2_28_x86_64.whl CPython 3.8 abi3 Linux glibc 2.28+ x86-64 Details for quprs-0.13.3-cp38-abi3-manylinux_2_28_x86_64.whl
quprs-0.13.3-cp38-abi3-manylinux_2_28_aarch64.whl CPython 3.8 abi3 Linux glibc 2.28+ ARM64 Details for quprs-0.13.3-cp38-abi3-manylinux_2_28_aarch64.whl
quprs-0.13.3-cp38-abi3-macosx_15_0_x86_64.whl CPython 3.8 abi3 macOS 15.0+ x86-64 Details for quprs-0.13.3-cp38-abi3-macosx_15_0_x86_64.whl
quprs-0.13.3-cp38-abi3-macosx_15_0_arm64.whl CPython 3.8 abi3 macOS 15.0+ ARM64 Details for quprs-0.13.3-cp38-abi3-macosx_15_0_arm64.whl

Total release size: 91.3 MB

Release files / quprs-0.13.3.tar.gz

Download URL quprs-0.13.3.tar.gz
Size 1.5 MB
Tags Source
SHA-256 checksum
How to use checksums
d883eee72863979fd0794eab1280a2037129b00b61563baa6158aca35dad0ad4
BLAKE2b-256 checksum
How to use checksums
be2c1f979025eece42a27d73b84e5af45f6e34175008e947436a14fb5179964f
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 Oct 20, 2026.

Transparency log

Release files / quprs-0.13.3-cp38-abi3-manylinux_2_28_x86_64.whl

Download URL quprs-0.13.3-cp38-abi3-manylinux_2_28_x86_64.whl
Size 35.4 MB
Tags CPython 3.8 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
b3fd04f590c7f81b2b47dd099290bf8a79e34103b553fc7d3cc50a3122569b62
BLAKE2b-256 checksum
How to use checksums
6868ec5a7e6867e1544f8096162c2afed54545788ebb69fda0b7091d50c08850
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 Oct 20, 2026.

Transparency log

Release files / quprs-0.13.3-cp38-abi3-manylinux_2_28_aarch64.whl

Download URL quprs-0.13.3-cp38-abi3-manylinux_2_28_aarch64.whl
Size 33.6 MB
Tags CPython 3.8 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
a1f39bf18ffa91334858d1f937a9cd56f15d07cc1841aa91b139f0d0c35ede63
BLAKE2b-256 checksum
How to use checksums
c446118a9c5b364b14366605ee985e4750e16039601d36315b9fb0d8e1fef9d9
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 Oct 20, 2026.

Transparency log

Release files / quprs-0.13.3-cp38-abi3-macosx_15_0_x86_64.whl

Download URL quprs-0.13.3-cp38-abi3-macosx_15_0_x86_64.whl
Size 10.9 MB
Tags CPython 3.8 abi3 macOS 15.0+ x86-64
SHA-256 checksum
How to use checksums
70eeec57c2ab5b5dc1f29f18ea4ed2e3919fd6cc5019e61ee4dbca4be1f5c775
BLAKE2b-256 checksum
How to use checksums
d1b9932bdd0bf4ac91eb51944fbd4a25169313ec08ddc0c8821ce41f65e40c92
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 Oct 20, 2026.

Transparency log

Release files / quprs-0.13.3-cp38-abi3-macosx_15_0_arm64.whl

Download URL quprs-0.13.3-cp38-abi3-macosx_15_0_arm64.whl
Size 9.9 MB
Tags CPython 3.8 abi3 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
299618d1fa9c807b5ac92a91c21b162655db938693b73bb8ac698c23558c8faa
BLAKE2b-256 checksum
How to use checksums
168da06d02c1b71b9c42ea81a94f71ff01d2f11d15fc44b9c6f21a10a2849a2c
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 Oct 20, 2026.

Transparency log

Security for QuPRS 0.13.3

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.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for quprs-0.13.3.tar.gz

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 Oct 20, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.13.3 This release

5 release files Full provenance

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