Skip to content

Commit 9180cc9

Browse files
committed
update week 6
1 parent c43fd69 commit 9180cc9

File tree

8 files changed

+1367
-1362
lines changed

8 files changed

+1367
-1362
lines changed

doc/pub/week6/html/week6-bs.html

Lines changed: 189 additions & 188 deletions
Large diffs are not rendered by default.

doc/pub/week6/html/week6-reveal.html

Lines changed: 181 additions & 181 deletions
Large diffs are not rendered by default.

doc/pub/week6/html/week6-solarized.html

Lines changed: 180 additions & 179 deletions
Large diffs are not rendered by default.

doc/pub/week6/html/week6.html

Lines changed: 180 additions & 179 deletions
Large diffs are not rendered by default.
0 Bytes
Binary file not shown.

doc/pub/week6/ipynb/week6.ipynb

Lines changed: 493 additions & 493 deletions
Large diffs are not rendered by default.

doc/pub/week6/pdf/week6.pdf

-234 Bytes
Binary file not shown.

doc/src/week6/week6.do.txt

Lines changed: 144 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,31 @@ variational quantum eigensolver is based on the variational principle:
238238

239239

240240

241+
242+
243+
!split
244+
===== Rayleigh-Ritz variational principle =====
245+
246+
The Rayleigh-Ritz variational principle states that for a given
247+
Hamiltonian $H$, the expectation value of a trial state or
248+
just ansatz $\vert \psi \rangle$ puts a lower bound on the ground state
249+
energy $E_0$.
250+
251+
!bt
252+
\[
253+
\frac{\langle \psi \vert H\vert \psi \rangle}{\langle \psi \vert \psi \rangle} \geq E_0.
254+
\]
255+
!et
256+
257+
!split
258+
===== The ansatz =====
259+
260+
The ansatz is typically chosen to be a parameterized superposition of
261+
basis states that can be varied to improve the energy estimate,
262+
$\vert \psi\rangle \equiv \vert \psi(\boldsymbol{\theta})\rangle$ where
263+
$\boldsymbol{\theta} = (\theta_1, \ldots, \theta_M)$ are the $M$
264+
optimization parameters.
265+
241266
!split
242267
===== Expectation value of Hamiltonian =====
243268

@@ -256,7 +281,7 @@ H|n\rangle=E_n|n\rangle.
256281
!split
257282
===== Expanding in the eigenstates =====
258283

259-
We can then expand our state $|\psi(\theta)\rangle$ in terms of said eigenstates
284+
We can then expand our state $|\psi(\theta)\rangle$ in terms of the eigenstates
260285

261286
!bt
262287
\[
@@ -278,6 +303,7 @@ which implies that we can minimize over the set of angles $\theta$ and arrive at
278303
\]
279304
!et
280305

306+
281307
!split
282308
===== Basic steps of the VQE algorithm =====
283309

@@ -301,6 +327,120 @@ FIGURE: [figures/vqe.png, width=700 frac=0.9]
301327

302328

303329

