Unverified Commit 66284986 authored by dwuggh's avatar dwuggh
Browse files

update measure.py

parent 59d9f508
......@@ -53,58 +53,73 @@ for i in range(dim):
p_odd += (a - b) / 2
ps = [p_even, p_odd]
p = 0.5
ps = [p, 1 - p]
p = ps[0]
# p = 0.5
# ps = [p, 1 - p]
print(p_even, p_odd)
def get_p(ks, p_g):
result = 1
for k in ks:
if k == 0:
result *= (1 - p_g)
else:
result *= p_g / 15
return result
def get_p(indices, p_g):
result_correct = []
result_error = []
for i in indices:
probs = np.ones(4) * (p_g / 15)
if i == 0:
probs[0] = 1 - p_g
def get_final_result(err_model: cc.ErrorModel):
c_even = np.zeros((4, 4, 4, 4))
c_odd = np.zeros((4, 4, 4, 4))
result_correct.append(probs[0] + probs[1])
result_error.append(probs[2] + probs[3])
return result_correct, result_error
def get_final_result(err_model: cc.ErrorModel, p):
c_correct = np.zeros((4, 4, 4, 4))
c_error = np.zeros((4, 4, 4, 4))
probs = 0
p_g = err_model.p_g
pm_correct, pm_error = measure_GHZ(err_model.p_m)
# channel for data qubit
for i in range(256):
dsi = cc.get_n_digits(i, 4, 4)
p_i = get_p(dsi, err_model.p_g)
pgs_correct, pgs_error = get_p(dsi, p_g)
_p1 = pgs_correct[2] * pgs_correct[3] + pgs_error[2] * pgs_error[3]
_p2 = pgs_correct[2] * pgs_error[3] + pgs_error[2] * pgs_correct[3]
pg_correct = pgs_correct[0] * (pgs_correct[1] * _p1 + pgs_error[1] * _p2) + pgs_error[0] * (pgs_correct[1] * _p2 + pgs_error[1] * _p1)
pg_error = pgs_correct[0] * (pgs_error[1] * _p1 + pgs_correct[1] * _p2) + pgs_error[0] * (pgs_error[1] * _p2 + pgs_correct[1] * _p1)
p_correct = p * (pg_correct * pm_correct + pg_error * pm_error) + (1 - p) * (pg_correct * pm_error + pg_error * pm_correct)
p_error = p * (pg_correct * pm_error + pg_error * pm_correct) + (1 - p) * (pg_correct * pm_correct + pg_error * pm_error)
c_correct[dsi[0], dsi[1], dsi[2], dsi[3]] = p_correct
# c_correct[dsi] += p_correct
c_error[dsi[0], dsi[1], dsi[2], dsi[3]] = p_error
# c_error[dsi] += p_error
# channel for GHZ qubit
# X error does not matter, Z error can flip measurement outcome
for j in range(256):
dsj = cc.get_n_digits(j, 4, 4)
p_j = get_p(dsj, err_model.p_g)
flip = 0
if i == 0:
print(pg_correct, pg_error)
print(p_correct, p_error)
print(dsi)
# print(c_correct[dsi])
for dj in dsj:
if dj == 2 or dj == 3:
flip = 1 - flip
p_success = ps[flip] * p_i * p_j
probs += p_success
e, o = measure_GHZ(err_model.p_m)
c_even[dsi] += p_success * e
c_odd[dsi] += p_success * o
print(probs)
return c_even / probs, c_odd / probs
return c_correct, c_error
def measure_GHZ(p_m):
even = p_m ** 4 + (1 - p_m) ** 4 + 6 * p_m ** 2 * (1 - p_m) ** 2
odd = 4 * p_m * (1 - p_m) ** 3 + 4 * p_m ** 3 * (1 - p_m)
return even, odd
c_even, c_odd = get_final_result(cc.ErrorModel(0.1, 0.006, 0.006))
print(c_even[0, 0, 0])
print(c_odd[0, 0, 0])
pm_correct = p_m ** 4 + (1 - p_m) ** 4 + 6 * p_m ** 2 * (1 - p_m) ** 2
pm_error = 4 * p_m * (1 - p_m) ** 3 + 4 * p_m ** 3 * (1 - p_m)
return pm_correct, pm_error
c_correct, c_error = get_final_result(cc.ErrorModel(0.1, 0.006, 0.006), p)
print(c_correct[0, 0, 0])
print(np.sum(c_correct), np.sum(c_error))
# print(c_error[0, 0, 0])
# print(c_odd)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment