Skip to content

Commit

Permalink
refactor: update classification, rabi amplitude and resonator spectro…
Browse files Browse the repository at this point in the history
…scopy routines
  • Loading branch information
stavros11 committed Jul 13, 2024
1 parent 69a3c6d commit e98ae67
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 37 deletions.
23 changes: 12 additions & 11 deletions src/qibocal/protocols/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import plotly.graph_objects as go
from qibolab import AcquisitionType, ExecutionParameters
from qibolab.platform import Platform
from qibolab.pulses import PulseSequence
from qibolab.pulses import Delay, PulseSequence
from qibolab.qubits import QubitId
from sklearn.metrics import roc_auc_score, roc_curve

Expand Down Expand Up @@ -169,24 +169,25 @@ def _acquisition(
sequences, all_ro_pulses = [], []
for state in [0, 1]:
sequence = PulseSequence()
RX_pulses = {}
ro_pulses = {}
for qubit in targets:
RX_pulses[qubit] = platform.create_RX_pulse(qubit, start=0)
ro_pulses[qubit] = platform.create_qubit_readout_pulse(
qubit, start=RX_pulses[qubit].finish
)
for q in targets:
qubit = platform.qubits[q]
rx_sequence = qubit.native_gates.RX.create_sequence(theta=np.pi, phi=0)
ro_sequence = qubit.native_gates.MZ.create_sequence()
if state == 1:
sequence.add(RX_pulses[qubit])
sequence.add(ro_pulses[qubit])
sequence.extend(rx_sequence)
sequence[qubit.measure.name].append(Delay(duration=rx_sequence.duration))
sequence.extend(ro_sequence)
ro_pulses[q] = ro_sequence[qubit.measure.name][0].id

sequences.append(sequence)
all_ro_pulses.append(ro_pulses)

data = SingleShotClassificationData(
nshots=params.nshots,
qubit_frequencies={
qubit: platform.qubits[qubit].drive_frequency for qubit in targets
qubit: platform.config(platform.qubits[qubit].drive.name).frequency
for qubit in targets
},
classifiers_list=params.classifiers_list,
savedir=params.savedir,
Expand All @@ -207,7 +208,7 @@ def _acquisition(

for ig, (state, ro_pulses) in enumerate(zip([0, 1], all_ro_pulses)):
for qubit in targets:
serial = ro_pulses[qubit].serial
serial = ro_pulses[qubit]
if params.unrolling:
result = results[serial][ig]
else:
Expand Down
4 changes: 2 additions & 2 deletions src/qibocal/protocols/rabi/amplitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _acquisition(
to find the drive pulse amplitude that creates a rotation of a desired angle.
"""

sequence, qd_pulses, _, durations = utils.sequence_amplitude(
sequence, qd_pulses, ro_pulses, durations = utils.sequence_amplitude(
targets, params, platform
)
# define the parameter to sweep and its range:
Expand Down Expand Up @@ -84,7 +84,7 @@ def _acquisition(
sweeper,
)
for qubit in targets:
prob = results[qubit].probability(state=1)
prob = results[ro_pulses[qubit].id].probability(state=1)
data.register_qubit(
RabiAmpType,
(qubit),
Expand Down
4 changes: 2 additions & 2 deletions src/qibocal/protocols/rabi/amplitude_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RabiAmplitudeSignalParameters(Parameters):
"""Maximum amplitude multiplicative factor."""
step_amp_factor: float
"""Step amplitude multiplicative factor."""
pulse_length: Optional[float]
pulse_length: Optional[float] = None
"""RX pulse duration [ns]."""


Expand Down Expand Up @@ -100,7 +100,7 @@ def _acquisition(
sweeper,
)
for qubit in targets:
result = results[ro_pulses[qubit].serial]
result = results[ro_pulses[qubit].id]
data.register_qubit(
RabiAmpSignalType,
(qubit),
Expand Down
24 changes: 14 additions & 10 deletions src/qibocal/protocols/rabi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from qibolab.platform import Platform
from qibolab.pulses import PulseSequence
from qibolab.pulses import Delay, PulseSequence
from qibolab.qubits import QubitId
from scipy.optimize import curve_fit

Expand Down Expand Up @@ -231,17 +231,21 @@ def sequence_amplitude(
qd_pulses = {}
ro_pulses = {}
durations = {}
for qubit in targets:
qd_pulses[qubit] = platform.create_RX_pulse(qubit, start=0)
for q in targets:
qubit = platform.qubits[q]
qd_sequence = qubit.native_gates.RX.create_sequence(theta=np.pi, phi=0)
ro_sequence = qubit.native_gates.MZ.create_sequence()

qd_pulses[q] = qd_sequence[qubit.drive.name][0]
if params.pulse_length is not None:
qd_pulses[qubit].duration = params.pulse_length
qd_pulses[q].duration = params.pulse_length

durations[qubit] = qd_pulses[qubit].duration
ro_pulses[qubit] = platform.create_qubit_readout_pulse(
qubit, start=qd_pulses[qubit].finish
)
sequence.add(qd_pulses[qubit])
sequence.add(ro_pulses[qubit])
durations[q] = qd_pulses[q].duration
ro_pulses[q] = ro_sequence[qubit.measure.name][0]

sequence[qubit.drive.name].append(qd_pulses[q])
sequence[qubit.measure.name].append(Delay(duration=durations[q]))
sequence[qubit.measure.name].append(ro_pulses[q])
return sequence, qd_pulses, ro_pulses, durations


Expand Down
25 changes: 14 additions & 11 deletions src/qibocal/protocols/resonator_spectroscopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,26 @@ def _acquisition(
amplitudes = {}
attenuations = {}

for qubit in targets:
ro_pulses[qubit] = platform.create_qubit_readout_pulse(qubit, start=0)
for q in targets:
qubit = platform.qubits[q]
ro_sequence = qubit.native_gates.MZ.create_sequence()
ro_pulses[q] = ro_sequence[qubit.measure.name][0]

if params.amplitude is not None:
ro_pulses[qubit].amplitude = params.amplitude
ro_pulses[q].amplitude = params.amplitude

amplitudes[qubit] = ro_pulses[qubit].amplitude
amplitudes[q] = ro_pulses[q].amplitude

if params.attenuation is not None:
platform.qubits[qubit].readout.attenuation = params.attenuation
platform.qubits[q].readout.attenuation = params.attenuation

try:
attenuation = platform.qubits[qubit].readout.attenuation
attenuation = platform.qubits[q].readout.attenuation
except AttributeError:
attenuation = None

attenuations[qubit] = attenuation
sequence.add(ro_pulses[qubit])
attenuations[q] = attenuation
sequence[qubit.measure.name].append(ro_pulses[q])

# define the parameter to sweep and its range:
delta_frequency_range = np.arange(
Expand All @@ -155,7 +157,7 @@ def _acquisition(
sweeper = Sweeper(
Parameter.frequency,
delta_frequency_range,
pulses=[ro_pulses[qubit] for qubit in targets],
channels=[platform.qubits[q].measure for q in targets],
type=SweeperType.OFFSET,
)
data = ResonatorSpectroscopyData(
Expand All @@ -173,15 +175,16 @@ def _acquisition(

# retrieve the results for every qubit
for qubit in targets:
result = results[ro_pulses[qubit].serial]
result = results[ro_pulses[qubit].id]
# store the results
ro_frequency = platform.config(platform.qubits[qubit].measure.name).frequency
data.register_qubit(
ResSpecType,
(qubit),
dict(
signal=result.average.magnitude,
phase=result.average.phase,
freq=delta_frequency_range + ro_pulses[qubit].frequency,
freq=delta_frequency_range + ro_frequency,
error_signal=result.average.std,
error_phase=result.phase_std,
),
Expand Down
1 change: 0 additions & 1 deletion src/qibocal/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import numpy as np
from qibolab import pulses
from qibolab.native import VirtualZPulse
from qibolab.platform import Platform
from qibolab.qubits import QubitId, QubitPairId

Expand Down

0 comments on commit e98ae67

Please sign in to comment.