Tools for generating and analyzing quantum error correction circuits for the paper "Stairway Codes: Floquetifying Bivariate Bicycle Codes and Beyond".
- Python 3.10 or higher
- pip package manager
It's recommended to use a virtual environment to avoid dependency conflicts:
# Create a virtual environment
python -m venv venv
# Activate the virtual environment
# On macOS/Linux:
source venv/bin/activate
# On Windows:
# venv\Scripts\activate# Install everything
pip install -e ".[all]"These are the operations required for reproducing the paper's result. Use the --help option for advanced use.
Plots are generated using the jupyter notebooks in notebooks directory.
This is used to generate sets of periodicity vectors (out/scanning/showcased_codes.csv.
python ./tools/generate_scanning_data.py \
--d1 4 \
--d2 6 \
--output_dir ./out/scanning/Analyze embedded code distance properties. Should use Gurobi if installed (recommended).
python ./tools/scan_distance.py \
--file ./out/scanning/showcased_codes.csv \
--filter "index < 200" \
--time_limit 100 \
--params k d1 d2 d3--file: Path to input CSV file--filter: Pandas query string to filter results--time_limit: Time limit for ILP calculation (default: 100)--params: Parameters to compute (choices: n, k, d1, d2, d3)--cores: Number of CPU cores to use--no_logs: Disable logging for better performance
Generate BB circuits with various configurations:
Stairway codes memory circuit generation:
python ./tools/make_2BGA_circuits.py \
--input_file "out/scanning/showcased_codes.csv" \
--query "index==index" \
--output_dir out/circuits/showcased_all \
--noise_model "em3" \
--p "$p" \
--rounds -1 #-1 generates d rounds (based on the input file)BB codes with SEC compiled to pairwise measurements:
python ./tools/make_circuits.py \
--output_dir out/circuits/BB_pairwise \
--code_params "$code_param" \
--p "$p" \
--rounds "$rounds" \
--noise_model "em3" \
--decompose_CNOTs \
--memory_type "Z"Sample and decode circuits. Note that decoding for Stairway codes is resource intensive and requires dividing the load on multiple machines.
python ./tools/decode.py \
--max_shots 1000 \
--circuit_files ./out/circuits/showcased_all/*.stim \
--print_progress \
--decoder "tesseract_short" \
--comment "showcased_all"--max_shots: Maximum number of shots to simulate (default: 10)--max_errors: Maximum number of errors to collect (default: 100)--circuit_files: List of circuit files to decode (supports wildcards)--print_progress: Display progress during decoding--detect_errors: Detect errors instead of correcting them--decoder: Decoder to use (default: 'bposd')--output_preamble: Prefix for output files (default: 'output')--comment: Additional comment for metadata
Combined tool that filters CSV data, generates 2BGA circuits, and calculates circuit distance:
python ./tools/scan_circuit_distance.py \
--file ./out/scanning/showcased_codes.csv \
--query "index < 50" \
--p 1e-3 \
--rounds 2 \
--noise_model em3 \
--decoder mip \
--memory_type both \
--no_cache \
--cores 1 \
--config basic_cellThis tool combines three operations:
- Reads and filters a CSV file (like scan_distance.py)
- Generates 2BGA circuits for each filtered row (like make_2BGA_circuits.py)
- Calculates the circuit distance using a decoder
--file: Path to input CSV file (required)--query: Pandas query string to filter results (required)--p: Physical error rate for circuit generation (required)--rounds: Number of syndrome measurement rounds (required)--noise_model: Noise model name to use (required)--decoder: Decoder for distance calculation (choices: bposd, bposd_long_bp, tesseract, tesseract_long, tesseract_short; default: bposd)--decoder_kwargs: Decoder arguments as comma-separated key=value pairs (e.g., "max_iter=100,bp_method=ms")--memory_type: Type of memory experiment (choices: X, Z, both; default: Z)--cores: Number of CPU cores to use--no_logs: Disable logging for better performance
python tools/add_noise_hyperbolic.py "out/circuits/hyperbolic_oscar/semi_hyperbolic_floquet_l=2_n=2048_k=66_d=8_basis=Z_num_sub_rounds=42.stim" --noise_model em3 --p 0.005 --output_dir out/hyperbolic_noisywith ILP decoder:
python ./tools/find_circuit_distance.py \
circuit.stim \
--decoder mip \
--decoder-kwargs "time_limit=100" \
--output-preamble "circuit_distance" \with bposd or another:
python ./tools/find_circuit_distance.py \
circuit.stim \
--decoder bposd \
--decoder-kwargs "max_bp_iters=5000,osd_order=10" \
--output-preamble "circuit_distance" \
--verbosesrc/: Core library codeBB.py: BB code implementationsstabilizer.py: Stabilizer code utilitiescircuit_distance.py: Circuit distance calculationsdecoder_utils.py: Decoder utilitiesfers_idea/: FERS-related implementations
tools/: Command-line toolsmake_circuits.py: Circuit generationmake_2BGA_circuits.py: 2BGA circuit generationdecode.py: Error correction decodingscan_distance.py: Distance scanningscan_circuit_distance.py: Combined circuit generation and distance calculation
notebooks/: Jupyter notebooks for analysis and plotsout/: Output directory for generated files
Generated circuits and results are saved in the out/ directory:
out/circuits/: Generated Stim circuit files (.stim) and metadata (.json)out/collection/: Decoding results (CSV format)out/fer/: Distance scanning resultsout/circuit_distance/: Circuit distance scanning resultsout/logs/: Log files