# ══════════════════════════════════════════════════════════════════════════
# ___ ___ ___ _ _ ___
# / _ \ / __|_ ) | | /_\ | _ )
# | (_) | (__ / / | |__ / _ \| _ \
# \__\_\\___/___| |____/_/ \_\___/
#
# 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:
#
# Axel Andersson, axean@chalmers.se
# Matteo Robbiati, robbiati@chalmers.se
# ══════════════════════════════════════════════════════════════════════════
"""
Node implementation for single-qubit randomized benchmarking (RB).
"""
import numpy as np
from bragi_quantum.experiments.nodes.characterization.randomized_benchmarking.analysis import (
RBAnalysis,
)
from bragi_quantum.experiments.nodes.characterization.randomized_benchmarking.measurement import (
RandomizedBenchmarkingMeasurement,
)
from bragi_quantum.experiments.nodes.characterization.randomized_benchmarking.parameters import (
RBQOI,
RBParameters,
)
from bragi_quantum.experiments.nodes.schedule_node import ScheduleQubitNode
[docs]
class RandomizedBenchmarking(ScheduleQubitNode):
"""
Execution node for single-qubit randomized benchmarking (SSRO-classified).
Each of the ``n_seeds`` independent random-Clifford realizations needs a
genuinely different compiled schedule (the random sequence is baked
directly into the pulses, not expressible as a hardware ``Variable``
sweep), so — unlike every other node so far — this one drives its outer
loop via ``ScheduleNode.outer_schedule_samplespace`` (recompile fresh
per iteration) rather than ``ExternalParameterFixedScheduleQubitNode``
(compile once, re-execute). ``seeds`` is the outer dimension; the
``clifford_sequence_lengths`` sweep is inner, expressed as a plain
Python loop within each seed's own compiled schedule (also not a
hardware ``Variable`` sweep, since each sequence length needs its own
randomly generated gates). Every per-seed compile also gets its own
automatic calibration-points block, so each seed's state populations are
normalized against its own calibration, never an average across seeds.
"""
measurement_cls = RandomizedBenchmarkingMeasurement
analysis_cls = RBAnalysis
append_calibration_points = True
parameters: RBParameters
def __init__(
self,
parameters: RBParameters,
qoi_cls: type[RBQOI] = RBQOI,
):
"""
Initializes the RB node.
Args:
parameters: Validated experimental parameters.
qoi_cls: The QOI class used to store results.
"""
super().__init__(
parameters=parameters,
qoi_cls=qoi_cls,
)
self.schedule_keywords = {
"loop_repetitions": self.parameters.number_of_shots,
}
self.schedule_samplespace = {
"cliffords": {
qubit: np.array(self.parameters.clifford_sequence_lengths)
for qubit in self.all_qubits
}
}
self.outer_schedule_samplespace = {
"seeds": {
qubit: np.arange(self.parameters.n_seeds) for qubit in self.all_qubits
}
}