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
begin
using LinearAlgebra
using LightGraphs
using Plots
using Printf
end
adjacency_matrix (generic function with 2 methods)
xxxxxxxxxx
begin
function adjacency_matrix(n :: Int64, e :: AbstractEdge)
f(i :: Int64) = [ convert(Float64, i == j) for j in 1:n ]
f(src(e)) .* f(dst(e))' + f(dst(e)) .* f(src(e))'
end
function adjacency_matrix(G :: SimpleGraph)
f(e) = adjacency_matrix(nv(G), e)
sum(f.(edges(G)))
end
end
Quantum Walk representation
I am representing a quantum walk as the adjacency matrix of the graph.
QuantumWalk
begin
struct QuantumWalk
A :: Matrix
end
function QuantumWalk(G :: SimpleGraph)
QuantumWalk(adjacency_matrix(G))
end
end
I also created a custom heatmap
function for displaying the matrices.
heatmap (generic function with 1 method)
xxxxxxxxxx
function heatmap(A :: Matrix; kargs...)
Plots.heatmap(A;
clim=(0.0, 1.0),
framestyle = :none,
ticks = false,
aspectratio = :equal,
c = :thermal,
kargs...
)
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
function animate(walk :: QuantumWalk, t0 :: Float64, t1 :: Float64)
step = (t1 - t0)/200
animation = for t in t0:step:t1
heatmap(abs.(exp(im * t * walk.A)), title= ("t = %.2f", t),)
end
gif(animation, fps=10)
end
Visualizations
I can now display some quantum walks. I will show for
xxxxxxxxxx
animate(QuantumWalk(path_graph(2)), 0.0, 2.0 * pi)
x
animate(QuantumWalk(path_graph(3)), 0.0, sqrt(2) * pi)
We can also observe the instantaneous uniform mixing of the claw graph at
.
xxxxxxxxxx
begin
claw_graph = SimpleGraph(4)
for i in 2:4
add_edge!(claw_graph, 1, i)
end
animate(QuantumWalk(claw_graph), 0.0, 4.0 * pi / (3 * sqrt(3)))
end
Cartesian product
There are two interesting things to do with the cartesian product. The first one is to watch how the quantum walk on the cartesian product reduces to the kronecker product in each matrix.
visualize_product (generic function with 1 method)
xxxxxxxxxx
function visualize_product(G :: SimpleGraph, H :: SimpleGraph, t0 :: Float64, t1 :: Float64)
step = (t1 - t0)/200
custom_heatmap(graph, t) =
heatmap(abs.(exp(im * t * adjacency_matrix(graph))), colorbar = false, title = "")
animation = for t in t0:step:t1
plot(
custom_heatmap(cartesian_product(G, H), t),
custom_heatmap(H, t),
custom_heatmap(G, t),
layout=3,
plot_title = "t = $(t)"
)
end
gif(animation, fps=10)
end
xxxxxxxxxx
visualize_product(path_graph(2), path_graph(2), 0.0, 2 * pi)
xxxxxxxxxx
visualize_product(path_graph(3), path_graph(3), 0.0, sqrt(2) * pi)
xxxxxxxxxx
visualize_product(path_graph(2), path_graph(3), 0.0, 2.0 * pi)
We may also consider the cartesian powers of a graph, and visualize the behavior of the quantum walks on them.
cartesian_power (generic function with 1 method)
xxxxxxxxxx
function cartesian_power(G :: SimpleGraph, k :: Int64)
if k == 0
SimpleGraph(1)
else
cartesian_product(G, cartesian_power(G, k - 1))
end
end
xxxxxxxxxx
animate(QuantumWalk(cartesian_power(path_graph(2), 2)), 0.0, 2.0 * pi)
xxxxxxxxxx
animate(QuantumWalk(cartesian_power(path_graph(3), 4)), 0.0, sqrt(2) * pi)