Skip to content

Commit 042fdb3

Browse files
committed
draft new quantum computing article
1 parent f8f1a20 commit 042fdb3

File tree

109 files changed

+7378
-708
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+7378
-708
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Quantum Computing
3+
menu:
4+
sidebar:
5+
name: Quantum Computing
6+
identifier: quantum_computing
7+
parent: physics
8+
weight: 11
9+
---

content/posts/physics/quantum_computing/example.ipynb renamed to content/posts/physics/quantum_computing/introduction/example.ipynb

+4
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,12 @@
162162
"# post-processing\n",
163163
"import matplotlib.pyplot as plt\n",
164164
"\n",
165+
"\n",
165166
"values = job.result().values\n",
166167
"\n",
168+
"\n",
169+
"\n",
170+
"\n",
167171
"plt.plot(observables_labels, values, '-o')"
168172
]
169173
},

content/posts/physics/quantum_computing/index.md renamed to content/posts/physics/quantum_computing/introduction/index.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ date: 2024-06-30T08:00:00+01:00
44
description: Python Implentation of simple quantum circuits
55
menu:
66
sidebar:
7-
name: Quantum Computing - Basic 1
8-
identifier: quantum_computing
9-
parent: physics
10-
weight: 9
7+
name: Introduction
8+
identifier: quantum_computing_intro
9+
parent: quantum_computing
10+
weight: 12
1111
hero: images/bell_state_sphere.png
1212
tags: ["Science", "Statistics", "Quantum", "Physics"]
1313
categories: ["Physics"]

content/posts/physics/quantum_computing/teleportation/example.ipynb

