def bds_circuit_(alpha, beta, gamma): # ref: arXiv:1912.06105 ket0 = st.cb(2, 0) ket1 = st.cb(2, 1) proj0 = mf.proj(2, ket0) proj1 = mf.proj(2, ket1) psi = ket0 for j in range(1, 4): psi = np.kron(psi, ket0) gate = np.kron(gates.O2(alpha / 2), gates.id(8)) psi = np.dot(gate, psi) cn = gates.cnot(4, 0, 1) psi = np.dot(cn, psi) gate = np.kron(gates.O2(beta / 2), gates.O2(gamma / 2)) gate = np.kron(gate, gates.id(4)) psi = np.dot(gate, psi) cn = gates.cnot(4, 0, 2) psi = np.dot(cn, psi) cn = gates.cnot(4, 1, 3) psi = np.dot(cn, psi) gate = np.kron(gates.id(8), gates.hadamard()) psi = np.dot(gate, psi) cn = gates.cnot(4, 3, 2) psi = np.dot(cn, psi) return psi
def dbs_rpv_test(): from states import bell ns = 5 * 10**3 cxx = np.zeros(ns) cyy = np.zeros(ns) czz = np.zeros(ns) for j in range(0, ns): rpv = rpvg.rpv_zhsl(4) rhor = rpv[0] * mf.proj(4, bell(0, 0)) + rpv[1] * mf.proj( 4, bell(0, 1)) rhor += (rpv[2] * mf.proj(4, bell(1, 0)) + rpv[3] * mf.proj(4, bell(1, 1))) cm = gm.corr_mat(2, 2, rhor) cxx[j] = cm[0][0] cyy[j] = cm[1][1] czz[j] = cm[2][2] fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(cxx, cyy, czz, c='b', marker='o', s=0.5) ax.set_xlabel('c_xx') ax.set_ylabel('c_yy') ax.set_zlabel('c_zz') ax.set_xlim(-1, 1) ax.set_ylim(-1, 1) ax.set_zlim(-1, 1) ax.plot([-1, 1], [-1, 1], [-1, -1], color='b') ax.plot([-1, 1], [1, -1], [1, 1], color='b') ax.plot([-1, 1], [-1, -1], [-1, 1], color='b') ax.plot([-1, -1], [-1, 1], [-1, 1], color='b') ax.plot([1, -1], [1, 1], [-1, 1], color='b') ax.plot([1, 1], [1, -1], [-1, 1], color='b') plt.show()
def dbs_circuit_test_(): ns = 5 * 10**3 cxx = np.zeros(ns) cyy = np.zeros(ns) czz = np.zeros(ns) p = np.zeros((2, 2)) a = np.zeros(4) for j in range(0, ns): rpv = rpvg.rpv_zhsl(4) a = np.reshape(rpv, (2, 2)) alpha, beta, gamma = bds_circuit_angles(a) psi = bds_circuit_(alpha, beta, gamma) rhor = ptr.pTraceL(4, 4, mf.proj(16, psi)) cm = gm.corr_mat(2, 2, rhor) cxx[j] = cm[0][0] cyy[j] = cm[1][1] czz[j] = cm[2][2] fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(cxx, cyy, czz, c='b', marker='o', s=0.75) ax.set_xlabel('c_xx') ax.set_ylabel('c_yy') ax.set_zlabel('c_zz') ax.set_xlim(-1, 1) ax.set_ylim(-1, 1) ax.set_zlim(-1, 1) ax.plot([-1, 1], [-1, 1], [-1, -1], color='b') ax.plot([-1, 1], [1, -1], [1, 1], color='b') ax.plot([-1, 1], [-1, -1], [-1, 1], color='b') ax.plot([-1, -1], [-1, 1], [-1, 1], color='b') ax.plot([1, -1], [1, 1], [-1, 1], color='b') ax.plot([1, 1], [1, -1], [-1, 1], color='b') plt.show()
def dbs_circuit_test(): ns = 5 * 10**3 cxx = np.zeros(ns) cyy = np.zeros(ns) czz = np.zeros(ns) for j in range(0, ns): rpv = rpvg.rpv_zhsl(4) theta = 2.0 * math.acos(math.sqrt(rpv[0] + rpv[1])) alpha = 2.0 * math.acos(math.sqrt(rpv[0] + rpv[2])) psi = bds_circuit(theta, alpha) rhor = ptr.pTraceL(4, 4, mf.proj(16, psi)) cm = gm.corr_mat(2, 2, rhor) cxx[j] = cm[0][0] cyy[j] = cm[1][1] czz[j] = cm[2][2] fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(cxx, cyy, czz, c='b', marker='o', s=1) ax.set_xlabel('c_xx') ax.set_ylabel('c_yy') ax.set_zlabel('c_zz') ax.set_xlim(-1, 1) ax.set_ylim(-1, 1) ax.set_zlim(-1, 1) ax.plot([-1, 1], [-1, 1], [-1, -1], color='b') ax.plot([-1, 1], [1, -1], [1, 1], color='b') ax.plot([-1, 1], [-1, -1], [-1, 1], color='b') ax.plot([-1, -1], [-1, 1], [-1, 1], color='b') ax.plot([1, -1], [1, 1], [-1, 1], color='b') ax.plot([1, 1], [1, -1], [-1, 1], color='b') plt.show()
def bds_circuit(theta, alpha): ket0 = st.cb(2, 0) ket1 = st.cb(2, 1) proj0 = mf.proj(2, ket0) proj1 = mf.proj(2, ket1) psi = ket0 for j in range(1, 4): psi = np.kron(psi, ket0) gate = np.kron(gates.O2(theta / 2), gates.O2(alpha / 2)) gate = np.kron(gate, gates.id(4)) psi = np.dot(gate, psi) cn = gates.cnot(4, 0, 2) psi = np.dot(cn, psi) cn = gates.cnot(4, 1, 3) psi = np.dot(cn, psi) gate = np.kron(gates.id(8), gates.hadamard()) psi = np.dot(gate, psi) cn = gates.cnot(4, 3, 2) psi = np.dot(cn, psi) return psi
def cnot(n, c, t): '''returns the control-NOT for n qubits, control c & target t''' list1 = [] list2 = [] for j in range(0, n): if j == c: list1.append(mf.proj(2, st.cb(2, 0))) list2.append(mf.proj(2, st.cb(2, 1))) elif j == t: list1.append(pauli(0)) list2.append(pauli(1)) else: list1.append(pauli(0)) list2.append(pauli(0)) kp1 = np.kron(list1[0], list1[1]) kp2 = np.kron(list2[0], list2[1]) for j in range(2, n): kp1 = np.kron(kp1, list1[j]) kp2 = np.kron(kp2, list2[j]) cn = kp1 + kp2 return cn
def dbs_circuit_test_angles_(): ns = 20**3 cxx = np.zeros(ns) cyy = np.zeros(ns) czz = np.zeros(ns) m = -1 da = math.pi / 20 alpha = -math.pi / 2 - da for j in range(0, 20): alpha += da beta = -da for k in range(0, 20): beta += da gamma = -da for l in range(0, 20): gamma += da psi = bds_circuit_(alpha, beta, gamma) rhor = ptr.pTraceL(4, 4, mf.proj(16, psi)) cm = gm.corr_mat(2, 2, rhor) m += 1 cxx[m] = cm[0][0] cyy[m] = cm[1][1] czz[m] = cm[2][2] fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(cxx, cyy, czz, c='b', marker='o', s=0.75) ax.set_xlabel('c_xx') ax.set_ylabel('c_yy') ax.set_zlabel('c_zz') ax.set_xlim(-1, 1) ax.set_ylim(-1, 1) ax.set_zlim(-1, 1) ax.plot([-1, 1], [-1, 1], [-1, -1], color='b') ax.plot([-1, 1], [1, -1], [1, 1], color='b') ax.plot([-1, 1], [-1, -1], [-1, 1], color='b') ax.plot([-1, -1], [-1, 1], [-1, 1], color='b') ax.plot([1, -1], [1, 1], [-1, 1], color='b') ax.plot([1, 1], [1, -1], [-1, 1], color='b') plt.show()
def Werner(w): return ((1 - w) / 4) * np.eye(4) + w * proj(4, Bell(1, 1))