Exemplo n.º 1
0
def distillation_Y(qs_list):

    data = CreateRegister(1)  # data qubit
    code = CreateRegister(7)  # logical qubit for Steane code
    anci = CreateRegister(1)  # ancilla qubit for S gate
    qubit_num = InitRegister(data, code, anci)
    qs = QState(qubit_num=qubit_num - len(anci))

    # bell state
    qs.h(data[0]).cx(data[0], code[6])

    # steane code
    qs.h(code[0]).h(code[1]).h(code[2])
    qs.cx(code[6], code[3]).cx(code[6], code[4])
    qs.cx(code[2], code[3]).cx(code[2], code[4]).cx(code[2], code[5])
    qs.cx(code[1], code[4]).cx(code[1], code[5]).cx(code[1], code[6])
    qs.cx(code[0], code[3]).cx(code[0], code[5]).cx(code[0], code[6])

    # S gates and measurements
    mval_list = []
    for i in range(7):
        qs_total = qs.tenspro(qs_list[i])
        qs_total.cx(code[i], anci[0]).h(anci[0]).cx(code[i],
                                                    anci[0]).h(anci[0])
        mval = int(qs_total.mx(qid=[code[i]]).last)
        mval_list.append(mval)
        qs = qs_total.partial(qid=data + code)

    if measure_X_stab(mval_list) == False:
        return None

    qs_pat = qs_total.partial(qid=data)
    if measure_logical_X(mval_list) == True: qs_pat.z(0)

    return qs_pat
Exemplo n.º 2
0
 def test_1(self):
 
     reg_0 = CreateRegister(5)
     reg_1 = CreateRegister(3,4)
     reg_2 = CreateRegister(2,3,4)
     reg_num = InitRegister(reg_0, reg_1, reg_2)
     self.assertEqual((reg_num, reg_0, reg_1, reg_2),
                      (41, [0,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]]]))
Exemplo n.º 3
0
    def test_1(self):

        qid_0 = CreateRegister(2)
        qid_1 = CreateRegister(3,4)
        qubit_num = InitRegister(qid_0, qid_1)
        
        cid_0 = CreateRegister(4)
        cid_1 = CreateRegister(2,3)
        cmem_num = InitRegister(cid_0, cid_1)
        
        bk = Backend(product='qlazy', device='qstate_simulator')
        qc = QCirc()
        qc.h(qid_0[1]).cx(qid_0[1], qid_1[0][2]).measure(qid=[qid_0[1], qid_1[0][2]], cid=[cid_1[0][0],cid_1[1][1]])
        res = bk.run(qcirc=qc, shots=10, cid=[cid_1[0][0],cid_1[1][1]])
        freq = res.frequency
        self.assertEqual(freq['00']+freq['11'], 10)
Exemplo n.º 4
0
def distillation_A(qs_list):

    data = CreateRegister(1)   # data qubit
    code = CreateRegister(15)  # logical qubit for Steane code
    anci = CreateRegister(1)   # ancilla qubit for S gate
    qubit_num = InitRegister(data, code, anci)
    qs = QState(qubit_num=qubit_num-len(anci))

    # bell state
    qs.h(data[0]).cx(data[0], code[14])

    # Reed-Muler code
    [qs.h(code[q-1]) for q in [1,2,4,8]]
    [qs.cx(code[8-1], code[q-1]) for q in [9,10,11,12,13,14,15]]
    [qs.cx(code[4-1], code[q-1]) for q in [5,6,7,12,13,14,15]]
    [qs.cx(code[2-1], code[q-1]) for q in [3,6,7,10,11,14,15]]
    [qs.cx(code[1-1], code[q-1]) for q in [3,5,7,9,11,13,15]]
    [qs.cx(code[15-1], code[q-1]) for q in [3,5,6,9,10,12]]

    # T_dag gates and measurements
    mval_list = []
    for i in range(15):
        qs_total = qs.tenspro(qs_list[i])
        m = qs_total.cx(anci[0], code[i]).m(qid=[code[i]]).last
        if m == '1': qs_total.x(anci[0])
        else: qs_total.s_dg(anci[0])
        mval = int(qs_total.mx(qid=[anci[0]]).last)
        mval_list.append(mval)
        qs = qs_total.partial(qid=data+code)

    if measure_X_stab(mval_list) == False: return None

    qs_pat = qs_total.partial(qid=data)
    if measure_logical_X(mval_list) == False: qs_pat.z(0)

    return qs_pat
Exemplo n.º 5
0
def main():

    row_length = 19
    col_length = 19
    qid = CreateRegister(row_length, col_length)  # 量子ビットは2次元配列(格子)に置く
    qubit_num = InitRegister(qid)
    
    qc = Stabilizer_SurfaceCode(qubit_num=qubit_num, gene_num=qubit_num)

    qc.initialize(qid=qid)        # 真空状態を作成
    qc.set_logical_plus()  # 論理|+>状態を準備
    qc.operate_Lh()        # 論理アダマール演算
    # qc.operate_Lx()        # 論理パウリX演算

    frequency = qc.measure_Lz(shots=100)  # 論理パウリZ演算子を測定
    # frequency = qc.measure_Lx(shots=100)  # 論理パウリX演算子を測定
    print("frequency =", frequency)
Exemplo n.º 6
0
            left = str(sum(map(int, list(k)[2:4])) % 2)
            total = right + left
            result_logical[total] += v

        return result_logical


