Exploring Hardware-Efficient Implementations of Bivariate Bicycle Codes
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:
- SWAP-based approach: Using SWAP gates to route long-range interactions
- Time-dynamic approach: Scheduling measurements across time to avoid SWAPs (analogous to honeycomb surface code mapping)
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?
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
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
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
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
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
- Python 3.8 or higher
- pip package manager
- Navigate to the project directory:
cd "/Users/khatran/Library/Mobile Documents/com~apple~CloudDocs/Aalto-yliopisto/Practical Quantum Computing/Project/bb_lattice_mapping"- Install dependencies:
pip install -r requirements.txtThe main dependency is Stim, a fast quantum error correction simulator.
Execute all four tasks sequentially:
python3 run_all_tasks.pyThis will run each task in order, with pauses between tasks for review.
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.pyModify 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 statisticsThe 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.
When qubits are too far apart for direct interaction:
- Find shortest path between qubits using BFS
- Insert SWAP gates to move qubits closer
- Perform the desired CNOT
- Un-SWAP to restore original positions
Trade-off: Adds circuit depth and additional error sources from SWAP gates.
Inspired by honeycomb surface code mapping:
- Partition checks into groups based on locality
- Schedule measurements across multiple time slices
- Alternate measurement patterns between cycles for refocusing
- Bridge distant qubits through intermediaries
Advantage: Eliminates SWAP gates entirely, reducing overhead.
Trade-off: Increased circuit depth due to sequential time slices.
-
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
-
SWAP-based approach:
- Significant SWAP overhead (ratio > 1.0)
- Moderate circuit depth
- Logical error rates depend on SWAP quality
-
Dynamic approach:
- Zero SWAP overhead
- Potentially larger circuit depth (more time slices)
- Logical error rates should be competitive or better
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.
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)
The SwapRouter class implements:
- BFS shortest path finding
- SWAP sequence generation
- Position tracking during routing
- Support for both CNOT directions (X and Z checks)
The DynamicSchedule class implements:
- Check partitioning based on locality
- Time-alternating measurement patterns
- Bridge qubit selection for indirect interactions
- Refocusing through time-reversed cycles
Both simulators use Stim's features:
- Fast circuit simulation
- Depolarizing noise models
- Detector and observable tracking
- Monte Carlo sampling
-
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.
-
Detector placement: Detectors are simplified. A production implementation would track individual stabilizer measurements and their correlations.
-
Noise model: Uses uniform depolarizing noise. Real hardware has biased and correlated errors.
-
Small lattices: Demonstrations use small lattices (3×3) for speed. Larger lattices would show clearer trends.
-
Exact BB codes: Implement the [[144,12,12]] gross code or [[288,12,18]] two-gross code with exact stabilizer patterns.
-
Logical operations: Extend to include logical gate implementations using the bicycle instruction set.
-
Decoder integration: Add matching-based or BP decoders for realistic error correction.
-
Hardware-specific noise: Model actual device characteristics (T1, T2, crosstalk).
-
Optimization: Optimize time slice scheduling for minimal depth while maintaining error detection.
-
Hexagonal geometry: Explicitly model hexagonal lattice connectivity for more direct comparison with surface code work.
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: A fast stabilizer circuit simulator by Craig Gidney
- Documentation: https://github.com/quantumlib/Stim
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
This project is provided for educational purposes. See individual source files for specific licensing information.
-
Install dependencies:
pip install stim numpy matplotlib
-
Run all tasks:
python3 run_all_tasks.py
-
Check results:
ls results/ cat results/task1_circuit_summary.txt cat results/task3_schedule_summary.txt python visualize_results.py
-
Analyze simulations:
python3 -c "import json; print(json.dumps(json.load(open('results/task2_simulation_results.json')), indent=2))"
Email: kha.tran@aalto.fi Phone: +358 465392406