Skip to content

Commit 2eafb66

Browse files
committed
adding codes and lecture slides
1 parent 0783860 commit 2eafb66

File tree

3 files changed

+227
-0
lines changed

3 files changed

+227
-0
lines changed

doc/src/week11/prograns/qpe.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import numpy as np
2+
3+
# Define basic quantum gates
4+
def hadamard(n):
5+
"""Creates an n-qubit Hadamard gate."""
6+
H = np.array([[1, 1], [1, -1]]) / np.sqrt(2)
7+
return np.linalg.matrix_power(np.kron(H, np.eye(2 ** (n - 1))), 1)
8+
9+
def phase_shift(theta):
10+
"""Single-qubit phase shift gate U = e^(2πiθ)."""
11+
return np.array([[1, 0], [0, np.exp(2j * np.pi * theta)]])
12+
13+
def controlled_U(U, n):
14+
"""Controlled-U gate for n qubits."""
15+
# Identity for control 0
16+
dim = 2 ** (n + 1)
17+
CU = np.eye(dim, dtype=complex)
18+
# Apply U when control is 1
19+
for i in range(2 ** n):
20+
if (i >> (n - 1)) & 1: # Check if the last qubit is 1
21+
CU[i, i] = U[1, 1]
22+
return CU
23+
24+
def inverse_qft(n):
25+
"""Inverse Quantum Fourier Transform (QFT†)."""
26+
dim = 2 ** n
27+
QFT = np.zeros((dim, dim), dtype=complex)
28+
omega = np.exp(-2j * np.pi / dim)
29+
for i in range(dim):
30+
for j in range(dim):
31+
QFT[i, j] = omega ** (i * j) / np.sqrt(dim)
32+
return QFT
33+
34+
# Initialize parameters
35+
t = 4 # Number of counting qubits (precision)
36+
theta = 0.3125 # Phase we are trying to estimate (0.3125 = 5/16)
37+
n_qubits = t + 1 # Total qubits (t counting + 1 target)
38+
39+
# Create the initial state |0...0⟩|1⟩
40+
state_dim = 2 ** n_qubits
41+
state = np.zeros(state_dim, dtype=complex)
42+
state[-1] = 1 # |0...01⟩
43+
44+
# Create Hadamard on counting qubits
45+
for i in range(t):
46+
H_i = np.eye(2 ** i) if i != 0 else 1
47+
H = np.kron(H_i, np.array([[1, 1], [1, -1]]) / np.sqrt(2))
48+
H = np.kron(H, np.eye(2 ** (t - i - 1)))
49+
state = H @ state
50+
51+
# Apply controlled U gates with increasing powers
52+
U = phase_shift(theta)
53+
for i in range(t):
54+
CU = controlled_U(np.linalg.matrix_power(U, 2 ** i), t)
55+
state = CU @ state
56+
57+
# Apply inverse QFT on counting qubits
58+
QFT_inv = inverse_qft(t)
59+
QFT_inv = np.kron(QFT_inv, np.eye(2)) # Do not apply on target qubit
60+
state = QFT_inv @ state
61+
62+
# Measure probabilities
63+
probabilities = np.abs(state) ** 2
64+
most_likely_state = np.argmax(probabilities)
65+
binary_result = bin(most_likely_state >> 1)[2:].zfill(t)
66+
estimated_phase = int(binary_result, 2) / (2 ** t)
67+
68+
# Output results
69+
print(f"Estimated Phase (binary): {binary_result}")
70+
print(f"Estimated Phase (decimal): {estimated_phase}")
71+
print(f"Actual Phase: {theta}")

doc/src/week13/Latexfiles/qrbm.pdf

167 KB
Binary file not shown.

