Skip to content

Commit

Permalink
better frequency estimation and plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
rodolfocarobene committed May 21, 2024
1 parent 4a1628b commit d69bbf7
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 41 deletions.
22 changes: 16 additions & 6 deletions src/qibocal/protocols/rabi/amplitude_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from qibocal.config import log
from qibocal.protocols.utils import table_dict, table_html

from ..two_qubit_interaction.utils import fit_flux_amplitude
from ..utils import HZ_TO_GHZ, chi2_reduced
from .amplitude_frequency_signal import (
RabiAmplitudeFrequencyVoltParameters,
Expand Down Expand Up @@ -164,8 +163,9 @@ def _fit(data: RabiAmplitudeFreqData) -> RabiAmplitudeFrequencyResults:
probability = data[qubit].prob
probability_matrix = probability.reshape(len(amps), len(freqs)).T

# guess amplitude computing FFT
frequency, index, _ = fit_flux_amplitude(probability_matrix, freqs, amps)
# guess optimal frequency maximizing oscillatio amplitude
index = np.argmax([max(x) - min(x) for x in probability_matrix])
frequency = freqs[index]

pguess = [0.5, 1, 1 / frequency, 0]
y = probability_matrix[index, :].ravel()
Expand Down Expand Up @@ -245,9 +245,19 @@ def _plot(
row=1,
col=1,
)
fig.add_trace(
go.Scatter(
x=[min(amplitudes), max(amplitudes)],
y=[fit.frequency[target] / 1e9] * 2,
mode="lines",
line=dict(color="white", width=4, dash="dash"),
),
row=1,
col=1,
)

fig.update_layout(
showlegend=True,
showlegend=False,
legend=dict(orientation="h"),
)

Expand All @@ -260,10 +270,10 @@ def _plot(
fitting_report = table_html(
table_dict(
target,
["Transition frequency", "Pi-pulse amplitude"],
["Optimal rabi frequency", "Pi-pulse amplitude"],
[
fit.frequency[target],
f"{fit.amplitude[target][0]:.2E} +- {fit.amplitude[target][1]:.2E} [a.u.]",
f"{fit.amplitude[target][0]} +- {fit.amplitude[target][1]} [a.u.]",
],
)
)
Expand Down
41 changes: 27 additions & 14 deletions src/qibocal/protocols/rabi/amplitude_frequency_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from qibocal.config import log
from qibocal.protocols.utils import table_dict, table_html

from ..two_qubit_interaction.utils import fit_flux_amplitude
from ..utils import HZ_TO_GHZ
from .amplitude_signal import RabiAmplitudeVoltResults
from .utils import rabi_amplitude_function
Expand Down Expand Up @@ -177,8 +176,9 @@ def _fit(data: RabiAmplitudeFreqVoltData) -> RabiAmplitudeFrequencyVoltResults:
signal = data[qubit].signal
signal_matrix = signal.reshape(len(amps), len(freqs)).T

# guess amplitude computing FFT
frequency, index, _ = fit_flux_amplitude(signal_matrix, freqs, amps)
# guess optimal frequency maximizing oscillatio amplitude
index = np.argmax([max(x) - min(x) for x in signal_matrix])
frequency = freqs[index]

pguess = [0.5, 1, 1 / frequency, 0]
y = signal_matrix[index, :].ravel()
Expand Down Expand Up @@ -237,21 +237,14 @@ def _plot(
horizontal_spacing=0.1,
vertical_spacing=0.2,
subplot_titles=(
"Normalised Signal [a.u.]",
"phase [rad]",
"Signal [a.u.]",
"Phase [rad]",
),
)
qubit_data = data[target]
frequencies = qubit_data.freq * HZ_TO_GHZ
amplitudes = qubit_data.amp

# n_amps = len(np.unique(qubit_data.amp))
# n_freq = len(np.unique(qubit_data.freq))
# for i in range(n_amps):
# qubit_data.signal[i * n_freq : (i + 1) * n_freq] = norm(
# qubit_data.signal[i * n_freq : (i + 1) * n_freq]
# )

fig.add_trace(
go.Heatmap(
x=amplitudes,
Expand All @@ -262,6 +255,16 @@ def _plot(
row=1,
col=1,
)
fig.add_trace(
go.Scatter(
x=[min(amplitudes), max(amplitudes)],
y=[fit.frequency[target] / 1e9] * 2,
mode="lines",
line=dict(color="white", width=4, dash="dash"),
),
row=1,
col=1,
)

fig.add_trace(
go.Heatmap(
Expand All @@ -273,9 +276,19 @@ def _plot(
row=1,
col=2,
)
fig.add_trace(
go.Scatter(
x=[min(amplitudes), max(amplitudes)],
y=[fit.frequency[target] / 1e9] * 2,
mode="lines",
line=dict(color="white", width=4, dash="dash"),
),
row=1,
col=2,
)

fig.update_layout(
showlegend=True,
showlegend=False,
legend=dict(orientation="h"),
)

Expand All @@ -289,7 +302,7 @@ def _plot(
fitting_report = table_html(
table_dict(
target,
["Transition frequency", "Pi-pulse amplitude"],
["Optimal rabi frequency", "Pi-pulse amplitude"],
[
fit.frequency[target],
fit.amplitude[target],
Expand Down
22 changes: 16 additions & 6 deletions src/qibocal/protocols/rabi/length_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from qibocal.config import log
from qibocal.protocols.utils import table_dict, table_html

from ..two_qubit_interaction.utils import fit_flux_amplitude
from ..utils import HZ_TO_GHZ, chi2_reduced
from .length_frequency_signal import (
RabiLengthFrequencyVoltParameters,
Expand Down Expand Up @@ -164,8 +163,9 @@ def _fit(data: RabiLengthFreqData) -> RabiLengthFrequencyResults:
probability = data[qubit].prob
probability_matrix = probability.reshape(len(durations), len(freqs)).T

# guess amplitude computing FFT
frequency, index, _ = fit_flux_amplitude(probability_matrix, freqs, durations)
# guess optimal frequency maximizing oscillatio amplitude
index = np.argmax([max(x) - min(x) for x in probability_matrix])
frequency = freqs[index]

y = probability_matrix[index, :].ravel()
pguess = [0, np.sign(y[0]) * 0.5, 1 / frequency, 0, 0]
Expand Down Expand Up @@ -261,9 +261,19 @@ def _plot(
row=1,
col=1,
)
fig.add_trace(
go.Scatter(
x=[min(durations), max(durations)],
y=[fit.frequency[target] / 1e9] * 2,
mode="lines",
line=dict(color="white", width=4, dash="dash"),
),
row=1,
col=1,
)

fig.update_layout(
showlegend=True,
showlegend=False,
legend=dict(orientation="h"),
)

Expand All @@ -276,10 +286,10 @@ def _plot(
fitting_report = table_html(
table_dict(
target,
["Transition frequency", "Pi-pulse duration"],
["Optimal rabi frequency", "Pi-pulse duration"],
[
fit.frequency[target],
f"{fit.length[target][0]*1e9:.2E} +- {fit.length[target][1]*1e9:.2E} ns",
f"{int(fit.length[target][0]*1e9)} +- {fit.length[target][1]*1e9:.2e} ns",
],
)
)
Expand Down
43 changes: 28 additions & 15 deletions src/qibocal/protocols/rabi/length_frequency_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from qibocal.config import log
from qibocal.protocols.utils import table_dict, table_html

from ..two_qubit_interaction.utils import fit_flux_amplitude
from ..utils import HZ_TO_GHZ
from .length_signal import RabiLengthVoltResults
from .utils import period_correction_factor, rabi_length_function
Expand Down Expand Up @@ -177,8 +176,9 @@ def _fit(data: RabiLengthFreqVoltData) -> RabiLengthFrequencyVoltResults:
signal = data[qubit].signal
signal_matrix = signal.reshape(len(durations), len(freqs)).T

# guess amplitude computing FFT
frequency, index, _ = fit_flux_amplitude(signal_matrix, freqs, durations)
# guess optimal frequency maximizing oscillatio amplitude
index = np.argmax([max(x) - min(x) for x in signal_matrix])
frequency = freqs[index]

y = signal_matrix[index, :].ravel()
pguess = [0, np.sign(y[0]) * 0.5, 1 / frequency, 0, 0]
Expand Down Expand Up @@ -243,21 +243,14 @@ def _plot(
horizontal_spacing=0.1,
vertical_spacing=0.2,
subplot_titles=(
"Normalised Signal [a.u.]",
"phase [rad]",
"Signal [a.u.]",
"Phase [rad]",
),
)
qubit_data = data[target]
frequencies = qubit_data.freq * HZ_TO_GHZ
durations = qubit_data.len

# n_amps = len(np.unique(qubit_data.amp))
# n_freq = len(np.unique(qubit_data.freq))
# for i in range(n_amps):
# qubit_data.signal[i * n_freq : (i + 1) * n_freq] = norm(
# qubit_data.signal[i * n_freq : (i + 1) * n_freq]
# )

fig.add_trace(
go.Heatmap(
x=durations,
Expand All @@ -268,6 +261,26 @@ def _plot(
row=1,
col=1,
)
fig.add_trace(
go.Scatter(
x=[min(durations), max(durations)],
y=[fit.frequency[target] / 1e9] * 2,
mode="lines",
line=dict(color="white", width=4, dash="dash"),
),
row=1,
col=1,
)
fig.add_trace(
go.Scatter(
x=[min(durations), max(durations)],
y=[fit.frequency[target] / 1e9] * 2,
mode="lines",
line=dict(color="white", width=4, dash="dash"),
),
row=1,
col=2,
)

fig.add_trace(
go.Heatmap(
Expand All @@ -281,7 +294,7 @@ def _plot(
)

fig.update_layout(
showlegend=True,
showlegend=False,
legend=dict(orientation="h"),
)

Expand All @@ -295,10 +308,10 @@ def _plot(
fitting_report = table_html(
table_dict(
target,
["Transition frequency", "Pi-pulse duration"],
["Optimal rabi frequency", "Pi-pulse duration"],
[
fit.frequency[target],
f"{fit.length[target]*1e9:.2E} ns",
f"{int(fit.length[target]*1e9)} ns",
],
)
)
Expand Down

0 comments on commit d69bbf7

Please sign in to comment.