-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlecture8.tex
452 lines (332 loc) · 13.1 KB
/
lecture8.tex
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
\section{Lecture 8: Entanglement, Bell State, and Intro to \texttt{Cirq}}
\label{sec:lecture8}
\subsection*{Review from Previous Lecture}
\qs{Quantum Circuit Final State}{
Given this circuit diagram and assuming an initial state $\ket{\psi_i}
=\ket{00}$, what will the final state $\ket{\psi_f}$ measure?
\[
\begin{quantikz}
q_1 \quad \lstick{$\zero$} & \ctrl{0} & \gate{X} & \ctrl{1} & \swap{1}
& \gate{H} & \meter{} \\
q_0 \quad \lstick{$\zero$} & \ctrl{0} & \qw & \gate{X} & \swap{-1} &
\gate{H} & \meter{} \\
\end{quantikz}
\]
}
\sol{\boxed{\ket{\psi_f} = \ket{--}}}
%%%%%%%%%%%%%%%
\index{entanglement}
\subsection*{Entanglement}
In this section, we introduce quantum entanglement—a phenomenon where the
states of two or more qubits become inseparably linked, leading to
correlations between measurement outcomes that cannot be explained classically.
\dfn{Entanglement}{
\textit{"\textbf{Quantum entanglement} is the phenomenon of a group of
particles being generated, interacting, or sharing spatial proximity in a
manner such that the quantum state of each particle of the group cannot be
described independently of the state of the others, including when the
particles are separated by a large distance."}\footnote{\url{https://en.wikipedia.org/wiki/Quantum_entanglement}}
}
\subsubsection*{What is Entanglement?}
To understand quantum entanglement, let's compare classical and quantum
communication systems:
\vspace{0.3cm}
\noindent
Consider two \textbf{classical} email clients, Alice and
Bob:
\begin{itemize}
\item When Alice sends an email, she knows exactly what she sent
\item Bob knows exactly what he received
\item The message state is definite and independent
\item Multiple copies can exist
\end{itemize}
\vspace{0.3cm}
\noindent
Now consider two \textbf{quantum} "email clients" with entangled qubits:
\begin{itemize}
\item Neither Alice nor Bob knows their qubit's state before measurement
\item When Alice measures her qubit, Bob's qubit instantly becomes correlated
\item The qubits share a single quantum state
\item No copies can be made (no-cloning theorem)
\item The correlation exists regardless of distance
\end{itemize}
\vspace{0.3cm}
This "spooky action at a distance"\footnote{\href{https://en.wikipedia.org/wiki/Action\_at\_a\_distance\#\%22Spooky\_action\_at\_a\_distance\%22}{"Spooky action at a distance": \texttt{https://en.wikipedia.org/wiki/Action\_at\_a\_distance}}},
as Einstein called it, has no classical analog and is a fundamental feature
of quantum mechanics.
\index{entanglement!Bell state}
\subsubsection*{Bell-Pair Circuit}
The Bell-Pair circuit is the most analogous thing to quantum computing's
\texttt{Hello, world!} program. It prepares a maximally entangled two-qubit
state (a Bell state).
\[
\begin{quantikz}
q_1 \quad \lstick{$\zero$} & \gate{H} & \ctrl{1} & \meter{} \\
q_0 \quad \lstick{$\zero$} & \qw & \gate{X} & \qw \\
\end{quantikz}
\]
\index{entanglement!proof@\textit{proof}}
\begin{proof}{\textbf{Showing Full Entanglement Mathematically}}
Starting with the initial state:
\[
\ket{\psi_0} = \ket{0}_1 \otimes \ket{0}_0 = \ket{00},
\]
we first apply a Hadamard gate on qubit \(q_1\):
\[
H\ket{0} = \frac{1}{\sqrt{2}}(\ket{0} + \ket{1}).
\]
Thus, the state after the Hadamard becomes:
\[
(H \otimes I)\ket{00} = \frac{1}{\sqrt{2}}(\ket{0} + \ket{1}) \otimes
\ket{0} = \frac{1}{\sqrt{2}}(\ket{00} + \ket{10}).
\]
Next, we apply the CNOT gate with qubit \(q_1\) as the control and qubit
\(q_0\) as the target. The CNOT gate acts as follows:
\[
\text{CNOT}\,\ket{00} = \ket{00}, \quad \text{CNOT}\,\ket{10} = \ket{11}.
\]
Thus, the final state after the CNOT is:
\[
\boxed{
\ket{\psi_{\text{Bell}}} = \frac{1}{\sqrt{2}}(\ket{00} + \ket{11}).
}
\]
This state is fully entangled since it cannot be factored as a tensor
product of individual qubit states.
\end{proof}
\vspace{0.3cm}
\noindent
\textbf{
As a consequence of being fully entangled:
}
\begin{enumerate}
\item Entangled circuits cannot be expressed as a product state. For
example, the Bell state
\[
\ket{\psi_{\text{Bell}}} = \frac{1}{\sqrt{2}}(\ket{00} + \ket{11})
\]
cannot be decomposed into \(\ket{\phi}_1 \otimes \ket{\chi}_0\).
\item Measurement outcomes are correlated. For instance, if qubit \(q_1\)
is measured as \(\ket{0}\), then qubit \(q_0\) will also be found in the
state \(\ket{0}\); similarly, if \(q_1\) is measured as \(\ket{1}\), then
\(q_0\) will be \(\ket{1}\).
\end{enumerate}
\index{entanglement!n-qubit Bell state}
\subsubsection*{Extending the Bell-Pair Circuit to a $n$-Qubit System}
The Bell state can be generalized to an \(n\)-qubit system, often taking the
form of a Greenberger–Horne–Zeilinger (GHZ) state:
\index{entanglement!GHZ state}
\[
\begin{quantikz}
q_{n - 1}\quad \lstick{$\zero$} & \gate{H} & \ctrl{1} & \qw & \qw & \qw \\
q_{n -2} \quad \lstick{$\zero$} & \qw & \gate{X} & \ctrl{0} & \qw & \qw \\
\vdots \\
q_{1} \quad \lstick{$\zero$} & \qw & \qw & \qw & \gate{X} & \ctrl{1} \\
q_{0} \quad \lstick{$\zero$} & \qw & \qw & \qw & \qw & \gate{X} \\
\end{quantikz}
\]
\vspace{0.3cm}
\noindent
\textbf{
The $n$-qubit Bell circuit follows a clear pattern:
}
\begin{enumerate}
\item Initial Hadamard gate on the topmost qubit creates superposition
\item Cascade of CNOT gates propagates the entanglement down
\item Each CNOT uses the previous qubit as control and current qubit as
target
\item Final state has all qubits entangled together
\end{enumerate}
The resulting state:
\[
\boxed{
\ket{\psi_f} = \frac{1}{\sqrt{2}}\lt(\ket{00\cdots 00} +
\ket{11\cdots11}\rt)
}
\]
represents a superposition where all qubits are either all 0 or all 1.
Measuring any qubit collapses the entire state, forcing all other qubits to
match the measured value.
\vspace{0.3cm}
\nt{
It is important to note that there are equivalent diagrams that can be
drawn for the $n$-qubit Bell state circuit, and that you should not be
fooled by diagrams that do not match the general diagram shown above.
}
\ex{Alternative $n$-Qubit Bell Circuit}{
\[
\begin{quantikz}
q_{n-1} \quad \lstick{$\zero$} & \gate{H} & \ctrl{1} & \ctrl{2} &
\ctrl{3} & \qw \\
q_{n-2} \quad \lstick{$\zero$} & \qw & \gate{X} & \qw & \qw & \qw \\
q_{1} \quad \lstick{$\zero$} & \qw & \qw & \gate{X} & \qw & \qw \\
q_{0} \quad \lstick{$\zero$} & \qw & \qw & \qw & \gate{X} & \qw
\end{quantikz}
\]
This alternative representation achieves the same final state by having the
first qubit control all CNOT operations directly. While functionally
equivalent, this requires longer-range interactions which may be harder to
implement on real quantum hardware.
}
\aside{\textbf{Shorthand Notation Used for Final Quantum States}\\
Common notational shortcuts can be confusing for beginners. Here are some
important distinctions:
\begin{itemize}
\item $\ket{+1}$ typically means $\frac{1}{\sqrt{2}}(\ket{01} +
\ket{11})$, not $\ket{+} \otimes \ket{1}$
\item $\ket{-1}$ represents $\frac{1}{\sqrt{2}}(\ket{01} - \ket{11})$,
not to be confused with $-\ket{1}$ or $Z\ket{1}$
\item In general, $\ket{\pm x}$ represents $\frac{1}{\sqrt{2}}(\ket{0x}
\pm \ket{1x})$ where $x$ is a bit string
\item The notation $\ket{\psi^+}$ and $\ket{\psi^-}$ is often used for
Bell states $\frac{1}{\sqrt{2}}(\ket{01} \pm \ket{10})$
\end{itemize}
Always check the context and definitions when encountering shorthand
notation, as conventions may vary between sources.
}
\index{entanglement!partial entanglement}
\paragraph{Partial Entanglement}
There also exists the middle ground of partially-entangled systems where only
some of the qubits are entangled while others have independent states.
\[
\begin{quantikz}
q_2 \quad \lstick{$\zero$} & \gate{H} & \qw & \qw \\
q_1 \quad \lstick{$\zero$} & \gate{H} & \ctrl{1} & \qw \\
q_0 \quad \lstick{$\zero$} & \qw & \gate{X} & \qw
\end{quantikz}
\]
In this case, \(q_1\) and \(q_0\) become entangled through the CNOT gate,
while \(q_2\) remains in a superposition state but independent of the other
qubits. The final state is:
\[
\ket{\psi_f} = \frac{1}{\sqrt{2}}\ket{+}_2 \otimes
\frac{1}{\sqrt{2}}(\ket{00}_{10} + \ket{11}_{10})
\]
%%%%%%%%%%%%%%%
\subsection*{Getting Started with \texttt{Cirq}}
\index{Cirq}
\texttt{Cirq}\footnote{\texttt{Cirq} documentation:
\url{https://quantumai.google/cirq}} is an open-source framework for
programming quantum computers, developed by Google Quantum AI. It provides
tools for creating, manipulating, and optimizing quantum circuits, as well as
simulating quantum computations.
\vspace{0.3cm}
\noindent
\textbf{
Key features of \texttt{Cirq} include:
}
\begin{itemize}
\item Native support for quantum gates and circuits
\item Built-in quantum simulator
\item Tools for noise modeling and error mitigation
\item Integration with TensorFlow Quantum
\end{itemize}
\index{Cirq!introduction}
\subsubsection*{Overview and Installation}
Cirq allows you to work with qubits, gates, and operations to build circuits.
To begin, install \texttt{Cirq} in your Python environment (a Google Colab
workbook is my personal recommendation):
\begin{minted}{python}
pip install --quiet cirq
\end{minted}
Then import the library:
\begin{minted}{python}
import cirq
\end{minted}
\subsubsection*{Defining Qubits}
Cirq supports different types of qubits:
\begin{itemize}
\item \textbf{NamedQubit}: Qubits with custom names.
\item \textbf{LineQubit}: Qubits arranged in a linear array.
\item \textbf{GridQubit}: Qubits arranged in a 2D grid.
\end{itemize}
For example, to create line qubits:
\begin{minted}{python}
q0, q1, q2 = cirq.LineQubit.range(3)
\end{minted}
\subsubsection*{Gates and Operations}
In Cirq, a \emph{Gate} represents an abstract quantum operation, while an
\emph{Operation} is a gate applied to specific qubits.
\begin{itemize}
\item Single-qubit gates: \texttt{cirq.X}, \texttt{cirq.H},
\texttt{cirq.S}, etc.
\item Two-qubit gates: \texttt{cirq.CNOT}, \texttt{cirq.CZ},
\texttt{cirq.SWAP}, etc.
\end{itemize}
Example: Applying a Hadamard gate to qubit \(q0\) and a CNOT with \(q0\) as
control and \(q1\) as target:
\begin{minted}{python}
circuit = cirq.Circuit()
circuit.append(cirq.H(q0))
circuit.append(cirq.CNOT(q0, q1))
\end{minted}
\subsubsection*{Circuits and Moments}
A \emph{Circuit} in Cirq is composed of \emph{Moments}—collections of
operations that occur simultaneously (on disjoint sets of qubits). When you
append operations, Cirq automatically schedules them into moments.
\subsubsection*{Simulation and Measurement}
Cirq provides a simulator to compute the resulting state vector or sample
measurement outcomes.
\begin{itemize}
\item \texttt{simulate()}: Returns the final state vector.
\item \texttt{run()}: Samples measurement outcomes.
\end{itemize}
\textbf{Example: Creating and Simulating a Bell State}
\begin{minted}{python}
import cirq
# Create two line qubits.
q0, q1 = cirq.LineQubit.range(2)
# Construct the Bell state circuit.
bell_circuit = cirq.Circuit(
cirq.H(q0), # Create superposition on q0.
cirq.CNOT(q0, q1) # Entangle q0 with q1.
)
print("Bell Circuit:")
print(bell_circuit)
# Initialize the simulator.
simulator = cirq.Simulator()
# Simulate to obtain the final state vector.
result = simulator.simulate(bell_circuit)
print("Final state vector:")
print(result.final_state_vector)
# Add measurement and run the circuit.
bell_circuit.append(cirq.measure(q0, q1, key='result'))
samples = simulator.run(bell_circuit, repetitions=1024)
print("Measurement histogram:")
print(samples.histogram(key='result'))
\end{minted}
\subsubsection*{Advanced Topics in Cirq}
Cirq also supports:
\begin{itemize}
\item \textbf{Parameter Sweeps}: Optimize variational algorithms using free
parameters.
\item \textbf{Unitary Access and Decomposition}: Retrieve matrix
representations and decompose complex gates.
\item \textbf{Transformers}: Automatically merge or re-schedule operations
for hardware compatibility.
\end{itemize}
\textbf{Example: Sweeping a Parameter in an \(X\) Gate}
\begin{minted}{python}
import sympy
import matplotlib.pyplot as plt
# Define a qubit.
q = cirq.GridQubit(1, 1)
# Create a circuit with an X gate raised to a symbolic exponent.
circuit = cirq.Circuit(cirq.X(q) ** sympy.Symbol('t'),
cirq.measure(q, key='m'))
# Sweep the parameter 't' from 0 to 2.
param_sweep = cirq.Linspace('t', start=0, stop=2, length=200)
# Simulate the sweep.
simulator = cirq.Simulator()
trials = simulator.run_sweep(circuit, param_sweep, repetitions=1000)
# Plot the frequency of measuring 1.
x_data = [trial.params['t'] for trial in trials]
y_data = [trial.histogram(key='m')[1] / 1000.0 for trial in trials]
plt.scatter(x_data, y_data)
plt.xlabel("Parameter t")
plt.ylabel("Frequency of 1")
plt.show()
\end{minted}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% End of Lecture 8
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%