doc/src/week13/Latexfiles/qrbm.tex

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
\documentclass[11pt]{article}
2+
\usepackage[margin=1in]{geometry}
3+
\usepackage{amsmath, amsfonts, amssymb, bm}
4+
\usepackage{graphicx}
5+
\usepackage{hyperref}
6+
\usepackage{physics}
7+
\usepackage{mathtools}
8+
\usepackage{braket}
9+
10+
\title{Advanced Topics in Quantum Boltzmann Machines}
11+
\author{Quantum Computing Lecture Series}
12+
\date{\today}
13+
14+
\begin{document}
15+
16+
\maketitle
17+
\tableofcontents
18+
\newpage
19+
20+
%-----------------------------------------------------------
21+
\section{Introduction to Quantum Boltzmann Machines (QBMs)}
22+
Quantum Boltzmann Machines (QBMs) are a quantum generalization of classical Boltzmann machines. They leverage quantum effects such as superposition and entanglement to model complex probability distributions. QBMs are well-suited for quantum machine learning tasks, particularly for generative modeling.
23+
24+
\subsection{Motivation}
25+
Classical Boltzmann Machines suffer from high-dimensional sampling complexity. Quantum mechanics offers exponential state space and quantum tunneling effects that can alleviate these issues.
26+
27+
\subsection{Key Concepts}
28+
\begin{itemize}
29+
\item Quantum States as Probability Distributions
30+
\item Quantum Tunneling for Escaping Local Minima
31+
\item Exponential State Space in Quantum Systems
32+
\end{itemize}
33+
34+
%-----------------------------------------------------------
35+
\section{Mathematical Framework}
36+
\subsection{Hamiltonian of a Quantum Boltzmann Machine}
37+
The quantum analog of the classical energy-based model is expressed by the Hamiltonian \( H \):
38+
39+
\begin{equation}
40+
H = H_Z + H_X,
41+
\end{equation}
42+
43+
where:
44+
\begin{align}
45+
H_Z &= -\sum_{i} b_i Z_i - \sum_{i<j} w_{ij} Z_i Z_j, \\[5pt]
46+
H_X &= -\sum_i \Gamma_i X_i.
47+
\end{align}
48+
49+
\begin{itemize}
50+
\item \( Z_i \) and \( X_i \) are Pauli operators acting on the \( i \)-th qubit.
51+
\item \( b_i \) represents the bias terms.
52+
\item \( w_{ij} \) represents the interaction between qubits.
53+
\item \( \Gamma_i \) is the transverse field strength.
54+
\end{itemize}
55+
56+
%-----------------------------------------------------------
57+
\subsection{Density Matrix and Boltzmann Distribution}
58+
The quantum Boltzmann distribution is defined by the density matrix:
59+
60+
\begin{equation}
61+
\rho = \frac{e^{-\beta H}}{Z},
62+
\end{equation}
63+
64+
where:
65+
\begin{itemize}
66+
\item \( \beta = 1/k_B T \) is the inverse temperature.
67+
\item \( Z = \Tr(e^{-\beta H}) \) is the partition function.
68+
\end{itemize}
69+
70+
In the classical case, this reduces to a Gibbs distribution.
71+
72+
%-----------------------------------------------------------
73+
\section{Training Quantum Boltzmann Machines}
74+
\subsection{Objective Function}
75+
The goal of training a QBM is to minimize the Kullback–Leibler (KL) divergence between the data distribution \( p_{\text{data}} \) and the model distribution \( p_{\theta} \):
76+
77+
\begin{equation}
78+
\mathcal{L}(\theta) = \text{KL}(p_{\text{data}} || p_{\theta}) = \sum_x p_{\text{data}}(x) \log \frac{p_{\text{data}}(x)}{p_{\theta}(x)}.
79+
\end{equation}
80+
81+
\subsection{Gradient-Based Optimization}
82+
The gradient of the loss function is computed using:
83+
84+
\begin{equation}
85+
\nabla_\theta \mathcal{L}(\theta) = \mathbb{E}_{p_{\text{data}}}[\nabla_\theta E(x)] - \mathbb{E}_{p_{\theta}}[\nabla_\theta E(x)],
86+
\end{equation}
87+
88+
where \( E(x) \) is the energy function derived from the Hamiltonian.
89+
90+
%-----------------------------------------------------------
91+
\section{Quantum Sampling Techniques}
92+
\subsection{Quantum Monte Carlo Methods}
93+
Quantum Monte Carlo (QMC) simulates quantum systems by sampling from the quantum density matrix using classical resources. However, it faces limitations due to the **sign problem**.
94+
95+
\subsection{Quantum Annealing}
96+
Quantum annealers leverage adiabatic evolution to reach low-energy states efficiently:
97+
98+
\begin{equation}
99+
H(t) = (1 - t/T) H_B + (t/T) H_P,
100+
\end{equation}
101+
102+
where:
103+
\begin{itemize}
104+
\item \( H_B \) is the mixing Hamiltonian.
105+
\item \( H_P \) is the problem Hamiltonian.
106+
\end{itemize}
107+
108+
%-----------------------------------------------------------
109+
\section{Advantages and Challenges}
110+
\subsection{Advantages}
111+
\begin{itemize}
112+
\item Quantum Parallelism
113+
\item Efficient Sampling in Complex Systems
114+
\item Potential for Exponential Speedups
115+
\end{itemize}
116+
117+
\subsection{Challenges}
118+
\begin{itemize}
119+
\item Noisy Quantum Hardware
120+
\item High Cost of Quantum Simulation
121+
\item Quantum Decoherence
122+
\end{itemize}
123+
124+
%-----------------------------------------------------------
125+
\section{Applications}
126+
\subsection{Generative Modeling}
127+
Quantum Boltzmann Machines can generate complex probability distributions with applications in:
128+
\begin{itemize}
129+
\item Image and Text Generation
130+
\item Quantum Chemistry
131+
\item Financial Modeling
132+
\end{itemize}
133+
134+
\subsection{Optimization Problems}
135+
QBMs are suitable for solving optimization problems where classical approaches suffer from local minima.
136+
137+
%-----------------------------------------------------------
138+
\section{Conclusion}
139+
Quantum Boltzmann Machines offer a promising path for leveraging quantum resources in machine learning. While hardware limitations currently restrict scalability, ongoing research in quantum algorithms and quantum hardware is likely to overcome these obstacles.
140+
141+
%-----------------------------------------------------------
142+
\section{References}
143+
\begin{thebibliography}{9}
144+
145+
\bibitem{Amin2018}
146+
M. Amin et al., "Quantum Boltzmann Machines", \textit{Physical Review X}, 2018.
147+
148+
\bibitem{Hinton1985}
149+
G. Hinton, "Boltzmann Machines: Constraints and Learning", \textit{Cognitive Science}, 1985.
150+
151+
\bibitem{Nielsen2000}
152+
M. Nielsen and I. Chuang, "Quantum Computation and Quantum Information", Cambridge University Press, 2000.
153+
154+
\end{thebibliography}
155+
156+
\end{document}

0 commit comments

Comments
 (0)