# ══════════════════════════════════════════════════════════════════════════
# ___ ___ ___ _ _ ___
# / _ \ / __|_ ) | | /_\ | _ )
# | (_) | (__ / / | |__ / _ \| _ \
# \__\_\\___/___| |____/_/ \_\___/
#
# 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
# Adrián Navarro Fuentes, adrianfu@chalmers.se
# Axel Andersson, axean@chalmers.se
# ══════════════════════════════════════════════════════════════════════════
from __future__ import annotations
from dataclasses import dataclass
from typing import Literal, override
from qblox_scheduler.operations.gate_library import Measure, Rxy
AcqProtocol = Literal[
"SSBIntegrationComplex",
"Trace",
"TriggerCount",
"NumericalWeightedIntegrationComplex",
"ThresholdedAcquisition",
]
[docs]
@dataclass(frozen=True)
class MeasureConfig:
name_prefix: str
operation_type: str
[docs]
class Rxy_12(Rxy):
"""
A single qubit rotation on the 12 transition.
"""
def __init__(
self, qubit: str, theta: float = 180, phi: float = 0, **device_overrides
):
super().__init__(theta=theta, phi=phi, qubit=qubit, **device_overrides)
self.data["name"] = (f"Rxy-12({theta:.8g}, {phi:.8g}, '{qubit}')",)
self.data["gate_info"]["unitary"] = None # this is not a Qubit operation
self.data["gate_info"][
"operation_type"
] = "rxy_12" # this key is used in compilation!
# No explicit hash refresh is needed: qblox_scheduler's Operation now
# derives its hash lazily from self.data (Operation.__hash__ ->
# make_hash(self.data)), so mutations above are picked up automatically.
@override
def __str__(self) -> str:
qubit = self.data["gate_info"]["device_elements"][0]
return f"{self.__class__.__name__}(qubit='{qubit}')"
[docs]
class BaseMeasureRO(Measure):
"""Shared logic for all RO measurement classes."""
CONFIG: MeasureConfig # Subclasses will override
def __init__(self, *qubits: str, **kwargs: dict):
super().__init__(*qubits, **kwargs)
self.data.update({"name": f"{self.CONFIG.name_prefix} {', '.join(qubits)}"})
self.data["gate_info"].update({"operation_type": self.CONFIG.operation_type})
# Hash is derived lazily from self.data (see Operation.__hash__), so the
# mutations above need no explicit refresh.
[docs]
class Measure_RO1(BaseMeasureRO):
CONFIG = MeasureConfig(
name_prefix="Measure_RO1",
operation_type="measure_1",
)
[docs]
class Measure_RO2(BaseMeasureRO):
CONFIG = MeasureConfig(
name_prefix="Measure_RO2",
operation_type="measure_2",
)
[docs]
class Measure_RO_3state_Opt(BaseMeasureRO):
CONFIG = MeasureConfig(
name_prefix="Measure_RO_3state_Opt",
operation_type="measure_3state_opt",
)
[docs]
class Measure_RO_2state_Opt(BaseMeasureRO):
CONFIG = MeasureConfig(
name_prefix="Measure_RO_2state_Opt",
operation_type="measure_2state_opt",
)