A BQSKit extension package for compiling quantum circuits to fault-tolerant gate sets.
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.
BQSKit-FT can be installed from PyPI using
pip install bqskit-ftFor the most up to date version install from github using:
git clone https://github.com/BQSKit/bqskit-ft.git
cd bqskit-ft
pip install -e .Synthesis to fault-tolerant gate sets is done by specifying a fault-tolerant MachineModel. For The Clifford+T gate set, that is the CliffordTModel. While the Clifford+RZ gate set is not fault-tolerant, it's useful to have. The Clifford+RZ gate set can be targeted by specifying a CliffordRZModel. Note that these methods use from bqskit import compile, not the compile function from bqskit.compiler.Compiler.
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) # or model = CliffordRZModel(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}")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")If using the Compiler() class, the passes that make up default Clifford+T and Clifford+RZ conversion workflows can be imported like:
from bqskit.ft.compiler import Compiler
from bqskit.ft.cliffordrz import build_cliffordrz_workflow
passes = build_cliffordrz_workflow()
with Compiler() as compiler:
result = compiler.compile(circuit, passes)
assert all([gate in clifford_rz_gates for gate in result.gate_set])Represents a fault-tolerant quantum computer with the Clifford+T gate set:
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
)Alternative model that keeps RZ gates (no T gate decomposition):
from bqskit.ft import CliffordRZModel
model = CliffordRZModel(num_qudits=3)Other gate sets can be targeted with the following:
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
)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}
}