BQSKit-FT: Fault-Tolerant Quantum Compilation
A BQSKit extension package for compiling quantum circuits to fault-tolerant gate sets.
Overview
BQSKit-FT extends the Berkeley Quantum Synthesis Toolkit (BQSKit) with specialized compilation workflows and machine models for fault-tolerant quantum computing. This package provides tools for compiling arbitrary quantum circuits into fault-tolerant gate sets such as Clifford+T and Clifford+RZ.
Key Features
Machine Models
- CliffordTModel: Fault-tolerant machine model with Clifford+T gate set
- CliffordRZModel: Fault-tolerant machine model with Clifford+RZ gate set
- FaultTolerantModel: Base class for custom fault-tolerant machine models
Synthesis Passes
- GridSynthPass: High-precision RZ gate synthesis using the gridsynth algorithm
- RoundToDiscreteZPass: Rounds RZ gates to discrete Clifford+T equivalents
- IsolateRZGatePass: Isolates RZ gates for individual processing
Compilation Workflows
- Pre-built workflows for circuit, unitary, state preparation, and state mapping compilation
- Support for multiple optimization levels (1-4)
- Configurable synthesis precision and error thresholds
- Optional RZ gate decomposition into Clifford+T
Installation
Dependencies
pip install bqskit numpy scipy pygridsynth
Install BQSKit-FT
git clone https://github.com/BQSKit/bqskit-ft.git
cd bqskit-ft
pip install -e .
Quick Start
Basic Clifford+T Compilation
from bqskit import Circuit, compile
from bqskit.ft import CliffordTModel
from bqskit.ir.gates import RZGate, CNOTGate
# Create a circuit with arbitrary rotations
circuit = Circuit(2)
circuit.append_gate(CNOTGate(), [0, 1])
circuit.append_gate(RZGate(), [0], [0.12345]) # Arbitrary angle
circuit.append_gate(RZGate(), [1], [0.67890])
# Define fault-tolerant machine model
model = CliffordTModel(2)
# Compile to Clifford+T gate set
ft_circuit = compile(circuit, model)
# Verify output uses only fault-tolerant gates
print(f"Gate set: {ft_circuit.gate_set}")
High-Precision RZ Synthesis
from bqskit.ft.ftpasses import GridSynthPass
from bqskit.compiler import Compiler
# Single RZ gate with arbitrary angle
circuit = Circuit(1)
circuit.append_gate(RZGate(), [0], [0.1234567890123456])
# High-precision synthesis (20 decimal places)
gridsynth = GridSynthPass(precision=20)
with Compiler() as compiler:
result = compiler.compile(circuit, [gridsynth])
print(f"Synthesized with {result.num_operations} gates")
Custom Workflows
from bqskit.ft.ftpasses import IsolateRZGatePass, GridSynthPass
from bqskit.passes import ForEachBlockPass, UnfoldPass
# Build custom workflow for mixed circuits
workflow = [
IsolateRZGatePass(), # Isolate RZ gates
ForEachBlockPass([GridSynthPass(15)]), # Synthesize each RZ gate
UnfoldPass(), # Flatten the circuit
]
with Compiler() as compiler:
result = compiler.compile(circuit, workflow)
Machine Models
CliffordTModel
Represents a fault-tolerant quantum computer with the Clifford+T gate set:
- Clifford gates: H, X, Y, Z, S, S†, √X, CNOT, CZ, SWAP
- Non-Clifford gates: T, T†, RZ
from bqskit.ft import CliffordTModel
# 4-qubit fault-tolerant machine
model = CliffordTModel(
num_qudits=4,
clifford_gates=None, # Use default Clifford gates
non_clifford_gates=None, # Use default T gates + RZ
)
CliffordRZModel
Alternative model that keeps RZ gates (no T gate decomposition):
- Clifford gates: H, X, Y, Z, S, S†, √X, CNOT, CZ, SWAP
- Non-Clifford gates: T, T†, RZ (RZ gates preserved)
from bqskit.ft import CliffordRZModel
model = CliffordRZModel(num_qudits=3)
Synthesis Passes
GridSynthPass
Implements the gridsynth algorithm for optimal Clifford+T synthesis of RZ gates:
from bqskit.ft.ftpasses import GridSynthPass
# Precision: 10^-15 approximation error
gridsynth = GridSynthPass(precision=15)
Features:
- Arbitrary precision synthesis using mpmath
- Provably optimal T-count for single-qubit unitaries
- Configurable precision (affects T-gate count vs. accuracy trade-off)
RoundToDiscreteZPass
Rounds RZ gates to the nearest π/4 multiple (Clifford+T equivalent):
from bqskit.ft.ftpasses import RoundToDiscreteZPass
rounder = RoundToDiscreteZPass(synthesis_epsilon=1e-8)
Use cases:
- Fast approximation for near-Clifford+T angles
- Pre-processing step before gridsynth
- Error-tolerant applications
Compilation Options
Optimization Levels
- Level 1: Fast compilation, basic optimization
- Level 2: Balanced speed/quality
- Level 3: Aggressive optimization
- Level 4: Maximum optimization (slowest)
Synthesis Parameters
synthesis_epsilon: Maximum unitary distance error (default: 1e-8)max_synthesis_size: Maximum block size for synthesis (default: 3)decompose_rz: Whether to decompose RZ gates to Clifford+T (default: True)
from bqskit import compile
from bqskit.ft import CliffordTModel
model = CliffordTModel(2)
# High-precision, aggressive optimization
result = compile(
circuit,
model,
optimization_level=4,
synthesis_epsilon=1e-12,
max_synthesis_size=4
)
Advanced Usage
Custom Gate Sets
from bqskit.ft import FaultTolerantModel
from bqskit.ir.gates import HGate, CNOTGate, TGate
# Custom fault-tolerant model
custom_clifford = [HGate(), CNOTGate()] # Minimal Clifford set
custom_non_clifford = [TGate()] # T gates only
model = FaultTolerantModel(
num_qudits=2,
clifford_gates=custom_clifford,
non_clifford_gates=custom_non_clifford
)
References
Citation
If you use bqskit-ft in your research, please cite:
@software{bqskit_ft,
title = {{BQSKit-FT}: Fault-Tolerant Quantum Compilation},
author = {Weiden, Mathias},
year = {2024},
url = {https://github.com/BQSKit/bqskit-ft}
}
Metadata
Release files for bqskit-ft 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| bqskit_ft-0.2.0.tar.gz | 14.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bqskit_ft-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 34.8 kB
Release files / bqskit_ft-0.2.0.tar.gz
| Download URL | bqskit_ft-0.2.0.tar.gz |
|---|---|
| Size | 14.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e6d482e422c3dc73bffc49d7a70fdf98c70518273f1c693686703c1672eac14c
|
|
BLAKE2b-256 checksum How to use checksums |
feb45f50f20bf10f875e47234884da325ef9f0557bbf1a402ac1be3f12121e92
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / bqskit_ft-0.2.0-py3-none-any.whl
| Download URL | bqskit_ft-0.2.0-py3-none-any.whl |
|---|---|
| Size | 19.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
02356d9dca0998d31e78c2e70bed49f4eac2045a8721ae47b9c0eef3ac9304eb
|
|
BLAKE2b-256 checksum How to use checksums |
4f0e8dc49f37da2b5b05ff30147efcad255b9d9b81198b21419aea7dfc82804c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Security for bqskit-ft 0.2.0
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.