Skip to content

Commit

Permalink
chore: update Ramsey routines
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros11 committed Oct 17, 2024
1 parent 541c9f4 commit 190bb74
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 77 deletions.
49 changes: 25 additions & 24 deletions src/qibocal/protocols/ramsey/ramsey.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from qibocal.auto.operation import QubitId, Routine
from qibocal.config import log
from qibocal.result import probability

from ..utils import chi2_reduced, table_dict, table_html
from .ramsey_signal import (
Expand Down Expand Up @@ -87,44 +88,42 @@ def _acquisition(
params.delay_between_pulses_step,
)

options = ExecutionParameters(
nshots=params.nshots,
relaxation_time=params.relaxation_time,
acquisition_type=AcquisitionType.DISCRIMINATION,
averaging_mode=AveragingMode.SINGLESHOT,
)

sequence = PulseSequence()

data = RamseyData(
detuning=params.detuning,
qubit_freqs={
qubit: platform.qubits[qubit].native_gates.RX.frequency for qubit in targets
qubit: platform.config(platform.qubits[qubit].drive).frequency
for qubit in targets
},
)

if not params.unrolling:
sequence = PulseSequence()
updates = []
if params.detuning != 0:
for qubit in targets:
sequence += ramsey_sequence(
platform=platform, qubit=qubit, detuning=params.detuning
)
channel = platform.qubits[qubit].drive
f0 = platform.config(channel).frequency
updates.append({channel: {"frequency": f0 + params.detuning}})

if not params.unrolling:
sequence, delays = ramsey_sequence(platform, targets)
sweeper = Sweeper(
Parameter.start,
waits,
[sequence.get_qubit_pulses(qubit).qd_pulses[-1] for qubit in targets],
type=SweeperType.ABSOLUTE,
parameter=Parameter.duration,
values=waits,
pulses=delays,
)

# execute the sweep
results = platform.sweep(
sequence,
options,
sweeper,
results = platform.execute(
[sequence],
[[sweeper]],
nshots=params.nshots,
relaxation_time=params.relaxation_time,
acquisition_type=AcquisitionType.DISCRIMINATION,
averaging_mode=AveragingMode.SINGLESHOT,
updates=updates,
)
for qubit in targets:
probs = results[qubit].probability(state=1)
ro_pulse = list(sequence.channel(platform.qubits[qubit].acquisition))[-1]
probs = probability(results[ro_pulse.id], state=1)
# The probability errors are the standard errors of the binomial distribution
errors = [np.sqrt(prob * (1 - prob) / params.nshots) for prob in probs]
data.register_qubit(
Expand All @@ -138,6 +137,8 @@ def _acquisition(
)

if params.unrolling:
raise NotImplementedError

sequences, all_ro_pulses = [], []
for wait in waits:
sequence = PulseSequence()
Expand Down
62 changes: 32 additions & 30 deletions src/qibocal/protocols/ramsey/ramsey_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
Sweeper,
)

from qibocal import update
from qibocal.auto.operation import Data, Parameters, QubitId, Results, Routine
from qibocal.config import log
from qibocal.result import magnitude

from ..utils import table_dict, table_html
from .utils import fitting, process_fit, ramsey_fit, ramsey_sequence
Expand Down Expand Up @@ -99,54 +99,55 @@ def _acquisition(
params.delay_between_pulses_step,
)

options = ExecutionParameters(
nshots=params.nshots,
relaxation_time=params.relaxation_time,
acquisition_type=AcquisitionType.INTEGRATION,
averaging_mode=AveragingMode.CYCLIC,
)

data = RamseySignalData(
detuning=params.detuning,
qubit_freqs={
qubit: platform.qubits[qubit].native_gates.RX.frequency for qubit in targets
qubit: platform.config(platform.qubits[qubit].drive).frequency
for qubit in targets
},
)

if not params.unrolling:
sequence = PulseSequence()
updates = []
if params.detuning != 0:
for qubit in targets:
sequence += ramsey_sequence(
platform=platform, qubit=qubit, detuning=params.detuning
)
channel = platform.qubits[qubit].drive
f0 = platform.config(channel).frequency
updates.append({channel: {"frequency": f0 + params.detuning}})

if not params.unrolling:
sequence, delays = ramsey_sequence(platform, targets)
sweeper = Sweeper(
Parameter.start,
waits,
[
sequence.get_qubit_pulses(qubit).qd_pulses[-1] for qubit in targets
], # TODO: check if it is correct
type=SweeperType.ABSOLUTE,
parameter=Parameter.duration,
values=waits,
pulses=delays,
)

# execute the sweep
results = platform.sweep(
sequence,
options,
sweeper,
results = platform.execute(
[sequence],
[[sweeper]],
nshots=params.nshots,
relaxation_time=params.relaxation_time,
acquisition_type=AcquisitionType.INTEGRATION,
averaging_mode=AveragingMode.CYCLIC,
updates=updates,
)
for qubit in targets:
result = results[sequence.get_qubit_pulses(qubit).ro_pulses[0].serial]
ro_pulse = list(sequence.channel(platform.qubits[qubit].acquisition))[-1]
result = results[ro_pulse.id]
# The probability errors are the standard errors of the binomial distribution
data.register_qubit(
RamseySignalType,
(qubit),
dict(
wait=waits,
signal=result.magnitude,
signal=magnitude(result),
),
)

else:
raise NotImplementedError

sequences, all_ro_pulses = [], []
for wait in waits:
sequence = PulseSequence()
Expand Down Expand Up @@ -289,10 +290,11 @@ def _plot(data: RamseySignalData, target: QubitId, fit: RamseySignalResults = No


def _update(results: RamseySignalResults, platform: Platform, target: QubitId):
if results.detuning is not None:
update.drive_frequency(results.frequency[target][0], platform, target)
else:
update.t2(results.t2[target][0], platform, target)
pass
# if results.detuning is not None:
# update.drive_frequency(results.frequency[target][0], platform, target)
# else:
# update.t2(results.t2[target][0], platform, target)


ramsey_signal = Routine(_acquisition, _fit, _plot, _update)
Expand Down
47 changes: 24 additions & 23 deletions src/qibocal/protocols/ramsey/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import Optional

import numpy as np
from qibolab import Platform, PulseSequence
from qibolab import Delay, Platform, PulseSequence
from scipy.optimize import curve_fit

from qibocal.auto.operation import QubitId
Expand All @@ -19,36 +17,39 @@

def ramsey_sequence(
platform: Platform,
qubit: QubitId,
wait: int = 0,
detuning: Optional[int] = None,
targets: list[QubitId],
):
"""Pulse sequence used in Ramsey (detuned) experiments.
The pulse sequence is the following:
RX90 -- wait -- RX90 -- MZ
If detuning is specified the RX90 pulses will be sent to
frequency = drive_frequency + detuning
"""

delays = []
sequence = PulseSequence()
first_pi_half_pulse = platform.create_RX90_pulse(qubit, start=0)
second_pi_half_pulse = platform.create_RX90_pulse(
qubit, start=first_pi_half_pulse.finish + wait
)
for qubit in targets:
natives = platform.natives.single_qubit[qubit]

# apply detuning:
if detuning is not None:
first_pi_half_pulse.frequency += detuning
second_pi_half_pulse.frequency += detuning
readout_pulse = platform.create_qubit_readout_pulse(
qubit, start=second_pi_half_pulse.finish
)
qd_channel, qd_pulse = natives.R(theta=np.pi / 2)[0]
ro_channel, ro_pulse = natives.MZ()[0]

qd_delay = Delay(duration=0)
ro_delay = Delay(duration=0)

sequence.extend(
[
(qd_channel, qd_pulse),
(qd_channel, qd_delay),
(qd_channel, qd_pulse),
(ro_channel, Delay(duration=2 * qd_pulse.duration)),
(ro_channel, ro_delay),
(ro_channel, ro_pulse),
]
)

delays.extend([qd_delay, ro_delay])

sequence.add(first_pi_half_pulse, second_pi_half_pulse, readout_pulse)
return sequence
return sequence, delays


def ramsey_fit(x, offset, amplitude, delta, phase, decay):
Expand Down

0 comments on commit 190bb74

Please sign in to comment.