Skip to content

Commit

Permalink
Merge pull request #611 from qiboteam/refactor_msr
Browse files Browse the repository at this point in the history
Refactor msr
  • Loading branch information
andrea-pasquale authored Nov 13, 2023
2 parents 478360a + e05429d commit c246183
Show file tree
Hide file tree
Showing 39 changed files with 280 additions and 320 deletions.
28 changes: 14 additions & 14 deletions src/qibocal/protocols/characterization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
from .allxy.drag_pulse_tuning import drag_pulse_tuning
from .classification import single_shot_classification
from .coherence.spin_echo import spin_echo
from .coherence.spin_echo_msr import spin_echo_msr
from .coherence.spin_echo_sequence import spin_echo_sequence
from .coherence.t1 import t1
from .coherence.t1_msr import t1_msr
from .coherence.t1_sequences import t1_sequences
from .coherence.t1_signal import t1_signal
from .coherence.t2 import t2
from .coherence.t2_msr import t2_msr
from .coherence.t2_sequences import t2_sequences
from .coherence.t2_signal import t2_signal
from .coherence.zeno import zeno
from .coherence.zeno_msr import zeno_msr
from .coherence.zeno_signal import zeno_signal
from .couplers.coupler_qubit_spectroscopy import coupler_qubit_spectroscopy
from .couplers.coupler_resonator_spectroscopy import coupler_resonator_spectroscopy
from .dispersive_shift import dispersive_shift
Expand All @@ -29,14 +29,14 @@
from .qubit_spectroscopy_ef import qubit_spectroscopy_ef
from .qutrit_classification import qutrit_classification
from .rabi.amplitude import rabi_amplitude
from .rabi.amplitude_msr import rabi_amplitude_msr
from .rabi.amplitude_signal import rabi_amplitude_signal
from .rabi.ef import rabi_amplitude_ef
from .rabi.length import rabi_length
from .rabi.length_msr import rabi_length_msr
from .rabi.length_sequences import rabi_length_sequences
from .rabi.length_signal import rabi_length_signal
from .ramsey import ramsey
from .ramsey_msr import ramsey_msr
from .ramsey_sequences import ramsey_sequences
from .ramsey_signal import ramsey_signal
from .randomized_benchmarking.standard_rb import standard_rb
from .readout_characterization import readout_characterization
from .readout_mitigation_matrix import readout_mitigation_matrix
Expand Down Expand Up @@ -67,21 +67,21 @@ class Operation(Enum):
rabi_amplitude = rabi_amplitude
rabi_length = rabi_length
rabi_length_sequences = rabi_length_sequences
rabi_amplitude_msr = rabi_amplitude_msr
rabi_length_msr = rabi_length_msr
rabi_amplitude_signal = rabi_amplitude_signal
rabi_length_signal = rabi_length_signal
ramsey = ramsey
ramsey_msr = ramsey_msr
ramsey_signal = ramsey_signal
ramsey_sequences = ramsey_sequences
t1 = t1
t1_msr = t1_msr
t1_signal = t1_signal
t1_sequences = t1_sequences
t2 = t2
t2_msr = t2_msr
t2_signal = t2_signal
t2_sequences = t2_sequences
time_of_flight_readout = time_of_flight_readout
single_shot_classification = single_shot_classification
spin_echo = spin_echo
spin_echo_msr = spin_echo_msr
spin_echo_sequence = spin_echo_sequence
allxy = allxy
allxy_drag_pulse_tuning = allxy_drag_pulse_tuning
drag_pulse_tuning = drag_pulse_tuning
Expand All @@ -94,7 +94,7 @@ class Operation(Enum):
resonator_frequency = resonator_frequency
fast_reset = fast_reset
zeno = zeno
zeno_msr = zeno_msr
zeno_signal = zeno_signal
chsh_pulses = chsh_pulses
chsh_circuits = chsh_circuits
readout_mitigation_matrix = readout_mitigation_matrix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from qibocal.auto.operation import Data, Qubits, Results, Routine
from qibocal.config import log