330+
!split
331+
===== Rotations =====
332+
333+
To have any flexibility in the
334+
ansatz $\vert \psi\rangle$, we need to allow for a given parametrization. The most
335+
common approach is the so-called $R_y$ ansatz, where we apply chained
336+
operations of rotating around the $y$-axis by $\boldsymbol{\theta} =
337+
(\theta_1,\ldots,\theta_Q)$ of the Bloch sphere and CNOT operations.
338+
339+
Applications of $y$ rotations
340+
specifically ensures that our coefficients always remain real, which
341+
often is satisfactory when dealing with many-body systems.
342+
343+
344+
345+
!split
346+
===== Measurements and more =====
347+
348+
After the ansatz has been constructed, the Hamiltonian must
349+
be applied. The Hamiltonian must be written in terms of
350+
Pauli strings in order to perform measurements properly.
351+
352+
To obtain the expectation value
353+
of the ground state energy, one can measure the expectation value of
354+
each Pauli string,
355+
!bt
356+
\begin{align*}
357+
E(\boldsymbol{\theta}) = \sum_i w_i\langle \psi(\boldsymbol{\theta})\vert P_i \vert \psi(\boldsymbol{\theta})\rangle \equiv \sum_i w_i f_i,
358+
\end{align*}
359+
!et
360+
where $f_i$ is the expectation value of the Pauli string $i$.
361+
362+
363+
!split
364+
===== Collecting data =====
365+
366+
This is estimated statistically by considering measurements in the
367+
appropriate basis of the operator in the Pauli string.
368+
369+
With $N_0$ and $N_1$ as the number of $0$ and $1$ measurements respectively, we can estimate $f_i$ since
370+
!bt
371+
\begin{align*}
372+
f_i = \lim_{N \to \infty} \frac{N_0 - N_1}{N},
373+
\end{align*}
374+
!et
375+
where $N$ as the number of shots (measurements).
376+
377+
Each Pauli string requires it own circuit, where multiple measurements
378+
of each string is required. Adding the results together with the
379+
corresponding weights, the ground state energy can be estimated. To
380+
optimize with respect to $\boldsymbol{\theta}$, a classical optimizer is often
381+
applied.
382+
383+
384+
!split
385+
===== Ansatzes =====
386+
387+
Every possible qubit wavefunction $\left| \psi \right\rangle$ can be presented as a vector:
388+
!bt
389+
\[
390+
\left| \psi \right\rangle = \begin{pmatrix}
391+
\cos{\left( \theta/2 \right)}\\
392+
e^{i \varphi} \cdot \sin{\left( \theta/2 \right)}
393+
\end{pmatrix},
394+
\]
395+
!et
396+
397+
where the numbers $\theta$ and $\varphi$ define a point on the unit
398+
three-dimensional sphere, the so-called Bloch sphere.
399+
400+
For a random one qubit Hamiltonian, a *good* quantum state preparation
401+
circuit should be able to generate all possible states on the Bloch
402+
sphere.
403+
404+
!split
405+
===== Preparing the states =====
406+
407+
Before quantum state preparation, our qubit is in the $\vert 0\rangle$ state.
408+
This corresponds to the vertical position of
409+
the vector in the Bloch sphere. In order to generate any possible
410+
$\left| \psi \right\rangle$ we will apply $R_x(t_1)$ and $R_y(t_2)$
411+
gates on the $\left| 0 \right\rangle$ initial state
412+
!bt
413+
\[
414+
R_y(\phi)R_x(\theta) \left| 0 \right\rangle = \left| \psi\right\rangle.
415+
\]
416+
!et
417+
418+
The rotation $R_x(\theta)$
419+
corresponds to the rotation in the Bloch
420+
sphere around the $x$-axis and $R_y(\phi)$ the rotation around the $y$-axis.
421+
422+
423+
!split
424+
===== Rotations used =====
425+
426+
These two gates with there parameters ($\theta$ and $\phi$) will generate
427+
for us the trial (ansatz) wavefunctions. The two parameters will be in
428+
control of the Classical Computer and its optimization model.
429+
430+
!split
431+
===== Implementing using qiskit =====
432+
!bc pycod
433+
import numpy as np
434+
from random import random
435+
from qiskit import *
436+
def quantum_state_preparation(circuit, parameters):
437+
q = circuit.qregs[0] # q is the quantum register where the info about qubits is stored
438+
circuit.rx(parameters[0], q[0]) # q[0] is our one and only qubit XD
439+
circuit.ry(parameters[1], q[0])
440+
return circuit
441+
!ec
442+
443+
304444

305445

306446
!split
@@ -310,7 +450,7 @@ To execute the second step of VQE, we need to understand how
310450
expectation values of operators can be estimated via quantum computers
311451
by post-processing measurements of quantum circuits in different
312452
basis sets. To rotate bases, one uses the basis rotator $R_\sigma$ which is
313-
defined for each Pauli gate $\sigma$ to be
453+
defined for each Pauli gate $\sigma$ to be (using the Hadamard rotation $H$ and Phase rotation $S$)
314454

315455
!bt
316456
\begin{align}
@@ -530,145 +670,6 @@ estimation subroutine within VQE requires $\mathcal{O}(1/\epsilon^2)$
530670
samples from circuits with depth $\mathcal{O}(1)$.
531671

532672

