# ══════════════════════════════════════════════════════════════════════════
# ___ ___ ___ _ _ ___
# / _ \ / __|_ ) | | /_\ | _ )
# | (_) | (__ / / | |__ / _ \| _ \
# \__\_\\___/___| |____/_/ \_\___/
#
# 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
# Joel Sandås, joel.sandas@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
"""
Node implementation for Qubit Spectroscopy vs coupler DC current.
Ported from tergite-autocalibration (QubitSpectroscopyVsCurrentNode).
"""
from typing import Any, 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.qubit_spectroscopy_vs_current.analysis import (
QubitSpectroscopyVsCurrentAnalysis,
)
from bragi_quantum.experiments.nodes.coupler.qubit_spectroscopy_vs_current.parameters import (
QubitSpectroscopyVsCurrentParameters,
QubitSpectroscopyVsCurrentQOI,
)
from bragi_quantum.experiments.nodes.external_parameter_node import (
ExternalParameterFixedScheduleCouplerNode,
)
from bragi_quantum.experiments.nodes.qubit_control.spectroscopy.measurement import (
TwoTonesMultidimMeasurement,
)
from bragi_quantum.experiments.utils.samplespace import qubit_samples
[docs]
class QubitSpectroscopyVsCurrent(ExternalParameterFixedScheduleCouplerNode):
"""
Qubit (two-tone) spectroscopy on both qubits of each coupler while
sweeping the coupler's DC bias current via the SPI rack.
The spectroscopy schedule is compiled once; for every current in the
external samplespace the coupler DACs are ramped and the schedule is
re-executed. The analysis tracks the fitted qubit frequency versus current
and reports the currents at which the coupler crosses the qubit, vetoing
candidates near the resonator crossings found by
resonator_spectroscopy_vs_current.
"""
measurement_cls = TwoTonesMultidimMeasurement
analysis_cls = QubitSpectroscopyVsCurrentAnalysis
parameters: QubitSpectroscopyVsCurrentParameters
def __init__(
self,
parameters: QubitSpectroscopyVsCurrentParameters,
qoi_cls: type[QubitSpectroscopyVsCurrentQOI] = QubitSpectroscopyVsCurrentQOI,
):
super().__init__(
parameters=parameters,
qoi_cls=qoi_cls,
)
if self.parameters.transition != "01":
logger.warning(
f"You entered an experimental transition for {self.__class__.__name__}: {self.parameters.transition}."
)
self.schedule_keywords = {
"transition": self.parameters.transition,
"repetitions": self.parameters.repetitions,
# "continuous" selects the constant-drive schedule; otherwise a
# per-qubit pulse length. See
# TwoTonesMultidimMeasurement.schedule_function.
"spec_pulse_duration": (
"continuous"
if self.parameters.continuous_mode
else {
qubit: self.parameters.resolve_spec_pulse_duration(
self.device.elements[qubit]
)
for qubit in self.all_qubits
}
),
"continuous_reset_duration": self.parameters.continuous_reset_duration,
# Drive each qubit at its calibrated optimal spectroscopy
# amplitude only — the sweep runs over frequency and current.
"spec_pulse_amplitudes": {
qubit: np.asarray(
[float(self.device.elements[qubit].spec.spec_ampl_optimal)]
)
for qubit in self.all_qubits
},
}
self.schedule_samplespace = {
"spec_frequencies": {
qubit: qubit_samples(
qubit,
transition=self.parameters.transition,
samples=self.parameters.samples,
half_width=self.parameters.half_width,
)
for qubit in self.all_qubits
}
}
self.external_samplespace = {
"dc_currents": {
coupler: np.arange(
self.parameters.min_current,
self.parameters.max_current,
self.parameters.current_step,
)
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):
# The measured schedule is a plain qubit spectroscopy on the coupled
# qubits; the coupler only enters through the DC bias.
return self.measurement_cls(self.transmons)
[docs]
@override
def pre_measurement_operation(self, reduced_ext_space: dict[str, Any]) -> None:
"""Ramp the coupler DACs to this iteration's currents before measuring."""
if self.spi_manager is None:
raise RuntimeError(
"No SPI DAC handler in the active session — the DC-current sweep "
"requires the device template's spi.yaml and measurement mode. If "
"this is unexpected, check if SessionOptions.spi_serial_port was "
"explicitly set to None."
)
self.spi_manager.set_dac_currents(reduced_ext_space["dc_currents"])
[docs]
@override
def final_operation(self) -> None:
"""Ramp all swept coupler DACs back to zero after the sweep."""
logger.info("Ramping coupler currents back to 0 A.")
self.spi_manager.set_dac_currents({coupler: 0.0 for coupler in self.couplers})