Clifford+T quantum gate compiler.
Project description
QDecomp
QDecomp is a standalone software package to perform multiple decompositions of single-qubit and two-qubit quantum gates.
The package primarily focuses on decomposing gates into the Clifford+T universal subset by implementing the algorithm proposed by Ross and Selinger [1].
This package was made in collaboration with D-Wave and Polytechnique Montréal.
The package contains 4 main subpackages:
- decompositions : Proposes user-oriented functions for decomposing various quantum gates
- utils : Contains the core algorithms and additional utility functions
- rings : Implements classes for symbolic calculations in mathematical rings
- plot : Offers visualization tools of core parts of the algorithm used mainly for debugging
Below is a figure illustrating the subpackages (green) and their associated modules (yellow) and classes (orange).
Documentation
Complete API documentation is available and can be built locally using Sphinx:
cd docs
make html
./build/html/index.html
The documentation is generated in docs/build/html/. Open docs/build/html/index.html in a browser to view it.
Installation
The QDecomp package can be installed from source by following the following steps:
- Clone the repository
git clone https://github.com/polyquantique/QDecomp.git
cd QDecomp
- (Optional) Create and activate a virtual environment
-
Linux / macOS:
python3 -m venv venv source venv/bin/activate
-
Windows (Command Prompt):
python -m venv venv venv\Scripts\activate
- Install the package and dependencies
-
Standard installation:
pip install .
-
Editable (developer) installation:
pip install -e .[dev]
- (Optional) Run the tests
pip install pytest
pytest tests
Usage Examples
Example #1: Single-Qubit Gate Decomposition
This example demonstrates the use of the qdcomp.decompositions.sqg_decomp function to decompose single-qubit gates (SQG) into the Clifford+T universal subset up to a tolerance error $\varepsilon$. Note that the algorithm guarantees the specified error only for $R_z$ gates, meaning the total error for SQG may exceed the user-defined tolerance due to error propagation.
>>> from scipy.stats import unitary_group
>>> from qdecomp.decompositions import sqg_decomp
>>> # Decompose a random single qubit gate with tolerance 0.001
>>> sqg = unitary_group.rvs(2, random_state=42)
>>> sequence, alpha = sqg_decomp(sqg, epsilon=0.001, add_global_phase=True)
>>> print(sequence, alpha)
sequence : T H S T H S T [...] S H S W W W W
alpha : 0.27
>>> # Decompose a random single qubit gate with tolerance 0.001 up to a global phase
>>> sqg = unitary_group.rvs(2, random_state=42)
>>> sequence, _ = sqg_decomp(sqg, epsilon=0.001, add_global_phase=False)
>>> print(sequence)
T H S T H S T [...] Z T H Z S H S
Example #2: Two-Qubit Gate Decomposition
This example demonstrates the use of the qdecomp.decompositions.tqg_decomp function to decompose two-qubit gates (TQG) into the Clifford+T universal subset up to a tolerance error $\varepsilon$. The function outputs a list of QGate objects representing the circuit. The target qubits and the corresponding sequence can be accessed through the QGate.target and QGate.sequence properties respectively.
>>> from scipy.stats import unitary_group
>>> from qdecomp.decompositions import tqg_decomp
>>> # Decompose a radnom single qubit gate with tolerance 0.001
>>> tqg = unitary_group.rvs(4, random_state=42)
>>> circuit = tqg_decomp(tqg, epsilon=0.001)
>>> for gates in circuit:
... print(f"{gate.target} -> {gate.sequence}")
(0,) -> S T H T [...] H Z S T
(1,) -> S T H T [...] S H S T
(0, 1) -> CNOT1
...
(1,) -> H T H S [...] T H Z S
License
Released under the Apache License 2.0. See LICENSE file.
Citing this package
If you use QDecomp in your research or projects, please cite it using the following BibTeX entry:
@software{qdecomp,
author = {Romain, Olivier and Girouard, Vincent and Trudeau, Marius and Blais, Francis},
title = {QDecomp},
year = {2025},
version = {1.0.1},
url = {https://github.com/polyquantique/QDecomp}
}
References
-
[1] N. J. Ross and P. Selinger, Optimal ancilla-free Clifford+T approximation of z-rotations, 2014. https://arxiv.org/abs/1403.2975
-
[2] V. Kliuchnikov, D. Maslov, and M. Mosca, Fast and efficient exact synthesis of single qubit unitaries generated by Clifford and T gates, 2012. https://arxiv.org/abs/1206.5538
-
[3] G. E. Crooks, Quantum gates, March 2024, version 0.11.0, https://threeplusone.com/pubs/on_gates.pdf
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 qdecomp-1.0.1.tar.gz.
File metadata
- Download URL: qdecomp-1.0.1.tar.gz
- Upload date:
- Size: 59.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d143f9cc6eeff6fd962a8693d274e8cde1cc164e1f275e0edd41e7c75c437675
|
|
| MD5 |
d28ed10e914716992fb275fcb9b1e210
|
|
| BLAKE2b-256 |
9daf6f1ab1b68c99fb58a816324a6628e523d7b92e04df5393011ad2913f3aae
|
File details
Details for the file qdecomp-1.0.1-py3-none-any.whl.
File metadata
- Download URL: qdecomp-1.0.1-py3-none-any.whl
- Upload date:
- Size: 77.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d09dc4c5fa750db36fbae140d13255142ce2b0504dde87afb871087fe18a5f9b
|
|
| MD5 |
453c43513eba0507277bc2a4d867e5c8
|
|
| BLAKE2b-256 |
93fd049948913b1c44bfbbf231f555f568c44803f12953ce1c2b83fb043b0ec6
|