-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteleportation.py
52 lines (33 loc) · 1.14 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
#Quantum teleportation: make Dest the same state as Source
import numpy as np
from pyqcl import *
Source = QubitSystem().make([0,1], [np.sqrt(1./3.), np.sqrt(2./3.)])
print("Source: ", Source)
Inter = QubitSystem().make([0, 1], [1, 0])
Dest = QubitSystem().make([0, 1], [1, 0])
System = Source.add_qubit(Inter).add_qubit(Dest)
#Turn the lower qubits from |00> to Bell_00
Bell = HadamardGate().kronecker(IGate()).composit(CNOTGate())
SystemBell = IGate().kronecker(Bell)
System = SystemBell(System)
#Apply CNOT to Source and Inter
SystemCNOT = CNOTGate().kronecker(IGate())
System = SystemCNOT(System)
#Apply Hadamard transfrom to Source
SystemHT = HadamardGate().kronecker(IGate()).kronecker(IGate())
System = SystemHT(System)
#Measure Source
M1 = System.measure_single(0)
#Measure Inter on reduced System
M2 = System.measure_single(0)
#System is now just Dest, since the other two have been measured
#if M2 is 1 apply X gate to System
if M2 == 1:
X = XGate()
System = X(System)
#if M1 is 1 apply Z gate to System
if M1 == 1:
Z = ZGate()
System = Z(System)
#print Dest. This is technically cheating, but eh.
print("\nDest: ", System)