Skip to main content

QuPRS: Quantum Path-sum Reduction and Solver

Project description

License PyPI version PyPI Downloads Docker Pulls GitHub last commit PyPI - Python Version DOI 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
    

    or install QuPRS latest commit:

    pip install git+https://github.com/PhysicsQoo/QuPRS.git
    

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",)
    

Cite

If you use QuPRS in your research, please consider citing it.

This code is associated with a forthcoming publication. Please cite this repository for now, and check back for the full paper citation.

DOI

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

quprs-0.12.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

quprs-0.12.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (28.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

quprs-0.12.0-cp311-cp311-macosx_15_0_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

quprs-0.12.0-cp311-cp311-macosx_14_0_arm64.whl (7.2 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

File details

Details for the file quprs-0.12.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for quprs-0.12.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 82cfac72baf9dbf4a876237e3032a0451b044c35afea7e5e9cbe822e153da9d5
MD5 5ac4e6442a436137a3f2dbfe2c79078b
BLAKE2b-256 08c66e28c8956cba9c146ea6e284a06424fcd29882a38b59c5078d07b17d5e81

See more details on using hashes here.

Provenance

The following attestation bundles were made for quprs-0.12.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-publish.yml on PhysicsQoo/QuPRS

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quprs-0.12.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for quprs-0.12.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e05de46054488465d723059bae8db246940d1919951373ae02576be58702f932
MD5 a25336b5a2840d46b29562fd7bc8797f
BLAKE2b-256 b65cb856c275a5a04d01bda287faad84ff08db84750f178ec608b96f0265bb91

See more details on using hashes here.

Provenance

The following attestation bundles were made for quprs-0.12.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: python-publish.yml on PhysicsQoo/QuPRS

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quprs-0.12.0-cp311-cp311-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for quprs-0.12.0-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 5df7d500e4ae20dc09a4679bac33adac02adc0c9a2785d4837d4db28ba74270a
MD5 6b8bcae8700688b06deb61d4b2dc6e80
BLAKE2b-256 2f3b97ab5fda10dc65a9eaa967ae9e50475059f0f4f7c533c158633a0d35ecab

See more details on using hashes here.

Provenance

The following attestation bundles were made for quprs-0.12.0-cp311-cp311-macosx_15_0_x86_64.whl:

Publisher: python-publish.yml on PhysicsQoo/QuPRS

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quprs-0.12.0-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for quprs-0.12.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 eca7cc4b157b0111710f8545450f7387a716b95c3f3afec45b36edb78178f521
MD5 ba47dc25096a335a2a7e8eee1e44be86
BLAKE2b-256 f9c80b65a45423694c5681e31511a5ddb4e2cdcb169932fdb87e8f66624064c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for quprs-0.12.0-cp311-cp311-macosx_14_0_arm64.whl:

Publisher: python-publish.yml on PhysicsQoo/QuPRS

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page