예제 #1
0
파일: test_QState.py 프로젝트: samn33/qlazy
 def test_reset(self):
     """test 'reset'
     """
     qs = QState(qubit_num=3).h(0).h(1).h(2)
     qs.reset()
     actual = qs.amp
     expect = np.array([1j, 0j, 0j, 0j, 0j, 0j, 0j, 0j])
     ans = equal_vectors(actual, expect)
     self.assertEqual(ans, True)
예제 #2
0
파일: t_gate.py 프로젝트: samn33/qlazy
def logical_zero():

    anc = [0, 1, 2, 3, 4, 5, 6]  # registers for ancila
    cod = [7, 8, 9, 10, 11, 12, 13]  # registers for steane code
    qs_total = QState(14)

    # g1
    qs_total.h(anc[0])
    [qs_total.cx(anc[0], anc[i]) for i in range(1, 4)]
    qs_total.cx(anc[0], cod[3]).cx(anc[1],
                                   cod[4]).cx(anc[2],
                                              cod[5]).cx(anc[3], cod[6])
    [qs_total.cx(anc[0], anc[i]) for i in range(1, 4)]
    qs_total.h(anc[0])
    mval = qs_total.m(qid=[anc[0]]).last
    if mval == '1': qs_total.z(cod[0]).z(cod[1]).z(cod[2]).z(cod[3])
    qs_total.reset(qid=anc)

    # g2
    qs_total.h(anc[0])
    [qs_total.cx(anc[0], anc[i]) for i in range(1, 4)]
    qs_total.cx(anc[0], cod[1]).cx(anc[1],
                                   cod[2]).cx(anc[2],
                                              cod[5]).cx(anc[3], cod[6])
    [qs_total.cx(anc[0], anc[i]) for i in range(1, 4)]
    qs_total.h(anc[0])
    mval = qs_total.m(qid=[anc[0]]).last
    if mval == '1': qs_total.z(cod[0]).z(cod[1]).z(cod[4]).z(cod[5])
    qs_total.reset(qid=anc)

    # g3
    qs_total.h(anc[0])
    [qs_total.cx(anc[0], anc[i]) for i in range(1, 4)]
    qs_total.cx(anc[0], cod[0]).cx(anc[1],
                                   cod[2]).cx(anc[2],
                                              cod[4]).cx(anc[3], cod[6])
    [qs_total.cx(anc[0], anc[i]) for i in range(1, 4)]
    qs_total.h(anc[0])
    mval = qs_total.m(qid=[anc[0]]).last
    if mval == '1': qs_total.z(cod[2]).z(cod[4]).z(cod[6])
    qs_total.reset(qid=anc)

    # g4
    qs_total.h(anc[0])
    [qs_total.cx(anc[0], anc[i]) for i in range(1, 4)]
    qs_total.cz(anc[0], cod[3]).cz(anc[1],
                                   cod[4]).cz(anc[2],
                                              cod[5]).cz(anc[3], cod[6])
    [qs_total.cx(anc[0], anc[i]) for i in range(1, 4)]
    qs_total.h(anc[0])
    mval = qs_total.m(qid=[anc[0]]).last
    if mval == '1': qs_total.x(cod[0]).x(cod[1]).x(cod[2]).x(cod[3])
    qs_total.reset(qid=anc)

    # g5
    qs_total.h(anc[0])
    [qs_total.cx(anc[0], anc[i]) for i in range(1, 4)]
    qs_total.cz(anc[0], cod[1]).cz(anc[1],
                                   cod[2]).cz(anc[2],
                                              cod[5]).cz(anc[3], cod[6])
    [qs_total.cx(anc[0], anc[i]) for i in range(1, 4)]
    qs_total.h(anc[0])
    mval = qs_total.m(qid=[anc[0]]).last
    if mval == '1': qs_total.x(cod[0]).x(cod[1]).x(cod[4]).x(cod[5])
    qs_total.reset(qid=anc)

    # g6
    qs_total.h(anc[0])
    [qs_total.cx(anc[0], anc[i]) for i in range(1, 4)]
    qs_total.cz(anc[0], cod[0]).cz(anc[1],
                                   cod[2]).cz(anc[2],
                                              cod[4]).cz(anc[3], cod[6])
    [qs_total.cx(anc[0], anc[i]) for i in range(1, 4)]
    qs_total.h(anc[0])
    mval = qs_total.m(qid=[anc[0]]).last
    if mval == '1': qs_total.x(cod[2]).x(cod[4]).x(cod[6])
    qs_total.reset(qid=anc)

    # g7
    qs_total.h(anc[0])
    [qs_total.cx(anc[0], anc[i]) for i in range(1, 7)]
    [qs_total.cz(anc[i], cod[i]) for i in range(7)]
    [qs_total.cx(anc[0], anc[i]) for i in range(1, 7)]
    qs_total.h(anc[0])
    mval = qs_total.m(qid=[anc[0]]).last
    if mval == '1': [qs_total.x(q) for q in cod]
    qs_total.reset(qid=anc)

    qs = qs_total.partial(qid=cod)

    return qs