Skip to main content

Documentation

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).

Package Structure

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:

  1. Clone the repository
git clone https://github.com/polyquantique/QDecomp.git
cd QDecomp
  1. (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
    
  1. Install the package and dependencies
  • Standard installation:

    pip install .
    
  • Editable (developer) installation:

    pip install -e .[dev]
    
  1. (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

Metadata

Release files for qdecomp 1.0.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 qdecomp 1.0.1
File Size Uploaded Provenance
qdecomp-1.0.1.tar.gz 59.7 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 137.3 kB

Release files / qdecomp-1.0.1.tar.gz

Download URL qdecomp-1.0.1.tar.gz
Size 59.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d143f9cc6eeff6fd962a8693d274e8cde1cc164e1f275e0edd41e7c75c437675
BLAKE2b-256 checksum
How to use checksums
9daf6f1ab1b68c99fb58a816324a6628e523d7b92e04df5393011ad2913f3aae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.13

Release files / qdecomp-1.0.1-py3-none-any.whl

Download URL qdecomp-1.0.1-py3-none-any.whl
Size 77.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d09dc4c5fa750db36fbae140d13255142ce2b0504dde87afb871087fe18a5f9b
BLAKE2b-256 checksum
How to use checksums
93fd049948913b1c44bfbbf231f555f568c44803f12953ce1c2b83fb043b0ec6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.13

Security for qdecomp 1.0.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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

1.0.1 This release

2 release files No 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