Unverified Commit 6c6bcb3f authored by dwuggh's avatar dwuggh
Browse files

update

parent 7fcf85e4
......@@ -19,11 +19,6 @@ class DensityOperator(QOperator):
super().__init__(qubits, mat)
# def print(self):
# print("qubits: ", self.qubits)
# print("shape: ", self.operator.shape)
# print(self.operator)
def deepcopy(self):
operator = self.operator
qubits = self.qubits
......
......@@ -6,6 +6,14 @@ class QOperator(object):
self.qubits = np.array(qubits)
self.operator = np.array(operator, dtype=np.float64)
# def __mul__(self, other):
# op = self.operator * other
# return QOperator(self.qubits, op)
# def __rmul__(self, rhs):
# self.__mul__(rhs)
# return self
def deepcopy(self):
operator = self.operator
qubits = self.qubits
......
......@@ -40,6 +40,7 @@ def bell_purify_1(ρ: DensityOperator, err_model: ErrorModel, data1, data2, q1,
ρ.evolution(c1, err_model.p_g)
ρ.evolution(c2, err_model.p_g)
# print("evolution")
# ρ.print()
ρ2 = bell_pair(err_model.p_n, [q2, q4])
......@@ -92,10 +93,14 @@ def bell_purify_2(ρ: DensityOperator, err_model: ErrorModel, data1, data2, q1,
c1 = cnot([q2, q1])
c2 = cnot([q4, q3])
ρ1.evolution(c1, err_model.p_g)
ρ1.evolution(c2, err_model.p_g)
ρ1.bell_measure(q2, q4, 'x', 'x', err_model.p_m)
# if debug:
# ρ1.print()
ρ3 = bell_pair(err_model.p_n, [q2, q4])
ρ1.merge(ρ3)
......@@ -106,9 +111,6 @@ def bell_purify_2(ρ: DensityOperator, err_model: ErrorModel, data1, data2, q1,
ρ1.bell_measure(q2, q4, 'x', 'x', err_model.p_m)
if debug:
ρ1.print()
# now, take ρ into consideration
ρ.merge(ρ1)
......@@ -130,6 +132,8 @@ def bell_purify_2(ρ: DensityOperator, err_model: ErrorModel, data1, data2, q1,
ρ.bell_measure(q1, q3, 'x', 'x', err_model.p_m)
'''
qubit indexing:
2 5
......@@ -199,8 +203,8 @@ def make_GHZ_with(ρ1: DensityOperator, err_model: ErrorModel, stringent = True,
# then the result density matrix would consist of 5 qubits of indices 0, 1, 3, 6, 9.
# However, if the ancilla indices are 1 2 7 8, everything works fine, at least seemingly.
# Don't know why, not even a clue.
# bell_purify_2(ρ1, err_model, 3, 9, 4, 5, 10, 11, 'z', stringent)
bell_purify_2(ρ1, err_model, 3, 9, 1, 2, 7, 8, 'z', stringent)
bell_purify_2(ρ1, err_model, 3, 9, 4, 5, 10, 11, 'z', stringent)
# bell_purify_2(ρ1, err_model, 3, 9, 1, 2, 7, 8, 'z', stringent)
return ρ1
......@@ -295,14 +299,11 @@ def BBPSSW_2(err_model: ErrorModel, detail = False):
if detail:
ρ1.print()
# c1 = cnot([1, 2])
c1 = cnot([2, 1])
c2 = cnot([4, 3])
c2 = multiply(c1, c2)
c2.broadcast_with([1, 3, 2, 4]).print()
# ρ1.evolution(c1, err_model.p_g)
ρ1.evolution(c2, err_model.p_g)
ρ1.broadcast_with_self([1, 3, 2, 4])
......
import calc_channel as cc
import numpy as np
def expedient():
err_model = cc.ErrorModel(0.1, 0.006, 0.006)
bell_operator = np.array(
[[0.4947, 0, 0, 0.4899],
[0, 0.005315, 0.003703, 0],
[0, 0.003703,0.005315, 0],
[0.4899, 0, 0, 0.4947]])
ρ1 = cc.DensityOperator([0, 3], bell_operator)
ρ = cc.make_GHZ_with(ρ1, err_model, False, 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.make_bell(err_model, True, False)
ρ1 = cc.DensityOperator([0, 3], bell_operator)
# ρ1.print()
ρ = cc.make_GHZ_with(ρ1, err_model, True, False)
return ρ
if __name__ == "__main__":
# a = test_1()
# test_3()
np.set_printoptions(edgeitems=16, linewidth=200,
formatter=dict(float=lambda x: "%6.4g" % x)
)
err_model = cc.ErrorModel(0.1, 0.006, 0.006)
stringent = False
bell = cc.make_bell(err_model, stringent, False, True)
bell_2 = bell.deepcopy()
bell_2.alter_qubits([6, 9])
bell.merge(bell_2)
cc.bell_purify_2(bell, err_model, 0, 6, 1, 2, 7, 8, 'z', stringent)
cc.bell_purify_2(bell, err_model, 3, 9, 1, 2, 7, 8, 'z', stringent)
bell.print()
ρ = stringent()
ρ.print()
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)
print(cc.entanglement_fidelity(ρ, GHZ_perfect)) # 0.9616 0.973911
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