from ..utils import V_TO_UV, table_dict, table_html
from ..utils import table_dict, table_html
from . import allxy_drag_pulse_tuning


Expand All @@ -40,7 +40,7 @@ class DragPulseTuningResults(Results):
"""Raw fitting output."""


DragPulseTuningType = np.dtype([("msr", np.float64), ("beta", np.float64)])
DragPulseTuningType = np.dtype([("signal", np.float64), ("beta", np.float64)])


@dataclass
Expand All @@ -67,7 +67,6 @@ def _acquisition(
params.beta_start, params.beta_end, params.beta_step
).round(4)

# create a DataUnits object to store the MSR, phase, i, q and the beta parameter
data = DragPulseTuningData()

for beta_param in beta_param_range:
Expand Down Expand Up @@ -144,7 +143,7 @@ def _acquisition(
DragPulseTuningType,
(qubit),
dict(
msr=r1.magnitude - r2.magnitude,
signal=r1.magnitude - r2.magnitude,
beta=beta_param,
),
)
Expand Down Expand Up @@ -175,7 +174,7 @@ def _fit(data: DragPulseTuningData) -> DragPulseTuningResults:

for qubit in qubits:
qubit_data = data[qubit]
voltages = qubit_data.msr * V_TO_UV
voltages = qubit_data.signal
beta_params = qubit_data.beta

