# ══════════════════════════════════════════════════════════════════════════
# ___ ___ ___ _ _ ___
# / _ \ / __|_ ) | | /_\ | _ )
# | (_) | (__ / / | |__ / _ \| _ \
# \__\_\\___/___| |____/_/ \_\___/
#
# 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:
#
# Adrián Navarro Fuentes, adrianfu@chalmers.se
# Matteo Robbiati, robbiati@chalmers.se
# Axel Andersson, axean@chalmers.se
# ══════════════════════════════════════════════════════════════════════════
"""Parameters and QOI classes for readout amplitude optimisation."""
import json
from typing import Any, override
from bragi_quantum.experiments.abstract.parameter_fields import (
acquisition_field,
analysis_field,
)
from bragi_quantum.experiments.abstract.parameters import (
BaseParameters,
BaseQoi,
)
[docs]
class ROCombinedOptimizationParameters(BaseParameters):
"""Configuration for readout amplitude optimisation nodes."""
# All data acquisition — sweep ranges / sizing / averaging.
amplitude_bins: int = acquisition_field(
default=21, description="Number of amplitude samples in the sweep."
)
amplitude_lower_fraction: float = acquisition_field(
default=1.0,
description="Lower bound of the amplitude sweep as a fraction of the nominal amplitude.",
)
amplitude_upper_fraction: float = acquisition_field(
default=1.0,
description="Upper bound of the amplitude sweep as a fraction of the nominal amplitude.",
)
frequency_samples: int = acquisition_field(
default=11, description="Number of readout-frequency samples."
)
frequency_half_width: float = acquisition_field(
default=0.3e6, description="Half-width of the frequency sweep window in Hz."
)
repetitions: int = acquisition_field(
default=1024, description="Number of repetitions (averages) per point."
)
min_amplitude: float = acquisition_field(
default=0.015, description="Minimum readout pulse amplitude."
)
max_amplitude: float = acquisition_field(
default=0.2, description="Maximum readout pulse amplitude."
)
iq_grid_row: "str | None" = analysis_field(
default=None,
description="e.g. 1; 3-5; 3,4,5",
)
iq_grid_col: "str | None" = analysis_field(
default=None,
description="e.g. 1; 3-5; 3,4,5",
)
[docs]
class ROTwoStateCombinedOptimizationQOI(BaseQoi):
"""QOI for the 2-state (|0>, |1>) RO amplitude optimisation."""
amplitude: float = 0.0
frequency: float = 0.0
rotation: float = 0.0
threshold: float = 0.0
fidelity: float = 0.0
lda_coef_0: float = 0.0
lda_coef_1: float = 0.0
lda_intercept: float = 0.0
[docs]
@override
def to_dict(self) -> dict[str, Any]:
return {
"measure_2state_opt.pulse_amp": self.amplitude,
"extended_clock_freqs:readout_2state_opt": self.frequency,
"measure_2state_opt.acq_rotation": self.rotation,
"measure_2state_opt.acq_threshold": self.threshold,
}
[docs]
def to_redis_dict(self) -> dict:
"""Convert the QOI to a dictionary suitable for Redis storage."""
return {
"measure_2state_opt:pulse_amp": {"value": self.amplitude, "error": 0.0},
"extended_clock_freqs:readout_2state_opt": {
"value": self.frequency,
"error": 0.0,
},
"measure_2state_opt:acq_rotation": {"value": self.rotation, "error": 0.0},
"measure_2state_opt:acq_threshold": {"value": self.threshold, "error": 0.0},
"measure_2state_opt:readout_fidelity": {
"value": self.fidelity,
"error": 0.0,
},
"measure_2state_opt:lda_coef_0": {"value": self.lda_coef_0, "error": 0.0},
"measure_2state_opt:lda_coef_1": {"value": self.lda_coef_1, "error": 0.0},
"measure_2state_opt:lda_intercept": {
"value": self.lda_intercept,
"error": 0.0,
},
}
[docs]
class ROThreeStateCombinedOptimizationQOI(BaseQoi):
"""Quantity of Interest (QOI) results from the readout 3 states amplitude optimization."""
amplitude: float = 0.0
frequency: float = 0.0
centroid_I: float = 0.0
centroid_Q: float = 0.0
omega_01: float = 0.0
omega_12: float = 0.0
omega_20: float = 0.0
inv_cm_opt: list[float] | None = None
fidelity: float = 0.0
[docs]
@override
def to_dict(self) -> dict[str, Any]:
return {
"measure_3state_opt.pulse_amp": self.amplitude,
"extended_clock_freqs:readout_3state_opt": self.frequency,
"measure_3state_opt.centroid_I": self.centroid_I,
"measure_3state_opt.centroid_Q": self.centroid_Q,
"measure_3state_opt.omega_01": self.omega_01,
"measure_3state_opt.omega_12": self.omega_12,
}
[docs]
def to_redis_dict(self) -> dict:
"""Convert the QOI to a dictionary suitable for Redis storage."""
return {
"measure_3state_opt:pulse_amp": {"value": self.amplitude, "error": 0.0},
"extended_clock_freqs:readout_3state_opt": {
"value": self.frequency,
"error": 0.0,
},
"measure_3state_opt:centroid_I": {"value": self.centroid_I, "error": 0.0},
"measure_3state_opt:centroid_Q": {"value": self.centroid_Q, "error": 0.0},
"measure_3state_opt:omega_01": {"value": self.omega_01, "error": 0.0},
"measure_3state_opt:omega_12": {"value": self.omega_12, "error": 0.0},
"measure_3state_opt:omega_20": {"value": self.omega_20, "error": 0.0},
"measure_3state_opt:inv_cm_opt": {
"value": json.dumps(self.inv_cm_opt),
"error": 0.0,
},
"measure_3state_opt:readout_fidelity_3state": {
"value": self.fidelity,
"error": 0.0,
},
}