if __name__ == '__main__':

    shots = 1000
    alpha, beta, gamma = random.uniform(0, 1), random.uniform(
        0, 1), random.uniform(0, 1)
    print("- alpha, beta, gamma = {:.4f}, {:.4f}, {:.4f}".format(
        alpha, beta, gamma))

    dat_left = CreateRegister(5)
    dat_right = CreateRegister(5)
    bnd = CreateRegister(1)
    anc = CreateRegister(1)
    qubit_num = InitRegister(dat_left, dat_right, bnd, anc)

    qs_logical = QStateLogical(qubit_num=qubit_num).set_register(
        dat_left, dat_right, bnd, anc)
    qs_logical.initialize(alpha=alpha, beta=beta, gamma=gamma)

    mval = qs_logical.split()
    print("- measured value =", mval)

    result_logical = qs_logical.measure(shots=shots)
    print("- actual =", result_logical)
Exemplo n.º 7
0
Arquivo: cnot.py Projeto: samn33/qlazy
    def split_cnt_int(self):

        return self.mx(qid=[self.__bnd['cnt'][0]]).last

    def measure(self, shots=1):

        return self.__indirect_measure(self.__lz, shots=shots).frequency

if __name__ == '__main__':

    shots = 100
    alpha, beta, gamma = random.uniform(0, 1), random.uniform(0, 1), random.uniform(0, 1)
    print("- alpha, beta, gamma = {:.4f}, {:.4f}, {:.4f}".format(alpha, beta, gamma))
    
    dat_cnt, dat_int, dat_tar = CreateRegister(5), CreateRegister(5), CreateRegister(5)
    bnd_cnt, bnd_tar, anc = CreateRegister(1), CreateRegister(1), CreateRegister(1)
    qubit_num = InitRegister(dat_cnt, dat_int, dat_tar, bnd_cnt, bnd_tar, anc)

    qs_logical = QStateLogical(qubit_num).set_register(dat_cnt, dat_int, dat_tar, bnd_cnt, bnd_tar, anc)
    qs_logical.initialize(alpha=alpha, beta=beta, gamma=gamma)
    qs_logical.merge_cnt_int()
    qs_logical.split_cnt_int()
    qs_logical.merge_int_tar()

    result_logical = qs_logical.measure(shots=shots)
    print("- actual =", result_logical)

    result = QState(qubit_num=1).rz(0, phase=alpha).rx(0, phase=beta).rz(0, phase=gamma).m(shots=shots)
    print("- expect =", result.frequency)
Exemplo n.º 8
0
        self.h(self.__anc[0])
        return self.m(qid=[self.__anc[0]], shots=shots).frequency


if __name__ == '__main__':

    alpha, beta, gamma = random.uniform(0, 1), random.uniform(
        0, 1), random.uniform(0, 1)
    meas = random.choice(['X', 'Z'])
    shots = 10000

    print("- alpha, beta, gamma = ", alpha, beta, gamma)
    print("- measure {}".format(meas))
    print("- shots =", shots)

    dat = CreateRegister(11)
    anc = CreateRegister(1)
    qubit_num = InitRegister(dat, anc)
    qs_logical = QStateLogical(qubit_num).set_register(dat, anc).initialize(
        alpha, beta, gamma)

    qs = QState(qubit_num=1).u3(0, alpha=alpha, beta=beta, gamma=gamma)

    if meas == 'X':
        result_actual = qs_logical.Mx(shots=shots)
        result_expect = qs.mx(shots=shots).frequency
    elif meas == 'Z':
        result_actual = qs_logical.Mz(shots=shots)
        result_expect = qs.mz(shots=shots).frequency

    print("- actual =", result_actual)
Exemplo n.º 9
0
        self.h(self.__anc[0])
        self.operate(ctrl=self.__anc[0], pp=self.__lz)
        self.h(self.__anc[0])
        return self.m(qid=[self.__anc[0]], shots=shots).frequency
    
if __name__ == '__main__':

    alpha, beta, gamma = random.uniform(0, 1), random.uniform(0, 1), random.uniform(0, 1)
    meas = random.choice(['X', 'Z'])
    shots = 10000

    print("- alpha, beta, gamma = ", alpha, beta, gamma)
    print("- measure {}".format(meas))
    print("- shots =", shots)
        
    dat = CreateRegister(5)
    anc = CreateRegister(1)
    qubit_num = InitRegister(dat, anc)
    qs_logical = QStateLogical(qubit_num).set_register(dat, anc).initialize(alpha, beta, gamma)

    qs = QState(qubit_num=1).u3(0, alpha=alpha, beta=beta, gamma=gamma)

    if meas == 'X':
        result_actual = qs_logical.Mx(shots=shots)
        result_expect = qs.mx(shots=shots).frequency
    elif meas == 'Z':
        result_actual = qs_logical.Mz(shots=shots)
        result_expect = qs.mz(shots=shots).frequency
        
    print("- actual =", result_actual)
    print("- expect =", result_expect)
Exemplo n.º 10
0
 def test_0(self):
     
     reg_0 = CreateRegister(3)
     reg_1 = CreateRegister(2)
     reg_num = InitRegister(reg_0, reg_1)
     self.assertEqual((reg_num, reg_0, reg_1), (5, [0,1,2], [3,4]))