# ══════════════════════════════════════════════════════════════════════════
# ___ ___ ___ _ _ ___
# / _ \ / __|_ ) | | /_\ | _ )
# | (_) | (__ / / | |__ / _ \| _ \
# \__\_\\___/___| |____/_/ \_\___/
#
# 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:
#
# Matteo Robbiati, robbiati@chalmers.se
# Axel Andersson, axean@chalmers.se
# Joel Sandås, joel.sandas@chalmers.se
# ══════════════════════════════════════════════════════════════════════════
# This code is part of Tergite
#
# (C) Copyright Eleftherios Moschandreou 2023, 2024
# (C) Copyright Liangyu Chen 2023, 2024
#
# 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/utils/dto/extended_transmon_element.py
from __future__ import annotations
import math
from typing import override
from qblox_scheduler.backends.circuit_to_device import (
DeviceCompilationConfig,
OperationCompilationConfig,
)
from qblox_scheduler.device_under_test.transmon_element import (
BasicTransmonElement,
pulse_factories,
)
from qblox_scheduler.operations import measurement_factories, pulse_library
from qblox_scheduler.structure.model import Numbers, Parameter, SchedulerSubmodule
from bragi_quantum.datalayer.models.measurement import (
Measure1ReadoutSubmodule,
Measure2ReadoutSubmodule,
MeasureReadoutSubmodule,
ThreeStateOptimalReadoutSubmodule,
TwoStateOptimalReadoutSubmodule,
)
[docs]
class ExtendedClockFreqsSubmodule(SchedulerSubmodule):
"""Submodule for storing extra clock frequencies."""
readout_1: float = Parameter(
initial_value=math.nan,
unit="Hz",
vals=Numbers(allow_nan=True, min_value=0.0),
)
readout_2: float = Parameter(
initial_value=math.nan,
unit="Hz",
vals=Numbers(allow_nan=True, min_value=0.0),
)
readout_2state_opt: float = Parameter(
initial_value=math.nan,
unit="Hz",
vals=Numbers(allow_nan=True, min_value=0.0),
)
readout_3state_opt: float = Parameter(
initial_value=math.nan,
unit="Hz",
vals=Numbers(allow_nan=True, min_value=0.0),
)
[docs]
class SpectroscopySubmodule(SchedulerSubmodule):
"""Submodule for dedicated solely for spectroscopy parameters."""
spec_duration: float = Parameter(
initial_value=math.nan,
unit="s",
vals=Numbers(allow_nan=True, min_value=0.0),
)
spec_duration_12: float = Parameter(
initial_value=math.nan,
unit="s",
vals=Numbers(allow_nan=True, min_value=0.0),
)
spec_amp: float = Parameter(
initial_value=math.nan,
unit="",
vals=Numbers(allow_nan=True, max_value=1.0, min_value=-1.0),
)
spec_ampl_optimal: float = Parameter(
initial_value=math.nan,
unit="",
vals=Numbers(allow_nan=True, max_value=1.0, min_value=-1.0),
)
spec_ampl_12_optimal: float = Parameter(
initial_value=math.nan,
unit="",
vals=Numbers(allow_nan=True, max_value=1.0, min_value=-1.0),
)
[docs]
class R12(SchedulerSubmodule):
"""Submodule for exciting the qubit using its 1->2 transition."""
ef_amp180: float = Parameter(
initial_value=math.nan,
unit="",
vals=Numbers(allow_nan=True, max_value=1.0, min_value=-1.0),
)
ef_beta: float = Parameter(
initial_value=0.0,
unit="",
vals=Numbers(max_value=1.0, min_value=-1.0),
)
ef_duration: float = Parameter(
initial_value=math.nan,
unit="s",
vals=Numbers(allow_nan=True, min_value=0.0),
)
[docs]
class ExtendedTransmon(BasicTransmonElement):
"""Fixed frequency qubit class with more submodules than the basic transmon object."""
measure: MeasureReadoutSubmodule
extended_clock_freqs: ExtendedClockFreqsSubmodule
measure_1: Measure1ReadoutSubmodule
measure_2: Measure2ReadoutSubmodule
measure_2state_opt: TwoStateOptimalReadoutSubmodule
measure_3state_opt: ThreeStateOptimalReadoutSubmodule
spec: SpectroscopySubmodule
r12: R12
[docs]
@override
def generate_device_config(self) -> DeviceCompilationConfig:
# make the device compilation config dictionary for the base transmon
# object, with extra clock submodules added.
cfg_dict = {
"elements": self._generate_config(),
"clocks": {
f"{self.name}.01": self.clock_freqs.f01,
f"{self.name}.12": self.clock_freqs.f12,
f"{self.name}.ro": self.clock_freqs.readout,
f"{self.name}.ro1": self.extended_clock_freqs.readout_1,
f"{self.name}.ro2": self.extended_clock_freqs.readout_2,
f"{self.name}.ro_2st_opt": self.extended_clock_freqs.readout_2state_opt,
f"{self.name}.ro_3st_opt": self.extended_clock_freqs.readout_3state_opt,
},
"edges": {},
}
# add operation compilation configs for the auxiliary measure gates
# gate_info_factory_kwargs lists the keys that are injected from the gate's
# call-site info (i.e. from the Schedule operation) into the factory at
# compile time, rather than being fixed here in the device config.
# Examples: acq_channel_override, acq_index, bin_mode, acq_protocol,
# feedback_trigger_label. We read these from the already-compiled base
# "measure" config so that any future upstream additions are picked up
# automatically without needing to update this file.
_base_gate_info_kwargs = cfg_dict["elements"][self.name][
"measure"
].gate_info_factory_kwargs
_aux_measures = {
"measure_1": (self.measure_1, f"{self.name}.ro1"),
"measure_2": (self.measure_2, f"{self.name}.ro2"),
"measure_2state_opt": (self.measure_2state_opt, f"{self.name}.ro_2st_opt"),
"measure_3state_opt": (self.measure_3state_opt, f"{self.name}.ro_3st_opt"),
}
for op_type, (submodule, clock_name) in _aux_measures.items():
cfg_dict["elements"][self.name][op_type] = OperationCompilationConfig(
factory_func=measurement_factories.dispersive_measurement_transmon,
factory_kwargs={
"port": self.ports.readout,
"clock": clock_name,
"pulse_type": submodule.pulse_type,
"pulse_amp": submodule.pulse_amp,
"pulse_duration": submodule.pulse_duration,
"acq_delay": submodule.acq_delay,
"acq_duration": submodule.integration_time,
"acq_channel": submodule.acq_channel,
"acq_protocol_default": "SSBIntegrationComplex",
"reset_clock_phase": submodule.reset_clock_phase,
"reference_magnitude": pulse_library.ReferenceMagnitude.from_parameter(
submodule.reference_magnitude
),
"acq_weights_a": submodule.acq_weights_a,
"acq_weights_b": submodule.acq_weights_b,
"acq_weights_sampling_rate": submodule.acq_weights_sampling_rate,
"acq_rotation": submodule.acq_rotation,
"acq_threshold": submodule.acq_threshold,
"num_points": submodule.num_points,
"freq": None,
},
gate_info_factory_kwargs=_base_gate_info_kwargs,
)
# add operation compilation config for the rxy_12 operation
cfg_dict["elements"][self.name]["rxy_12"] = OperationCompilationConfig(
factory_func=pulse_factories.rxy_drag_pulse,
factory_kwargs={
"amp180": self.r12.ef_amp180,
"beta": self.r12.ef_beta,
"port": self.ports.microwave,
"clock": f"{self.name}.12",
"duration": self.r12.ef_duration,
},
gate_info_factory_kwargs=["theta", "phi"],
)
dev_cfg = DeviceCompilationConfig.model_validate(cfg_dict)
return dev_cfg