533-
!split
534-
===== Rayleigh-Ritz variational principle =====
535-
536-
The Rayleigh-Ritz variational principle states that for a given
537-
Hamiltonian $H$, the expectation value of a trial state or
538-
just ansatz $\vert \psi \rangle$ puts a lower bound on the ground state
539-
energy $E_0$.
540-
541-
!bt
542-
\[
543-
\frac{\langle \psi \vert H\vert \psi \rangle}{\langle \psi \vert \psi \rangle} \geq E_0.
544-
\]
545-
!et
546-
547-
!split
548-
===== The ansatz =====
549-
550-
The ansatz is typically chosen to be a parameterized superposition of
551-
basis states that can be varied to improve the energy estimate,
552-
$\vert \psi\rangle \equiv \vert psi(\boldsymbol{\theta})\rangle$ where
553-
$\boldsymbol{\theta} = (\theta_1, \ldots, \theta_M)$ are the $M$
554-
optimization parameters.
555-
556-
557-
558-
559-
!split
560-
===== Rotations again =====
561-
562-
To have any flexibility in the
563-
ansatz $\vert \psi\rangle$, we need to allow for parametrization. The most
564-
common approach is the so-called $R_y$ ansatz, where we apply chained
565-
operations of rotating around the $y$-axis by $\boldsymbol{\theta} =
566-
(\theta_1,\ldots,\theta_Q)$ of the Bloch sphere and CNOT operations.
567-
568-
Applications of $y$ rotations
569-
specifically ensures that our coefficients always remain real, which
570-
often is satisfactory when dealing with many-body systems.
571-
572-
573-
574-
!split
575-
===== Measurements and more =====
576-
577-
After the ansatz has been constructed, the Hamiltonian must
578-
be applied. As discussed, the Hamiltonian must be written in terms of
579-
Pauli strings.
580-
581-
To obtain the expectation value
582-
of the ground state energy, one can measure the expectation value of
583-
each Pauli string,
584-
!bt
585-
\begin{align*}
586-
E(\boldsymbol{\theta}) = \sum_i w_i\langle \psi(\boldsymbol{\theta})\vert P_i \vert \psi(\boldsymbol{\theta})\rangle \equiv \sum_i w_i f_i,
587-
\end{align*}
588-
!et
589-
where $f_i$ is the expectation value of the Pauli string $i$.
590-
591-
592-
!split
593-
===== Collecting data =====
594-
595-
This is estimated statistically by considering measurements in the
596-
appropriate basis of the operator in the Pauli string.
597-
598-
With $N_0$ and $N_1$ as the number of $0$ and $1$ measurements respectively, we can estimate $f_i$ since
599-
!bt
600-
\begin{align*}
601-
f_i = \lim_{N \to \infty} \frac{N_0 - N_1}{N},
602-
\end{align*}
603-
!et
604-
where $N$ as the number of shots (measurements).
605-
606-
Each Pauli string requires it own circuit, where multiple measurements
607-
of each string is required. Adding the results together with the
608-
corresponding weights, the ground state energy can be estimated. To
609-
optimize with respect to $\boldsymbol{\theta}$, a classical optimizer is often
610-
applied.
611-
612-
613-
!split
614-
===== Ansatzes =====
615-
616-
Every possible qubit wavefunction $\left| \psi \right\rangle$ can be presented as a vector:
617-
!bt
618-
\[
619-
\left| \psi \right\rangle = \begin{pmatrix}
620-
\cos{\left( \theta/2 \right)}\\
621-
e^{i \varphi} \cdot \sin{\left( \theta/2 \right)}
622-
\end{pmatrix},
623-
\]
624-
!et
625-
626-
where the numbers $\theta$ and $\varphi$ define a point on the unit
627-
three-dimensional sphere, the so-called Bloch sphere.
628-
629-
For a random one qubit Hamiltonian, a *good* quantum state preparation
630-
circuit should be able to generate all possible states in the Bloch
631-
sphere.
632-
633-
!split
634-
===== Preparing the states =====
635-
636-
Before quantum state preparation, our qubit is in the $\vert 0\rangle$ state.
637-
This corresponds to the vertical position of
638-
the vector in the Bloch sphere. In order to generate any possible
639-
$\left| \psi \right\rangle$ we will apply $R_x(t_1)$ and $R_y(t_2)$
640-
gates on the $\left| 0 \right\rangle$ initial state
641-
!bt
642-
\[
643-
R_y(\phi)R_x(\theta) \left| 0 \right\rangle = \left| \psi\right\rangle.
644-
\]
645-
!et
646-
647-
The rotation $R_x(\theta)$
648-
corresponds to the rotation in the Bloch
649-
sphere around the $x$-axis and $R_y(\phi)$ the rotation around the $y$-axis.
650-
651-
652-
!split
653-
===== Rotations used =====
654-
655-
These two gates with there parameters ($\theta$ and $\phi$) will generate
656-
for us the trial (ansatz) wavefunctions. The two parameters will be in
657-
control of the Classical Computer and its optimization model.
658-
659-
!split
660-
===== Implementing using qiskit =====
661-
!bc pycod
662-
import numpy as np
663-
from random import random
664-
from qiskit import *
665-
def quantum_state_preparation(circuit, parameters):
666-
q = circuit.qregs[0] # q is the quantum register where the info about qubits is stored
667-
circuit.rx(parameters[0], q[0]) # q[0] is our one and only qubit XD
668-
circuit.ry(parameters[1], q[0])
669-
return circuit
670-
!ec
671-
672673

673674
!split
674675
===== VQE and efficient computations of gradients =====
@@ -874,6 +875,7 @@ We have
874875
\end{pmatrix},
875876
\end{align*}
876877
!et
878+
877879
!split
878880
===== For the other two matrices =====
879881

@@ -1026,7 +1028,7 @@ For a one-qubit system we can reach every point on the Bloch sphere
10261028
(as discussed earlier) with a rotation about the $x$-axis and the
10271029
$y$-axis.
10281030

1029-
We can express this mathematically through the following operations (see whiteboard for the drawing), giving us a new state $\vert \psi\rangle$
1031+
We can express this mathematically through a a new state $\vert \psi\rangle$
10301032
!bt
10311033
\[
10321034
\vert\psi\rangle = R_y(\phi)R_x(\theta)\vert 0 \rangle.

0 commit comments

Comments
 (0)