Visualizing quantum walks on small graphs
This page has all the Julia code necessary for creating the images; as such, it must begin with a couple of trivialities, as loading the dependencies and defining the adjacency matrix of a graph.
xxxxxxxxxx
6
1
begin
2
using LinearAlgebra
3
using LightGraphs
4
using Plots
5
using Printf
6
end
adjacency_matrix (generic function with 2 methods)
xxxxxxxxxx
13
1
begin
2
3
function adjacency_matrix(n :: Int64, e :: AbstractEdge)
4
f(i :: Int64) = [ convert(Float64, i == j) for j in 1:n ]
5
f(src(e)) .* f(dst(e))' + f(dst(e)) .* f(src(e))'
6
end
7
8
function adjacency_matrix(G :: SimpleGraph)
9
f(e) = adjacency_matrix(nv(G), e)
10
sum(f.(edges(G)))
11
end
12
13
end
Quantum Walk representation
I am representing a quantum walk as the adjacency matrix of the graph.
QuantumWalk
1
begin
2
struct QuantumWalk
3
A :: Matrix
4
end
5
6
function QuantumWalk(G :: SimpleGraph)
7
QuantumWalk(adjacency_matrix(G))
8
end
9
end
I also created a custom heatmap
function for displaying the matrices.
heatmap (generic function with 1 method)
xxxxxxxxxx
10
1
function heatmap(A :: Matrix; kargs...)
2
Plots.heatmap(A;
3
clim=(0.0, 1.0),
4
framestyle = :none,
5
ticks = false,
6
aspectratio = :equal,
7
c = :thermal,
8
kargs...
9
)
10
end
Then it is easy to create an animation: Just iterate over a bunch of times and display the component-wise absolute value of
animate (generic function with 1 method)
x
1
function animate(walk :: QuantumWalk, t0 :: Float64, t1 :: Float64)
2
step = (t1 - t0)/200
3
animation = for t in t0:step:t1
4
heatmap(abs.(exp(im * t * walk.A)), title= ("t = %.2f", t),)
5
end
6
gif(animation, fps=10)
7
end
Visualizations
I can now display some quantum walks. I will show for
xxxxxxxxxx
1
1
animate(QuantumWalk(path_graph(2)), 0.0, 2.0 * pi)