Skip to main content

BQSKit extension for compiling to Fault-Tolerant gate sets.

Project description

BQSKit-FT: Fault-Tolerant Quantum Compilation

A BQSKit extension package for compiling quantum circuits to fault-tolerant gate sets.

Python 3.8+ License

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}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bqskit_ft-0.2.0.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bqskit_ft-0.2.0-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file bqskit_ft-0.2.0.tar.gz.

File metadata

  • Download URL: bqskit_ft-0.2.0.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for bqskit_ft-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e6d482e422c3dc73bffc49d7a70fdf98c70518273f1c693686703c1672eac14c
MD5 3f17dfd3bfcb6f06ec6b17d375fd67ca
BLAKE2b-256 feb45f50f20bf10f875e47234884da325ef9f0557bbf1a402ac1be3f12121e92

See more details on using hashes here.

File details

Details for the file bqskit_ft-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: bqskit_ft-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for bqskit_ft-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 02356d9dca0998d31e78c2e70bed49f4eac2045a8721ae47b9c0eef3ac9304eb
MD5 d10bfebe39ca312d5086ae7c414d1089
BLAKE2b-256 4f0e8dc49f37da2b5b05ff30147efcad255b9d9b81198b21419aea7dfc82804c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page