Skip to content

Balrog-Q/BB-Lattice-Mapping

Repository files navigation

BB Code Lattice Mapping Project

Exploring Hardware-Efficient Implementations of Bivariate Bicycle Codes

Overview

This project investigates practical implementations of the Bivariate Bicycle (BB) code, a promising quantum Low-Density Parity-Check (LDPC) code for fault-tolerant quantum computing. The BB code achieves excellent code parameters but requires long-range connectivity between qubits (6 neighbors per qubit), making it challenging to implement on 2D hardware architectures.

Inspired by successful mappings of the surface code to honeycomb lattices, this project explores two approaches for implementing BB codes on 2D lattices:

  1. SWAP-based approach: Using SWAP gates to route long-range interactions
  2. Time-dynamic approach: Scheduling measurements across time to avoid SWAPs (analogous to honeycomb surface code mapping)

Motivation

The BB code has emerged as a serious candidate for fault-tolerant quantum computing architectures due to:

  • High code rate: More logical qubits per physical qubit than surface codes
  • Good distance: Strong error correction capability
  • Modular structure: Fits well with the bicycle architecture

However, the BB code's requirement for 6-neighbor connectivity and long-range CNOTs poses implementation challenges. This project addresses the question:

Can the BB code be mapped to 2D lattices using time-dynamic scheduling, similar to how the surface code has been successfully mapped to hexagonal lattices?

Project Structure

bb_lattice_mapping/
├── src/
│   ├── utils/
│   │   ├── bb_lattice.py          # BB code lattice geometry and connectivity
│   │   └── swap_routing.py        # SWAP routing algorithms
│   ├── task1_swap/
│   │   └── bb_code_swap.py        # Task 1: SWAP-based implementation
│   ├── task2_sim_swap/
│   │   └── simulate_swap_bb.py    # Task 2: Stim simulation (SWAP)
│   ├── task3_schedule/
│   │   └── dynamic_schedule.py    # Task 3: Time-dynamic schedule
│   └── task4_sim_dynamic/
│       └── simulate_dynamic_bb.py # Task 4: Stim simulation (dynamic)
├── results/                        # Output files from simulations
├── data/                          # Input data (if needed)
├── docs/                          # Additional documentation
├── run_all_tasks.py               # Main execution script
├── requirements.txt               # Python dependencies
└── README.md                      # This file

Tasks

Task 1: SWAP Circuit Implementation

Goal: Implement BB code on a 2D lattice using SWAP gates for long-range connectivity.

Approach:

  • Map BB code unit cells to a 2D grid
  • Use BFS-based routing to find optimal SWAP paths
  • Generate complete stabilizer measurement circuit with SWAPs

Output: Circuit summary showing gate counts and SWAP overhead

Task 2: Stim Simulation (SWAP-based)

Goal: Simulate logical failure rates of the SWAP-based BB code.

Approach:

  • Build Stim circuit with depolarizing noise model
  • Run Monte Carlo simulations across multiple error rates
  • Measure logical error rate vs physical error rate

Output: JSON file with simulation results and error suppression ratios

Task 3: Time-Dynamic Schedule

Goal: Design a measurement schedule that avoids SWAPs using time-dynamic techniques.

Approach:

  • Partition stabilizer checks into time slices
  • Each slice uses only nearest-neighbor gates
  • Implement time-alternating patterns for refocusing (inspired by honeycomb mapping)
  • Use bridge qubits for indirect interactions

Output: Schedule summary showing time slices and gate requirements

Task 4: Stim Simulation (Dynamic Schedule)

Goal: Simulate logical failure rates of the time-dynamic BB code.

Approach:

  • Build Stim circuit using dynamic schedule
  • Compare performance with SWAP-based approach
  • Analyze overhead and error rates

Output: JSON file with results and comparison with Task 2

Installation

Prerequisites

  • Python 3.8 or higher
  • pip package manager

Setup

  1. Navigate to the project directory:
cd "/Users/khatran/Library/Mobile Documents/com~apple~CloudDocs/Aalto-yliopisto/Practical Quantum Computing/Project/bb_lattice_mapping"
  1. Install dependencies:
pip install -r requirements.txt

The main dependency is Stim, a fast quantum error correction simulator.

Usage

Run All Tasks

Execute all four tasks sequentially:

python3 run_all_tasks.py

This will run each task in order, with pauses between tasks for review.

Run Individual Tasks

Each task can be run independently:

# Task 1: SWAP circuit generation
python3 src/task1_swap/bb_code_swap.py

# Task 2: SWAP simulation
python3 src/task2_sim_swap/simulate_swap_bb.py

# Task 3: Dynamic schedule generation
python3 src/task3_schedule/dynamic_schedule.py

# Task 4: Dynamic simulation
python3 src/task4_sim_dynamic/simulate_dynamic_bb.py

Customization

Modify simulation parameters by editing the main() functions in each task file:

# Example: Change lattice size
lattice_size = (4, 4)  # 4×4 instead of 3×3

# Example: Adjust error rates
error_rates = [0.0001, 0.001, 0.01, 0.1]

# Example: Increase simulation shots
num_shots = 100000  # More shots = better statistics

Key Concepts

BB Code Structure

The BB code uses an ℓ×m grid of unit cells, each containing:

  • 1 Left (L) qubit
  • 1 Right (R) qubit
  • 1 Z check operator
  • 1 X check operator

