Skip to content

Conversation

@paulQM
Copy link
Collaborator

@paulQM paulQM commented Jan 12, 2026

Add Two-Qubit Randomized Benchmarking Implementation

Summary

This PR adds a complete implementation of two-qubit randomized benchmarking (RB) functionality, including both standard RB and interleaved CZ RB calibration nodes. The implementation provides comprehensive utilities for circuit generation, QUA program execution, data analysis, and visualization.

Changes

New Calibration Nodes

  1. 22_two_qubit_standard_rb.py - Standard two-qubit randomized benchmarking calibration node

    • Measures average gate fidelity of the two-qubit Clifford group
    • Generates random Clifford sequences and measures survival probability vs. circuit depth
  2. 23_two_qubit_interleaved_cz_rb.py - Interleaved CZ randomized benchmarking calibration node

    • Measures the fidelity of the CZ gate specifically
    • Interleaves CZ gates between random Clifford sequences to isolate CZ gate error

New Utility Modules (calibration_utils/two_qubit_interleaved_rb/)

  1. parameters.py - Parameter definitions for RB experiments

    • Configurable circuit lengths, number of shots, operation types (cz_flattop, cz_unipolar, cz_bipolar)
    • Support for state discrimination and input streams
    • Configurable reset types (active/thermal)
  2. rb_utils.py - Core RB circuit generation and analysis

    • StandardRB class for generating standard RB circuits
    • InterleavedRB class for generating interleaved RB circuits
    • Circuit generation using Qiskit Clifford gates
    • Exponential decay curve fitting for fidelity estimation
  3. circuit_utils.py - Circuit processing utilities

    • Conversion of quantum circuits to integer representations for efficient QUA execution
    • Circuit layerization for two-qubit gate execution
    • Gate mapping for single-qubit and two-qubit operations
  4. qua_utils.py - QUA program generation and execution

    • QuaProgramHandler class for managing QUA program execution
    • Gate playing functions with support for various gate types
    • Efficient switch-case structure for circuit execution
    • Qubit reset and readout utilities
  5. data_utils.py - Data analysis and result processing

    • RBResult class for standard RB analysis
    • InterleavedRBResult class for interleaved RB analysis
    • Exponential decay fitting with error estimation
    • Fidelity calculation from decay parameters
  6. analysis.py - Analysis utilities

    • Raw dataset processing
    • Result logging and reporting
    • Integration with qualibrate framework
  7. plot_utils.py - Visualization utilities

    • Gate mapping for debugging and visualization
    • Integer-to-gate-name conversion for circuit inspection

Technical Details

  • Circuit Generation: Uses Qiskit's Clifford group generators to create random RB sequences
  • Gate Set: Default basis gates are ['rz', 'sx', 'x', 'cz']
  • Execution: Circuits are transpiled and executed layer-by-layer using QUA switch-case blocks
  • Analysis: Fits exponential decay curves (A * alpha^m + B) to extract gate fidelity
  • Fidelity Calculation:
    • Standard RB: F = (1 - alpha) * (1 - 1/4^n) where n is number of qubits
    • Interleaved RB: F_CZ = 1 - (1 - alpha_interleaved/alpha_standard) * (4^n - 1)/4^n

Code Quality

  • ✅ All code passes pylint checks
  • ✅ All code formatted with black
  • ✅ Comprehensive docstrings and type hints
  • ✅ Modular design with clear separation of concerns

Files Added

  • calibration_utils/two_qubit_interleaved_rb/analysis.py (162 lines)
  • calibration_utils/two_qubit_interleaved_rb/circuit_utils.py (147 lines)
  • calibration_utils/two_qubit_interleaved_rb/data_utils.py (302 lines)
  • calibration_utils/two_qubit_interleaved_rb/parameters.py (42 lines)
  • calibration_utils/two_qubit_interleaved_rb/plot_utils.py (75 lines)
  • calibration_utils/two_qubit_interleaved_rb/qua_utils.py (468 lines)
  • calibration_utils/two_qubit_interleaved_rb/rb_utils.py (337 lines)
  • calibrations/CZ_calibration_fixed_couplers/22_two_qubit_standard_rb.py (238 lines)
  • calibrations/CZ_calibration_fixed_couplers/23_two_qubit_interleaved_cz_rb.py (235 lines)

Total: 9 files, ~2,006 lines of code

Testing

The implementation follows the existing patterns in the codebase and integrates with the qualibrate framework. All code has been validated to pass linting and formatting checks.

@paulQM
Copy link
Collaborator Author

paulQM commented Jan 12, 2026

@sebastianorbell-qm could you please check why this passes on python 3.12 but not on 3.11 and 3.10?

@sebastianorbell-qm
Copy link

@paulQM

File: qualibration_graphs/superconducting/calibration_utils/two_qubit_interleaved_rb/analysis.py

Line 40:
s_alpha = f"\tFitted alpha: {fit_result["alpha"]:.6f} a.u."

Line 41:
s_fidelity = f"\tFitted fidelity: {100*fit_result["fidelity"]:.6f} %"

Both lines use double quotes inside double-quoted f-strings, which is only supported in Python 3.12+. To fix for Python 3.10 and 3.11 compatibility, change the inner quotes to single quotes:

s_alpha = f"\tFitted alpha: {fit_result['alpha']:.6f} a.u."
s_fidelity = f"\tFitted fidelity: {100*fit_result['fidelity']:.6f} %"

"sequence": xr.DataArray(np.arange(node.parameters.num_circuits_per_length)),
}

standard_RB = InterleavedRB(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small point, but shall we call this variable interleaved_RB for completeness.

Copy link

@sebastianorbell-qm sebastianorbell-qm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

@sebastianorbell-qm
Copy link

@paulQM fix the double quote error and then I'm happy for you to merge it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants