Skip to content

Commit

Permalink
refactor: Use None instead of 0 for detuning
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-pasquale committed Sep 24, 2024
1 parent 3dad308 commit de9db23
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
22 changes: 15 additions & 7 deletions src/qibocal/protocols/ramsey/ramsey_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RamseySignalParameters(Parameters):
"""Final delay between RX(pi/2) pulses in ns."""
delay_between_pulses_step: int
"""Step delay between RX(pi/2) pulses in ns."""
detuning: Optional[int] = 0
detuning: Optional[int] = None
"""Frequency detuning [Hz] (optional).
If 0 standard Ramsey experiment is performed."""
unrolling: bool = False
Expand All @@ -52,6 +52,9 @@ class RamseySignalResults(Results):
fitted_parameters: dict[QubitId, list[float]]
"""Raw fitting output."""

def is_detuned(self, qubit: QubitId):
return int(self.delta_phys[qubit][0]) != int(self.delta_fitting[qubit][0])


RamseySignalType = np.dtype([("wait", np.float64), ("signal", np.float64)])
"""Custom dtype for coherence routines."""
Expand All @@ -61,7 +64,7 @@ class RamseySignalResults(Results):
class RamseySignalData(Data):
"""Ramsey acquisition outputs."""

detuning: int
detuning: Optional[int] = None
"""Frequency detuning [Hz]."""
qubit_freqs: dict[QubitId, float] = field(default_factory=dict)
"""Qubit freqs for each qubit."""
Expand Down Expand Up @@ -195,8 +198,13 @@ def _fit(data: RamseySignalData) -> RamseySignalResults:
try:
popt, perr = fitting(waits, signal)
delta_fitting = popt[2] / (2 * np.pi)
sign = np.sign(data.detuning) if data.detuning != 0 else 1
delta_phys = int(sign * (delta_fitting * GHZ_TO_HZ - np.abs(data.detuning)))
if data.detuning is not None:
sign = np.sign(data.detuning)
delta_phys = int(
sign * (delta_fitting * GHZ_TO_HZ - np.abs(data.detuning))
)
else:
delta_phys = int(sign * (delta_fitting * GHZ_TO_HZ))
corrected_qubit_frequency = int(qubit_freq - delta_phys)
t2 = 1 / popt[4]
freq_measure[qubit] = [
Expand Down Expand Up @@ -295,10 +303,10 @@ def _plot(data: RamseySignalData, target: QubitId, fit: RamseySignalResults = No


def _update(results: RamseySignalResults, platform: Platform, target: QubitId):
if int(results.delta_phys[target][0]) == int(results.delta_fitting[target][0]):
update.t2(results.t2[target][0], platform, target)
else:
if results.is_detuned(target):
update.drive_frequency(results.frequency[target][0], platform, target)
else:
update.t2(results.t2[target][0], platform, target)


ramsey_signal = Routine(_acquisition, _fit, _plot, _update)
Expand Down
9 changes: 5 additions & 4 deletions src/qibocal/protocols/ramsey/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
def ramsey_sequence(
platform: Platform,
qubit: QubitId,
wait: Optional[int] = 0,
detuning: Optional[int] = 0,
wait: int = 0,
detuning: Optional[int] = None,
):
"""Pulse sequence used in Ramsey (detuned) experiments.
Expand All @@ -41,8 +41,9 @@ def ramsey_sequence(
)

# apply detuning:
first_pi_half_pulse.frequency += detuning
second_pi_half_pulse.frequency += detuning
if detuning is not None:
first_pi_half_pulse.frequency += detuning
second_pi_half_pulse.frequency += detuning
readout_pulse = platform.create_qubit_readout_pulse(
qubit, start=second_pi_half_pulse.finish
)
Expand Down

0 comments on commit de9db23

Please sign in to comment.