# ══════════════════════════════════════════════════════════════════════════
# ___ ___ ___ _ _ ___
# / _ \ / __|_ ) | | /_\ | _ )
# | (_) | (__ / / | |__ / _ \| _ \
# \__\_\\___/___| |____/_/ \_\___/
#
# 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:
#
# Filip Eriksson, filieri@chalmers.se
# Joel Sandås, joel.sandas@chalmers.se
# Matteo Robbiati, robbiati@chalmers.se
# Michele Faucci Giannelli, faucci@chalmers.se
# ══════════════════════════════════════════════════════════════════════════
"""
Node implementation for the CZ wall finder.
Ported from tergite-autocalibration (CZWallFinder).
"""
from typing import override
import numpy as np
from bragi_quantum.datalayer.models.qubit import ExtendedTransmon
from bragi_quantum.datalayer.utils.logging import logger
from bragi_quantum.experiments.nodes.coupler.cz_parametrization.measurement import (
CZParametrizationFixDurationMeasurement,
)
from bragi_quantum.experiments.nodes.coupler.cz_transition_frequency import (
get_cz_transition_frequency,
)
from bragi_quantum.experiments.nodes.coupler.cz_wall_finder.analysis import (
CZWallFinderAnalysis,
)
from bragi_quantum.experiments.nodes.coupler.cz_wall_finder.parameters import (
CZWallFinderParameters,
CZWallFinderQOI,
)
from bragi_quantum.experiments.nodes.schedule_node import ScheduleCouplerNode
[docs]
class CZWallFinder(ScheduleCouplerNode):
"""
Sweeps the coupler's CZ flux pulse amplitude at a single fixed frequency
(its CZ transition frequency) to find, per qubit, the amplitude beyond
which the magnitude response departs from its baseline -- a "wall" past
which driving the coupler further is unsafe or uncontrolled. Reuses
CZParametrizationFixDuration's measurement (fixed duration, swept
frequency/amplitude), collapsed here to a single frequency point.
"""
measurement_cls = CZParametrizationFixDurationMeasurement
analysis_cls = CZWallFinderAnalysis
parameters: CZWallFinderParameters
def __init__(
self,
parameters: CZWallFinderParameters,
qoi_cls: type[CZWallFinderQOI] = CZWallFinderQOI,
):
super().__init__(parameters=parameters, qoi_cls=qoi_cls)
valid_couplers = []
for coupler in self.couplers:
if (
self._transition_frequency(coupler)
> self.parameters.max_transition_frequency
):
logger.warning(
f"Coupler {coupler} skipped: transition frequency exceeds "
f"max_transition_frequency="
f"{self.parameters.max_transition_frequency / 1e6:.3f} MHz."
)
continue
valid_couplers.append(coupler)
self.couplers = valid_couplers
self.all_qubits = sorted(set(self.get_coupled_qubits()))
self.schedule_keywords = {
"repetitions": self.parameters.repetitions,
"cz_pulse_duration": {
coupler: self.parameters_by_coupler[coupler].cz_pulse_duration
for coupler in self.couplers
},
"downconvert_frequency": {
coupler: self.parameters_by_coupler[coupler].downconvert_frequency
for coupler in self.couplers
},
}
self.schedule_samplespace = {
"cz_pulse_frequencies": {
coupler: np.array([self._transition_frequency(coupler)])
for coupler in self.couplers
},
"cz_pulse_amplitudes": {
coupler: self._amplitude_sweep(coupler) 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)
def _transition_frequency(self, coupler: str) -> float:
"""
CZ transition frequency (Hz): the detuning between the |11> state
and the targeted |20> / |02> state. Prefers the value saved to Redis
by cz_currents_from_spectroscopies; falls back to computing it from
the qubits' calibrated 01/12 clock frequencies if Redis has nothing
stored yet.
"""
params = self.parameters_by_coupler[coupler]
return get_cz_transition_frequency(
device=self.device,
redis_connection=self.redis_connection,
coupler=coupler,
cz_transition=params.cz_transition,
cz_half_frequency_wp=params.cz_half_frequency_wp,
)
def _amplitude_sweep(self, coupler: str) -> np.ndarray:
params = self.parameters_by_coupler[coupler]
# amp=1.0 rounds up past the AWG gain limit during compilation, so cap
# the sweep range itself (rather than clipping individual points
# afterwards, which can break the strictly increasing point order).
# Mirrors cz_parametrization's own amplitude sweep.
max_amplitude = min(params.amplitude_max, 0.70)
return np.linspace(params.amplitude_min, max_amplitude, params.amplitude_bins)