Skip to content

Commit

Permalink
Merge pull request #484 from qiboteam/delay_to_start
Browse files Browse the repository at this point in the history
Change delay sweeper to start sweeper
  • Loading branch information
Jacfomg committed Jun 12, 2023
2 parents 4c4c092 + ab97dec commit 2bb8ac8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
20 changes: 10 additions & 10 deletions src/qibolab/instruments/qm.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,13 +541,13 @@ def __init__(self, pulse: Pulse):
"""Time (in clock cycles) to wait before playing this pulse.
Calculated and assigned by :meth:`qibolab.instruments.qm.Sequence.add`."""
self.wait_time_variable: Optional[_Variable] = None
"""Time (in clock cycles) to wait before playing this pulse when we are sweeping delay."""
"""Time (in clock cycles) to wait before playing this pulse when we are sweeping start."""
self.acquisition: Acquisition = None
"""Data class containing the variables required for data acquisition for the instrument."""

self.next: set = set()
"""Pulses that will be played after the current pulse.
These pulses need to be re-aligned if we are sweeping the delay or duration."""
These pulses need to be re-aligned if we are sweeping the start or duration."""

self.baked = None
"""Baking object implementing the pulse when 1ns resolution is needed."""
Expand All @@ -559,7 +559,7 @@ def wait_cycles(self):
"""Instrument clock cycles (1 cycle = 4ns) to wait before playing the pulse.
This property will be used in the QUA ``wait`` command, so that it is compatible
with and without delay sweepers.
with and without start sweepers.
"""
if self.wait_time_variable is not None:
return self.wait_time_variable + self.wait_time
Expand Down Expand Up @@ -938,22 +938,22 @@ def sweep_bias(self, sweepers, qubits, qmsequence, relaxation_time):

self.sweep_recursion(sweepers[1:], qubits, qmsequence, relaxation_time)

def sweep_delay(self, sweepers, qubits, qmsequence, relaxation_time):
def sweep_start(self, sweepers, qubits, qmsequence, relaxation_time):
sweeper = sweepers[0]
if min(sweeper.values) < 16:
raise_error(ValueError, "Cannot sweep delay less than 16ns.")
raise_error(ValueError, "Cannot sweep start less than 16ns.")

delay = declare(int)
start = declare(int)
values = np.array(sweeper.values) // 4
with for_(*from_array(delay, values.astype(int))):
with for_(*from_array(start, values.astype(int))):
for pulse in sweeper.pulses:
qmpulse = qmsequence.pulse_to_qmpulse[pulse.serial]
# find all pulses that are connected to ``qmpulse`` and update their delays
# find all pulses that are connected to ``qmpulse`` and update their starts
to_process = {qmpulse}
while to_process:
next_qmpulse = to_process.pop()
to_process |= next_qmpulse.next
next_qmpulse.wait_time_variable = delay
next_qmpulse.wait_time_variable = start

self.sweep_recursion(sweepers[1:], qubits, qmsequence, relaxation_time)

Expand All @@ -962,7 +962,7 @@ def sweep_delay(self, sweepers, qubits, qmsequence, relaxation_time):
Parameter.amplitude: sweep_amplitude,
Parameter.relative_phase: sweep_relative_phase,
Parameter.bias: sweep_bias,
Parameter.delay: sweep_delay,
Parameter.start: sweep_start,
}

def sweep_recursion(self, sweepers, qubits, qmsequence, relaxation_time):
Expand Down
14 changes: 7 additions & 7 deletions src/qibolab/instruments/zhinst.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def select_sweeper(sweeper):
uid=sweeper.parameter.name,
values=sweeper.values,
)
if sweeper.parameter is Parameter.delay:
if sweeper.parameter is Parameter.start:
return lo.SweepParameter(
uid=sweeper.parameter.name,
values=sweeper.values * NANO_TO_SECONDS,
Expand Down Expand Up @@ -521,7 +521,7 @@ def sequence_zh(self, sequence, qubits, sweepers):

SWEEPER_SET = {"amplitude", "frequency", "duration", "relative_phase"}
SWEEPER_BIAS = {"bias"}
SWEEPER_DELAY = {"delay"}
SWEEPER_START = {"start"}

for sweeper in sweepers:
if sweeper.parameter.name in SWEEPER_SET:
Expand All @@ -548,8 +548,8 @@ def sequence_zh(self, sequence, qubits, sweepers):
for qubit in sweeper.qubits:
zhsequence[f"flux{qubit.name}"] = [ZhSweeperLine(sweeper, qubit, sequence)]

# FIXME: This may not place the Zhsweeper when the delay occurs among different sections or lines
if sweeper.parameter.name in SWEEPER_DELAY:
# FIXME: This may not place the Zhsweeper when the start occurs among different sections or lines
if sweeper.parameter.name in SWEEPER_START:
pulse = sweeper.pulses[0]
aux_list = zhsequence[f"{pulse.type.name.lower()}{pulse.qubit}"]
for element in aux_list:
Expand Down Expand Up @@ -658,7 +658,7 @@ def play_sweep_select_single(exp, qubit, pulse, section, parameters, partial_swe
phase=pulse.zhsweeper, # FIXME: I believe this is the global phase sweep
# increment_oscillator_phase=pulse.zhsweeper, #FIXME: I believe this is the relative phase sweep
)
elif "frequency" in partial_sweep.uid or partial_sweep.uid == "delay":
elif "frequency" in partial_sweep.uid or partial_sweep.uid == "start":
exp.play(
signal=f"{section}{qubit.name}",
pulse=pulse.zhpulse,
Expand Down Expand Up @@ -763,7 +763,7 @@ def drive(self, exp, qubits):
elif isinstance(pulse, ZhSweeperLine):
exp.delay(signal=f"drive{q}", time=pulse.zhsweeper)

# TODO: Patch for T1 delay, general ?
# TODO: Patch for T1 start, general ?
if isinstance(self.sequence[f"readout{q}"][0], ZhSweeperLine):
exp.delay(signal=f"drive{q}", time=self.sequence[f"readout{q}"][0].zhsweeper)
self.sequence[f"readout{q}"].remove(self.sequence[f"readout{q}"][0])
Expand Down Expand Up @@ -1000,7 +1000,7 @@ def sweep_recursion(self, qubits, exp, exp_calib, exp_options):
for qubit in sweeper.qubits:
parameter = ZhSweeperLine(sweeper, qubit, self.sequence_qibo).zhsweeper

elif sweeper.parameter is Parameter.delay:
elif sweeper.parameter is Parameter.start:
parameter = ZhSweeperLine(sweeper).zhsweeper

elif parameter is None:
Expand Down
2 changes: 1 addition & 1 deletion src/qibolab/sweeper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Parameter(Enum):
amplitude = auto()
duration = auto()
relative_phase = auto()
delay = auto()
start = auto()

attenuation = auto()
gain = auto()
Expand Down
12 changes: 6 additions & 6 deletions tests/test_instruments_qmsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def test_qmsim_sweep_bias(simulator, folder):
assert_regression(samples, folder, "sweep_bias")


def test_qmsim_sweep_delay(simulator, folder):
def test_qmsim_sweep_start(simulator, folder):
qubits = list(range(simulator.nqubits))
sequence = PulseSequence()
qd_pulses = {}
Expand All @@ -192,16 +192,16 @@ def test_qmsim_sweep_delay(simulator, folder):
sequence.add(ro_pulses[qubit])
values = [20, 40]
pulses = [ro_pulses[qubit] for qubit in qubits]
sweeper = Sweeper(Parameter.delay, values, pulses=pulses)
sweeper = Sweeper(Parameter.start, values, pulses=pulses)
options = ExecutionParameters(
nshots=1, relaxation_time=0, acquisition_type=AcquisitionType.INTEGRATION, averaging_mode=AveragingMode.CYCLIC
)
result = simulator.sweep(sequence, options, sweeper)
samples = result.get_simulated_samples()
assert_regression(samples, folder, "sweep_delay")
assert_regression(samples, folder, "sweep_start")


def test_qmsim_sweep_delay_two_pulses(simulator, folder):
def test_qmsim_sweep_start_two_pulses(simulator, folder):
qubits = list(range(simulator.nqubits))
sequence = PulseSequence()
qd_pulses1 = {}
Expand All @@ -216,13 +216,13 @@ def test_qmsim_sweep_delay_two_pulses(simulator, folder):
sequence.add(ro_pulses[qubit])
values = [20, 60]
pulses = [qd_pulses2[qubit] for qubit in qubits]
sweeper = Sweeper(Parameter.delay, values, pulses=pulses)
sweeper = Sweeper(Parameter.start, values, pulses=pulses)
options = ExecutionParameters(
nshots=1, relaxation_time=0, acquisition_type=AcquisitionType.INTEGRATION, averaging_mode=AveragingMode.CYCLIC
)
result = simulator.sweep(sequence, options, sweeper)
samples = result.get_simulated_samples()
assert_regression(samples, folder, "sweep_delay_two_pulses")
assert_regression(samples, folder, "sweep_start_two_pulses")


gatelist = [
Expand Down
8 changes: 4 additions & 4 deletions tests/test_instruments_zhinst.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_zhpulse(shape):
assert zhpulse.zhpulse.length == 40e-9


@pytest.mark.parametrize("parameter", [Parameter.bias, Parameter.delay])
@pytest.mark.parametrize("parameter", [Parameter.bias, Parameter.start])
def test_select_sweeper(dummy_qrc, parameter):
swept_points = 5
platform = create_platform("zurich")
Expand All @@ -48,7 +48,7 @@ def test_select_sweeper(dummy_qrc, parameter):
sequence.add(ro_pulses[q])

parameter_range = np.random.randint(swept_points, size=swept_points)
if parameter is Parameter.delay:
if parameter is Parameter.start:
sweeper = Sweeper(parameter, parameter_range, pulses=[qd_pulses[q]])
if parameter is Parameter.bias:
sweeper = Sweeper(parameter, parameter_range, qubits=q)
Expand Down Expand Up @@ -206,7 +206,7 @@ def test_experiment_execute_pulse_sequence(dummy_qrc, fast_reset):
assert "acquire0" in IQM5q.experiment.signals


@pytest.mark.parametrize("parameter1", [Parameter.delay, Parameter.duration])
@pytest.mark.parametrize("parameter1", [Parameter.start, Parameter.duration])
def test_experiment_sweep_single(dummy_qrc, parameter1):
platform = create_platform("zurich")
platform.setup()
Expand Down Expand Up @@ -252,7 +252,7 @@ def test_experiment_sweep_single(dummy_qrc, parameter1):
Parameter.frequency,
Parameter.amplitude,
Parameter.duration,
Parameter.delay,
Parameter.start,
Parameter.relative_phase,
}

Expand Down

0 comments on commit 2bb8ac8

Please sign in to comment.