Skip to content

Commit

Permalink
feat: Kickstart sweepers implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
alecandido committed Dec 10, 2024
1 parent 4f4c4db commit 298ef28
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
46 changes: 40 additions & 6 deletions src/qibolab/_core/instruments/qblox/program.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from qibolab._core.execution_parameters import ExecutionParameters
from qibolab._core.execution_parameters import AveragingMode, ExecutionParameters
from qibolab._core.pulses.pulse import Pulse, PulseLike
from qibolab._core.sequence import PulseSequence
from qibolab._core.sweeper import ParallelSweepers

from .ast_ import (
Instruction,
Line,
Loop,
Move,
Expand All @@ -12,6 +14,7 @@
Reference,
Register,
Stop,
Wait,
WaitSync,
)

Expand Down Expand Up @@ -42,14 +45,33 @@ def execution(sequence: PulseSequence, waveforms: WaveformIndices) -> list[Line]
]


def loop(sweepers, experiment: list[Line]):
def loop(
sweepers: list, experiment: list[Line], relaxation_time: int, outer_shots: bool
):
shots = (0, [Nop()])
sweep = [
(i, parameters_update(parsweep)) for i, parsweep in enumerate(sweepers, start=1)
]
loops = [shots] + sweep if outer_shots else sweep + [shots]

return (
[Line(instruction=Nop(), label="shots")]
[
inst
for lp in loops
for inst in (
[Line(instruction=lp[1][0], label=f"l{lp[0]}")]
+ [Line(instruction=inst_) for inst_ in lp[1][1:]]
)
]
+ experiment
+ [Line(instruction=Wait(duration=relaxation_time))]
+ [
Line(
instruction=Loop(a=Register(number=0), address=Reference(label="shots"))
instruction=Loop(
a=Register(number=lp[0]), address=Reference(label=f"l{lp[0]}")
)
)
for lp in loops
]
)

Expand All @@ -59,6 +81,10 @@ def finalization() -> list:
return [Line(instruction=Stop())]


def parameters_update(sweepers: ParallelSweepers) -> list[Instruction]:
return [Nop()]


def play(pulse: PulseLike, waveforms: WaveformIndices) -> list[Line]:
"""Process the individual pulse in experiment."""
return (
Expand All @@ -77,11 +103,19 @@ def play(pulse: PulseLike, waveforms: WaveformIndices) -> list[Line]:


def program(
sequence: PulseSequence, waveforms: WaveformIndices, options: ExecutionParameters
sequence: PulseSequence,
waveforms: WaveformIndices,
options: ExecutionParameters,
sweepers: list[ParallelSweepers],
):
return Program(
elements=initialization(options.nshots)
+ setup()
+ loop([], execution(sequence, waveforms))
+ loop(
sweepers,
execution(sequence, waveforms),
relaxation_time=options.relaxation_time,
outer_shots=options.averaging_mode is not AveragingMode.SEQUENTIAL,
)
+ finalization()
)
2 changes: 1 addition & 1 deletion src/qibolab/_core/instruments/qblox/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ def from_pulses(
waveforms=waveforms_,
weights={},
acquisitions={},
program=program(sequence, waveform_indices(waveforms_), options),
program=program(sequence, waveform_indices(waveforms_), options, sweepers),
)

0 comments on commit 298ef28

Please sign in to comment.