-
Notifications
You must be signed in to change notification settings - Fork 4
Tutorial for adiabatic sweep #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
20d12ea
Add code for adiabatic sweep tutorial
TendonFFF 345082d
1st complete version of the tutorial
TendonFFF 61f374a
fix typo
TendonFFF e136ae8
fix lowrank.qmd
TendonFFF b7daa11
Fix indentation inconsistency and grammar
TendonFFF 9a9488b
fix text \emph
TendonFFF 7a96db2
Improve `QuantumObjectEvolution` usage and use `multisite_operator`
TendonFFF File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
--- | ||
title: "Adiabatic sweep (with `QuantumObjectEvolution`)" | ||
author: Li-Xun Cai | ||
date: 2025-04-09 # last update (keep this comment as a reminder) | ||
|
||
engine: julia | ||
--- | ||
|
||
Inspirations taken from [the QuTiP tutorial](https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v5/lectures/Lecture-8-Adiabatic-quantum-computing.ipynb) by J. R. Johansson. | ||
|
||
This tutorial mainly demonstrates the use of [`QuantumObjectEvolution`](https://qutip.org/QuantumToolbox.jl/stable/resources/api#QuantumToolbox.QuantumObjectEvolution). | ||
|
||
## Introduction | ||
|
||
The quantum adiabatic theorem is a fundamental principle in quantum mechanics that describes how quantum systems evolve when subjected to time-dependent conditions. This theorem states that if a quantum system is initialized in an eigenstate (typically the ground state) of its initial Hamiltonian, and if the Hamiltonian changes sufficiently slow, the system will remain in the corresponding eigenstate of the evolving Hamiltonian throughout the process. | ||
|
||
For this theorem to hold, certain conditions must be satisfied: the system must evolve slow enough compared to the energy gap between the relevant eigenstate and other energy levels, and this gap must remain non-zero throughout the evolution. | ||
|
||
Here, we will demonstrate the well-known application of the adiabatic theorem in quantum computing called $\text{\emph{adiabatic sweep}}$. This is a method for preparing some desired quantum state by slowly evolving a quantum system with a time-dependent Hamiltonian. Essentially, the adiabatic theorem allows us to prepare the ground state of the final Hamiltonian $H_1$ from the ground state of the initial Hamiltonian $H_0$. | ||
|
||
## Model | ||
|
||
We consider a chain of $N$-identical spin-$1/2$ particles to study their spin dynamics and set our interest in finding the ground state of the condition that the spin chain has some random gap, leading to the random magnitude $g_i$ of $\hat{\sigma}^i_x \hat{\sigma}^{i+1}_x$ interaction with the neighboring spin. | ||
|
||
Initially, we prepare the system such that the spins are free from interaction with each other and are all in the ground state, i.e., | ||
|
||
$$H_0 = \sum_i^N \frac{\varepsilon_0}{2} \hat{\sigma}^i_z,$$ | ||
$$|\psi(0)\rangle = \bigotimes_{i=1}^N |g\rangle$$ | ||
|
||
Then, gradually, the Hamiltonian evolves to: | ||
|
||
$$H_1 = \sum_{i=1}^N \frac{\varepsilon_0}{2} \hat{\sigma}^i_z + \sum_{i=1}^{N-1} g_i \hat{\sigma}^i_x \hat{\sigma}^{i+1}_x,$$ | ||
|
||
whose ground state are desired. By gradual change, we are subject to the simplest form of adiabatic sweep, i.e., | ||
|
||
$$H(t,T) = H_0 * (1-t/T) + H_1 * t/T,$$ | ||
|
||
where the parameter $T$ determines how slow the Hamiltonian changes in time. | ||
|
||
## Code demonstration | ||
|
||
```{julia} | ||
using QuantumToolbox | ||
using CairoMakie | ||
``` | ||
|
||
```{julia} | ||
N = 8 # number of spins | ||
ε0 = 1 # energy gap of the spins | ||
|
||
gs = rand(N-1) # use rand function for the random interaction strengths | ||
``` | ||
|
||
```{julia} | ||
Is = Vector{QuantumObject}(fill(qeye(2), N)); | ||
|
||
H0 = QuantumObject( | ||
zeros((2^N, 2^N)), | ||
Operator, | ||
Tuple(fill(2, N)) | ||
) | ||
|
||
for idx in 1:N | ||
is = copy(Is) | ||
is[idx] = ε0/2 * sigmaz() | ||
H0 += kron(is...) | ||
end | ||
|
||
ψ0 = kron(fill(basis(2,1), N)...) | ||
print(H0) | ||
TendonFFF marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
```{julia} | ||
H1 = QuantumObject( | ||
zeros((2^N, 2^N)), | ||
Operator, | ||
Tuple(fill(2, N)) | ||
) | ||
|
||
for idx in 1:N | ||
is = copy(Is) | ||
is[idx] = ε0/2 * sigmaz() | ||
H1 += kron(is...) | ||
end | ||
|
||
for idx in 1:N-1 | ||
is = copy(Is) | ||
is[idx] = gs[idx] * sigmax() | ||
is[idx+1] = sigmax() | ||
|
||
h_int = kron(is...) | ||
|
||
H1 += h_int | ||
end | ||
|
||
print(H1) | ||
TendonFFF marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
Here, we define the function `H(T)` where `T` is the total evolution time. | ||
```{julia} | ||
H(T) = QuantumObjectEvolution(( | ||
(H0, (p,t) -> 1 - t/T), # the dummy parameter `p` is not used but still required by the ODE solver | ||
(H1, (p,t) -> t/T), | ||
)) | ||
TendonFFF marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
```{julia} | ||
function ψg(H) | ||
_, vecs = eigenstates(H) | ||
return vecs[1] | ||
end | ||
|
||
ψf_truth = ψg(H1) |> to_sparse | ||
print(ψf_truth) | ||
``` | ||
|
||
We can see that the truthful ground state we are preparing is indeed very complex. | ||
|
||
For the adiabatic theorem to apply, we have to check for the gap between the ground state and first excited state remaining non-zero throughout the evolution. | ||
```{julia} | ||
T = 10 | ||
tlist = 0:0.1:T | ||
eigs = Array{Real}(undef, length(tlist), 2^N) | ||
TendonFFF marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
for (idx, t) in enumerate(tlist) | ||
vals, _ = eigenstates(H(T)(t)) | ||
eigs[idx,:] = vals | ||
end | ||
TendonFFF marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
```{julia} | ||
fig = Figure() | ||
TendonFFF marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ax = Axis(fig[1,1], xticks = (0:0.25:1, ["$(t)T" for t in 0:0.25:1])) | ||
|
||
for idx in 1:20 # only check for the lowest 20 eigenvalues | ||
color = (idx == 1) ? :magenta : (:gray,0.5) | ||
lines!(ax, range(0,1,length(tlist)), eigs[:,idx], label = string(idx), color = color) | ||
end | ||
|
||
display(fig) | ||
``` | ||
|
||
The plot shows that the gap is nonvanishing and thus validates the evolution. | ||
```{julia} | ||
Tlist = 10 .^ (0:0.25:1.25) | ||
results = map(Tlist) do T | ||
tlist = range(0,T, 101) | ||
sesolve(H(T), ψ0, tlist, e_ops = [H1, ket2dm(ψf_truth)]) | ||
# check the expectation value with respect to the final Hamiltonian and | ||
# the fidelity to the truthful ground state throughout the evolution | ||
end; | ||
TendonFFF marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
```{julia} | ||
fig = Figure(size = (800,400)) | ||
axs = Axis.([fig[1,1], fig[1,2]]) | ||
axs[1].title = L"\langle H_f \rangle" | ||
axs[1].xticks = (0:0.25:1, ["$(t)T" for t in 0:0.25:1]) | ||
axs[2].title = L"|\langle \psi_G^f |\psi(t)\rangle|^2" | ||
axs[2].xticks = (0:0.25:1, ["$(t)T" for t in 0:0.25:1]) | ||
|
||
for ax_idx in 1:2, T_idx in 1:length(Tlist) | ||
T = Tlist[T_idx] | ||
exps = results[T_idx].expect | ||
tlist = range(0,1,101) | ||
lines!(axs[ax_idx], tlist, real(exps[ax_idx,:]), label = L"10^{%$(string(log10(T)))}") | ||
end | ||
|
||
Legend(fig[1,3], axs[1], L"T") | ||
|
||
display(fig) | ||
``` | ||
As the plot showed, the fidelity between the prepared final state and the truthful ground state reaches 1 as the total evolution time $T$ increases, showcasing the requirement of the adiabatic theorem that the change has to be gradual. | ||
|
||
|
||
## Version Information | ||
```{julia} | ||
QuantumToolbox.versioninfo() | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.