+423
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,320 @@
1+
# Quantum Teleportation: Concept, Mathematics, and Implementation
2+
3+
## Introduction
4+
5+
Quantum teleportation is a fundamental protocol in quantum information science that enables the transfer of quantum information from one location to another. Despite its name, it doesn't involve the transportation of matter, but rather the transmission of the quantum state of a particle.
6+
7+
## The Concept
8+
9+
In quantum teleportation, we have three main parties:
10+
11+
1. Alice: The sender who wants to transmit a quantum state.
12+
2. Bob: The receiver who will receive the quantum state.
13+
3. A quantum channel: Usually an entangled pair of qubits shared between Alice and Bob.
14+
15+
The goal is for Alice to transmit the state of her qubit to Bob using only classical communication and their shared entanglement.
16+
17+
## Mathematical Formulation
18+
19+
Let's walk through the mathematical formulation of quantum teleportation:
20+
21+
1. Initial state:
22+
Alice has a qubit in an unknown state |ψ⟩ = α|0⟩ + β|1⟩, where |α|² + |β|² = 1.
23+
Alice and Bob share an entangled pair in the Bell state |Φ⁺⟩ = (1/√2)(|00⟩ + |11⟩).
24+
25+
2. The initial state of the entire system:
26+
|Ψ₀⟩ = |ψ⟩ ⊗ |Φ⁺⟩ = (1/√2)(α|0⟩ + β|1⟩) ⊗ (|00⟩ + |11⟩)
27+
28+
3. Expanding the state:
29+
|Ψ₀⟩ = (1/√2)[α|000⟩ + α|011⟩ + β|100⟩ + β|111⟩]
30+
31+
4. Alice applies a CNOT gate to her qubits:
32+
|Ψ₁⟩ = (1/√2)[α|000⟩ + α|011⟩ + β|110⟩ + β|101⟩]
33+
34+
5. Alice applies a Hadamard gate to her first qubit:
35+
|Ψ₂⟩ = (1/2)[α(|000⟩ + |100⟩) + α(|011⟩ + |111⟩) + β(|010⟩ - |110⟩) + β(|001⟩ - |101⟩)]
36+
37+
6. Rearranging terms:
38+
|Ψ₂⟩ = (1/2)[|00⟩(α|0⟩ + β|1⟩) + |01⟩(α|1⟩ + β|0⟩) + |10⟩(α|0⟩ - β|1⟩) + |11⟩(α|1⟩ - β|0⟩)]
39+
40+
7. Alice measures her qubits, collapsing the state. There are four possible outcomes:
41+
- 00: Bob's qubit is in state α|0⟩ + β|1⟩
42+
- 01: Bob's qubit is in state α|1⟩ + β|0⟩
43+
- 10: Bob's qubit is in state α|0⟩ - β|1⟩
44+
- 11: Bob's qubit is in state α|1⟩ - β|0⟩
45+
46+
8. Based on Alice's measurement, Bob applies the appropriate correction:
47+
- 00: I (identity, do nothing)
48+
- 01: X (bit flip)
49+
- 10: Z (phase flip)
50+
- 11: ZX (bit and phase flip)
51+
52+
After Bob's correction, his qubit is in the state α|0⟩ + β|1⟩, which is the original state of Alice's qubit.
53+
54+
## The Protocol: Step-by-Step
55+
56+
1. Preparation:
57+
- Alice has a qubit in state |ψ⟩ = α|0⟩ + β|1⟩.
58+
- Alice and Bob share an entangled pair in the Bell state |Φ⁺⟩ = (1/√2)(|00⟩ + |11⟩).
59+
60+
2. Alice's operations:
61+
- Alice applies a CNOT gate with her qubit as control and her half of the entangled pair as target.
62+
- Alice applies a Hadamard gate to her qubit.
63+
64+
3. Measurement:
65+
- Alice measures both of her qubits in the computational basis.
66+
67+
4. Classical communication:
68+
- Alice sends the two classical bits resulting from her measurement to Bob.
69+
70+
5. Bob's correction:
71+
- Based on the classical bits received, Bob applies the appropriate quantum gate(s) to his qubit.
72+
73+
6. Result:
74+
- Bob's qubit is now in the state α|0⟩ + β|1⟩, the original state of Alice's qubit.
75+
76+
## Implementation in Qiskit
77+
78+
Let's implement the quantum teleportation protocol using Qiskit:
79+
80+
81+
```python
82+
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
83+
from qiskit_aer import AerSimulator
84+
from qiskit.visualization import plot_histogram
85+
from qiskit.result import marginal_distribution
86+
from qiskit.circuit.library import UGate
87+
from numpy import pi, random
88+
import matplotlib.pyplot as plt
89+
import seaborn as sns
90+
91+
# Create quantum and classical registers
92+
qubit = QuantumRegister(1, "Q")
93+
ebit0 = QuantumRegister(1, "A")
94+
ebit1 = QuantumRegister(1, "B")
95+
a = ClassicalRegister(1, "a")
96+
b = ClassicalRegister(1, "b")
97+
98+
# Create quantum circuit
99+
protocol = QuantumCircuit(qubit, ebit0, ebit1, a, b)
100+
101+
# Initialize Q to |1⟩ state
102+
# protocol.x(qubit)
103+
104+
# Prepare entangled pair (Bell state) for teleportation
105+
protocol.h(ebit0)
106+
protocol.cx(ebit0, ebit1)
107+
protocol.barrier()
108+
109+
# Alice's operations
110+
protocol.cx(qubit, ebit0)
111+
protocol.h(qubit)
112+
protocol.barrier()
113+
114+
# Alice measures and sends classical bits to Bob
115+
protocol.measure(ebit0, a)
116+
protocol.measure(qubit, b)
117+
protocol.barrier()
118+
119+
# Bob uses the classical bits to conditionally apply gates
120+
with protocol.if_test((a, 1)):
121+
protocol.x(ebit1)
122+
with protocol.if_test((b, 1)):
123+
protocol.z(ebit1)
124+
125+
# Display the circuit
126+
display(protocol.draw('mpl', scale=2))
127+
```
128+
129+
130+
131+
![png](images/example_1_0.png)
132+
133+
134+
135+
136+
```python
137+
# verification_circuit = QuantumCircuit(qubit, ClassicalRegister(1, 'c'))
138+
# # verification_circuit.x(qubit)
139+
# verification_circuit.measure(qubit, 0)
140+
141+
# simulator = AerSimulator()
142+
# result = simulator.run(verification_circuit, shots=1000).result()
143+
# counts = result.get_counts()
144+
# print(counts)
145+
```
146+
147+
148+
This code creates a quantum circuit that implements the quantum teleportation protocol. Let's break down the steps:
149+
150+
1. We create quantum registers for the qubit to be teleported (Q), Alice's entangled qubit (A), and Bob's entangled qubit (B). We also create classical registers to store measurement results.
151+
152+
2. We prepare the entangled pair shared by Alice and Bob using a Hadamard gate and a CNOT gate.
153+
154+
3. Alice performs her operations: a CNOT gate with Q as control and A as target, followed by a Hadamard gate on Q.
155+
156+
4. Alice measures her qubits and stores the results in classical bits.
157+
158+
5. Based on Alice's measurement results, Bob applies X and/or Z gates to his qubit.
159+
160+
## Verifying the Teleportation
161+
162+
To verify that the teleportation worked, we can prepare the initial qubit in a specific state, run the teleportation protocol, and then measure Bob's qubit to see if it matches the initial state. Here's how we can do that:
163+
164+
### Random Gate
165+
We'll use a randomly generated single-qubit unitary gate (U gate) to create an arbitrary quantum state. Here's how we create this random gate:
166+
167+
**Why Add a Random U Gate?**
168+
169+
The addition of a random U gate serves several important purposes in our verification process:
170+
171+
1. Generality: By using a random state, we're testing the teleportation protocol for a general, arbitrary quantum state, not just specific states like |0⟩, |1⟩, or |+⟩.
172+
2. Robustness: If the protocol works for a randomly chosen state, it's likely to work for all states. This provides a more thorough verification than testing with a few predetermined states.
173+
3. Avoiding Bias: Random testing helps avoid any unintentional bias in our verification process that might arise from choosing specific test states.
174+
4. Simulating Real-World Scenarios: In practical applications, the states we need to teleport are often unknown or arbitrary. Testing with a random state better simulates these real-world scenarios.
175+
176+
177+
```python
178+
from qiskit.circuit.library import UGate, XGate, HGate
179+
from numpy import pi, random
180+
181+
random_gate = UGate(
182+
theta=random.random() * 2 * pi,
183+
phi=random.random() * 2 * pi,
184+
lam=random.random() * 2 * pi,
185+
)
186+
187+
xgate = XGate()
188+
hgate = HGate()
189+
190+
display(random_gate.to_matrix(), xgate.to_matrix())
191+
```
192+
193+
194+
array([[-0.61747588+0.j , 0.28776308+0.7320628j ],
195+
[-0.78573506-0.03665989j, -0.19886638-0.58457559j]])
196+
197+
198+
199+
array([[0.+0.j, 1.+0.j],
200+
[1.+0.j, 0.+0.j]])
201+
202+
203+
204+
```python
205+
# Create a new circuit including the same bits and qubits used in the
206+
# teleportation protocol.
207+
test = QuantumCircuit(qubit, ebit0, ebit1, a, b)
208+
209+
# Start with the randomly selected gate on Q
210+
Q_input = [0, 1]
211+
212+
if Q_input == [0, 1]:
213+
# |1⟩ state, so append X gate before the random gate
214+
test.append(xgate, qubit)
215+
# test.barrier()
216+
217+
test.append(random_gate, qubit)
218+
test.barrier()
219+
220+
# Append the entire teleportation protocol from above.
221+
test = test.compose(protocol)
222+
test.barrier()
223+
224+
# Finally, apply the inverse of the random unitary to B and measure.
225+
test.append(random_gate.inverse(), ebit1)
226+
result = ClassicalRegister(1, "Result")
227+
test.add_register(result)
228+
test.measure(ebit1, result)
229+
230+
display(test.draw("mpl", scale=2))
231+
```
232+
233+
234+
235+
![png](images/example_5_0.png)
236+
237+
238+
239+
Let's break down this process:
240+
241+
* We apply the random U gate to qubit Q (by default is set to **|0⟩**), creating a random quantum state.
242+
* We then run the teleportation protocol, which should teleport this random state from Q to B.
243+
* After teleportation, we apply the inverse of our random U gate to B.
244+
* Finally, we measure B.
245+
246+
If the teleportation worked correctly, applying the inverse of the random U gate to B should return it to the |0⟩ state (or |1⟩ if X operator is applied), and our measurement should always yield 0.
247+
248+
249+
```python
250+
from qiskit_aer import AerSimulator
251+
from qiskit.visualization import plot_histogram
252+
from qiskit.result import marginal_distribution
253+
254+
plt.style.use("ggplot")
255+
plt.rcParams.update({'figure.figsize':(8,5), 'figure.dpi':200})
256+
257+
result = AerSimulator().run(test, shots=2048).result()
258+
statistics = result.get_counts()
259+
display(plot_histogram(statistics))
260+
261+
# Filter statistics to focus on the test result qubit
262+
filtered_statistics = marginal_distribution(statistics, [2]) #2 means the leftmost/ bottom qubit (B in this case)
263+
display(plot_histogram(filtered_statistics))
264+
```
265+
266+
267+
268+
![png](images/example_7_0.png)
269+
270+
271+
272+
273+
274+
![png](images/example_7_1.png)
275+
276+
277+
278+
279+
```python
280+
281+
```
282+
283+
284+
This code creates a function `run_teleportation` that takes an initial state, runs the teleportation protocol, and returns the measurement results. We then test this function with various initial states.
285+
286+
## Mathematical Analysis of the Verification
287+
288+
Let's analyze what happens in each case:
289+
290+
1. |0⟩ state:
291+
- Initial state: |ψ⟩ = |0⟩ = 1|0⟩ + 0|1⟩
292+
- Expected final state: |0⟩
293+
- Expected measurement: 100% |0⟩
294+
295+
2. |1⟩ state:
296+
- Initial state: |ψ⟩ = |1⟩ = 0|0⟩ + 1|1⟩
297+
- Expected final state: |1⟩
298+
- Expected measurement: 100% |1⟩
299+
300+
3. |+⟩ state:
301+
- Initial state: |ψ⟩ = |+⟩ = (1/√2)(|0⟩ + |1⟩)
302+
- Expected final state: |+⟩
303+
- Expected measurement: 50% |0⟩, 50% |1⟩
304+
305+
4. |−⟩ state:
306+
- Initial state: |ψ⟩ = |−⟩ = (1/√2)(|0⟩ - |1⟩)
307+
- Expected final state: |−⟩
308+
- Expected measurement: 50% |0⟩, 50% |1⟩
309+
310+
Note that for the |+⟩ and |−⟩ states, the measurement results will be the same (50-50 split between |0⟩ and |1⟩). To distinguish between these states, we would need to measure in a different basis (e.g., the X basis).
311+
312+
## Conclusion
313+
314+
Quantum teleportation is a cornerstone protocol in quantum information science. It demonstrates the power of quantum entanglement and how it can be used in conjunction with classical communication to transmit quantum information. While it doesn't allow for faster-than-light communication or the transportation of matter, it's a crucial building block for many quantum communication protocols and quantum computing algorithms.
315+
316+
The mathematical formulation reveals the intricate quantum mechanics at play, showing how entanglement and quantum measurement work together to achieve the seemingly impossible task of transmitting a quantum state using only classical communication.
317+
318+
The implementation in Qiskit allows us to simulate this protocol and verify its correctness. As quantum hardware continues to improve, we may see practical applications of quantum teleportation in secure communication systems and distributed quantum computing networks.
319+
320+
For further details, I suggest this amazing course from IBM: https://learning.quantum.ibm.com/course/basics-of-quantum-information/
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)