Skip to content

Commit

Permalink
fix: Initialize and increment bin counter
Browse files Browse the repository at this point in the history
  • Loading branch information
alecandido committed Dec 12, 2024
1 parent aa79d75 commit 5f75b8f
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions src/qibolab/_core/instruments/qblox/sequence/program.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import Sequence
from enum import Enum
from typing import Union

import numpy as np

Expand All @@ -18,6 +19,7 @@

from ..ast_ import (
Acquire,
Add,
Instruction,
Line,
Loop,
Expand All @@ -44,23 +46,30 @@ class Registers(Enum):
shots = Register(number=1)


Loops = list[tuple[Register, int]]
Loops = list[tuple[Register, int, bool]]


def loops(sweepers: list, nshots: int, inner_shots: bool) -> Loops:
shots = (Registers.shots.value, nshots)
shots = (Registers.shots.value, nshots, True)
sweep = [
(Register(number=i), iteration_length(parsweep))
(Register(number=i), iteration_length(parsweep), False)
for i, parsweep in enumerate(sweepers, start=2)
]
return [shots] + sweep if inner_shots else sweep + [shots]


def setup(loops: Loops) -> Sequence[Instruction]:
def setup(loops: Loops) -> Sequence[Union[Line, Instruction]]:
"""Set up."""
return [Move(source=lp[1], destination=lp[0]) for lp in loops] + [
WaitSync(duration=4)
]
return (
[
Line(
instruction=Move(source=0, destination=Registers.bin.value),
comment="init bin counter",
)
]
+ [Move(source=lp[1], destination=lp[0]) for lp in loops]
+ [WaitSync(duration=4)]
)


def execution(
Expand Down Expand Up @@ -105,16 +114,27 @@ def parameters_update(sweepers: ParallelSweepers) -> list[Instruction]:

def loop(
loops: Loops, experiment: list[Instruction], relaxation_time: int
) -> list[Line]:
) -> Sequence[Union[Line, Instruction]]:
return (
[Line(instruction=experiment[0], label=START)]
+ [Line.instr(i_) for i_ in experiment[1:]]
+ [Line.instr(Wait(duration=relaxation_time))]
+ experiment[1:]
+ [
Line.instr(i_)
Line(instruction=Wait(duration=relaxation_time), comment="relaxation"),
Line(
instruction=Add(
a=Registers.bin.value, b=1, destination=Registers.bin.value
),
comment="bin increment",
),
]
+ [
i_
for lp in loops
for i_ in [
Loop(a=lp[0], address=Reference(label=START)),
Line(
instruction=Loop(a=lp[0], address=Reference(label=START)),
comment="loop over shots" if lp[2] else None,
),
Move(source=lp[1], destination=lp[0]),
]
][:-1]
Expand Down

0 comments on commit 5f75b8f

Please sign in to comment.