Skip to content

Commit

Permalink
Merge pull request #825 from qiboteam/fix_chevron
Browse files Browse the repository at this point in the history
Fix bug in chevron fitting
  • Loading branch information
andrea-pasquale authored May 8, 2024
2 parents 1c6252a + e809c34 commit c358b07
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from qibocal import update
from qibocal.auto.operation import Data, Parameters, Results, Routine
from qibocal.config import log
from qibocal.protocols.characterization.utils import table_dict, table_html

from ..utils import fit_flux_amplitude, order_pair
Expand Down Expand Up @@ -148,15 +149,13 @@ def _aquisition(
dt=params.dt,
)
ordered_pair = order_pair(pair, platform)

# TODO: move in function to avoid code duplications
sweeper_amplitude = Sweeper(
Parameter.amplitude,
params.amplitude_range,
pulses=[sequence.get_qubit_pulses(ordered_pair[1]).qf_pulses[0]],
type=SweeperType.FACTOR,
)

data.native_amplitude[ordered_pair] = (
sequence.get_qubit_pulses(ordered_pair[1]).qf_pulses[0].amplitude
)
Expand All @@ -172,6 +171,7 @@ def _aquisition(
sequence,
ExecutionParameters(
nshots=params.nshots,
relaxation_time=params.relaxation_time,
acquisition_type=AcquisitionType.DISCRIMINATION,
averaging_mode=AveragingMode.CYCLIC,
),
Expand All @@ -193,35 +193,28 @@ def _fit(data: ChevronData) -> ChevronResults:
durations = {}
amplitudes = {}
for pair in data.data:
pair_amplitude = []
pair_duration = []
amps = data.amplitudes(pair)
times = data.durations(pair)

for qubit in pair:
signal = (
data.low_frequency(pair)
if pair[0] == qubit
else data.high_frequency(pair)
)
signal_matrix = signal.reshape(len(times), len(amps)).T
signal = data.low_frequency(pair)
signal_matrix = signal.reshape(len(times), len(amps)).T

# guess amplitude computing FFT
amplitude, index, delta = fit_flux_amplitude(signal_matrix, amps, times)
# estimate duration by rabi curve at amplitude previously estimated
y = signal_matrix[index, :].ravel()
# guess amplitude computing FFT
amplitude, index, delta = fit_flux_amplitude(signal_matrix, amps, times)
# estimate duration by rabi curve at amplitude previously estimated
y = signal_matrix[index, :].ravel()

try:
popt, _ = curve_fit(
chevron_fit, times, y, p0=[delta, 0, np.mean(y), np.mean(y)]
)

# duration can be estimated as the period of the oscillation
duration = 1 / (popt[0] / 2 / np.pi)
pair_amplitude.append(amplitude)
pair_duration.append(duration)

amplitudes[pair] = np.mean(pair_amplitude)
durations[pair] = int(np.mean(duration))
amplitudes[pair] = amplitude
durations[pair] = int(duration)
except Exception as e:
log.warning(f"Chevron fit failed for pair {pair} due to {e}")

return ChevronResults(amplitude=amplitudes, duration=durations)

Expand Down Expand Up @@ -288,7 +281,7 @@ def _plot(data: ChevronData, fit: ChevronResults, target: QubitPairId):
legendgroup="Voltage",
),
row=1,
col=1 if measured_qubit == target[0] else 2,
col=1,
)

fig.update_layout(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def _aquisition(
sequence,
ExecutionParameters(
nshots=params.nshots,
relaxation_time=params.relaxation_time,
acquisition_type=AcquisitionType.INTEGRATION,
averaging_mode=AveragingMode.CYCLIC,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def chevron_sequence(

sequence.add(measure_lowfreq)
sequence.add(measure_highfreq)

return sequence


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ def _acquisition_pulses(
)
for basis, sequence in chsh_sequences.items():
results = platform.execute_pulse_sequence(
sequence, ExecutionParameters(nshots=params.nshots)
sequence,
ExecutionParameters(
nshots=params.nshots, relaxation_time=params.relaxation_time
),
)
frequencies = calculate_frequencies(results, list(pair))
data.register_basis(pair, bell_state, basis, frequencies)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ def _acquisition(
sequence,
ExecutionParameters(
nshots=params.nshots,
relaxation_time=params.relaxation_time,
acquisition_type=AcquisitionType.DISCRIMINATION,
averaging_mode=AveragingMode.CYCLIC,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def _acquisition(
sequence,
ExecutionParameters(
nshots=params.nshots,
relaxation_time=params.relaxation_time,
acquisition_type=AcquisitionType.INTEGRATION,
averaging_mode=AveragingMode.CYCLIC,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def fit_flux_amplitude(matrix, amps, times):
fs.append(2 * np.pi * f)

low_freq_interval = np.where(fs == np.min(fs))
amplitude = median_high(amps[low_freq_interval])
amplitude = median_high(amps[::-1][low_freq_interval])
index = int(np.where(np.unique(amps) == amplitude)[0])
delta = np.min(fs)
return amplitude, index, delta

0 comments on commit c358b07

Please sign in to comment.