def test_qwhile(self): q1 = self.q1 seq1 = [X90(q1), Y90(q1)] seq2 = qwhile(0, seq1) seq3 = [label(seq2), CmpNeq("m", 0), Goto(endlabel(seq2))] + seq1 + \ [Goto(label(seq2)), endlabel(seq2)] assert (seq2 == seq3)
def test_qwhile(self): q1 = self.q1 seq1 = [X90(q1), Y90(q1)] label(seq1) # print qwhile(0, seq1) # print [CmpNeq(0), Goto(endlabel(seq1))] + seq1 assert( qwhile(0, seq1) == [CmpNeq(0), Goto(endlabel(seq1))] + seq1 )
def test_qif(self): q1 = self.q1 seq1 = [X90(q1), Y90(q1)] seq2 = [X(q1), Y(q1), Z(q1)] label(seq1) label(seq2) # print qif(0, seq1, seq2) # print ([CmpEq(0), Goto(label(seq1))] + seq2 + [Goto(endlabel(seq1))] + seq1 assert( qif(0, seq1, seq2) == [CmpEq(0), Goto(label(seq1))] + seq2 + [Goto(endlabel(seq1))] + seq1 )
def test_qif(self): q1 = self.q1 seq1 = [X90(q1), Y90(q1)] seq2 = [X(q1), Y(q1), Z(q1)] label(seq1) label(seq2) assert (qif(0, seq1, seq2) == [CmpEq("m", 0), Goto(label(seq1))] + seq2 + [Goto(endlabel(seq1))] + seq1)
def reset_result(self, cmp_instr, mask): q1 = QubitFactory('q1') if_seq = [X(q1)] else_seq = [Id(q1)] expectedseq = [ MEAS(q1), cmp_instr('m', mask), Goto(label(if_seq)), else_seq, Goto(endlabel(if_seq)), if_seq, X90(q1) ] expectedseq = testable_sequence(expectedseq) return expectedseq
def test_qcall(self): q1 = self.q1 @qfunction def Reset(q): return qwhile(1, [X(q)]) crseq = Reset(q1) seq1 = [Call(label(crseq[1]))] # print seq1 subseq2 = crseq[1][2:-1] seq2 = [CmpNeq(1), Goto(endlabel(subseq2))] + subseq2 + [Return()] seq2[0].label = crseq[1][0].label # print seq2 assert( Reset(q1) == (seq1, seq2) )
def test_runtime1(self): resFunction = compile_function("test/code/reset.py", "runtime1") seqs = resFunction() q1 = QubitFactory('q1') if_seq = [X(q1)] else_seq = [Z(q1)] expectedseq = [ MEAS(q1), MEAS(q1), Store("r", "my_operator(m1, m2)"), CmpEq("r", 1), Goto(label(if_seq)), else_seq, Goto(endlabel(if_seq)), if_seq, X90(q1) ] expectedseq = testable_sequence(expectedseq) expectedseq = match_labels(expectedseq, seqs) assertPulseSequenceEqual(self, seqs, expectedseq)
def test_qwhile(self): q1 = self.q1 seq1 = [X90(q1), Y90(q1)] seq2 = qwhile(0, seq1) seq3 = [label(seq2), CmpNeq(0), Goto(endlabel(seq2))] + seq1 + [Goto(label(seq2)), endlabel(seq2)] assert( seq2 == seq3)