# ══════════════════════════════════════════════════════════════════════════
# ___ ___ ___ _ _ ___
# / _ \ / __|_ ) | | /_\ | _ )
# | (_) | (__ / / | |__ / _ \| _ \
# \__\_\\___/___| |____/_/ \_\___/
#
# 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
# ══════════════════════════════════════════════════════════════════════════
from typing import override
from pydantic import Field
from bragi_quantum.experiments.abstract.parameter_fields import acquisition_field
from bragi_quantum.experiments.abstract.parameters import BaseParameters, BaseQoi
[docs]
class CZChevronParameters(BaseParameters):
"""
Parameters for the CZ chevron: sweeping the coupler's flux pulse
frequency and duration (amplitude held fixed) to find whether a usable
|11>-|20> (or |11>-|02>) avoided crossing exists at a candidate current,
and to refine the CZ pulse duration itself. Ported from
tergite-autocalibration (CZChevronNode).
"""
repetitions: int = acquisition_field(
default=1024, description="Repetitions (averages) per point."
)
# Frequency sweep (Hz), centered on each coupler's CZ transition frequency
# (computed from the qubits' calibrated 01/12 clock frequencies).
frequency_sweep: float = acquisition_field(
default=10e6, description="Half-width (Hz) of the CZ pulse frequency sweep."
)
frequency_bins: int = acquisition_field(
default=15, description="Number of frequency points."
)
# Duration sweep (s) of the CZ flux pulse.
duration_min: float = acquisition_field(
default=20e-9, description="Start of the duration sweep (s)."
)
duration_max: float = acquisition_field(
default=700e-9, description="End of the duration sweep (s)."
)
duration_bins: int = acquisition_field(
default=30, description="Number of duration points."
)
# CZ pulse amplitude, fixed for this chevron scan.
cz_pulse_amplitude: float = acquisition_field(
default=0.5,
ge=-1,
le=1,
description="Amplitude of the CZ flux pulse (fullscale).",
)
# Which avoided crossing the CZ pulse targets: "20" drives the first
# qubit of the coupler (by name order) towards |2>, the second towards
# |0>; "02" is the reverse.
cz_transition: str = acquisition_field(
default="20", description="Targeted transition: '20' or '02'."
)
cz_half_frequency_wp: bool = acquisition_field(
default=False,
description="Center the frequency sweep at half the computed CZ "
"transition frequency, for couplers operated at a half-frequency "
"working point.",
)
# Informational only: the DC current the coupler is currently parked at
# when this scan runs (set by a previous cz_currents_from_spectroscopies
# run). Not applied to hardware by this node.
parking_current: float = Field(
default=0.0, description="Coupler DC parking current (A), for plot labels only."
)
# Flux-line IF/LO scheme: the CZ pulse clock is programmed at
# -frequency + downconvert_frequency. Hardware-wiring specific; override
# per coupler via custom_parameters for lines with a different LO setup.
downconvert_frequency: float = Field(
default=4.4e9, description="Flux-line downconversion offset (Hz)."
)
# SPI-rack safety limit — do not change casually.
max_transition_frequency: float = Field(
default=1e9,
description="Couplers whose computed transition frequency exceeds "
"this (Hz) are skipped entirely.",
)
# If more than this fraction of the 9 support-trace fits (neighboring
# frequencies around the chosen working point) fail to resolve a genuine
# duration oscillation, the working point is discarded even if the
# coarser two-qubit compatibility check passed.
trace_fit_failure_threshold: float = acquisition_field(
default=0.66,
description="Support-trace fit failure fraction above which a "
"working point is discarded.",
)
[docs]
class CZChevronQOI(BaseQoi):
"""
Quantities of Interest for the CZ chevron on one coupler: the
(frequency, duration) working point found, plus diagnostics on how many
of the neighboring support-trace fits resolved a genuine oscillation.
"""
cz_pulse_frequency: float = 0.0
cz_pulse_frequency_error: float = 0.0
cz_pulse_duration: float = 0.0
cz_pulse_duration_error: float = 0.0
# JSON-encoded list of [frequency, avg_period] pairs for the neighboring
# support-trace fits that converged to a resolvable oscillation period.
cz_chevron_trace_periods: str = "[]"
# Fraction of the neighboring support traces whose fit failed to resolve
# a genuine oscillation (see CZChevronAnalysis.TRACE_FIT_FAILURE_THRESHOLD).
cz_chevron_trace_fit_failure_fraction: float = 0.0
[docs]
def items(self):
"""
Iterate like a mapping so bragi_quantum.datalayer's ``update_redis_trusted_values`` can
inspect the QOI keys when routing coupler results.
"""
return self.to_dict().items()
[docs]
@override
def to_dict(self) -> dict:
return {
"cz.cz_freq": self.cz_pulse_frequency,
"cz.square_duration": self.cz_pulse_duration,
"cz_chevron_trace_fit_failure_fraction": self.cz_chevron_trace_fit_failure_fraction,
}
[docs]
def to_redis_dict(self) -> dict[str, dict]:
# "cz:cz_freq" / "cz:square_duration" follow the device
# 'submodule:field' convention so BaseNode._apply_qoi_to_device writes
# them straight onto the coupler edge's ParametricCZSubmodule.
return {
"cz:cz_freq": {
"value": self.cz_pulse_frequency,
"error": self.cz_pulse_frequency_error,
},
"cz:square_duration": {
"value": self.cz_pulse_duration,
"error": self.cz_pulse_duration_error,
},
"cz_chevron_trace_fit_failure_fraction": {
"value": self.cz_chevron_trace_fit_failure_fraction,
"error": 0.0,
},
}