Skip to content

Commit 4363ed3

Browse files
committed
update
1 parent 6743ea9 commit 4363ed3

File tree

3 files changed

+3712
-0
lines changed

3 files changed

+3712
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import pennylane as qml
2+
from pennylane import numpy as np
3+
4+
# Heisenberg coefficients
5+
a1, a2, a3 = 1.0, 0.5, 0.8
6+
7+
# Quantum device (statevector backend)
8+
dev = qml.device("default.qubit", wires=2)
9+
10+
# Ansatz circuit with 4 parameters
11+
def ansatz(params):
12+
qml.RY(params[0], wires=0)
13+
qml.RY(params[1], wires=1)
14+
qml.CNOT(wires=[0, 1])
15+
qml.RY(params[2], wires=0)
16+
qml.RY(params[3], wires=1)
17+
18+
# Measurement circuits
19+
@qml.qnode(dev)
20+
def measure_xx(params):
21+
ansatz(params)
22+
qml.Hadamard(0)
23+
qml.Hadamard(1)
24+
return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1))
25+
26+
@qml.qnode(dev)
27+
def measure_yy(params):
28+
ansatz(params)
29+
qml.S(0).inv()
30+
qml.Hadamard(0)
31+
qml.S(1).inv()
32+
qml.Hadamard(1)
33+
return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1))
34+
35+
@qml.qnode(dev)
36+
def measure_zz(params):
37+
ansatz(params)
38+
return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1))
39+
40+
# Cost function = weighted sum of expectation values
41+
def cost(params):
42+
return a1 * measure_xx(params) + a2 * measure_yy(params) + a3 * measure_zz(params)
43+
44+
# Initialize parameters
45+
np.random.seed(42)
46+
params = np.random.uniform(0, np.pi, 4, requires_grad=True)
47+
48+
# Optimization loop
49+
opt = qml.AdamOptimizer(stepsize=0.2)
50+
max_iter = 100
51+
52+
for i in range(max_iter):
53+
params, energy = opt.step_and_cost(cost, params)
54+
if i % 10 == 0:
55+
print(f"Iter {i:03d} | Energy: {energy:.6f}")
56+
57+
print("\nFinal VQE energy:", energy)
58+
59+
60+
# Exact energy for comparison
61+
# Pauli matrices
62+
X = np.array([[0, 1], [1, 0]])
63+
Y = np.array([[0, -1j], [1j, 0]])
64+
Z = np.array([[1, 0], [0, -1]])
65+
I = np.eye(2)
66+
67+
H_matrix = (
68+
a1 * np.kron(X, X)
69+
+ a2 * np.kron(Y, Y)
70+
+ a3 * np.kron(Z, Z)
71+
)
72+
73+
eigvals = np.linalg.eigvalsh(H_matrix)
74+
print("Exact ground state energy:", np.min(eigvals))

doc/src/week7/.dlog

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,3 +422,206 @@ states, again as expected due to the ratio of the interaction matrix
422422
elements and the single-particle energies.
423423

424424

