-
Notifications
You must be signed in to change notification settings - Fork 0
/
teleportation.py
113 lines (89 loc) · 2.34 KB
/
teleportation.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import numpy as np
from scipy.linalg import hadamard
import matplotlib.pyplot as plt
import math as mt
def firstEval(nm):
escalar = 1. / (mt.sqrt(2))
hada=hadamard(2)*escalar
hada2= np.kron(hada,np.eye(2))
#Primer estado
r1 = hada2 @ nm
print("Evaluamos el primer estado")
print(r1)
print()
#Segundo estado
cnot = np.array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 0., 1.], [0., 0., 1., 0.]])
r2 = cnot@r1
print("Evaluamos el segundo estado")
print(r2)
#gatex(r2)
print()
#Tercera estado
r3 = hada2@r2
print("Evaluamos el tercera estado")
print(r3)
print()
def secondEval(nm):
escalar = 1. / (mt.sqrt(2))
hada=hadamard(2)*escalar
hada2= np.kron(hada,np.eye(2))
#Primer estado
r1 = hada2 @ nm
print("Evaluamos el primer estado")
print(r1)
#Segundo estado
cnot = np.array([[1,0,0,0],[0,0,0,1],[0,0,1,0],[0,1,0,0]])
r2 = cnot@r1
print("Evaluamos el segundo estado")
print(r2)
#Tercera estado
r3 = hada2@r2
print("Evaluamos el tercera estado")
print(r3)
def gatex(q):
x = np.array([[0,1],[1,0]])
print("Gate x to q")
print(x@q)
def gatez(q):
x = np.array([[1.,0.],[0.,-1.]])
print("Gate z to q")
print(x@q)
def IwannaWinThisS(nm0, nm1):
plt.title('Quantum in state 1 and 2')
plt.hist(nm0, bins=60, alpha=1, edgecolor='red', linewidth=1, label='Q0')
plt.hist(nm1, bins=60, alpha=1, edgecolor='blue', linewidth=1, label='Q1')
plt.legend(loc='upper right')
plt.grid(True)
plt.show()
plt.clf()
def IwannaWinThisQ(q):
plt.title('Quantum in state 3')
plt.hist(q, bins=60, alpha=1, edgecolor='black', linewidth=1, label="Q3")
plt.legend(loc='upper right')
plt.grid(True)
plt.show()
plt.clf()
def opq2x(q2):
print(gatex(q2))
def opq2z(q2):
print(gatez(q2))
def makeOperation():
q0 = [1.,0.]
q1 = [0.,1.]
q2 = [0.,1.]
nmq0 = np.kron(q0, q1)
nmq1 = np.kron(q1, q0)
nmq2 = np.kron(q2, q2)
print()
firstEval(nmq0)
print("Finaliza el proceso del primer estado")
secondEval(nmq1)
print("Finaliza el proceso del segundo estado")
firstEval(nmq2)
secondEval(nmq2)
print("Finaliza el proceso del tercer estado")
IwannaWinThisS(nmq0, nmq1)
opq2x(q2)
opq2z(q2)
IwannaWinThisQ(q2)
makeOperation()