-
Notifications
You must be signed in to change notification settings - Fork 12
/
test_Scheduler.py
109 lines (84 loc) · 3.35 KB
/
test_Scheduler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import unittest
from QGL import *
from .helpers import setup_test_lib
class SchedulerTest(unittest.TestCase):
def setUp(self):
setup_test_lib()
self.q1 = QubitFactory('q1')
self.q2 = QubitFactory('q2')
self.q3 = QubitFactory('q3')
self.q4 = QubitFactory('q4')
def test_1q_ops(self):
q1, q2, q3 = self.q1, self.q2, self.q3
# uniform fill on first time step
seq = [X(q1), Y(q2), Z(q3),
X(q1), Y(q2)]
result = schedule(seq)
assert(result == [X(q1)*Y(q2)*Z(q3),
X(q1)*Y(q2)] )
# add an extra pulse on q1
seq = [X(q1), X(q1), Y(q2), Z(q3), X(q1), Y(q2)]
result = schedule(seq)
assert(result == [X(q1)*Y(q2)*Z(q3),
X(q1)*Y(q2),
X(q1)] )
# same sequence but with a Barrier
seq = [X(q1),
Barrier(q1, q2, q3),
X(q1), Y(q2), Z(q3),
X(q1), Y(q2)]
result = schedule(seq)
assert(result == [X(q1),
X(q1)*Y(q2)*Z(q3),
X(q1)*Y(q2)] )
def test_1q_composite(self):
q1, q2, q3 = self.q1, self.q2, self.q3
seq = [X(q1)+Y(q1), X(q2),
Y(q1), Y(q2)]
result = schedule(seq)
assert(result == [(X(q1)+Y(q1))*X(q2),
Y(q1)*Y(q2)] )
def test_2q_ops(self):
q1, q2, q3, q4 = self.q1, self.q2, self.q3, self.q4
seq = [X(q1), CNOT_simple(q2, q3),
X(q1), Y(q2)]
result = schedule(seq)
assert(result == [X(q1)*CNOT_simple(q2, q3),
X(q1)*Y(q2)] )
seq = [X(q1), CNOT_CR(q2, q3),
X(q1), Y(q2)]
result = schedule(seq)
assert(result == [X(q1)*CNOT_CR(q2, q3),
X(q1)*Y(q2)] )
seq = [CNOT_simple(q1, q2), CNOT_simple(q3, q4), X(q1), X(q2)]
result = schedule(seq)
assert(result == [CNOT_simple(q1, q2) * CNOT_simple(q3, q4),
X(q1) * X(q2)] )
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
q1, q2, q3, q4 = self.q1, self.q2, self.q3, self.q4
cond_seq = qif(1, [Y(q1),Y(q2),X90(q1)], [Z(q1),Z(q2),X90(q1)])
seq = [X(q1),X(q2),
CNOT(q1,q2)] + \
cond_seq + \
[Y90(q1),Y90(q2)]
result = schedule(seq)
# construct the scheduled conditional from the original to preserve labels
cond_seq_scheduled = cond_seq[:2] + \
[Z(q1) * Z(q2), X90(q1)] + \
cond_seq[5:7] + \
[Y(q1) * Y(q2), X90(q1)] + \
cond_seq[-1:]
assert(result == [X(q1) * X(q2),
CNOT(q1, q2)] + \
cond_seq_scheduled + \
[Y90(q1) * Y90(q2)])
# test that "global" control flow injects barriers
seq = [X(q1)] + \
cond_seq + \
[Y90(q1),Y90(q2)]
result = schedule(seq)
assert(result == [X(q1)] + \
cond_seq_scheduled + \
[Y90(q1) * Y90(q2)])