Skip to content

Commit

Permalink
feat: Introduce primitive loops support
Browse files Browse the repository at this point in the history
  • Loading branch information
alecandido committed Dec 10, 2024
1 parent 0eb4bdd commit 938efd7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 9 deletions.
66 changes: 58 additions & 8 deletions src/qibolab/_core/instruments/qblox/program.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
from qibolab._core.execution_parameters import ExecutionParameters
from qibolab._core.pulses.pulse import Pulse, PulseLike
from qibolab._core.sequence import PulseSequence

from .ast_ import Line, Play, Program
from .ast_ import (
Line,
Loop,
Move,
Nop,
Play,
Program,
Reference,
Register,
Stop,
WaitSync,
)

ComponentId = tuple[str, int]
WaveformIndices = dict[ComponentId, int]
Expand All @@ -11,7 +23,44 @@ def pulse_uid(pulse: Pulse) -> str:
return str(hash(pulse))


def instructions(pulse: PulseLike, waveforms: WaveformIndices) -> list:
def initialization(nshots: int) -> list:
"""Initialize registers."""
return [Line(instruction=Move(source=nshots, destination=Register(number=0)))]


def setup() -> list:
"""Set up."""
return [Line(instruction=WaitSync(duration=4))]


def execution(sequence: PulseSequence, waveforms: WaveformIndices) -> list[Line]:
"""The representation of the actual experiment to be executed."""
return [
el
for block in (play(pulse, waveforms) for _, pulse in sequence)
for el in block
]


def loop(sweepers, experiment: list[Line]):
return (
[Line(instruction=Nop(), label="shots")]
+ experiment
+ [
Line(
instruction=Loop(a=Register(number=0), address=Reference(label="shots"))
)
]
)


def finalization() -> list:
"""Finalize."""
return [Line(instruction=Stop())]


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


def program(sequence: PulseSequence, waveforms: WaveformIndices):
def program(
sequence: PulseSequence, waveforms: WaveformIndices, options: ExecutionParameters
):
return Program(
elements=[
el
for block in (instructions(pulse, waveforms) for _, pulse in sequence)
for el in block
]
elements=initialization(options.nshots)
+ setup()
+ loop([], execution(sequence, waveforms))
+ 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_)),
program=program(sequence, waveform_indices(waveforms_), options),
)

0 comments on commit 938efd7

Please sign in to comment.