try:
Expand Down Expand Up @@ -209,7 +208,7 @@ def _plot(data: DragPulseTuningData, qubit, fit: DragPulseTuningResults):
fig.add_trace(
go.Scatter(
x=qubit_data.beta,
y=qubit_data.msr * V_TO_UV,
y=qubit_data.signal,
mode="markers",
name="Probability",
showlegend=True,
Expand Down Expand Up @@ -247,7 +246,7 @@ def _plot(data: DragPulseTuningData, qubit, fit: DragPulseTuningResults):
showlegend=True,
uirevision="0", # ``uirevision`` allows zooming while live plotting
xaxis_title="Beta parameter",
yaxis_title="MSR[uV] [Rx(pi/2) - Ry(pi)] - [Ry(pi/2) - Rx(pi)]",
yaxis_title="Signal [a.u.] [Rx(pi/2) - Ry(pi)] - [Ry(pi/2) - Rx(pi)]",
)

figures.append(fig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@
from qibocal import update
from qibocal.auto.operation import Qubits, Routine

from ..utils import V_TO_UV, table_dict, table_html
from ..utils import table_dict, table_html
from . import spin_echo
from .t1_msr import CoherenceType, T1MSRData
from .t1_signal import CoherenceType, T1SignalData
from .utils import exp_decay, exponential_fit


@dataclass
class SpinEchoMSRParameters(spin_echo.SpinEchoParameters):
"""SpinEcho MSR runcard inputs."""
class SpinEchoSignalParameters(spin_echo.SpinEchoParameters):
"""SpinEcho Signal runcard inputs."""


@dataclass
class SpinEchoMSRResults(spin_echo.SpinEchoResults):
"""SpinEchoMSR outputs."""
class SpinEchoSignalResults(spin_echo.SpinEchoResults):
"""SpinEchoSignal outputs."""


class SpinEchoMSRData(T1MSRData):
class SpinEchoSignalData(T1SignalData):
"""SpinEcho acquisition outputs."""


def _acquisition(
params: SpinEchoMSRParameters,
params: SpinEchoSignalParameters,
platform: Platform,
qubits: Qubits,
) -> SpinEchoMSRData:
) -> SpinEchoSignalData:
"""Data acquisition for SpinEcho"""
# create a sequence of pulses for the experiment:
# Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout
Expand Down Expand Up @@ -67,7 +67,7 @@ def _acquisition(
params.delay_between_pulses_step,
)

data = SpinEchoMSRData()
data = SpinEchoSignalData()

# sweep the parameter
for wait in ro_wait_range:
Expand Down Expand Up @@ -96,21 +96,21 @@ def _acquisition(
(qubit),
dict(
wait=np.array([wait]),
msr=np.array([result.magnitude]),
signal=np.array([result.magnitude]),
phase=np.array([result.phase]),
),
)
return data


def _fit(data: SpinEchoMSRData) -> SpinEchoMSRResults:
def _fit(data: SpinEchoSignalData) -> SpinEchoSignalResults:
"""Post-processing for SpinEcho."""
t2Echos, fitted_parameters = exponential_fit(data)

return SpinEchoMSRResults(t2Echos, fitted_parameters)
return SpinEchoSignalResults(t2Echos, fitted_parameters)


def _plot(data: SpinEchoMSRData, qubit, fit: SpinEchoMSRResults = None):
def _plot(data: SpinEchoSignalData, qubit, fit: SpinEchoSignalResults = None):
"""Plotting for SpinEcho"""

figures = []
Expand All @@ -125,7 +125,7 @@ def _plot(data: SpinEchoMSRData, qubit, fit: SpinEchoMSRResults = None):
fig.add_trace(
go.Scatter(
x=waits,
y=qubit_data.msr * V_TO_UV,
y=qubit_data.signal,
opacity=1,
name="Voltage",
showlegend=True,
Expand Down Expand Up @@ -158,18 +158,18 @@ def _plot(data: SpinEchoMSRData, qubit, fit: SpinEchoMSRResults = None):
fig.update_layout(
showlegend=True,
uirevision="0", # ``uirevision`` allows zooming while live plotting
xaxis_title="Time (ns)",
yaxis_title="MSR (uV)",
xaxis_title="Time [ns]",
yaxis_title="Signal [a.u.]",
)

figures.append(fig)

return figures, fitting_report


def _update(results: SpinEchoMSRResults, platform: Platform, qubit: QubitId):
def _update(results: SpinEchoSignalResults, platform: Platform, qubit: QubitId):
update.t2_spin_echo(results.t2_spin_echo[qubit], platform, qubit)


spin_echo_msr = Routine(_acquisition, _fit, _plot, _update)
spin_echo_sequence = Routine(_acquisition, _fit, _plot, _update)
"""SpinEcho Routine object."""
16 changes: 7 additions & 9 deletions src/qibocal/protocols/characterization/coherence/t1_sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

from qibocal.auto.operation import Qubits, Routine

from . import t1, t1_msr
from . import t1, t1_signal


def _acquisition(
params: t1_msr.T1MSRParameters, platform: Platform, qubits: Qubits
) -> t1_msr.T1MSRData:
params: t1_signal.T1SignalParameters, platform: Platform, qubits: Qubits
) -> t1_signal.T1SignalData:
r"""Data acquisition for T1 experiment.
In a T1 experiment, we measure an excited qubit after a delay. Due to decoherence processes
(e.g. amplitude damping channel), it is possible that, at the time of measurement, after the delay,
Expand Down Expand Up @@ -50,8 +50,7 @@ def _acquisition(
params.delay_before_readout_step,
)

# create a DataUnits object to store the MSR, phase, i, q and the delay time
data = t1_msr.T1MSRData()
data = t1_signal.T1SignalData()

# repeat the experiment as many times as defined by software_averages
# sweep the parameter
Expand All @@ -70,19 +69,18 @@ def _acquisition(
),
)
for qubit in qubits:
# average msr, phase, i and q over the number of shots defined in the runcard
result = results[ro_pulses[qubit].serial]
data.register_qubit(
t1_msr.CoherenceType,
t1_signal.CoherenceType,
(qubit),
dict(
wait=np.array([wait]),
msr=np.array([result.magnitude]),
signal=np.array([result.magnitude]),
phase=np.array([result.phase]),
),
)
return data


t1_sequences = Routine(_acquisition, t1_msr._fit, t1_msr._plot, t1._update)
t1_sequences = Routine(_acquisition, t1_signal._fit, t1_signal._plot, t1._update)
"""T1 Routine object."""
Loading

0 comments on commit c246183

Please sign in to comment.