With long-range connections (typically distance-2), each qubit has 6 neighbors, making direct implementation on 2D hardware challenging.

SWAP-Based Approach

When qubits are too far apart for direct interaction:

  1. Find shortest path between qubits using BFS
  2. Insert SWAP gates to move qubits closer
  3. Perform the desired CNOT
  4. Un-SWAP to restore original positions

Trade-off: Adds circuit depth and additional error sources from SWAP gates.

Time-Dynamic Approach

Inspired by honeycomb surface code mapping:

  1. Partition checks into groups based on locality
  2. Schedule measurements across multiple time slices
  3. Alternate measurement patterns between cycles for refocusing
  4. Bridge distant qubits through intermediaries

Advantage: Eliminates SWAP gates entirely, reducing overhead.

Trade-off: Increased circuit depth due to sequential time slices.

Results Interpretation

Metrics

  • SWAP Overhead Ratio: (# SWAPs) / (# logical CNOTs needed)

    • Lower is better
    • 0.0 for dynamic schedule (no SWAPs)
  • Logical Error Rate (p_L): Probability of logical error per code cycle

  • Error Suppression Ratio: p_L / p_physical

    • < 1.0 indicates error suppression (good!)
    • 1.0 indicates error amplification (code distance or rounds too small)

  • Circuit Depth: Number of sequential gate layers

    • Affects total execution time
    • More depth = more opportunities for errors

Expected Outcomes

  1. SWAP-based approach:

    • Significant SWAP overhead (ratio > 1.0)
    • Moderate circuit depth
    • Logical error rates depend on SWAP quality
  2. Dynamic approach:

    • Zero SWAP overhead
    • Potentially larger circuit depth (more time slices)
    • Logical error rates should be competitive or better

Comparison

The key question: Does the dynamic approach achieve comparable or better logical error rates despite increased depth?

If yes, this suggests BB codes can be efficiently implemented on 2D hardware using time-dynamic scheduling, similar to the hexagonal surface code mapping.

Technical Details

Lattice Geometry

The BBLattice class handles:

  • Toric boundary conditions (periodic wrapping)
  • Coordinate systems for visualization
  • Connectivity graphs (which qubits can interact)
  • Check operator support (which qubits participate in each stabilizer)

SWAP Routing

The SwapRouter class implements:

  • BFS shortest path finding
  • SWAP sequence generation
  • Position tracking during routing
  • Support for both CNOT directions (X and Z checks)

Dynamic Scheduling

The DynamicSchedule class implements:

  • Check partitioning based on locality
  • Time-alternating measurement patterns
  • Bridge qubit selection for indirect interactions
  • Refocusing through time-reversed cycles

Stim Integration

Both simulators use Stim's features:

  • Fast circuit simulation
  • Depolarizing noise models
  • Detector and observable tracking
  • Monte Carlo sampling

Limitations and Future Work

Current Limitations

  1. Simplified stabilizers: The current implementation uses a simplified version of BB code stabilizers for demonstration purposes. A full implementation would use the exact stabilizer structure from the literature.

  2. Detector placement: Detectors are simplified. A production implementation would track individual stabilizer measurements and their correlations.

  3. Noise model: Uses uniform depolarizing noise. Real hardware has biased and correlated errors.

  4. Small lattices: Demonstrations use small lattices (3×3) for speed. Larger lattices would show clearer trends.

Future Extensions

  1. Exact BB codes: Implement the [[144,12,12]] gross code or [[288,12,18]] two-gross code with exact stabilizer patterns.

  2. Logical operations: Extend to include logical gate implementations using the bicycle instruction set.

  3. Decoder integration: Add matching-based or BP decoders for realistic error correction.

  4. Hardware-specific noise: Model actual device characteristics (T1, T2, crosstalk).

  5. Optimization: Optimize time slice scheduling for minimal depth while maintaining error detection.

  6. Hexagonal geometry: Explicitly model hexagonal lattice connectivity for more direct comparison with surface code work.

References

BB Codes and Bicycle Architecture Tour de gross: A modular quantum computer based on bivariate bicycle codes [https://arxiv.org/pdf/2506.03094]

  • Bivariate bicycle codes: Quantum LDPC codes with high rate and distance
  • Bicycle architecture: Modular framework for fault-tolerant quantum computing

Surface Code on Hexagonal Lattices Demonstrating dynamic surface code [https://arxiv.org/pdf/2412.14360]

  • Time-dynamic surface code implementation using alternating measurement cycles with lateral shifts and refocusing

Stim

Authors and Acknowledgments

This project was developed for the Practical Quantum Computing course at Aalto University.

Acknowledgments:

  • Stim library by Craig Gidney
  • BB code research community
  • Surface code on hexagonal lattices research

License

This project is provided for educational purposes. See individual source files for specific licensing information.


Quick Start Guide

  1. Install dependencies:

    pip install stim numpy matplotlib
  2. Run all tasks:

    python3 run_all_tasks.py
  3. Check results:

    ls results/
    cat results/task1_circuit_summary.txt
    cat results/task3_schedule_summary.txt
    python visualize_results.py
  4. Analyze simulations:

    python3 -c "import json; print(json.dumps(json.load(open('results/task2_simulation_results.json')), indent=2))"

Contact

Email: kha.tran@aalto.fi Phone: +358 465392406

About

This is a BB code lattice mapping for a course CS-C3260 Practical Quantum Computing

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published