425+
*** error: more than one subsection in a slide (insert missing !split):
426+
% !split
427+
\subsection{Quantum computing and solving the eigenvalue problem for the Lipkin model}
428+
429+
We will study a simpler variant of the Lipkin model without the $W$-term and a total spin of $J=1$ only as maximum value of the spin.
430+
This corresponds to a system with $N=2$ particles (fermions in our case).
431+
Our Hamiltonian is given by the quasispin operators (see below)
432+
\[
433+
\hat{H} = \epsilon\hat{J}_z -\frac{1}{2}V(\hat{J}_+\hat{J}_++\hat{J}_-\hat{J}_-).
434+
\]
435+
436+
As discussed earlier
437+
the quasispin operators act like lowering and raising angular momentum
438+
operators.
439+
440+
With these properties we can calculate the Hamiltonian
441+
matrix for the Lipkin model by computing the various matrix elements
442+
\begin{equation}
443+
\langle JJ_z|H|JJ_z'\rangle,
444+
\end{equation}
445+
where the non-zero elements are given by
446+
\[
447+
\begin{split}
448+
\langle JJ_z|H|JJ_z'\rangle & = \epsilon J_z\\
449+
\langle JJ_z|H|JJ_z'\pm 2\rangle & = \langle JJ_z\pm 2|H|JJ_z'\rangle \\ &= -\frac{1}{2}VC,
450+
\end{split}
451+
\]
452+
where $C$ is the Clebsch-Gordan coefficients (from the raising and lowering operators) one gets when
453+
$J_{\pm}^2$ operates on the state $|JJ_z\rangle$. Using the above
454+
definitions we can calculate the exact solution to the Lipkin model.
455+
456+
With the $V$-interaction terms, we obtain the following Hamiltonian matrix
457+
\begin{equation}
458+
\begin{pmatrix}-\epsilon & 0 & -V\\
459+
0&0&0\\
460+
-V&0&\epsilon
461+
\end{pmatrix}
462+
\end{equation}
463+
464+
\subsection{Quantum Circuit, rewriting the Lipkin model in terms of Pauli matrices}
465+
466+
Before we proceed however, we need to rewrite the quasispin operators in terms of Pauli spin matrices/operators.
467+
468+
We take the liberty here of reminding you of some of the derivations done previously.
469+
470+
We defined the number operator as
471+
\[
472+
N=\sum_{n\sigma}a^\dagger_{n\sigma}a_{n\sigma},
473+
\]
474+
475+
which commutes with the Lipkin Hamiltonian. This can be seen by
476+
examining the Lipkin model Hamiltonian and noticing that the one-body
477+
part simply counts particles while the two-body term moves particles
478+
in pairs. Thus, the Hamiltonian conserves particle number. To find
479+
more symmetries we rewrote the Lipkin Hamiltonian in terms of $SU(2)$ quasispin
480+
operators
481+
\begin{align}
482+
H = \epsilon J_z + \frac{1}{2}V(J^2_++J^2_-),
483+
\end{align}
484+
via the mappings
485+
\[
486+
J_z=\sum_{n}j_z^{(n)},
487+
\]
488+
and
489+
\[
490+
J_\pm=\sum_nj^{(n)}_{\pm},
491+
\]
492+
where we have the onebody operators
493+
\[
494+
j_z^{(n)}=\frac{1}{2}\sum_{\sigma}\sigma a^\dagger_{n\sigma}a_{n\sigma},
495+
\]
496+
and
497+
\[
498+
j^{(n)}_{\pm}=a^\dagger_{n\pm}a_{n\mp}.
499+
\]
500+
501+
These operators obey the $SU(2)$ commutation relations
502+
503+
\[
504+
[J_+,J_-]=2J_z,
505+
\]
506+
and
507+
\[
508+
[J_z,J_\pm]=\pm J_\pm.
509+
\]
510+
Here the ladder operators are defined as $J_{\pm}= J_x\pm iJ_y$. With this rewriting, we can see that the total spin operator $J^2$, which is defined as
511+
\[
512+
J^2= J^2_x+J^2_y+J^2_z =
513+
\frac{1}{2}\{J_+,J_-\}+J_z^2,
514+
\]
515+
commutes with the Hamiltonian since the Hamiltonian.
516+
We note also that the rotation operator
517+
\[
518+
R=e^{i\phi J_z},
519+
\]
520+
commutes with the Hamiltonian, which can be explained as follows. Writing $J_z$ as
521+
\[
522+
J_z=\frac{1}{2}(N_+-N_-),
523+
\]
524+
where $N_\pm=\sum_{n\pm}a^\dagger_{n\pm}a_{n\pm}$, allows us to see that it measures half the difference between the number of particles in the upper and lower levels. Thus, the possible eigenvalues $r$ of the signature operator are
525+
\begin{align}
526+
r=+1, & j_z=2n \\
527+
r=+i, & j_z=2n+\frac{1}{2} \\
528+
r=-1, & j_z=2n+1 \\
529+
r=-i, & j_z=2n+\frac{3}{2} \\
530+
\end{align}
531+
532+
for $n\in\mathbb{Z}$. Note that $r$ is real or imaginary if the number
533+
of particles $N$ is even or odd, respectively. Since, as discussed
534+
above, the Lipkin Hamiltonian conserves $N$, $r$ cannot jump between
535+
being real and imaginary. Additionally, because particles must be
536+
moved in pairs, and $J_z$ measures half the difference between
537+
particles in the upper and lower levels, $j_z$ can only change by as
538+
539+
\[
540+
j_z\rightarrow \frac{1}{2}[(N_+\pm 2n)-(N_-\mp 2n)]
541+
\]
542+
or $j_z\rightarrow J_z\pm2n$.
543+
544+
To solve the Lipkin model with a quantum computer, the first step is
545+
to map the system to a set of qubits. We will restrict ourselves here
546+
to the half-filled case where the number of particles $N$ equals the
547+
degeneracy of the states $\Omega$. One could assign each possible
548+
state $(n,\sigma)$ a qubit such that the qubit being in the state
549+
$\vert 1\rangle$ or $\vert 0\rangle$ would imply that the state
550+
$(n,\sigma)$ is occupied or unoccupied, respectively. This mapping
551+
scheme (which we will call occupation mapping) requires 2$\Omega$
552+
qubits.
553+
554+
However, because there are only two energy levels in the Lipkin model,
555+
any other natural mapping is possible. In this mapping scheme (which
556+
we will call level mapping) each doublet ($(n,+1)$, $(n,-1)$) would be
557+
assigned a qubit such that the qubit being in the state $\vert 0\rangle$ or
558+
$\vert 1\rangle$ would imply that the particle is in the $(n,+1)$ or $(n,-1)$
559+
state, respectively. Note that these are the only two possible
560+
configurations of the doublet as we are restricting ourselves to the
561+
half-filled case and the Lipkin Hamiltonian only moves particles
562+
between energy levels, not degenerate states. Thus the level mapping
563+
only requires $\Omega$ qubits which is half that of the occupation
564+
mapping.
565+
566+
The Hamiltonian takes the form
567+
568+
\begin{align}
569+
H=\epsilon J_z + \frac{1}{2}V(J^2_++J^2_-).
570+
\end{align}
571+
572+
Plugging the mapping from the total $J$ operators to the individual one-body $j$ operators yields
573+
574+
\begin{align}
575+
H &= \epsilon\sum_{n}j_z^{(n)} + \frac{1}{2}V\left[\left(\sum_nj^{(n)}_{+}\right)^2+\left(\sum_nj^{(n)}_{-}\right)^2\right]
576+
\\
577+
&= \epsilon\sum_{n}j_z^{(n)} + \frac{1}{2}V\sum_{n,m}\left(j^{(n)}_+j^{(m)}_++j^{(n)}_-j^{(m)}_-\right)
578+
\\
579+
&= \epsilon\sum_{n}j_z^{(n)} + 2V\sum_{n<m}\left(j^{(n)}_xj^{(m)}_x-j^{(n)}_yj^{(m)}_y\right),
580+
\end{align}
581+
where we have used the definitions
582+
\[
583+
j_{\pm}^{(n)}=j_x^{(n)}\pm ij_y^{(n)}.
584+
\]
585+
To convert to Pauli matrices, we make the transformations
586+
\[
587+
j_x^{(n)} \rightarrow X_n/2,
588+
\]
589+
and
590+
\[
591+
j_y^{(n)} \rightarrow Y_n/2,
592+
\]
593+
and finally
594+
\[
595+
j_z^{(n)} \rightarrow Z_n/2,
596+
\]
597+
which preserve the above $SU(2)$ commutation relations.
598+
The factor of $1/2$
599+
is due to the eigenvalues of the Pauli matrices being $\pm 1$
600+
while we are dealing with spin $1/2$ particles.
601+
602+
This transforms our Hamiltonian into
603+
\[
604+
H=\frac{1}{2}\epsilon\sum_{k=1}^nZ_k+\frac{1}{2}V\sum_{n\neq j=1}^N(X_kX_j-Y_kY_j).
605+
\]
606+
607+
With this form, we can clearly see that the first (one-body) term in
608+
the Hamiltonian returns the energy $-\epsilon/2$ or $+\epsilon/2$ if
609+
the qubit representing the particle of a doublet is in the ground
610+
($\vert 1\rangle$) or excited ($\vert 0\rangle$) state,
611+
respectively. The action of the second (two-body) term in the
612+
Hamiltonian can be determined by noting that
613+
\begin{align}
614+
\frac{1}{2}(XX-YY)\vert 00\rangle &= \vert 11\rangle,
615+
\\
616+
\frac{1}{2}(XX-YY)\vert 01\rangle &= 0,
617+
\\
618+
\frac{1}{2}(XX-YY)\vert 10\rangle &= 0,
619+
\\
620+
\frac{1}{2}(XX-YY)\vert 11\rangle &= \vert 00\rangle.
621+
\end{align}
622+
623+
That is, the two-body term moves a pair of particles between the
624+
ground states $\vert 00\rangle$ and the excited states $\vert
625+
11\rangle$ of their respective doublets.
626+
627+

0 commit comments

Comments
 (0)