# ══════════════════════════════════════════════════════════════════════════
# ___ ___ ___ _ _ ___
# / _ \ / __|_ ) | | /_\ | _ )
# | (_) | (__ / / | |__ / _ \| _ \
# \__\_\\___/___| |____/_/ \_\___/
#
# 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
# Theresa Fuchs, gerda@chalmers.se
# Matteo Robbiati, robbiati@chalmers.se
# Michele Faucci Giannelli, faucci@chalmers.se
# ══════════════════════════════════════════════════════════════════════════
from typing import Literal, override
import numpy as np
from pydantic import Field, model_validator
from bragi_quantum.experiments.abstract.parameter_fields import (
acquisition_field,
analysis_field,
)
from bragi_quantum.experiments.abstract.parameters import (
BaseQoi,
)
from bragi_quantum.experiments.nodes.characterization.coherence_parameters import (
CoherenceParameters,
)
def _default_t1_delays(max_duration: float, num_steps: int) -> list[float]:
"""Uniformly spaced delays, 0 to ~max_duration in ~num_steps steps.
Must be a true linear sweep (constant, whole-nanosecond step): the
hardware loop register reconstructs every point as ``start + index *
step``. The step is rounded to the nearest nanosecond first, which
means the actual last delay can differ slightly from max_duration
when it doesn't divide evenly into (num_steps - 1) whole nanoseconds.
"""
step_ns = round(max_duration * 1e9 / (num_steps - 1))
return (step_ns * np.arange(num_steps) * 1e-9).tolist()
[docs]
class T1Parameters(CoherenceParameters):
"""Parameters for T1 relaxation-time characterization."""
transition: Literal["01"] = acquisition_field(default="01", variant=True)
max_duration: float = acquisition_field(
default=360e-6,
gt=0.0,
description=(
"Longest waiting time, in seconds. Recommended: 5x expected T1 of the qubit."
"Ignored if list of delays is given explicitly."
),
)
num_steps: int = acquisition_field(
default=31,
ge=2,
description=(
"Number of points between 0 and max_duration, default is 31."
"Ignored if list of delays is given explicitly."
),
)
# Delays (s) between the excitation pulse and the readout. Leave unset to
# auto-generate a linspace from max_duration and num_steps instead.
delays: list[float] | None = acquisition_field(
default=None,
description=(
"Explicit delays between the excitation pulse and the readout, in seconds."
"If defined, this overwrites max_duration and num_steps."
),
)
repetitions: int = acquisition_field(
default=1024,
description="Number of hardware-averaged shots per delay point.",
)
t1_repetitions: int = acquisition_field(
default=3,
description=(
"Number of independent repeats of the full delay sweep (and its "
"own calibration points). T1 is fitted separately per repeat; the "
"reported t1 is the mean across repeats and t1_error is their "
"standard deviation."
),
)
histogram_bins: int = analysis_field(
default=10,
description="Number of bins for the per-repeat T1 histogram plot.",
)
@model_validator(mode="after")
def _resolve_delays(self) -> "T1Parameters":
if self.delays is None:
self.delays = _default_t1_delays(self.max_duration, self.num_steps)
return self
[docs]
class T1QOI(BaseQoi):
"""Quantities of Interest from T1 characterization.
Times are stored in microseconds, matching the fitting units.
"""
t1: float = Field(default=0.0)
t1_error: float = Field(default=0.0)
offset: float = Field(default=0.0)
offset_error: float = Field(default=0.0)
amplitude: float = Field(default=0.0)
amplitude_error: float = Field(default=0.0)
[docs]
@override
def to_dict(self) -> dict[str, float]:
# T1 is a characterization quantity; there is no device-model
# attribute to write back.
return {}
[docs]
def to_redis_dict(self) -> dict[str, dict[str, float]]:
return {
"t1": {"value": self.t1, "error": self.t1_error},
"t1_offset": {"value": self.offset, "error": self.offset_error},
"t1_amplitude": {"value": self.amplitude, "error": self.amplitude_error},
}