diff --git a/src/qibocal/protocols/characterization/rabi/amplitude.py b/src/qibocal/protocols/characterization/rabi/amplitude.py index 68de5974a..3b2f6cc68 100644 --- a/src/qibocal/protocols/characterization/rabi/amplitude.py +++ b/src/qibocal/protocols/characterization/rabi/amplitude.py @@ -150,7 +150,7 @@ def _fit(data: RabiAmplitudeData) -> RabiAmplitudeResults: index = local_maxima[0] if len(local_maxima) > 0 else None # 0.5 hardcoded guess for less than one oscillation f = x[index] / (x[1] - x[0]) if index is not None else 0.5 - pguess = [0.5, 0.5, 1 / f, np.pi / 2] + pguess = [0.5, 0.5, 1 / f, 0] try: popt, perr = curve_fit( utils.rabi_amplitude_function, @@ -165,7 +165,7 @@ def _fit(data: RabiAmplitudeData) -> RabiAmplitudeResults: sigma=qubit_data.error, ) perr = np.sqrt(np.diag(perr)) - pi_pulse_parameter = np.abs(popt[2] / 2) + pi_pulse_parameter = utils.correct_period(period=popt[2], phase=popt[3]) except: log.warning("rabi_fit: the fitting was not succesful") diff --git a/src/qibocal/protocols/characterization/rabi/amplitude_signal.py b/src/qibocal/protocols/characterization/rabi/amplitude_signal.py index 5447cd65f..620ac303e 100644 --- a/src/qibocal/protocols/characterization/rabi/amplitude_signal.py +++ b/src/qibocal/protocols/characterization/rabi/amplitude_signal.py @@ -155,7 +155,9 @@ def _fit(data: RabiAmplitudeVoltData) -> RabiAmplitudeVoltResults: popt[2] * (x_max - x_min), popt[3] - 2 * np.pi * x_min / (x_max - x_min) / popt[2], ] - pi_pulse_parameter = np.abs((translated_popt[2]) / 2) + pi_pulse_parameter = utils.correct_period( + period=translated_popt[2], phase=translated_popt[3] + ) except: log.warning("rabi_fit: the fitting was not succesful") diff --git a/src/qibocal/protocols/characterization/rabi/length.py b/src/qibocal/protocols/characterization/rabi/length.py index 126a359bc..3c4ca89c9 100644 --- a/src/qibocal/protocols/characterization/rabi/length.py +++ b/src/qibocal/protocols/characterization/rabi/length.py @@ -169,7 +169,7 @@ def _fit(data: RabiLengthData) -> RabiLengthResults: sigma=qubit_data.error, ) perr = np.sqrt(np.diag(perr)) - pi_pulse_parameter = np.abs(popt[2] / 2) + pi_pulse_parameter = utils.correct_period(period=popt[2], phase=popt[3]) except: log.warning("rabi_fit: the fitting was not succesful") pi_pulse_parameter = 0 diff --git a/src/qibocal/protocols/characterization/rabi/length_signal.py b/src/qibocal/protocols/characterization/rabi/length_signal.py index 37757a72a..321b3f338 100644 --- a/src/qibocal/protocols/characterization/rabi/length_signal.py +++ b/src/qibocal/protocols/characterization/rabi/length_signal.py @@ -161,7 +161,10 @@ def _fit(data: RabiLengthVoltData) -> RabiLengthVoltResults: popt[3] - 2 * np.pi * x_min / popt[2] / (x_max - x_min), popt[4] / (x_max - x_min), ] - pi_pulse_parameter = np.abs(translated_popt[2] / 2) + pi_pulse_parameter = utils.correct_period( + period=translated_popt[2], phase=translated_popt[3] + ) + except: log.warning("rabi_fit: the fitting was not succesful") pi_pulse_parameter = 0 diff --git a/src/qibocal/protocols/characterization/rabi/utils.py b/src/qibocal/protocols/characterization/rabi/utils.py index 00b1e8aeb..1442935bc 100644 --- a/src/qibocal/protocols/characterization/rabi/utils.py +++ b/src/qibocal/protocols/characterization/rabi/utils.py @@ -12,7 +12,7 @@ def rabi_amplitude_function(x, offset, amplitude, period, phase): Args: x: Input data. """ - return offset + amplitude * np.sin(2 * np.pi * x / period + phase) + return offset + amplitude * np.cos(2 * np.pi * x / period + phase) def rabi_length_function(x, offset, amplitude, period, phase, t2_inv): @@ -190,3 +190,17 @@ def extract_rabi(data): if "RabiLength" in data.__class__.__name__: return "length", "Time [ns]", rabi_length_function raise RuntimeError("Data has to be a data structure of the Rabi routines.") + + +def correct_period(period: float, phase: float): + """Correct period by taking phase into account. + + https://github.com/qiboteam/qibocal/issues/656 + """ + + naive_half_period = period / 2 + # solution of cos (2 pi x / period + phase) = +/- 1 for k in [-2,2] + solutions = [naive_half_period * (k - phase / np.pi) for k in [-2, -1, 0, 1, 2]] + # chose solution closest to naive_half period + + return solutions[np.argmin(np.abs(solutions - naive_half_period))]