QuPRS: Quantum Path-sum Reduction and Solver
Project description
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:
- Hybrid mode (RR + WMC): Combines the efficiency of reduction rules and the completeness of weighted model counting.
- Reduction rules only (RR): Extremely fast, suitable for circuits that can be simplified by local rules.
- WMC only: A powerful SAT-based method for more complex circuit structures.
- Seamless integration with Qiskit ecosystem: Circuits can be directly loaded from Qiskit
QuantumCircuitobjects or QASM files.
Contents
Installation
It is recommended to install QuPRS in a virtual environment.
-
Create and activate a Conda virtual environment:
conda create --name QuPRS python=3.12 # Or your preferred Python version conda activate QuPRS
-
Install
QuPRSusing pip:pip install QuPRS
or install
QuPRSlatest 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
QuantumCircuitobjects: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.interface.load_qiskit import qasm_eq_check_with_wmc output_dict = qasm_eq_check_with_wmc(circuit1, circuit2)
-
Using Reduction Rules (RR)
This method checks if two circuits are equivalent primarily using Reduction Rules.
from QuPRS.interface.load_qiskit import qasm_eq_check output_dict, circuit = qasm_eq_check(circuit1, circuit2)
-
WMC only (without RR)
To perform equivalence checking using only WMC, you need to disable the Reduction Rules switch.
from QuPRS.interface.load_qiskit import qasm_eq_check_with_wmc from QuPRS.pathsum import pathsum pathsum.set_reduction_switch(False) output_dict = qasm_eq_check_with_wmc(circuit1, circuit2)
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.
License Information
- This project’s original source code is licensed under: MIT
- Kenji Hashimoto’s binary component (
QuPRS/utils/gpmc) is licensed under the MIT License and the file (QuPRS/utils/Qiskit_Circuit_Utils.py) contains functions (random_circuit,random_clifford_T_circuit) that are derived from the Qiskit library. The original Qiskit code is licensed under the Apache 2.0. see: NOTICE
Acknowledgements
This project utilizes gpmc, a binary component developed by Kenji Hashimoto, for parts of its Weighted Model Counting functionality.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file quprs-0.5.0.tar.gz.
File metadata
- Download URL: quprs-0.5.0.tar.gz
- Upload date:
- Size: 363.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95e097e73f9954631b9efcfa75b49d2994bc37f521eadf50c8cb919a1f006c2c
|
|
| MD5 |
6d012d1cdcd275b35a00ba0ec91d7e5f
|
|
| BLAKE2b-256 |
223a1c8b571d11b50081d7d45fced5c47d2bc118ee1aa7f6d7f07398121854f7
|
Provenance
The following attestation bundles were made for quprs-0.5.0.tar.gz:
Publisher:
python-publish.yml on PhysicsQoo/QuPRS
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
quprs-0.5.0.tar.gz -
Subject digest:
95e097e73f9954631b9efcfa75b49d2994bc37f521eadf50c8cb919a1f006c2c - Sigstore transparency entry: 237583877
- Sigstore integration time:
-
Permalink:
PhysicsQoo/QuPRS@870d4ed089513122c8b3cfaca7989d5386ae6d30 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/PhysicsQoo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@870d4ed089513122c8b3cfaca7989d5386ae6d30 -
Trigger Event:
push
-
Statement type:
File details
Details for the file quprs-0.5.0-py3-none-any.whl.
File metadata
- Download URL: quprs-0.5.0-py3-none-any.whl
- Upload date:
- Size: 363.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c4fbcbfe254b2e213620a992892378f14178c30818ac6b89e38d214eea11a40
|
|
| MD5 |
acaae132aacd811969ebb8ef0b5970fe
|
|
| BLAKE2b-256 |
1fd7b19f3c1c29a09528addfe4849d3c53c953d68acb8b8462153535c34b239c
|
Provenance
The following attestation bundles were made for quprs-0.5.0-py3-none-any.whl:
Publisher:
python-publish.yml on PhysicsQoo/QuPRS
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
quprs-0.5.0-py3-none-any.whl -
Subject digest:
2c4fbcbfe254b2e213620a992892378f14178c30818ac6b89e38d214eea11a40 - Sigstore transparency entry: 237583881
- Sigstore integration time:
-
Permalink:
PhysicsQoo/QuPRS@870d4ed089513122c8b3cfaca7989d5386ae6d30 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/PhysicsQoo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@870d4ed089513122c8b3cfaca7989d5386ae6d30 -
Trigger Event:
push
-
Statement type: