# Ramsey Experiment

As the next step, we will do a Ramsey experiment. For this experiment, we excite the qubit with two consecutive π/2-pulses, and sweep the delay time between the pulses.

As before, we start by defining some experimental parameters. Here, we set the minimum and maximum delay between the two qubit excitation pulses as well as the number of sweep steps and averages per point. We also define the π/2-pulse with a Gaussian waveform envelope, and use the amplitude as calibrated in the Rabi experiment before.

# delay range for ramsey pulses
ramsey_min = 0.0
ramsey_max = 2.5 * qubit_parameters['T2_ramsey']
# how many delay points to sweep
ramsey_num = 150

# how many averages per point: 2^n_average
n_average = 10

# set up delay sweep parameter
ramsey_sweep = LinearSweepParameter(uid="ramsey_delay", start=ramsey_min, stop=ramsey_max, count=ramsey_num)

# Ramsey excitation pulse - qubit pi/2 pulse - will be slightly detuned
x90 = pulse_library.gaussian(
uid="x90", length=qubit_parameters['qb_len'], amplitude=qubit_parameters['pihalf_amp']
)

The sweep parameter in the Ramsey experiment is the delay between the two π/2-pulses played on the qubit drive line. The qubit readout section is the same as before. Note that here we also introduce an artificial detuning of the qubit excitation pulse frequency, with the value of the detuning defined through parameter called 'ramsey_det'. For a perfectly calibrated qubit, this artificial detuning will ensure that the measured signal shows oscillations over the delay time. Any additional frequency contribution in the data can then be attributed to a prior miscalibration of the qubit frequency, and the Ramsey experiment is often used to fine-calibrate the qubit resonance frequency.

# Create Experiment
exp_ramsey = Experiment(
uid="Ramsey",
signals=[
ExperimentSignal("drive"),
ExperimentSignal("measure"),
ExperimentSignal("acquire"),
],
)

## define Experiment sequence
# outer loop - real-time averaging
with exp_ramsey.acquire_loop_rt(uid="ramsey_shots", count=pow(2, n_average), averaging_mode=AveragingMode.CYCLIC, acquisition_type=AcquisitionType.INTEGRATION):
# inner loop - sweep Ramsey delay in real time
with exp_ramsey.sweep(uid="ramsey_sweep", parameter=ramsey_sweep, alignment=SectionAlignment.RIGHT):
# Ramsey pulse sequence on qubit
with exp_ramsey.section(uid="qubit_excitation", length=ramsey_max+2*x90.length, alignment=SectionAlignment.RIGHT):
exp_ramsey.play(signal="drive", pulse=x90)
exp_ramsey.delay(signal="drive", time=ramsey_sweep)
exp_ramsey.play(signal="drive", pulse=x90)
# readout pulse and data acquisition
)