Skip to content

Commit

Permalink
Merge pull request #482 from qiboteam/improve_rabi_fitting
Browse files Browse the repository at this point in the history
Fix problems with Rabi fitting
  • Loading branch information
andrea-pasquale authored Sep 5, 2023
2 parents 5fb3700 + 6359aa1 commit 076716d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/qibocal/protocols/characterization/rabi/amplitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from qibolab.qubits import QubitId
from qibolab.sweeper import Parameter, Sweeper, SweeperType
from scipy.optimize import curve_fit
from scipy.signal import find_peaks

from qibocal.auto.operation import Data, Parameters, Qubits, Results, Routine
from qibocal.config import log
Expand Down Expand Up @@ -161,9 +162,10 @@ def _fit(data: RabiAmplitudeData) -> RabiAmplitudeResults:
# Guessing period using fourier transform
ft = np.fft.rfft(y)
mags = abs(ft)
index = np.argmax(mags) if np.argmax(mags) != 0 else np.argmax(mags[1:]) + 1
f = x[index] / (x[1] - x[0])

local_maxima = find_peaks(mags, threshold=10)[0]
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, 1, f, np.pi / 2]
try:
popt, _ = curve_fit(
Expand Down
7 changes: 5 additions & 2 deletions src/qibocal/protocols/characterization/rabi/length.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from qibolab.qubits import QubitId
from qibolab.sweeper import Parameter, Sweeper, SweeperType
from scipy.optimize import curve_fit
from scipy.signal import find_peaks

from qibocal.auto.operation import Data, Parameters, Qubits, Results, Routine
from qibocal.config import log
Expand Down Expand Up @@ -168,8 +169,10 @@ def _fit(data: RabiLengthData) -> RabiLengthResults:
# Guessing period using fourier transform
ft = np.fft.rfft(y)
mags = abs(ft)
index = np.argmax(mags) if np.argmax(mags) != 0 else np.argmax(mags[1:]) + 1
f = x[index] / (x[1] - x[0])
local_maxima = find_peaks(mags, threshold=1)[0]
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 = [1, 1, f, np.pi / 2, 0]
try:
Expand Down
8 changes: 6 additions & 2 deletions src/qibocal/protocols/characterization/ramsey.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from qibolab.qubits import QubitId
from qibolab.sweeper import Parameter, Sweeper, SweeperType
from scipy.optimize import curve_fit
from scipy.signal import find_peaks

from qibocal.auto.operation import Data, Parameters, Qubits, Results, Routine
from qibocal.config import log
Expand Down Expand Up @@ -227,8 +228,11 @@ def _fit(data: RamseyData) -> RamseyResults:
ft = np.fft.rfft(y)
freqs = np.fft.rfftfreq(len(y), x[1] - x[0])
mags = abs(ft)
index = np.argmax(mags) if np.argmax(mags) != 0 else np.argmax(mags[1:]) + 1
f = freqs[index] * 2 * np.pi

local_maxima = find_peaks(mags, threshold=10)[0]
index = local_maxima[0] if len(local_maxima) > 0 else None
# 0.5 hardcoded guess for less than one oscillation
f = freqs[index] * 2 * np.pi if index is not None else 0.5
p0 = [
0.5,
0.5,
Expand Down

0 comments on commit 076716d

Please sign in to comment.