def stringent(): err_model = cc.ErrorModel(0.1, 0.0075, 0.0075) ρ0 = bosonic_bell_pair([0, 3]) ρ1 = cc.make_bell_with(ρ0, err_model, True, False) ρ1.print() ρ = cc.make_GHZ_with(ρ1, err_model, True, False) return ρ
def stringent(): err_model = cc.ErrorModel(0.1, 0.0075, 0.0075) bell_operator = np.array([[0.4972, 0, 0, 0.4953], [0, 0.002758, 0.001367, 0], [0, 0.001367, 0.002758, 0], [0.4953, 0, 0, 0.4972]]) ρ1 = cc.DensityOperator([0, 3], bell_operator) ρ1 = cc.make_bell(err_model, True, False) ρ1.print() ρ = cc.make_GHZ_with(ρ1, err_model, True, False) return ρ
def expedient(): err_model = cc.ErrorModel(0.1, 0.006, 0.006) bell_operator = np.array([[0.4978, 0, 0, 0.4962], [0, 0.002229, 0.001136, 0], [0, 0.001136, 0.002229, 0], [0.4962, 0, 0, 0.4978]]) ρ1 = cc.DensityOperator([0, 3], bell_operator) # ρ1 = cc.make_bell(err_model, True, False) # ρ1.print() ρ = cc.make_GHZ_with(ρ1, err_model, False, False) return ρ
def custom(p, stringent): err_model = cc.ErrorModel(0.1, p, p) ρ1 = cc.make_bell(err_model, stringent, False) # ρ1.print() ρ = cc.make_GHZ_with(ρ1, err_model, stringent, False) result_correct, result_error = cc.get_result(ρ.operator, err_model) with open('data/custom_result.npz', 'wb') as f: np.savez(f, result_correct, result_error) np.set_printoptions(suppress=True) r1 = result_correct.reshape((1, -1))[0] r2 = result_error.reshape((1, -1))[0] print(r1) print(r2) return ρ
def test_BBPSSW_2(p_n=0.1): err_model = cc.ErrorModel(p_n) # perfect_bell = cc.bell_pair([0, 1]) perfect_bell = cc.bell_pair(0, [0, 1]) noise_bell = cc.bell_pair(err_model.p_n, [0, 1]) ρ = cc.BBPSSW_2(err_model, True) # f1 is just 1 - p_n f1 = cc.entanglement_fidelity(noise_bell, perfect_bell) f2 = cc.entanglement_fidelity(ρ, perfect_bell) p_theory = (f1**2 + 2 * f1 * (1 - f1) / 3 + 5 * ((1 - f1) / 3)**2) f_theory = (f1**2 + ((1 - f1) / 3)**2) / p_theory print("no purification: ", f1) print("after purification: ", f2) print("fidelity in theory: ", f_theory) print("success probability in theory: ", p_theory)
def expedient(p = 0.006): err_model = cc.ErrorModel(0.1, p, p)jjk # [[0.4915 0 0 0.486] # [ 0 0.008491 0.007086 0] # [ 0 0.007086 0.008491 0] # [ 0.486 0 0 0.4915]] # [[0.49150882 0 0 0.48603865] # [ 0 0.0084911765 0.0070856237 0] # [ 0 0.0070856237 0.0084911765 0] # [0.48603865 0 0 0.49150882]] ρ0 = bosonic_bell_pair([0, 3]) ρ1 = cc.make_bell_with(ρ0, err_model, False, False) ρ1.print() ρ = cc.make_GHZ_with(ρ1, err_model, False, False) return ρ
def test_BBPSSW(p_n=0.1): np.set_printoptions(edgeitems=16, linewidth=200, formatter=dict(float=lambda x: "%8.4g" % x)) err_model = cc.ErrorModel(p_n) perfect_bell = cc.BBPSSW_bell_pair([0, 1]) noise_bell = cc.BBPSSW_bell_pair([0, 1], err_model.p_n) ρ = cc.BBPSSW(err_model, True) # f1 is just 1 - p_n f1 = cc.entanglement_fidelity(noise_bell, perfect_bell) f2 = cc.entanglement_fidelity(ρ, perfect_bell) p_theory = (f1**2 + 2 * f1 * (1 - f1) / 3 + 5 * ((1 - f1) / 3)**2) f_theory = (f1**2 + ((1 - f1) / 3)**2) / p_theory print("no purification: ", f1) print("after purification: ", f2) print("fidelity in theory: ", f_theory) print("success probability in theory: ", p_theory)
def test_1(): err_model = cc.ErrorModel() ρ1 = cc.bell_pair(err_model.p_n, [1, 3]) ρ2 = cc.bell_pair(err_model.p_n, [2, 4]) # ρ1.print() # print(ρ1.operator.trace()) ρ1.merge(ρ2) # ρ1.print() print("trace of ρ1", ρ1.operator.trace()) # ρ1.print() c1 = cc.cphase([2, 1]) c2 = cc.cphase([4, 3]) ρ1.evolution(c1) ρ1.evolution(c2) print("trace of ρ1", ρ1.operator.trace()) ρ1.bell_measure(2, 4, 'z', 'z') ρ1.print() return ρ1
# print(probs) print("sum", np.sum(probs)) print("trace", mat.trace()) c_correct = np.zeros((4, 4, 4, 4)) c_error = np.zeros((4, 4, 4, 4)) for (i, ps) in enumerate(probs): _c_correct, _c_error = get_pair_result_1(err_model, ps[0], ps[1], i) c_correct += _c_correct c_error += _c_error return c_correct, c_error # _pair_result_1(cc.ErrorModel(0.1, 0.0075, 0.0075), p)air_result_1(cc.ErrorModel(0.1, 0.0075, 0.0075), p) # p = 0.9535 c_correct1, c_error1 = get_result(GHZ_expedient, cc.ErrorModel(0.1, 0.006, 0.006)) with open('data/expedient_GHZ.npy', 'wb') as f: np.save(f, GHZ_expedient, False) with open('data/expedient_result_correct.npy', 'wb') as f: np.save(f, c_correct1, False) with open('data/expedient_result_error.npy', 'wb') as f: np.save(f, c_error1, False) c_correct2, c_error2 = get_result(GHZ_stringent, cc.ErrorModel(0.1, 0.0075, 0.0075)) with open('data/stringent_GHZ.npy', 'wb') as f: np.save(f, GHZ_stringent, False)
if __name__ == "__main__": np.set_printoptions(edgeitems=16, linewidth=200, formatter=dict(float=lambda x: "%6.4g" % x) ) # ρ = expedient() # ρ = stringent() GHZ_perfect = np.array([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) GHZ_perfect = np.outer(GHZ_perfect, GHZ_perfect) / 2 GHZ_perfect = cc.DensityOperator([0, 3, 6, 9], GHZ_perfect) ps = np.arange(0.002, 0.004, 0.00025) results_c = [] results_e = [] for p in ps: print("running probs ", p) error_model = cc.ErrorModel(1, p, p) ρ1 = cc.make_bell(error_model, False, False) ρ1.print() ρ = cc.make_GHZ_with(ρ1, error_model, False, False) result_correct, result_error = cc.get_result(ρ.operator, error_model) print(cc.entanglement_fidelity(ρ, GHZ_perfect)) ρ.print() results_c.append(result_correct) results_e.append(result_error) for i in range(len(ps)): print(ps[i], " : ", results_c[i][0, 0, 0, 0], " ", results_e[i][0, 0, 0, 0]) with open('data/scan_result.npz', 'wb') as f: np.savez(f, results_c, results_e)
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 1 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 2 [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], # 3 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 4 [0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], # 5 [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0], # 6 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 7 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 8 [0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], # 9 [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0], # 10 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 11 [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], # 12 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 13 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 14 [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], # 15 ]) / 2 print("\n--------------\n") print(array) if __name__ == '__main__': np.set_printoptions(edgeitems=16, linewidth=200, formatter=dict(float=lambda x: "%8.4g" % x)) err_model = cc.ErrorModel(0.1, 0.006, 0.006) ρ = cc.bell_pair(err_model.p_n, [0, 3]) cc.bell_purify_1(ρ, err_model, 0, 3, 1, 2, 4, 5, 'z') ρ.print()