Source code for bragi_quantum.experiments.nodes.coupler.tqg_randomized_benchmarking.node

# ══════════════════════════════════════════════════════════════════════════
#     ___   ___ ___   _      _   ___
#    / _ \ / __|_  ) | |    /_\ | _ )
#   | (_) | (__ / /  | |__ / _ \| _ \
#    \__\_\\___/___| |____/_/ \_\___/
#
#   QC2 @ CHALMERS CALIBRATION TOOLKIT
#   (c) 2026 Chalmers University of Technology and Project Contributors
# ──────────────────────────────────────────────────────────────────────────
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       https://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
# ──────────────────────────────────────────────────────────────────────────
#   CONTRIBUTORS list:
#
#   Joel Sandås, joel.sandas@chalmers.se
#   Axel Andersson, axean@chalmers.se
#   Matteo Robbiati, robbiati@chalmers.se
#   Michele Faucci Giannelli, faucci@chalmers.se
# ══════════════════════════════════════════════════════════════════════════


"""
Node implementations for two-qubit-gate randomized benchmarking (TQG RB).

Ported from tergite-autocalibration (TQGRandomizedBenchmarkingSSRONode /
TQGRandomizedBenchmarkingInterleavedSSRONode). ``TQGRandomizedBenchmarking``
runs standard RB; ``TQGRandomizedBenchmarkingInterleaved`` additionally
interleaves a bare CZ Clifford into every sequence, and combines its decay
parameter with the standard run's (via Redis) to derive the CZ gate fidelity.
Both share the same measurement class and coupler CZ settings, resolved here
from ``self.edges[coupler].cz`` rather than read from Redis directly
(matching the ``cz_phases`` / ``cz_parametrization`` convention).
"""

from typing import override

import numpy as np

from bragi_quantum.datalayer.models.qubit import ExtendedTransmon
from bragi_quantum.experiments.nodes.coupler.tqg_randomized_benchmarking.analysis import (
    TQGRandomizedBenchmarkingAnalysis,
    TQGRandomizedBenchmarkingInterleavedAnalysis,
)
from bragi_quantum.experiments.nodes.coupler.tqg_randomized_benchmarking.measurement import (
    CZ_INDEX,
    TQGRandomizedBenchmarkingMeasurement,
)
from bragi_quantum.experiments.nodes.coupler.tqg_randomized_benchmarking.parameters import (
    TQGRandomizedBenchmarkingInterleavedQOI,
    TQGRandomizedBenchmarkingParameters,
    TQGRandomizedBenchmarkingQOI,
)
from bragi_quantum.experiments.nodes.schedule_node import ScheduleCouplerNode


[docs] class TQGRandomizedBenchmarking(ScheduleCouplerNode): """Standard two-qubit-gate randomized benchmarking on a coupler.""" measurement_cls = TQGRandomizedBenchmarkingMeasurement analysis_cls = TQGRandomizedBenchmarkingAnalysis parameters: TQGRandomizedBenchmarkingParameters def __init__( self, parameters: TQGRandomizedBenchmarkingParameters, qoi_cls: type[TQGRandomizedBenchmarkingQOI] = TQGRandomizedBenchmarkingQOI, ): super().__init__(parameters=parameters, qoi_cls=qoi_cls) self.outer_schedule_samplespace = { "seeds": { coupler: np.arange(self.parameters_by_coupler[coupler].n_seeds) for coupler in self.couplers } } self.schedule_samplespace = { "number_of_cliffords": { coupler: self.parameters_by_coupler[coupler].clifford_sequence_lengths for coupler in self.couplers }, } self.schedule_keywords = { "loop_repetitions": self.parameters.number_of_shots, "apply_inverse_gate": self.parameters.apply_inverse_gate, "cz_transition": { coupler: self.parameters_by_coupler[coupler].cz_transition for coupler in self.couplers }, "downconvert_frequency": { coupler: self.parameters_by_coupler[coupler].downconvert_frequency for coupler in self.couplers }, "cz_pulse_frequency": { coupler: float(self.edges[coupler].cz.cz_freq) for coupler in self.couplers }, "cz_pulse_duration": { coupler: float(self.edges[coupler].cz.square_duration) for coupler in self.couplers }, "cz_pulse_amplitude": { coupler: float(self.edges[coupler].cz.square_amp) for coupler in self.couplers }, "control_phase_correction": { coupler: float(self.edges[coupler].cz.control_phase_correction) for coupler in self.couplers }, "target_phase_correction": { coupler: float(self.edges[coupler].cz.target_phase_correction) for coupler in self.couplers }, } @property def transmons(self) -> dict[str, ExtendedTransmon]: """The coupled qubits' transmons; measured (and read out) by this node.""" return {k: v for k, v in self.device.elements.items() if k in self.all_qubits} @override def _build_measurement(self): return self.measurement_cls(self.transmons, self.edges)
[docs] class TQGRandomizedBenchmarkingInterleaved(TQGRandomizedBenchmarking): """ Two-qubit-gate RB with a bare CZ Clifford interleaved into every sequence, used to extract the CZ gate fidelity against a prior standard RB run on the same coupler. """ analysis_cls = TQGRandomizedBenchmarkingInterleavedAnalysis def __init__( self, parameters: TQGRandomizedBenchmarkingParameters, qoi_cls: type[ TQGRandomizedBenchmarkingInterleavedQOI ] = TQGRandomizedBenchmarkingInterleavedQOI, ): super().__init__(parameters=parameters, qoi_cls=qoi_cls) self.schedule_keywords["interleaving_clifford_id"] = CZ_INDEX