-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteleport.py
65 lines (54 loc) · 1.38 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
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
import math
from IPython.display import display
from qiskit import BasicAer, ClassicalRegister, QuantumCircuit, QuantumRegister, execute
from qiskit.visualization import array_to_latex
alice = QuantumRegister(1, name="alice")
ep = QuantumRegister(1, name="entangled_pair")
bob = QuantumRegister(1, name="bob")
alice_c = ClassicalRegister(1, name="alice_c")
ep_c = ClassicalRegister(1, name="entangled_pair_c")
bob_c = ClassicalRegister(1, name="bob_c")
qc = QuantumCircuit(alice, ep, bob, alice_c, ep_c, bob_c)
# Entangle
qc.h(ep)
qc.cx(ep, bob)
qc.barrier()
# Prep payload
qc.reset(alice)
qc.h(alice)
qc.rz(math.radians(45), alice)
qc.h(alice)
qc.barrier()
# Send
qc.cx(alice, ep)
qc.h(alice)
qc.measure(alice, alice_c)
qc.measure(ep, ep_c)
qc.barrier()
# Receive
qc.x(bob).c_if(ep_c, 1)
qc.z(bob).c_if(alice_c, 1)
qc.barrier()
# Verify
qc.h(bob)
qc.rz(math.radians(-45), bob)
qc.h(bob)
qc.measure(bob, bob_c)
# Run circuit
backend = BasicAer.get_backend("statevector_simulator")
job = execute(qc, backend)
result = job.result()
counts = result.get_counts(qc)
print("counts:", counts)
# Display statevector
outputstate = result.get_statevector(qc, decimals=3)
display(array_to_latex(outputstate, prefix="\\text{Statevector} = "))
# Draw the circuit
qc.draw(
output="mpl",
style="iqp",
cregbundle=False,
initial_state=True,
fold=-1,
filename="./docs/_static/teleport.png",
)