# ══════════════════════════════════════════════════════════════════════════
# ___ ___ ___ _ _ ___
# / _ \ / __|_ ) | | /_\ | _ )
# | (_) | (__ / / | |__ / _ \| _ \
# \__\_\\___/___| |____/_/ \_\___/
#
# 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
# ══════════════════════════════════════════════════════════════════════════
"""
Parameters and QOIs for CZ phase calibration.
Ported from tergite-autocalibration (lib/nodes/coupler/cz_phases). The three
node variants there (CZConditionalPhaseSSRONode, CZLocalPhaseSSRONode,
CZLocalPhaseSwapSSRONode) differed only by two booleans on one shared
measurement/analysis pair, so here they share a single ``CZPhasesParameters``
and node class, and are registered in nodes.yaml as three ``parameters:``
variants of it (see the "shared class + parameter variants" convention
documented at the top of nodes.yaml, e.g. resonator_spectroscopy_1/_2).
"""
from typing import Any, ClassVar, 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 CZPhasesParameters(BaseParameters):
"""
Parameters for CZ phase calibration (conditional phase and local phases).
Sweeps a Ramsey-type phase on the target qubit, with the coupler's CZ
pulse (at its already-calibrated frequency/amplitude/duration) turned on
or off / applied with the control qubit in |0> or |1>, depending on
``local_phases`` / ``swap_control_and_target``:
- Conditional phase (``local_phases=False``): compares the target
qubit's Ramsey phase with the control qubit in |0> vs |1>, with the
coupler's virtual-Z phase corrections applied. The difference is the
CZ conditional phase (ideal: 180 degrees).
- Local phase (``local_phases=True``, ``swap_control_and_target=False``):
compares the target qubit's Ramsey phase with the CZ pulse off vs on
(no virtual-Z corrections, no conditional X on the control qubit),
giving the local phase the target qubit itself picks up from the CZ
pulse.
- Local phase, swapped (``local_phases=True``,
``swap_control_and_target=True``): same as above with the control and
target roles swapped, giving the local phase on the other qubit.
"""
invalid_variant_combinations: ClassVar[tuple[dict[str, Any], ...]] = (
{"local_phases": False, "swap_control_and_target": True},
)
repetitions: int = acquisition_field(
default=1024, description="Repetitions (averages) per point."
)
ramsey_phases_max: float = acquisition_field(
default=720.0, description="End of the Ramsey-phase sweep (degrees)."
)
ramsey_phases_bins: int = acquisition_field(
default=25, description="Number of Ramsey-phase points."
)
# Which avoided crossing the coupler's CZ pulse targets; determines which
# qubit of the coupler plays "Control" vs "Target" for this measurement.
# Same field/convention as cz_parametrization's ``cz_transition``.
cz_transition: str = acquisition_field(
default="20", description="Targeted transition: '20' or '02'."
)
local_phases: bool = acquisition_field(
default=False,
variant=True,
description="If False, measure the CZ conditional phase. If True, "
"measure a local phase instead (gate off vs on, no virtual-Z "
"corrections).",
)
swap_control_and_target: bool = acquisition_field(
default=False,
variant=True,
description="Only used when local_phases=True: swap which qubit of "
"the coupler plays Control vs Target, to measure the other qubit's "
"local phase.",
)
# Flux-line IF/LO scheme: the CZ pulse clock is programmed at
# -frequency + downconvert_frequency. Same convention as
# cz_parametrization's field of the same name.
# A hardware-specific constant, so it is not a acquisition_field.
downconvert_frequency: float = Field(
default=4.4e9, description="Flux-line downconversion offset (Hz)."
)
[docs]
class CZConditionalPhaseQOI(BaseQoi):
"""QOI for the CZ conditional-phase node."""
cz_phase: float = 0.0
cz_phase_error: float = 0.0
cz_pop_loss: 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_phase": self.cz_phase,
"cz_pop_loss": self.cz_pop_loss,
}
[docs]
def to_redis_dict(self) -> dict[str, dict]:
# No ParametricCZSubmodule field corresponds to these (unlike the
# local-phase QOIs below); recorded as informational extended_state
# only, matching cz_parametrization's transition_quality precedent.
return {
"cz_phase": {"value": self.cz_phase, "error": self.cz_phase_error},
"cz_pop_loss": {"value": self.cz_pop_loss, "error": 0.0},
}
[docs]
class CZLocalPhaseQOI(BaseQoi):
"""QOI for the CZ local-phase (target qubit) node."""
cz_local_target: float = 0.0
cz_local_target_error: 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.target_phase_correction": self.cz_local_target}
[docs]
def to_redis_dict(self) -> dict[str, dict]:
return {
"cz:target_phase_correction": {
"value": self.cz_local_target,
"error": self.cz_local_target_error,
}
}
[docs]
class CZLocalPhaseSwapQOI(BaseQoi):
"""QOI for the CZ local-phase (control qubit, swapped) node."""
cz_local_control: float = 0.0
cz_local_control_error: 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.control_phase_correction": self.cz_local_control}
[docs]
def to_redis_dict(self) -> dict[str, dict]:
return {
"cz:control_phase_correction": {
"value": self.cz_local_control,
"error": self.cz_local_control_error,
}
}