-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteleport.py
38 lines (30 loc) · 1.06 KB
/
teleport.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
import numpy as np
from taichi_q import Engine, Gate
if __name__ == "__main__":
eng = Engine(
num_qubits=3,
state_init=[[-1/np.sqrt(5), 2j/np.sqrt(5)], [1, 0], [1, 0]],
device='cpu')
eng.State_Check(plot_state=True)
# Step 1: A Third Party [Telamon] created an entangled qubit pair. One to Alice, another to Bob
eng.Ops(Gate.H(), [1])
eng.Ops(Gate.X(), [2], [1])
eng.State_Check()
eng.circuit_print()
# Step 2: Alice applies CNOT to q1 controlled by q0 (qubit send to Bob) and H to q0
eng.Ops(Gate.X(), [1], [0])
eng.Ops(Gate.H(), [0])
eng.State_Check()
eng.circuit_print()
# Step 3: Alice measure both q0 and q1 and send measure results to Bob
eng.Measure(0)
eng.Measure(1)
eng.State_Check()
eng.circuit_print()
# Step 4: Bob got q2 and measure result from Alice, then applied Gate.
eng.Ops(Gate.X(), [2], [1])
eng.Ops(Gate.Z(), [2], [0])
# q0 states successfully teleported to q2
eng.State_Check(plot_state=True)
eng.circuit_print()
eng.circuit_visualize()