# ══════════════════════════════════════════════════════════════════════════
# ___ ___ ___ _ _ ___
# / _ \ / __|_ ) | | /_\ | _ )
# | (_) | (__ / / | |__ / _ \| _ \
# \__\_\\___/___| |____/_/ \_\___/
#
# 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
# Abdullah-Al Amin, alamina@chalmers.se
# Matteo Robbiati, robbiati@chalmers.se
# Michele Faucci Giannelli, faucci@chalmers.se
# Yanchen Lin, linya@chalmers.se
# ══════════════════════════════════════════════════════════════════════════
# This code is part of Tergite
#
# (C) Copyright Eleftherios Moschandreou 2023, 2024
# (C) Copyright Michele Faucci Giannelli 2024, 2025
# (C) Copyright Stefan Hill 2024, 2025
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
#
# Modified from tergite-autocalibration
# (https://github.com/tergite/tergite-autocalibration), file:
# tergite_autocalibration/lib/nodes/coupler/spectroscopy/node.py
from typing import override
from pydantic import Field
from bragi_quantum.experiments.abstract.parameters import BaseQoi
from bragi_quantum.experiments.nodes.qubit_control.spectroscopy.parameters import (
QubitSpectroscopyParameters,
)
[docs]
class QubitSpectroscopyVsCurrentParameters(QubitSpectroscopyParameters):
"""
Parameters for Qubit Spectroscopy vs coupler DC current.
Extends the plain qubit (two-tone) spectroscopy parameters with the
external DC-current sweep applied to each coupler and the thresholds used
by the crossing-current detection.
"""
# External DC-current sweep (Amps), applied per coupler via the SPI rack.
min_current: float = Field(
default=-2.5e-3, description="Start of the DC-current sweep in Amps."
)
max_current: float = Field(
default=2.5e-3, description="End (exclusive) of the DC-current sweep in Amps."
)
current_step: float = Field(
default=50e-6, description="Step of the DC-current sweep in Amps."
)
# Crossing detection thresholds
crossing_threshold: float = Field(
default=2e6,
description="Minimum qubit frequency jump (Hz) between consecutive "
"detected points to count as a coupler crossing.",
)
spurious_threshold: float = Field(
default=300e3,
description="Maximum frequency difference (Hz) between the neighbours of "
"a missing point for it to be filled in as a spurious gap.",
)
min_crossing_interval: float = Field(
default=0.3e-3,
description="Minimum current span (A) a group of jumps must cover before "
"it is collapsed into a single crossing current.",
)
resonator_crossing_interval: float = Field(
default=0.15e-3,
description="Candidate crossings within this current distance (A) of a "
"known resonator crossing (from resonator_spectroscopy_vs_current) are "
"discarded as resonator artefacts.",
)
# Per-current fits are independent and CPU-bound (Lorentzian curve fits),
# so they run in a process pool. None auto-sizes to the machine's core
# count; set explicitly to cap usage on a shared measurement-control host.
max_fit_workers: int | None = Field(
default=None,
description="Worker processes for the per-current-slice fits. None "
"auto-sizes to os.cpu_count().",
)
[docs]
class QubitSpectroscopyVsCurrentQOI(BaseQoi):
"""
Quantities of Interest for Qubit Spectroscopy vs current on one coupler.
Holds, for each of the coupler's two qubits, the list of DC currents at
which the coupler crosses the qubit.
"""
crossing_currents: dict[str, list[float]] = Field(
default_factory=dict,
description="Mapping from qubit name to the detected qubit "
"crossing currents in Amps.",
)
[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[str, list[float]]:
return {
f"qubit_crossing_points_{qubit}": crossings
for qubit, crossings in self.crossing_currents.items()
}
[docs]
def to_redis_dict(self) -> dict[str, dict[str, str]]:
# Values are stored as the string repr of the list, since Redis hash
# fields cannot hold Python lists. Keys deliberately contain no ':'
# so they are not interpreted as device submodule fields.
return {
f"qubit_crossing_points_{qubit}": {
"value": str([float(c) for c in crossings]),
"error": 0.0,
}
for qubit, crossings in self.crossing_currents.items()
}