Skip to content

Commit

Permalink
WIP on scheduling with control flow instructions.
Browse files Browse the repository at this point in the history
  • Loading branch information
blakejohnson committed May 22, 2017
1 parent eecee62 commit 942e715
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
13 changes: 9 additions & 4 deletions QGL/Scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .Channels import Edge
from .PulseSequencer import PulseBlock
from .ControlFlow import Barrier, ControlInstruction
from .BlockLabel import BlockLabel
from .PatternUtils import flatten
from warnings import warn

Expand All @@ -21,11 +22,15 @@ def schedule(seq):
if isinstance(instr, Barrier):
synchronize_counters(counters, instr.chanlist)
continue
channels = get_channels(instr)
# find the most advanced counter in the channel set
idx = max(counters.get(ch, 0) for ch in channels)
if isinstance(instr, (ControlInstruction, BlockLabel)):
channels = counters.keys()
idx = len(out_seq)
else:
channels = get_channels(instr)
# find the most advanced counter in the channel set
idx = max(counters.get(ch, 0) for ch in channels)

if idx > len(out_seq) - 1:
if (idx > len(out_seq) - 1) or isinstance(out_seq[idx], ControlInstruction):
out_seq.append(instr)
else:
out_seq[idx] *= instr
Expand Down
23 changes: 22 additions & 1 deletion tests/test_Scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,25 @@ def test_2q_ops(self):
def test_controlflow(self):
# TODO to do this properly we need ControlInstructions to be valid operands
# in tensor products, i.e. we want qif(..) * qif(...) to be valid
pass
q1, q2, q3, q4 = self.q1, self.q2, self.q3, self.q4

seq = [X(q1),X(q2),
CNOT(q1,q2)] + \
qif(1, [Y(q1),Y(q2),X90(q1)], [Z(q1),Z(q2),X90(q1)]) + \
[Y90(q1),Y90(q2)]

result = schedule(seq)
assert(result == [X(q1) * X(q2),
CNOT(q1, q2)] + \
qif(1, [Y(q1)*Y(q2), X90(q1)], [Z(q1)*Z(q2), X90(q1)]) + \
[Y90(q1) * Y90(q2)])

# test that "global" control flow injects barriers
seq = [X(q1)] + \
qif(1, [Y(q1),Y(q2),X90(q1)], [Z(q1),Z(q2),X90(q1)]) + \
[Y90(q1),Y90(q2)]

result = schedule(seq)
assert(result == [X(q1)] + \
qif(1, [Y(q1)*Y(q2), X90(q1)], [Z(q1)*Z(q2), X90(q1)]) + \
[Y90(q1) * Y90(q2)])

0 comments on commit 942e715

Please sign in to comment.