# ══════════════════════════════════════════════════════════════════════════
# ___ ___ ___ _ _ ___
# / _ \ / __|_ ) | | /_\ | _ )
# | (_) | (__ / / | |__ / _ \| _ \
# \__\_\\___/___| |____/_/ \_\___/
#
# 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
# Matteo Robbiati, robbiati@chalmers.se
# Michele Faucci Giannelli, faucci@chalmers.se
# ══════════════════════════════════════════════════════════════════════════
"""
Node implementation for single-qubit purity benchmarking.
"""
import numpy as np
from bragi_quantum.experiments.nodes.characterization.purity_benchmarking.analysis import (
PurityBenchmarkingAnalysis,
)
from bragi_quantum.experiments.nodes.characterization.purity_benchmarking.measurement import (
PurityBenchmarkingMeasurement,
)
from bragi_quantum.experiments.nodes.characterization.purity_benchmarking.parameters import (
PurityBenchmarkingParameters,
PurityBenchmarkingQOI,
)
from bragi_quantum.experiments.nodes.schedule_node import ScheduleQubitNode
[docs]
class PurityBenchmarking(ScheduleQubitNode):
"""
Execution node for single-qubit purity benchmarking.
As in ``RandomizedBenchmarking``, each of the ``n_seeds`` independent
random-Clifford realizations needs its own compiled schedule (the random
sequence is baked directly into the pulses), so this node drives its
outer loop via ``ScheduleNode.outer_schedule_samplespace`` (recompile
fresh per seed) rather than ``ExternalParameterFixedScheduleQubitNode``.
``seeds`` is the outer dimension; ``clifford_sequence_lengths`` and the
three measurement bases are inner, expressed as plain Python loops
within each seed's own compiled schedule. Every per-seed compile also
gets its own automatic calibration-points block, so each seed's
populations are normalized against its own calibration, never an
average across seeds.
"""
measurement_cls = PurityBenchmarkingMeasurement
analysis_cls = PurityBenchmarkingAnalysis
append_calibration_points = True
parameters: PurityBenchmarkingParameters
def __init__(
self,
parameters: PurityBenchmarkingParameters,
qoi_cls: type[PurityBenchmarkingQOI] = PurityBenchmarkingQOI,
):
"""
Initializes the purity benchmarking 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 = {
"repetitions": self.parameters.repetitions,
}
self.schedule_samplespace = {
"cliffords": {
qubit: np.array(self.parameters.clifford_sequence_lengths)
for qubit in self.all_qubits
},
# 0=X, 1=Y, 2=Z: see BASES in measurement.py.
"basis": {qubit: np.arange(3) for qubit in self.all_qubits},
}
self.outer_schedule_samplespace = {
"seeds": {
qubit: np.arange(self.parameters.n_seeds) for qubit in self.all_qubits
}
}