\message{ !name(report_1.tex)}\documentclass[11pt]{article}
\usepackage[margin = 1in]{geometry}
\usepackage{amsmath,amsthm,amsfonts,amssymb}
\usepackage{mathtools}
\usepackage{color,graphicx,overpic}
\usepackage{mathrsfs}
\usepackage{enumitem}
\usepackage{braket}
\usepackage{parskip}
\usepackage[numbers]{natbib}
\usepackage[colorlinks,allcolors=blue]{hyperref}
\bibliographystyle{hyperabbrv}
\usepackage{caption}
\captionsetup[figure]{labelfont=bf}
% \bibliographystyle{plainnat}

\newtheorem{thm}{Theorem}
\newtheorem*{thm*}{Theorem}
\newtheorem{claim}[thm]{Claim}
\newtheorem{algorithm}{Algorithm}
\newtheorem{cor}[thm]{Corollary}
\newtheorem{lem}[thm]{Lemma}
\newtheorem{prop}[thm]{Proposition}
\newtheorem{proto}{Protocol}
\newtheorem{con}[thm]{Conjecture}
\theoremstyle{definition}
\newtheorem{remark}{Remark}
\newtheorem{observation}{Observation}
\newtheorem{example}{Example}
\newtheorem{conjecture}{Conjecture}
\newtheorem{dfn}[thm]{Definition}
\theoremstyle{plain}

% \newtheoremstyle{dotless}{}{}{\itshape}{}{\bfseries}{}{ }{}
% \theoremstyle{dotless}

% \newtheorem{theorem}{Theorem}[section]
% \newtheorem{corollary}{Corollary}[theorem]
% \newtheorem{claim}{Claim}[section]

\allowdisplaybreaks{}

\begin{document}

\message{ !name(report_1.tex) !offset(-3) }

\title{\bf Collision Probability in Pseudo-Random Quantum Circuits}
\date{July 27, 2017}
\author{Matthew Khoury}
\maketitle

\noindent\makebox[\linewidth]{\rule{\textwidth}{1pt}}
\numberwithin{equation}{section}

% \section{test}
% what do I want to write in this section This is how you cite something or someone {\cite{matthewkhoury96_2017}}, here is\cite{aaronson}, here is\cite{random_clifford}, this is\cite{n_and_c} \\
% \\
% Here is a figure

% \begin{figure}[!htp]
% \centering
% \includegraphics[width=.75\textwidth]{1D_circuit.pdf}
% \caption{Put a caption here}
% \end{figure}

\section{Introduction}
Current research suggests that quantum computers may be able to outperform classical computers in certain classes of algorithms. For example, as described in {\cite{supremacy_1}} and {\cite{supremacy_2}}, certain sampling tasks may be more efficient on small quantum computers than on current classical computers. Specifically, apply a set of random gates to $n$ qubits in the state $\ket{0}^{\otimes n}$, then measure the qubits in the computational basis.

One feasable way to accompish this task is to lay the $n$ qubits out onto a 1D, 2D, or 3D lattice and then apply a polynomial number of random two qubit gates. We will refer to such a set of gates as a \emph{pseudo-random quantum circuit}. In this paper, we will describe numerical simulations that we have used to test one of the statistical properties of these pseudo-random quantum circuits.

\section{Statistical Property of Pseudo-Random Quantum Circuits}

\subsection{Definition of Collision Probability}
Imagine we prepare two identical quantum states of $n$ qubits represented as $\ket{\psi} \in \mathbb{C}^{2^n}$. We then measure both states in the computational basis, letting random variables $M_1$ and $M_2$ denote the outcome of the two measurements. We then define the \emph{collision probability} $P_c$ as the probability of measuring the same state twice, so we have
\begin{equation}
P_c = P(M_1 = M_2)
\end{equation}
Using the basic rules of probability along with the fact that the two measurements are independent, we can simplify $P_c$ by writing
\begin{align}
  P_c &= P(M_1 = M_2) \\
      &= P \bigl( \bigl\{ \{M_1 = z_1\} \cap \{M_2 = z_1\} \bigr\} \cup \cdots \cup
        \bigl\{ \{M_1 = z_{2^n}\} \cap \{M_2 = z_{2^n}\} \bigr\} \bigr) \\
      &= \sum\limits_{z \in \mathbb{F}_2^n} P(\{M_1 = z\} \cap \{M_2 = z\}) \\
      &= \sum\limits_{z \in \mathbb{F}_2^n} P(M_1 = z) P(M_2 = z) \\
      &= \sum\limits_{z \in \mathbb{F}_2^n} {(p(z))}^2
\end{align}
Where $p(z)$ is the probability of measuring state $\ket{z}$ from $\ket{\psi}$. We know that we can write this probability as
\begin{equation}
  p(z) = |\braket{z | \psi}|^2 = \braket{z | \psi} \braket{z | \psi}^*
  = \braket{z | \psi} \braket{\psi | z}
\end{equation}
Likewise, we can rewrite the collision probability as
\begin{equation}\label{collision_probability}
  P_c = \sum\limits_{z \in \mathbb{F}_2^n} {(p(z))}^2
  = \sum\limits_{z \in \mathbb{F}_2^n} {\left( \braket{z | \psi} \braket{\psi | z} \right)}^2
\end{equation}

\subsection{Collision Probability in Pseudo-Random Quantum Circuits}\label{cp_conjecture}
If we have applied a total of $N = O(\text{poly}(n))$ gates in a psuedo-random quantum circuit, then the \emph{depth} $d$ of the circuit is defined as $d \sim N / n$. The statistical property of pseudo-random quantum circuits we are interested in testing is how the collision probability changes as a function of the depth of the circuit.Specifically, we would like test the following conjecture. \\
\begin{conjecture}\label{conjecture_1}
  A pseudo-random quantum circuit arranged in a $w$-dimensional lattice will have a collision probability
  \begin{equation}
    P_c = \frac{2^{O(n/d^w)}}{2^n}
  \end{equation}
  Equivalently, if we let $k = - \log_2(P_c)$, then we will have
  \begin{equation}
    k = - \log_2(P_c) = n - O\left( \frac{n}{d^w} \right)
    = n \left(1 - O\left( \frac{1}{d^w} \right) \right)
  \end{equation}
\end{conjecture}
We also say that the collision probability is \emph{saturated} once $k = n - 1$. Thus, the conjecture also predicts that collision probabiliy saturates when
\begin{equation}
  O\left(\frac{1}{d^w} \right) = \frac{1}{n} \quad \Rightarrow \quad
  d \sim n^{1/w}
\end{equation}

\section{The Stabilizer Formalism}

\subsection{Motivation}
In general, simulating a pseudo-random quantum circuit on a classical computer will take both exponentially large storage and an exponentially large runtime. Thus, in order to simulate a psuedo-random quantum circuit to numerically test Conjecture {\ref{conjecture_1}}, we make use of the Gottesman-Knill Theorem.

The Gottesman-Knill Theorem states that a quantum circuit composed only of Clifford Gates can be efficiently simulated on a classical computer. In this section, we review some of the mathematical principles underlying the Gottesman-Knill Theorem, as they will be necessary for explaining how our simulations work. Many concepts in this section can be found more thoroughly described in Chapter 10.5 of {\cite{nc}}.

\subsection{The Pauli Group}
We let $G_n$ denote the Pauli Group on $n$ qubits. Formally, we define \begin{equation}
  G_1 = \{ \pm I, \pm i I, \pm X, \pm iX, \pm Y, \pm i Y, \pm Z, \pm i Z \}
\end{equation}
Where
\begin{equation}
I =
\begin{bmatrix}
  1 & 0 \\
  0 & 1 \\
\end{bmatrix} \quad
X =
\begin{bmatrix}
  0 & 1 \\
  1 & 0 \\
\end{bmatrix} \quad
Y =
\begin{bmatrix}
  0 & -i \\
  i & 0 \\
\end{bmatrix} \quad
Z =
\begin{bmatrix}
  1 & 0 \\
  0 & -1 \\
\end{bmatrix}
\end{equation}
Likewise, the set $G_n$ consists of all the $n$-fold tensor product of the matrices in $G_1$. We see that the Pauli Group is closed under matrix multiplication, as these matrices satisfy
\begin{align}
  & X^2 = Y^2 = Z^2 = I \label{pauli_1}\\
  & XY = iZ \quad YX = -iZ \\
  & YZ = iX \quad ZY = -iX \\
  & ZX = iY \quad XZ = -iY \label{pauli_3}
\end{align}
From this we also see that all of the elements in $P_n$ either commute or anti-commute. We also note that any $g \in G_n$ can be written as
\begin{equation}\label{pauli_2}
  g = {(-1)}^a \ i^b \ g_1 \otimes g_2 \otimes \cdots \otimes
  g_n \quad \text{for} \quad a, b \in \mathbb{F}_2 \quad \text{and} \quad
  g_j \in \{ I, X, Y, Z \}
\end{equation}

\subsection{Isomorphism to $\mathbb{F}_2$}
We use $\mathbb{F}_2$ to refer to the finite field $\mathbb{F}_2 \in \{0, 1\}$. All operations are done modulo 2, so we will have $1 + 1 = 0$ and $x = -x$. We can also see that $\mathbb{F}_2$ defines a group closed under addition modulo 2.

We define the map $M: \mathbb{F}_2^2 \rightarrow \{I, X, Y, Z\}$ as
\begin{equation}
  00 \rightarrow I, \quad 01 \rightarrow Z, \quad 10 \rightarrow X, \quad
  11 \rightarrow Y
\end{equation}
Likewise, from {\ref{pauli_2}}, if we let $u = (u_s, u_i, u_{x_1}, \ldots, u_{x_n}, u_{z_1}, \ldots, u_{z_n}) \in \mathbb{F}_2^{2n+2}$, we can write any element $g \in G_n$ as
\begin{equation}
  g = {(-1)}^{u_s} \ i^{u_i} \ M(u_{x_1}, u_{z_1}) \otimes \cdots \otimes
  M(u_{x_n}, u_{z_n})
\end{equation}
In shorthand, we will write that $v = (v_{x_1}, \ldots, v_{x_n}, v_{z_1}, \ldots, v_{z_n}) = (v_x, v_z) \in \mathbb{F}_2^{2n}$ and that
\begin{equation}\label{shorthand_1}
  M(v) = M(v_x, v_z) = M(v_{x_1}, v_{z_1}) \otimes \cdots \otimes
  M(v_{x_n}, v_{z_n})
\end{equation}

We also let $[A]$ be the set of operators that are the same up to a global phase so that
\begin{equation}
  [A] = \{\beta A : \beta \in \mathbb{C} , |\beta| = 1 \}
\end{equation}
Using {\ref{pauli_1}} {--} {\ref{pauli_3}}, we can see that the map $M$ induces an isomorphism $[M]: \mathbb{F}_2^{2n} \rightarrow [G_n]$ because addition of vectors in $\mathbb{F}_2^{2n}$ corresponds to the multiplication of matrices in $G_n$ up to a global phase
\begin{equation}\label{isomorphism}
  [M(u + v)] = [M(u)][M(v)] \quad \text{for} \quad u, v \in \mathbb{F}_2^{2n}
\end{equation}

\subsection{The Stabilizer Group}
A quantum state $\ket{\psi}$ is said to be \emph{stabilized} by a unitary operator $g$ if and only if $g \ket{\psi} = \ket{\psi}$. The \emph{stabilizer group} $S$ is a subgroup of $G_n$, which we denote as $S \leq G_n$. We then define a \emph{stabilizer subspace} $V_S$ to be the set of states that is stabilized by $S$, or more formally
\begin{equation}
  V_S = \left\{ \ket{\psi} : g \ket{\psi} = \ket{\psi} , \forall g \in S \right\}
\end{equation}
Here we note that if $g, h \in S$, then we must also have $gh \in S$ and $g^{-1} \in S$ because
\begin{equation}\label{stab_1}
  gh \ket{\psi} = g \ket{\psi} = \ket{\psi} \quad \text{and} \quad
  \ket{\psi} = g^{-1} g \ket{\psi} = g^{-1} \ket{\psi}
\end{equation}
We also note that if we would like $V_S$ to be a non-trivial vector space\footnote{The trivial vector space is $V_s = \{0 \}$}, $S$ must satisfy two conditions
\begin{enumerate}[label = (\arabic*)]
\item\label{cond_1} The elements of $S$ must commute
\item\label{cond_2} $-I$ cannot be an element of $S$
\end{enumerate}
We see that condition {\ref{cond_1}} must hold because if $-I \in S$, then we will have that $-I \ket{\psi} = \ket{\psi}$, which can only be satisfied by $\ket{\psi} = 0$. We see that condition {\ref{cond_2}} must also hold because all of the elements in $S$ either commute or anti-commute, as $S \leq P_n$. This means that if two elements $g, h \in S$ do not commute, then they must anti-commute so that $gh = -hg$. But if this is the case, then $-\ket{\psi} = -hg \ket{\psi} = gh \ket{\psi} = \ket{\psi}$, which can also only satisfied if $\ket{\psi} = 0$.

Moreover, if $g \in S$, then $g$ cannot have an overall phase of $\pm i$. This follows because if we let
\begin{equation}
  g = \pm i \ g_1 \otimes g_2 \otimes \cdots \otimes g_n
  \quad \text{for} \quad g_j \in \{I, X, Y, Z \}
\end{equation}
Then using {\ref{pauli_1}} and {\ref{stab_1}}, we see that
\begin{equation}
  \ket{\psi} = g \ket{\psi} = g^2 \ket{\psi} = {(\pm i)}^2 I^{\otimes n} \ket{\psi}
  = -\ket{\psi}
\end{equation}
Again, this is only satisfied when $\ket{\psi} = 0$. Thus, if $S$ stabilizes a non-trivial vector space, then we can write any element $g \in S$ as
\begin{equation}
  g = \pm 1 \ g_1 \otimes g_2 \otimes \cdots \otimes g_n
  \quad \text{for} \quad g_j \in \{I, X, Y, Z \}
\end{equation}
In terms of the $\mathbb{F}_2$ linear algebra perspective, this means that we can represent any $g \in S$ as a vector $u = (u_s, u_x, u_z) \in \mathbb{F}_2^{2n+1}$ where using the shorthand notation in {\ref{shorthand_1}} we have
\begin{equation}\label{stab_shorthand}
  g = {(-1)}^{u_s} M(u_x, u_z)
\end{equation}

\subsection{Clifford Gates}\label{clifford_gates}
It has been shown in {\cite{nc}} and {\cite{aaronson}} that we can actually make use of the $\mathbb{F}_2$ linear algebra perspective to efficiently simulate quantum circuits composed of the following gates
\begin{align}
  H \left( \alpha \ket{0} + \beta \ket{1} \right) &= (\alpha + \beta) \ket{0}
    + (\alpha - \beta) \ket{1} \\
  P \left( \alpha \ket{0} + \beta \ket{1} \right) &= \alpha \ket{0}
    + i \beta \ket{1} \\
  C_{a,b}\left( \ket{a} \otimes \ket{b} \right) &= \ket{a} \otimes \ket{a + b}
    \quad \text{for} \quad a, b \in \mathbb{F}_2
\end{align}
In order to do this, we keep track of the generators of the stabilizer group of $\ket{\psi}$, which we initialize as $\ket{0}^{\otimes n}$. We then update the generators as described in {\cite{aaronson}} each time we apply one of the gates above. Moreover, it has been shown that $\ket{\psi}$ is uniquely determined by a stabilizer group $S \leq P_n$ that contains $2^n$ elements. Likewise, we only need a total of $n$ generators, or vectors in $\mathbb{F}_2^{2n+1}$, in order to uniquely determine state $\ket{\psi}$.\footnote{If $G$ is a group closed under multiplication, then a set of elements $g_1, \ldots, g_l \in G$ is said to generate a group $G$ if every element in $G$ can be written as a product of the elements in $g_1, \ldots, g_l$. Moreover, it is a known fact from Group Theory that a finite group $G$ of size $|G|$ has a set of $\log |G|$ generators. }

\subsection{Projectors}
If $W \subseteq \mathbb{C}^{2^n}$ is a $w$-dimensional vector subspace, then a \emph{projector} $\Pi_W$ onto the vector subspace $W$ is a linear operator that satisfies two conditions
\begin{enumerate}[label = (\arabic*)]
\item\label{p_cond_1}
  For all $\ket{\phi} \in \mathbb{C}^{2^n}$, $\Pi_W \ket{\phi} \in W$
\item\label{p_cond_2} $\Pi_W^2 = \Pi_W$
\end{enumerate}
Likewise, if $W$ has an orthonormal basis $\ket{1}, \ket{2}, \ldots, \ket{w}$, then
\begin{equation}\label{proj_1}
  \Pi_W = \sum\limits_{j=1}^w \ket{j}\bra{j}
\end{equation}

\begin{claim}
$\Pi_S$ given by
\begin{equation}\label{proj_2}
  \Pi_S = \frac{1}{|S|} \sum\limits_{g \in S} g
\end{equation}
is a projector onto the stabilizer subspace $V_S$.
\begin{proof} First we note that if $g \in S$, then using {\ref{stab_1}}
\begin{equation}
  g \Pi_S = g \frac{1}{|S|} \sum\limits_{h \in S} h
  = \frac{1}{|S|} \sum\limits_{h \in S} gh
  = \frac{1}{|S|} \sum\limits_{h' = gh \in S} h'
  = \Pi_s
\end{equation}
From this, we see that $\Pi_S$ satisfies condition {\ref{p_cond_1}} because for all $\ket{\phi} \in \mathbb{C}^{2^n}$ and for all $g \in S$ we have $g \Pi_S \ket{\phi} = \Pi_S \ket{\phi}$. By definition, this means that $\Pi_S \ket{\phi} \in V_S$. We also see that $\Pi_S$ satisfies condition {\ref{p_cond_2}} because
\begin{equation}
  \Pi_S^2 = \left( \frac{1}{|S|} \sum\limits_{g \in S} g \right) \Pi_S
  = \frac{1}{|S|} \sum\limits_{g \in S} g \Pi_S
  = \frac{1}{|S|} \sum\limits_{g \in S} \Pi_S
  = \frac{1}{|S|} \ |S| \ \Pi_S = \Pi_S
\end{equation}
\end{proof}
\end{claim}

Here we also note that if $V_S$ contains only one vector so that $V_S = \{ \ket{\psi} \}$, then combining {\ref{proj_1}} and {\ref{proj_2}}, we see that
\begin{equation}\label{proj_3}
    \Pi_S = \frac{1}{|S|} \sum\limits_{g \in S} g = \ket{\psi} \bra{\psi}
\end{equation}

\section{Efficiently Computing Collision Probability}

\subsection{Preliminaries}
As described in Section {\ref{clifford_gates}}, we can efficiently simulate psuedo-random quantum circuits composed only of Clifford Gates by keeping track of the $n$ generators of the stabilizer group $S$ that uniquely determine a stabilizer state $V_S = \{ \ket{\psi} \}$. Moreover, keeping track of these $n$ generators is equivalent to keeping track of $n$ vectors in $\mathbb{F}_2^{2n+1}$. In this section, we will present an algorithm to compute the collision probability of a stabilizer state $V_S = \{ \ket{\psi} \}$ given the $n$ vectors in $\mathbb{F}_2^{2n+1}$ corresponding to the $n$ generators of $S$.

Throughout this section we will always let $\ket{\psi}$ be a state that has been created by applying a set of Clifford Gates to the initial state $\ket{0}^{\otimes n}$. Equivalently, we let $\ket{\psi}$ be the state uniquely determined by the stabilizer group $S$ so that $V_S = \{ \ket{\psi} \}$. Moreover, we let $S = \langle g^{(1)}, \ldots, g^{(n)} \rangle$, meaning $S$ is generated by the $n$ Pauli Matrices $g^{(1)}, \ldots, g^{(n)}$. For every element $g \in S$, we also let $u = (u_s, u_x, u_z) \in \mathbb{F}_2^{2n+1}$ be the vector representation of $g$ as written in {\ref{stab_shorthand}}.

By construction, we can use the fact that $|S| = 2^n$ along with {\ref{proj_3}} to write
\begin{equation}\label{prelim_1}
  \ket{\psi} \bra{\psi} = \Pi_S = \frac{1}{2^n} \sum\limits_{g \in S} g
\end{equation}
Here, we also note some properties of the trace of a matrix. Specifically for a vector $\ket{\phi}$ and matrices $A, B$ of the appropriate shape, we will have
\begin{align}
  \text{tr}(A \ket{\phi} \bra{\phi}) &=  \braket{\phi | A | \phi} \\
  \text{tr}(A + B) &= \text{tr}(A) + \text{tr}(B) \\
  \text{tr}(A \otimes B) &= \text{tr}(A) \text{tr}(B)
\end{align}
The last tool we need is the following:\\
\begin{claim}
If $a \in \mathbb{F}_2^n$ and we let $Z^a = Z^{a_1} \otimes \cdots \otimes Z^{a_n}$, then
\begin{equation}\label{prelim_2}
  \sum\limits_{z \in \mathbb{F}_2^n} \ket{z} \bra{z} \otimes \ket{z} \bra{z}
  = \frac{1}{2^n} \ \sum\limits_{a \in \mathbb{F}_2^n} Z^a \otimes Z^a
\end{equation}
\begin{proof}
First, we note that
\begin{equation}
  \ket{0} \bra{0} =
  \begin{bmatrix}
    1 & 0 \\
    0 & 0 \\
  \end{bmatrix} = \frac{I + Z}{2} \qquad
  \ket{1} \bra{1} =
  \begin{bmatrix}
    0 & 0 \\
    0 & 1 \\
  \end{bmatrix} = \frac{I - Z}{2}
\end{equation}
As a result, we can write that for $z \in \mathbb{F}_2^n$
\begin{align}
  \ket{z} \bra{z} &= \ket{z_1} \bra{z_1} \otimes \cdots \otimes
                    \ket{z_n} \bra{z_n} \\
                  &= \frac{I + {(-1)}^{z_1} Z}{2} \otimes \cdots \otimes
                    \frac{I + {(-1)}^{z_n}Z}{2} \\
                  &= \frac{1}{2^n} \biggl(I \otimes I \otimes \cdots \otimes I
                    \ + \ {(-1)}^{z_1} Z \otimes I \otimes \ldots \otimes I
                    \ + \ I \otimes {(-1)}^{z_2} Z \otimes \cdots \otimes I
                    \nonumber \\
                  & \qquad \qquad
                    \ + \ \cdots \ + \
                    {(-1)}^{z_1} Z \otimes {(-1)}^{z_2} Z \otimes \cdots
                    \otimes {(-1)}^{z_n} Z \biggr) \\
                  &= \frac{1}{2^n} \sum\limits_{a \in \mathbb{F}_2^n}
                    {(-1)}^{\braket{a, z}} Z^a \label{prelim_4}
\end{align}
Second, we also note that for $w \in \mathbb{F}_2^n$
\begin{equation}\label{prelim_5}
  \sum\limits_{z \in \mathbb{F}_2^n} {(-1)}^{\braket{w, z}} = 2^n \ \delta_{w = 0}
\end{equation}
We see this is the case whenever $w = 0$ because $\braket{0, z} = 0$ for all values of $z$.\footnote{In these notes, the function $\delta_{v}$ evaluates to 1 if $v$ is true and evaluates to 0 if $v$ is false} However, if $w$ has a $1$ in one or more entries, then for every $z$ such that $\braket{w, z} = 1$, there will be a $z'$ such that $\braket{w, z'} = 0$ that can be constructed by flipping one bit in $z$ that is in the same entry as a $1$ in $w$. Likewise, it follows that half of the values in the sum will evaluate to $(-1)$ while the other half evaluate to $1$, meaning the whole sum is just $0$.

Using {\ref{prelim_4}} and {\ref{prelim_5}}, we can now prove the original claim by writing
\begin{align}
  \sum\limits_{z \in \mathbb{F}_2^n} \ket{z}\bra{z} \otimes \ket{z}\bra{z}
  &= \sum\limits_{z \in \mathbb{F}_2^n}
    \left( \frac{1}{2^n} \sum\limits_{a \in \mathbb{F}_2^n}
    {(-1)}^{\braket{a,z}} Z^a \right)  \ \otimes \
    \left( \frac{1}{2^n} \sum\limits_{b \in \mathbb{F}_2^n}
    {(-1)}^{\braket{b,z}} Z^b \right) \\
  &= \frac{1}{4^n} \ \sum\limits_{a \in \mathbb{F}_2^n}
    \sum\limits_{b \in \mathbb{F}_2^n} \sum\limits_{z \in \mathbb{F}_2^n}
    {(-1)}^{\braket{a,z} + \braket{b, z}} \ Z^a \otimes Z^b  \\
  &= \frac{1}{4^n} \ \sum\limits_{a \in \mathbb{F}_2^n}
    \sum\limits_{b \in \mathbb{F}_2^n} \left( \sum\limits_{z \in \mathbb{F}_2^n}
    {(-1)}^{\braket{a + b,z}} \right) \ Z^a \otimes Z^b  \\
  &= \frac{1}{4^n} \ \sum\limits_{a \in \mathbb{F}_2^n}
    \sum\limits_{b \in \mathbb{F}_2^n} \left( 2^n \ \delta_{a+b = 0} \right)
    \ Z^a \otimes Z^b  \\
  &= \frac{1}{2^n} \  \sum\limits_{a \in \mathbb{F}_2^n}
    \sum\limits_{b \in \mathbb{F}_2^^n} \ \delta_{a = b} \
    \ Z^a \otimes Z^b \\
  &= \frac{1}{2^n} \sum\limits_{a \in \mathbb{F}_2^n} \ Z^a \otimes Z^a
\end{align}
\end{proof}
\end{claim}

\subsection{Simplifying Collision Probability}\label{simplifying_cp}
We now use {\ref{prelim_1}} {--} {\ref{prelim_2}} to simplify the expression for $P_c$ given in {\ref{collision_probability}} by writing
\begin{align}
  P_c &= \sum\limits_{z \in \mathbb{F}_2^n}
        {\left( \braket{z | \psi} \braket{\psi | z} \right)}^2 \\
      &= \sum\limits_{z \in \mathbb{F}_2^n}
        {\left( \braket{z | \Pi_S | z} \right)}^2 \\
      &= \sum\limits_{z \in \mathbb{F}_2^n}
        {\left( \text{tr}\left(\Pi_S \ket{z} \bra{z}\right) \right)}^2 \\
      &= \sum\limits_{z \in \mathbb{F}_2^n}
        \text{tr}\left( \left(\Pi_S \otimes \Pi_S \right)
        \left(\ket{z} \bra{z} \otimes \ket{z} \bra{z} \right) \right)  \\
      &= \text{tr}\left( \left(\Pi_S \otimes \Pi_S \right)
        \sum\limits_{z \in \mathbb{F}_2^n}
        \ket{z} \bra{z} \otimes \ket{z} \bra{z} \right)  \\
      &= \frac{1}{2^n} \ \text{tr}\left( \left(\Pi_S \otimes \Pi_S \right)
        \sum\limits_{a \in \mathbb{F}_2^n}
        Z^a \otimes Z^a \right)  \\
      &= \frac{1}{2^n} \  \sum\limits_{a \in \mathbb{F}_2^n}
        \text{tr}\left( \left(\Pi_S \otimes \Pi_S \right)
        \left(Z^a \otimes Z^a \right) \right) \\
      &= \frac{1}{2^n} \  \sum\limits_{a \in \mathbb{F}_2^n}
        {\left( \text{tr} \left(\Pi_S \ Z^a \right) \right)}^2 \\
      &= \frac{1}{2^n} \  \sum\limits_{a \in \mathbb{F}_2^n}
        {\left( \text{tr} \left(\frac{1}{2^n} \
        \sum\limits_{g \in S} g \ Z^a \right) \right)}^2 \\
      &= \frac{1}{2^{n}} \  \sum\limits_{a \in \mathbb{F}_2^n}
        {\left( \frac{1}{2^n} \ \sum\limits_{g \in S}
        \text{tr} \left(  g \ Z^a \right) \right)}^2 \label{simplify_1}
\end{align}
We now find an expression for the trace in {\ref{simplify_1}} by writing that for any $g \in S$ and $a \in \mathbb{F}_2^n$ we have
\begin{align}
  \text{tr} \left( g \ Z^a \right)
  &= \text{tr} \left({(-1)}^{u_s} M(u_x, u_z) Z^a \right) \\
  &= {(-1)}^{u_s} \prod\limits_{j=1}^n
    \text{tr} \left(M(u_{x_j}, u_{z_j}) Z^{a_j} \right) \label{simplify_2}\\
  &= {(-1)}^{u_s} \prod\limits_{j=1}^n
    ( 2 \ \delta_{u_{x_j}= 0} \ \delta_{u_{z_j}=a_j} ) \label{simplify_3}\\
  &= {(-1)}^{u_s} \ (2^n) \ \delta_{u_x = 0} \ \delta_{u_z = a} \label{simplify_4}
\end{align}
Where in {\ref{simplify_3}} we have used that the trace in {\ref{simplify_2}} is 2 only when the inner term evaluates to $I$. Otherwise, the trace in {\ref{simplify_2}} is just 0.

We now combine {\ref{simplify_1}} with {\ref{simplify_4}} to write
\begin{align}
P_c &= \frac{1}{2^{n}} \  \sum\limits_{a \in \mathbb{F}_2^n}
        {\left( \frac{1}{2^n} \ \sum\limits_{g \in S}
      {(-1)}^{u_s} \ (2^n) \ \delta_{u_x = 0} \ \delta_{u_z = a}  \right)}^2 \\
    &=  \frac{1}{2^{n}} \  \sum\limits_{a \in \mathbb{F}_2^n}
      {\left( \ \sum\limits_{g \in S}
      {(-1)}^{u_s} \ \delta_{u_x = 0} \ \delta_{u_z = a}  \right)}^2 \\
    &=  \frac{1}{2^{n}} \  \sum\limits_{a \in \mathbb{F}_2^n}
      {\left( \delta_{(0, 0, a) \in S} -
      \delta_{(1, 0, a)\in S} \right)}^2 \label{simplify_5}
\end{align}
Where in {\ref{simplify_5}} we use the shorthand notation $(u_s, u_x, u_z) \in S$ to mean that the matrix $g = {(-1)}^{u_s} M(u_x, u_z) \in S$. We now note that we cannot have both $(0, u_x, u_z) \in S$ and $(1, u_x, u_z) \in S$ because $V_S = \{ \ket{\psi} \}$, which is a non-trivial vector space. We see this is true because if both $(0, u_x, u_z) \in S$ and $(1, u_x, u_z) \in S$, then both $g \in S$ and $-g \in S$. As a result this would require that
\begin{equation}
  \ket{\psi} = g \ket{\psi} = -g \ket{\psi} = - \ket{\psi}
\end{equation}
And this can only be satisfied by the trivial vector space. Thus, we can further simplify {\ref{simplify_5}} by writing
\begin{align}
  P_c &=  \frac{1}{2^{n}} \  \sum\limits_{a \in \mathbb{F}_2^n}
      {\left( \pm \delta_{(0, 0, a) \in S \ \text{or} \ (1, 0, a) \in S } \right)}^2 \\
      &= \frac{1}{2^{n}} \  \sum\limits_{a \in \mathbb{F}_2^n}
        \delta_{(0, 0, a) \in S \ \text{or} \ (1, 0, a) \in S} \\
      &= \frac{ |\{(u_s, u_x, u_z) \in S : u_x = 0 \}| } {2^n}
\end{align}
We now define $U, V, W$ as
\begin{align}
  U &= \{(u_x, u_z) \in \mathbb{F}_2^{2n} : (0, u_x, u_z) \in S \text{ or }
  (1, u_x, u_z) \in S \} \label{simplify_6}\\
  V &= \{(v_x, v_z) \in \mathbb{F}_2^{2n} : v_x = 0 \} \label{simplify_7}\\
  W &= U \cap V \label{simplify_8}
\end{align}
Again, because only $(0, u_x, u_z) \in S$ or $(1, u_x, u_z) \in S$, we will have that $|U| = |S|$. Moreover, it has been shown in Chapter 10.5 of {\cite{nc}} that the $n$ vectors $u^{(1)}, \ldots, u^{(n)} \in U$ corresponding to the $n$ generators $g^{(1)}, \ldots, g^{(n)}$ of $S$ are linearly independent. Using this along with {\ref{isomorphism}}, we see that taking linear combinations of basis vectors in $U$ is isomorphic to matrix multiplying the generators of $S$. Thus, $U, V, W$ are actually all subspaces of $\mathbb{F}_2^{2n}$, which we write as $U, V, W \subseteq \mathbb{F}_2^{2n}$.

If we let $\text{dim}(W)$ be the number of basis vectors of $W$, then we see that $|W| = 2^{\text{dim}(W)}$, meaning we can write
\begin{equation}\label{simplify_9}
  P_c = \frac{|W|}{2^n} = \frac{2^{\text{dim}(W)}}{2^n} = \frac{1}{2^{n - \text{dim}(W)}}
\end{equation}

\subsection{An Algorithm to Efficiently Compute Collision Probability}
Assume we are given a set of basis vectors for the subspace $U$, which we denote as $u^{(1)}, \ldots, u^{(n)}$. To re-iterate, these $n$ basis vectors correspond to the $n$ generators $g^{(1)}, \ldots, g^{(n)}$ of the stabilizer group $S$ that uniquely determines the stabilizer state $V_S = \ket{\psi}$ so that $g^{(j)} = \pm M(u_x^{(j)}, u_z^{(j)})$. We now provide an algorithm to efficiently compute the collision probability of the state $\ket{\psi}$\\
\begin{algorithm}\label{algo_1}
  Given the vectors $u^{(1)}, \ldots, u^{(n)}$, do the following
  \begin{enumerate}[label = (\arabic*)]
  \item Define the following vectors where each $v^{(j)} \in \mathbb{F}_2^{2n}$
    \begin{align}
      v^{(1)} &= (0, \ldots, 0, 1, 0, \ldots, 0) \\
      v^{(2)} &= (0, \ldots, 0, 0, 1, \ldots, 0) \\
              & \vdotswithin{=} \nonumber \\
      v^{(n)} &= (0, \ldots, 0, 0, 0, \ldots, 1)
    \end{align}
    Note that these form a basis for the vector space $V$ as defined in {\ref{simplify_7}} while $u^{(1)}, \ldots, u^{(n)}$ form a basis for the vector space $U$ as defined in {\ref{simplify_6}}
  \item Define the following matrices $A, B \in \mathbb{F}_2^{2n \times n}$ and $C \in \mathbb{F}_2^{2n \times 2n}$
    \begin{align}
      A &= \begin{bmatrix} {u^{(1)}}^T & {u^{(2)}}^T & \cdots & {u^{(n)}}^T
      \end{bmatrix} \\
      B &= \begin{bmatrix} {v^{(1)}}^T & {v^{(2)}}^T & \cdots & {v^{(n)}}^T
      \end{bmatrix} \\
      C &= \begin{bmatrix} A & B \end{bmatrix}
    \end{align}
  \item\label{algo_step}
    Let $r$ be the number of pivot columns in $\text{REF}(C)$. We then have $\text{dim}(W) = \text{dim}(\text{Ker}(C)) = 2n - r$, so return
    \begin{equation}\label{algo_cp}
      P_c = \frac{1}{2^{n - \text{dim}(W)}}
      = \frac{1}{2^{n - (2n - r)}} = \frac{1}{2^{r-n}}
    \end{equation}
  \end{enumerate}
\begin{proof}
  As shown in Section {\ref{simplifying_cp}}, the column vectors of matrices $A$ and $B$ are the basis vectors of the respective subspaces $U$ and $V$. Moreover, the expression for the collision probability in {\ref{algo_cp}} was also derived in section {\ref{simplifying_cp}}. Likewise, the only thing left to justify is the claim that $\text{dim}(W) = \text{dim}(\text{Ker}(C)) = 2n - r$.

  To see this, we note that the Kernel of $C = \begin{bmatrix} A & B \end{bmatrix}$ will be given by the vectors $(x, y) = \\(x_1, x_2, \ldots, x_n, y_1, y_2, \ldots, y_n) \in \mathbb{F}_2^{2n}$ such that
\begin{equation}
  \begin{bmatrix}
    A & B
  \end{bmatrix}
  \begin{bmatrix}
    x^T \\
    y^T \\
  \end{bmatrix}
  = 0
\end{equation}
Thus, all vectors ${(x, y)}^T \in \text{Ker}(C)$ will have
\begin{equation}\label{ker_1}
  Ax^T + By^T = 0 \quad \Rightarrow \quad Ax^T = By^T
\end{equation}
Where we have used that $y^T = -y^T$ when working in $\mathbb{F}_2^n$. Equivalently, this means that every vector in the $\text{Ker}(C)$ forms a simultaneous linear combination of the basis vectors in $U$ and $V$ because expanding {\ref{ker_1}} gives us
\begin{equation}
  x_1 u^{(1)} + x_2 u^{(2)} + \cdots + x_n u^{(n)} =
  y_1 v^{(1)} + y_2 v^{(2)} + \cdots + y_n v^{(n)}
\end{equation}
Likewise, we see that by definition ${(x, y)}^T \in \text{Ker}(C)$ if and only if $Ax^T = By^T \in U \cap V$. We also see that if ${(x^{(1)}, y^{(1)})}^T, {(x^{(2)}, y^{(2)})}^T \in \text{Ker}(C)$, then
\begin{equation}
\alpha (A x^{(1)} + B y^{(1)}) + \beta (A x^{(2)} + B y^{(2)}) = 0
\end{equation}
And we can rewrite this as
\begin{equation}
A (\alpha {x^{(1)}}^T + \beta {x^{(2)}}^T) = B (\alpha {y^{(1)}}^T + \beta {y^{(2)}}^T)
\end{equation}
From this we see that taking linear combinations of vectors in $\text{Ker}(C)$ is equivalent to taking linear combinations of vectors in $U \cap V = W$. Thus, the basis vectors of the $\text{Ker}(C)$ will also form a basis for the vectors in $W$. As a result, we will have
\begin{equation}\label{algo_proof_1}
  \text{dim}(\text{Ker}(C)) = \text{dim}(W)
\end{equation}
Lastly, by the Rank-Nullity Theorem, for the $2n \times 2n$ matrix $C$, we will have
\begin{equation}\label{algo_proof_2}
\text{dim}({\text{Im}(C)}) + \text{dim}(\text{Ker}(C)) = 2n
\end{equation}
In step {\ref{algo_step}} of the algorithm, we set $r$ equal to the number of pivot columns in $\text{REF}(C)$, which is the same as the $\text{dim}(\text{Im}(C))$. Thus, combining {\ref{algo_proof_1}} and {\ref{algo_proof_2}} we see
\begin{equation}
  \text{dim}(W) = \text{dim}(\text{Ker}(C)) = 2n - \text{dim}({\text{Im}(C)})
  = 2n - r
\end{equation}
\end{proof}
\end{algorithm}

\section{Simulations and Numerical Results}

\subsection{Simulation Protocol}
As described in Section {\ref{cp_conjecture}}, we are specifically interested in the relationship between the collision probability as a function of the depth of the circuit. In order to explore this relationship, we simulate pseudo-random quantum circuits in 1D, 2D, and 3D lattices. Likewise, we restrict our simulations to stabilizer states that are created by applying Clifford Gates to the computational basis $\ket{0}^{\otimes n}$, as described in Section {\ref{clifford_gates}}

Our simulations use a tableau as described in {\cite{aaronson}} to keep track of the vector representations of the generators of the stabilizer group $S$ of the stabilizer state $V_S = \{ \ket{\psi} \}$. However, we do not keep track of the phase bits, as they will not be necessary in order to compute the collision probability of the state $\ket{\psi}$. See {\cite{aaronson}} for details on how to initialize and update the tableau.

In order to generate random Clifford Gates, we use the algorithm described in {\cite{random_clifford}}. Again, we ignore the phase bits as they will not affect the collision probability. Likewise, in order to generate a random Clifford Gate that acts on two qubits, we can equivalently generate a $4 \times 4$ Symplectic Matrix. We then decompose these Symplectic Matrices into Clifford Gates using the algorithm described in {\cite{aaronson}}.

Lastly, we use Algorithm {\ref{algo_1}} in order to efficiently compute the collision probability of the stabilizer state $\ket{\psi}$ using the tableau that keeps track of the generators of the stabilizer group.

Using these algorithms, all of our simulations use the following protocol to collect data in order to test Conjecture {\ref{conjecture_1}}. \\
\begin{proto}\label{proto_1} Our simulations perform the following steps
  \begin{enumerate}[label = (\arabic*)]
  \item\label{protocol_1}
    Initialize a tableau to keep track of the generators of our stabilizer state $\ket{\psi}$. This tableau corresponds to the state $\ket{0}^{\otimes n }$. Initialize the depth $d = 0$. Initialize a list of coordinates $K = [(d_1 = 0, k_1 = 0)]$
  \item\label{protocol_2}
    Based on the geometry of the circuit, create a list $L$ that contains pairs of qubits. We construct $L$ so that after applying two qubit gates to all pairs of qubits in $L$ the depth of the circuit with increase by one.
  \item For every pair of qubits in $L$, do the following. Pick a uniformly random $4 \times 4$ Symplectic Matrix and decompose it into Clifford Gates. Apply these two qubit gates to the pair of qubits by appropriately modifying the tableau.
  \item\label{protocol_3}
    Compute the collision probability of the state using the tableau. Update the depth so that $d \leftarrow d + 1$. If we let $k = -\log_2 (P_c)$, then append the pair $(d, k)$ to the list $K$.
  \item\label{protocol_4}
    Repeat steps {\ref{protocol_2}} {--} {\ref{protocol_3}} a on the order of $O(n^{1/w})$ times for a $w$-dimensional grid.
  \item Repeat steps {\ref{protocol_1}} {--} {\ref{protocol_4}} a total of $m$ times, storing all $m$ lists of coordinates. Compute the mean and standard deviation across the $m$ lists of coordinates, creating another list $[(d_1, k_1, \Delta k_1), (d_2, k_2, \Delta k_2), \ldots ]$.
  \end{enumerate}
\end{proto}

We have written code in Python 3.5 to implement the steps in Protocol {\ref{proto_1}}, which can be found online at {\cite{matthewkhoury96}}. This code also includes implementations of the algorithms described in {\cite{aaronson}} and {\cite{random_clifford}} as well as an implementation of Algorithm {\ref{algo_1}}. In order to enhance performance, our code includes some methods to parallelize some of the steps in Protocol {\ref{proto_1}}. This implementation also precomputes the decomposition of all $4 \times 4$ Symplectic Matrices in order to save time.

In the following sections, we describe how to obtain $L$ for 1D, 2D, and 3D lattices. We also provide some of our numerical results obtained using the implementation of Protocol {\ref{proto_1}} on 1D, 2D, and 3D lattices.

\subsection{1D Lattice}
The pairs of qubits in a 1D lattice that correspond to depth of $1$ can be seen in Figure {\ref{fig_1d}}. Specifically, we simply alternate between two lists of pairs of qubits, which we refer to as two seperate rounds. Likewise, each round corresponds to a depth of 1. Figures {\ref{plot_1d_1}} and {\ref{plot_1d_2}} show our results for a 1D letattice for $n = 100$ and $n = 625$ respectively. In both simulations we let $m = 25$, meaning we collected a total of $25$ samples, which we used to compute the mean and standard deviation of the values of $k$ as a function of $d$.

\begin{figure}[!htp]
\centering
\includegraphics[width=.75\textwidth]{figures/1D_circuit.pdf}
\caption{Qubits in a 1D Lattice. We alternate between the two rounds and each round corresponds to a depth of 1. Black dots represent qubits, black lines represent random two qubit gates, grey lines represent inactive gates. }
\label{fig_1d}
\end{figure}
\begin{figure}[!htp]
\centering
\includegraphics[width=.75\textwidth]{figures/plot_100_1D.pdf}
\caption{$k$ as a function of $d$ in a 1D lattice with $n = 100$ qubits and $m = 25$ samples.}
\label{plot_1d_1}
\end{figure}
\begin{figure}[!htp]
\centering
\includegraphics[width=.75\textwidth]{figures/plot_625_1D.pdf}
\caption{$k$ as a function of $d$ in a 1D lattice with $n = 625$ qubits and $m =25$ samples.}
\label{plot_1d_2}
\end{figure}

We would like to note here that we slightly deviated from Protocol {\ref{proto_1}} for the 1D lattice, as we did not compute the collision probability at each depth. Rather, we only computed the collision probability for 50 different values of the depth, which were approximately evenly spaced. The reasoning for this is two-fold. First, computing the collision probability given a tableau is the most expensive operation in our simulations. Second, in the 1D lattice, we needed to compute the collision probability for large values of depth on the order of $O(n)$. Likewise, limiting the number of data points we collected to $50$ saved a significant amount of time while running our simulations.

Looking that Figures {\ref{plot_1d_1}} and {\ref{plot_1d_2}}, we see that our numerical results obtained from our simulations support Conjecture {\ref{conjecture_1}}. Specifically, for a 1D lattice, the Conjecture predicts that
\begin{equation}
k = n \left( 1 - O\left(\frac{1}{d} \right) \right)
\end{equation}
Moreover, for a 1D lattice, we would expect the circuit to saturate at a depth of $d \sim n$. Likewise, looking at the figures above, it is clear that we will have $k = O(n - n/d)$ and the circuits in the clearly saturate well before $d = n$. Thus, the results of our simulations seem to support Conjecture {\ref{conjecture_1}} for a 1D lattice.

\subsection{2D Lattice}
The pairs of qubits in a 2D lattice that correspond to a depth of $1$ can be seen in Figure {\ref{fig_2d}}. Similar to the 1D lattice, we simply perform a round robin throughout the four different rounds when applying our sets of two qubit gates. Each round in this round robin increases the depth of the circuit by $1$. Figures {\ref{plot_2d_1}} and

\begin{figure}[!htp]
\centering
\includegraphics[width=.9\textwidth]{figures/2D_circuit.pdf}
\caption{Qubits in a 2D Lattice. We alternate between the four rounds and each round corresponds to a depth of 1. Black dots represent qubits, black lines represent random two qubit gates, grey lines represent inactive gates. }
\label{fig_2d}
\end{figure}

\begin{figure}[!htp]
\centering
\includegraphics[width=.75\textwidth]{figures/plot_100_1D.pdf}
\caption{$k$ as a function of $d$ in a 2D lattice with $n = 100$ qubits and $m = 25$ samples.}
\label{plot_2d_1}
\end{figure}

\begin{figure}[!htp]
\centering
\includegraphics[width=.75\textwidth]{figures/plot_900_2D.pdf}
\caption{$k$ as a function of $d$ in a 2D lattice with $n = 900$ qubits and $m =25$ samples.}
\label{plot_2d_2}
\end{figure}

\clearpage

\subsection{3D Lattice}

\begin{figure}[!htp]
\centering
\includegraphics[width=.75\textwidth]{figures/3D_circuit.pdf}
\caption{Qubits in a 3D Lattice. We alternate between the six rounds and each round corresponds to a depth of 1. Black dots represent qubits, black lines represent random two qubit gates, grey lines represent inactive gates. }
\label{fig_3d}
\end{figure}

\begin{figure}[!htp]
\centering
\includegraphics[width=.75\textwidth]{figures/plot_125_3D.pdf}
\caption{$k$ as a function of $d$ in a 3D lattice with $n = 125$ qubits and $m = 25$ samples.}
\label{plot_3d_1}
\end{figure}

\begin{figure}[!htp]
\centering
\includegraphics[width=.75\textwidth]{figures/plot_1000_3D.pdf}
\caption{$k$ as a function of $d$ in a 3D lattice with $n = 1000$ qubits and $m =25$ samples.}
\label{plot_3d_2}
\end{figure}

\clearpage

\bibliography{mybib}

\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:

\message{ !name(report_1.tex) !offset(-654) }


\section{Introduction}

In \field, various procedures use the same few atomic operations. For instance, accessing the neighbours of a given node is key to a wide range of problems such as computing shortest paths, finding connected components, detecting communities etc. Making this type of elementary operation faster would improve such algorithms without having to modify their implementation \cite{gorder}.
Cache optimisation can have that effect: if two variables are often accessed together by algorithms, they should be stored side-by-side in memory so that they are copied together on a cache line. In a graph, it means reordering the nodes so that neighbours have close-enough indices. A cache-miss happens when data is not available in cache. The processor then has to fetch it in main memory, which is up to twenty times slower, depending on the machine architecture. As this cache stall is known to represent a significant share of the computation time \cite{cache,cache2}, reducing it can lead to important speedups.

This work replicates~\cite{gorder} by Hao Wei \textit{et al.} which introduces Gorder, a new procedure to order nodes in a graph, and compares it to other standard orderings using typical algorithms and datasets as benchmarks. Because of the variety of graph algorithms, it is impossible to find an ideal ordering, which makes it interesting to propose and compare different strategies. The authors of the original paper claim an improvement of 10 to 50\% in \runtime, due to lower cache-miss rate.

We were able to replicate most of the experiments and confirm that ordering nodes according to Gorder makes the implementations 10 to 50\% faster than without ordering.
%
Section~\ref{method} presents the algorithms, orderings and datasets as well as issues faced during the replication. Our results are presented in Section~\ref{results} and are compared to the original results. Finally, Section~\ref{discussion} discusses the relevance of such an ordering compared to simpler ordering methods that offer satisfactory performances.

\begin{figure}%[h]
\begin{subfigure}{0.49\textwidth}
\includegraphics[width=\linewidth, height=5cm]{img/img-cache-original.pdf}
\caption{Original order}
\label{img-cache-original}
\end{subfigure}
\begin{subfigure}{0.49\textwidth}
\includegraphics[width=\linewidth, height=5cm]{img/img-cache-gorder.pdf}
\caption{Gorder}
\label{img-cache-gorder}
\end{subfigure}
\caption{\textbf{CPU execution and cache stall.} Original order and Gorder are compared for all algorithms on \textit{sdarc} dataset. Grey bars are time spent on CPU operations, black bars represent time spent waiting for data retrieval. Figure~(a) shows the normalised \runtime s with the original order, figure~(b) shows the \runtime s when the network has been reordered following the Gorder procedure. While both need about the same CPU time, the latter is significantly faster due to cache stall reduction. Compare to Figure~1 in~\cite{gorder}.}
\label{img-cache}
\end{figure}

\section{Method} \label{method}

The original study~\cite{gorder} was motivated by the observation that cache stall can take up to 70\% of the whole computation time, which is supported by the observations reported in Figure~\ref{img-cache}.
%
 This issue has been addressed for specific algorithms such as breadth-first search~\cite{bfs-cache}.
 In~\cite{gorder}, the authors use a more general method: they reorganise the data to draw more benefit from the cache system, regardless of the algorithm or of the exact hardware specifications.

 Gorder clusters nodes that are likely to be accessed simultaneously by any graph algorithm.
 %
 More precisely, let us consider a graph $G=(V,E)$ with $n=|V|$ nodes and $m=|E|$ edges. The proximity of two nodes $u$ and $v$ is measured by a score $S(u,v)$ which increases if they are neighbours and if they share many common in‐neighbours.
 %
 The total score $F$ is the sum of $S(u,v)$ for all nodes $u$ and $v$ that have close indices.
 %
 Window size $w$ is the parameter that defines this closeness.
 %
 Gorder creates an arrangement $\pi$ of the indices to maximise $F$.
  %
 We note $\pi_u$ the index of a node $u$ in such an arrangement.
 %
 We give a more formal definition in Section~\ref{orders}.

 The authors prove that finding the optimal ordering $\pi$ is a NP-hard problem and propose a heuristic method with a theoretical approximation bound. % consequently
%
 They also present practical optimisations to reduce its time complexity.
 Finally, they run extensive experiments to compare their order to other standard orders.

Although the theoretical results of the original paper are important to explain the efficiency of Gorder, we only focus here on the algorithms and experiments. They provide an extensive analysis by comparing the \runtime s for nine typical algorithms on eight large datasets with nine possible orderings. The current section describes them all and presents the replication issues that they imply. It also details the data structures that we used in this project. All the codes and instructions for this purpose can be found in our repository\footnote{\url{https://github.com/lecfab/rescience-gorder}}.

%%%%%%%%%%%%%% ALGORITHMS

\subsection{Algorithms} \label{algorithms}

The original paper selects typical graph algorithms to test the different orderings.
%
As implementation details are not fully documented and as its authors were not able to provide answers to some of our questions on this topic, we list below the details of our implementations.

\subsubsection{Neighbour query (NQ)}

Listing the neighbours of a given node is a standard elementary operation in \field.
%
As defined in~\cite{gorder}, this operation must \textit{access the out-neighbours} of each node. To ensure that neighbours are put in cache, thus benefiting from a wise node ordering, an arbitrary operation is made over the set of neighbours. We compute for each node $u$ the sum of degrees of its neighbours:
$q_u=\sum_{v\in N_u} d_v$.

\subsubsection{Breadth and Depth-first search (BFS, DFS)}
BFS and DFS are standard graph traversal algorithms~\cite{cormen}. We adapted them to the data structure detailed in Section~\ref{datasets}. Note that neighbours are selected in lexicographic order.

\subsubsection{Strongly connected components (SCC)}
To cluster nodes of the graph that can be accessed from one another, we use \tarjan~\cite{tarjan}, which is a based on DFS.

\subsubsection{Shortest paths (SP)}
As in the original paper, we use \bellman~\cite{cormen} to compute the minimum distance from a source node to any other node. The time complexity after simple optimisations is in $O(\Delta m)$ where $\Delta$ is the diameter of the graph and $m$ is the number of edges.
%
As real-world networks are known to have relatively small diameters ($\Delta \ll n$), this algorithm works on massive datasets (see section~\ref{datasets}).
%
Note that for unweighted graphs, shortest paths can be computed in linear time and space using a BFS, but we keep the algorithm suggested in~\cite{gorder} for comparison purposes.

\subsubsection{Page rank (PR)}
This is the algorithm presented in~\cite{pagerank} to rank webpages. It gives a score to each node according to its importance in the network structure.
%
The original paper hints at an approximation based on the power iteration method with 100 iterations. We implement it with a damping factor set to $\alpha=0.85$ which is a usual configuration.

\subsubsection{Dominating set (DS)}
A dominating set is a subset of nodes such that every node of the graph either belongs to the subset or has a neighbour in it. The implementation is not described in the original paper so we use a greedy approximation~\cite{cormen}: first, we select the node with the most uncovered neighbours and add it to the dominating set. Second, this node and all its neighbours are removed from the graph because they are now covered. The two steps are then repeated among the remaining nodes.

\subsubsection{Core decomposition (Kcore)}
This graph pealing algorithm~\cite{kcore} recursively removes the node of smallest degree until only a core of well-connected nodes remains. We use a binary heap structure to keep track of the degrees, leading to a quasi-linear time complexity.

\subsubsection{Diameter (Diam)}
Efficient approximations with theoretical bounds exist~\cite{BFSdiameter} to compute the aforementioned diameter $\Delta$. In~\cite{gorder}, the authors run 5000 times the shortest paths algorithm SP from a random node, and output the highest distance obtained.
%
Note that the accuracy and efficiency of the algorithm are not key here, as the aim is to compare the performances in terms of computation time of different orderings.

%%%%%%%%%%%%%% DATASETS

\subsection{Datasets and data structure} \label{datasets}

\subsubsection{Size}
Eight real-world datasets are used as benchmarks in the original work~\cite{gorder}. Their basic features are reported in Table~\ref{table-datasets}.
%
As per usual with real-world graphs~\cite{networkProperties}, these graphs are sparse ($m \ll n^2$) and have small diameter and a skewed degree distribution, etc.
%
As shown in Table~\ref{table-datasets}, their sizes range from 1.6 million nodes and 30 million edges to almost 100 million nodes and two billion edges.
%
In order to facilitate further experiments, we attach the \textit{epinion} dataset to the repository, a smaller network on which our code can be tested quickly.

\subsubsection{Sources}
In the original paper, the sources are provided in the form of URLs where datasets can be downloaded. These data are available with the links given in Table~\ref{table-datasets}.
%, there is now a fee to access data from the Konect project.

\subsubsection{Categories}
The authors of~\cite{gorder} selected two main categories of real-world networks: online social platforms, where a node is a user and a directed edge represents a social interaction, and web graphs, where a node is a web page and an edge is a hyperlink.

\begin{table}[]
\include{includes/table-datasets}\label{table-datasets}
\end{table}

\subsubsection{Format}
The datasets are directed graphs given as lists of edges.
Most algorithms (\textit{e.g.} computing shortest paths) have different results depending on whether edges are directed or not.
%
In order to store large graphs in main memory, an efficient data structure is needed.
%
Libraries exist for that purpose, but we develop our own light structure to have better control over the implementation of the algorithms.
%
A list of edges does not provide quick access to the list of neighbours of a given node, which is the crucial operation for most of the above graph algorithms. The data is therefore converted into an adjacency list, where a node points to the list of its neighbours. To store it efficiently, we use a \textit{Compressed Sparse Row} format, as described in Figure~\ref{img-format}.

\begin{figure}[h]
    \centering
    \begin{subfigure}{0.25\textwidth}
        \includegraphics[width=\linewidth]{img/format-adjlist.png}
        \caption{Adjacency list}\label{img-format-adjlist}
    \end{subfigure}\hspace{0.05\textwidth}
    \begin{subfigure}{0.5\textwidth}
        \includegraphics[width=\linewidth]{img/format-csr.png}
        \caption{Compressed Sparse Row}\label{img-format-crf}
    \end{subfigure}
    \caption{\textbf{Graph representations.} An adjacency list stores a list of neighbours for each node. In CSR, all the neighbours are stored in a shared array of size $m$, and each node has a pointer to its first neighbour. This is an equivalent but more compact format which allows for faster memory access. }\label{img-format}
\end{figure}

%%%%%%%%%%%%%% ORDERINGS

\subsection{Orderings} \label{orders}

We list below the different ordering methods considered in the original study and used as a benchmark for comparison with Gorder.

\subsubsection{Original}
Datasets are collected in a way that is not random but is rarely reported.
%
As shown in Section~\ref{results}, the original orderings perform quite well regarding cache miss.

\subsubsection{Random (added)}
In comparison to~\cite{gorder}, we added a random ordering, obtained by shuffling the indices of nodes.
%
We use it as a non-favourable benchmark for comparison to all other orderings.

\begin{figure}[]
    \centering
    \includegraphics[width=.6\linewidth]{img/tune_sa.png}
    \caption{\textbf{Tuning simulated annealing.} The colour represents the energy of the best permutation $\pi$ obtained for various parameters on \textit{epinion}. Number of steps $S$ ranges from  $n$ to $m\log n$ (logarithmic scale), which we consider to be the maximal acceptable time for the heuristic implementation. Standard energy $k$ ranges from $1/(mn)$ to $mn$ (logarithmic scale). We observe that a) the higher $S$, the lower the resulting energy, b) when $k$ is high, the resulting energy is at a maximum: all swaps are accepted regardless of their quality which results in a random arrangement, c) any low value of $k$ has the same result, in particular for $k=0$ which corresponds to a local search.}\label{img-tune-sa}
\end{figure}

\subsubsection{MinLA and MinLogA} These acronyms stand for \textit{minimum linear} (respectively \textit{logarithmic}) \textit{arrangement}. The goal is to find an arrangement $\pi$ of the nodes that minimises a given ``energy" function. The energy $\mathcal{E}$ is computed over the set $E$ of edges in the following way:
$$\mathcal{E}_{MinLA}=\sum_{(u,v)\in E} |\pi_u-\pi_v|
\qquad\text{ and }\qquad
\mathcal{E}_{MinLogA}=\sum_{(u,v)\in E} \log|\pi_u-\pi_v|$$
%
As both exact optimisations are NP-hard, a heuristic method is necessary. The authors of~\cite{gorder} use simulated annealing: random permutations are achieved to decrease the energy $\mathcal{E}$, while the temperature goes down which allows less and less modifications.
%
Simulated annealing is known to be hard to tune. Our implementation has two parameters: the number of steps $S$
%(how many random swaps are performed before stopping)
and the standard energy $k$.
%(what typical tolerance is given to bad swaps).
%
The temperature $T$ decreases linearly so that, at step $s$, $$T(s) = 1 - s/S$$
%
At each step, two nodes are picked at random. Swapping their indices in $\pi$ leads to a variation $e$ of the total energy $\mathcal{E}$. If $e$ is negative, the swap is registered. Otherwise, it is registered with a probability $p$, inspired by statistical physics:
$$p(e,T)=\exp\left(-\frac{e}{k\cdot T}\right)$$

 In Figure~\ref{img-tune-sa} we test a wide range of values of $S$ and $k$ on \textit{epinion}.
 %
 While we cover a significant fraction of the parameter space,  we are not able to find a combination of $S$ and $k$ that outperforms a simple local search ($k=0,p=0$), where only the favourable swaps are accepted. Below, we set $S=m$ and $k=m/n$.

\subsubsection{RCM}
The Reverse Cuthill–McKee ordering \cite{rcm} is a Breadth-First Search where nodes of small degree are favoured. It is meant to find an arrangement $\pi$ that reduces the bandwidth of a sparse graph, given by $\max_{(u,v)\in E} |\pi_u-\pi_v|$ with $ \pi_u $ the index of node $u$.

\subsubsection{Degsort}
As proposed in the original paper, nodes are sorted in descending order of in-going degree.

\subsubsection{Chdfs}
We assume that the \textit{children-depth first search traversal} mentioned in~\cite{gorder} is a usual Depth-First Search algorithm. The first node is chosen at random, then the selection of children is made following the original order of node indices.

\subsubsection{SlashBurn (simplified)}
%
SlashBurn is an iterative process that separates hubs (high-degree nodes) from low-degree nodes connected to hubs.
%
It creates an ordering by iterating over an array of size $n$, initially empty.
%
Each iteration divides the array in parts A, B and C. Part A takes only one node, selected at random among those with highest degree. All isolated nodes go to part C. Then these nodes are removed from the graph which creates new isolated nodes, and degrees are updated. Part B is filled by the next iteration until no node remains.

The original SlashBurn algorithm~\cite{slashburn} fills part C with disconnected components instead of isolated nodes and puts $r$ hubs in part A, where $r$ is a parameter. As no precise information was given in \cite{gorder}, we implement the simpler version described above instead.

\subsubsection{LDG}
Linear Deterministic Greedy partitioning \cite{ldg} creates $\frac{n}{k}$ bins of size $k$ and puts nodes in the bin where most of their neighbours belong.
%
Larger bins are penalised: a node $u$ with neighbours $N_u$ is placed in a bin that achieves
$$\arg\max_{\text{bin }B}\Big(1+|N_u\cap B|\Big) \times \Big(1-\frac{|B|}{k}\Big)$$
%
At the end of the process, each bin contains about $k$ nodes.
%
In~\cite{gorder}, the authors choose $k=64$ so that a bin can fit on a cache line. Indeed, common contemporary processors have L1 caches of a few dozen kilobytes (32kB in our case) made of lines of 64 bytes each.

\subsubsection{Metis (removed)}
Metis is a powerful and extensive tool for graph partitioning. A C++ implementation is available\footnote{\url{http://glaros.dtc.umn.edu/gkhome/metis/metis/overview}} but it is not suitable for large graphs: the original paper could only test it on the three smallest datasets because of its excessive memory consumption. Since this ordering does not scale, we do not use it in our experiments.

\subsubsection{Gorder} Gorder is the ordering method introduced in~\cite{gorder}, where it is precisely described. A C++ implementation is available\footnote{\url{https://github.com/datourat/Gorder}}.
%
As mentioned at the beginning of Section~\ref{method}, the authors define the quality function $F$ of an arrangement $\pi$ by:
$$F(\pi)=\sum_{0<\pi_u-\pi_v\leq w}S(u,v)
=\sum_{0<\pi_u-\pi_v\leq w}\Big(S_s(u,v) + S_n(u,v)\Big)$$
%
where $w$ is the window size;
$S_s(u,v)$ is the number of times $u$ and $v$ coexist in sibling relationships or their number of common in-neighbours; $S_n(u,v)$ is the number of times they are in a neighbour relationship, which is either 0, 1 or 2 since both edges $(u,v)$ and $(v,u)$ may exist.

The greedy algorithm presented in~\cite{gorder} creates the ordering $\pi$ by recursively inserting the node that has the highest proximity to nodes presently within the window.
%
Storing the proximity scores $S$ requires a complex structure called unit heap, made of a linked list and pointers to different positions. We took the functions provided in the original code and adapted them to our data structure.

%%%%%%%%%%%%%%%%%%%%% Continue Alexis' review
In~\cite{gorder}, Figure~8 shows how parameter $w$ is selected.
%
The authors create versions of Gorder for window sizes ranging from 1 to 8. For each version, they run the PR algorithm on \textit{flickr} dataset. The fastest runtime is obtained with $w=5$, so they use this value for subsequent experiments. However, the 8 versions only lead to a small relative variation of runtime (3\%).

In Figure~\ref{img-tune-w} we compare a wider range of window sizes, because $w$ could in theory be anything between 1 and $n$.
%
We find that setting $w$ between 64 and 2048 gives a further 3\% speedup compared to $w=5$.
%
\begin{figure}[hb]
    \centering
    \includegraphics[width=.6\linewidth]{img/tune_w.pdf}
    \caption{\textbf{Tuning window size.} Versions of Gorder obtained for window sizes ranging from $w=1$ to $w=2^{20}\simeq 10^6$ are tested in PageRank over \textit{flickr} (with $n\simeq 2\cdot 10^6$ nodes). Median and 90\% confidence interval are shown for 100 repetitions. The plateau from $w=64$ to $w=2^{11}= 2048$ gives better results than $w=5$. This figure can be compared to Figure~8 in~\cite{gorder}; note that the absolute \runtime s are different because of hardware differences.
    }\label{img-tune-w}
\end{figure}

The choice of a small $w$ is yet relevant because of two other factors: first, the computation of Gorder is faster when the window is narrow, because a candidate node has to compute its proximity score $S$ with all the nodes of the window. Second, the authors of the original paper show that their heuristic is a $\frac{1}{2w}$-approximation of the optimal score: reducing $w$ makes this bound tighter.
%

Considering all these remarks and for the purpose of replication, we also use $w=5$ in the following experiments.

\section{Results} \label{results}

\subsection{Implementation hardware}
To deal with bigger datasets and ensure stability, we run the experiments on an isolated cluster (SGI UV2000 Intel Xeon E5-4650L @2.6 GHz, 128GB RAM). Each processor has three levels of cache of respective size 32kB, 256kB and 20MB.
%laptop (Intel Core i7-10810U @1.1GHz, 32GB RAM, Linux 5.4, Ubuntu 20.04.1, compiler GCC 9.3.0)
%a server (Intel Xeon Silver @2.40GHz, 256GB RAM, Linux 4.18, CentOS 8, GCC 8.3.1).

The hardware used in~\cite{gorder} has similar cache and RAM storage but higher clock frequency, which can explain the differences in \runtime\ (in addition to programming techniques and optimisation). Note however that these differences should not modify the relative performance of different orderings.

\subsection{Ordering time}
Computing an ordering on a large network can be a long process, and some of the ordering methods have limited scalability. As mentioned above, Metis has been removed from the experiments for this reason.
%
Table~\ref{table-order-time} reports the duration of the ordering processes. For datasets under a hundred million edges, they can all be computed in a couple of minutes at most, with DegSort and ChDFS orderings requiring less than a second.

When the number of edges rises however, the computation takes hours for MinLA, MinLogA, and Gorder. In the case of MinLA and MinLogA, the number of steps is chosen arbitrarily as described in Section~\ref{orders}. The process could thus be interrupted earlier, at the cost of a less efficient resulting ordering.
%
As for Gorder, we can see that it does not scale linearly: the edges processed per second decrease from 380k for \textit{pokec} to 60k for \textit{sdarc}, which requires an almost 9-hour-long computation. Using a smaller window size accelerates the process but slightly worsens the resulting ordering, as seen in Figure~\ref{img-tune-w}.

\begin{table}[h]
\centering
\begin{tabular}{r||c|c|c|c|c|c|c|c}
  %\hline
& \textit{pokec} & \textit{flickr} & \textit{livejournal} & \textit{wiki} & \textit{gplus} & \textit{pldarc} & \textit{twitter} & \textit{sdarc}\\
  \hline%\hline
MinLA & 28 & 27 & 92 & 441 & 539 & 579 & \textbf{2956} & \textbf{4884}\\
MinLogA & 89 & 64 & 217 & \textbf{2169} & 1662 & \textbf{2258} & \textbf{10245} & \textbf{17168}\\
RCM & 3 & 5 & 10 & 60 & 49 & 63 & 158 & 406\\
DegSort & 0.8 & 0.4 & 1 & 5 & 9 & 14 & 30 & 85\\
ChDFS & 1 & 0.8 & 1 & 3 & 8 & 10 & 54 & 76\\
SlashBurn & 3 & 9 & 16 & 37 & 90 & 189 & 633 & 1066\\
LDG & 6 & 7 & 13 & 68 & 101 & 144 & 673 & 798\\
Gorder \footnotesize{$w$=$5$} & 79 & 110 & 118 & 988 & \textbf{3324} & \textbf{8783} & \textbf{25475} & \textbf{32488} \\
\hline
  Edges \footnotesize{$m$} & 31M & 33M & 69M & 437M & 463M & 623M & 1.47G & 1.94G
\end{tabular}
\caption{\textbf{Graph ordering time.} We indicate the time to compute each ordering in seconds (in bold font when above 30 minutes). We also indicate the number of edges for each dataset to help evaluating the scalability of a method. Comparing to Table~9 in~\cite{gorder} is possible for RCM, DegSort, ChDFS and Gorder because the implementations are alike: it shows that our hardware is 2 to 5 times slower than in~\cite{gorder}. For the other orderings, the implementations are likely too different to be compared.}\label{table-order-time}
\end{table}

%%%%%%%%%%%%
\begin{figure}%\newgeometry{left=10mm, right=10mm}
    \begin{adjustwidth}{-25mm}{-15mm}
    \centering
    \includegraphics[width=\linewidth]{img/img-speedup.pdf}
    \caption{\textbf{Speedup of Gorder.} For each algorithm and each dataset, we display the absolute runtime for Gorder. Bars represent the relative time of all other orderings compared to this reference. For readability, the y-axis is cut above factor~2, but values go as high as 3.7. This figure can be compared to Figure~9 in~\cite{gorder}. Another visualisation is show in supplementary figure~\ref{img-speedup-grouped}.}\label{img-speedup}
    \end{adjustwidth}
\end{figure}%\restoregeometry

\subsection{Running time}
%
The main purpose of~\cite{gorder} is to measure if the node orderings listed above allow for faster execution of standard graph algorithms.
%
We compare in Figure~\ref{img-speedup} the performances of all the orderings to Gorder. The results are reported for each dataset and algorithm in the same way as Figure~9 of the original paper.
%
We also propose in supplementary figure~\ref{img-speedup-grouped} another visualisation of the same results but grouped by ordering instead of dataset, which emphasises the overall performance of an ordering method.

A first few observations can be made from the raw results of the experiments.
%
As in~\cite{gorder}, we observe that Gorder almost always leads to the fastest execution times.
%
The speed-up factor reaches up to 2.5 compared to default for Diameter on \textit{sdarc} and 3.7 compared to random for PageRank on \textit{wiki}, but for the sake of clarity we limit the y-axis of Figure~\ref{img-speedup} to a factor~2.

To help making sense of the results, we propose an aggregated visualisation in Figure~\ref{img-ranking}, where each ordering is ranked according to its performance in comparison to the other orderings through the 81 series of experiments reported in Figure~\ref{img-speedup}. It shows in particular that Gorder is the best ordering method in half of the experiments, and second-best in most other cases.

Below, we comment on the performances of the different ordering methods under examination.

\subsubsection{Original ordering}
The experiments show that the default ordering performs better than more elaborate methods such as MinLA or MinLogA, which have a high computation overhead as shown in Table~\ref{table-order-time}. It was also observed in~\cite{gorder}.
%
This indicates that the way in which datasets are constructed tends to give close indices to nodes that are in the same neighbourhood.
%
In a web graph for instance, if webpages are listed alphabetically by URL, it is likely that two consecutive nodes have a hyperlink between them since they belong to the same website.

\subsubsection{Poorly performing orderings}
The random ordering is always the worst performer except for 6 experiments where it is second-worst. It is not surprising as any other ordering tends to bring neighbouring nodes together, which should improve the algorithm \runtime.
%
Note however that LDG performs only slightly better than random, and that it is almost always the slowest in~\cite{gorder} too. In a quarter of the experiments, it is more than twice as slow as Gorder. These poor results lead to think that either its parameter (the size of bins $k=64$) is not optimal, or that its quality function is not highly correlated to cache efficiency.
%
MinLA and MinLogA are always faster than LDG but, except for \textit{twitter} dataset, they are slower than the original ordering. As reported in Figure~\ref{img-tune-sa}, we could not find any parameters with better results than local search, which is not ideal when the problem has local minima.

\subsubsection{Degree-based orderings}
%
Both InDegSort and SlashBurn use the degree of nodes as their main criterion. The experiments show that they outperform the default orderings, especially for larger datasets. For some algorithms such as BFS or NQ, they are less than 20\% slower than Gorder. This indicates that cache misses are reduced when nodes of similar degree are copied together on a cache line.
The original paper found similar results, though their implementation of SlashBurn did not perform as well; the different version that we use here (see Section~\ref{orders}) may be responsible for this discrepancy.

\subsubsection{Orderings outperforming Gorder on specific algorithms}
%
We also notice that some orderings perform particularly well on specific algorithms, even outperforming Gorder.
The ChDFS ordering is the most efficient for DFS algorithm on all datasets. This is due to the close relation between these two processes: the algorithm explores the graph in the exact same way as the ordering is created.
%
Likewise, RCM is a variation of a BFS that takes node degrees into account and it is the most efficient ordering for BFS algorithm.

Both also outperform Gorder for algorithms that are not as visibly related: ChDFS is up to 10\% more efficient for SCC on smaller datasets, and RCM is the most efficient for Diameter and SP.
More generally, Figure~\ref{img-ranking} shows that these two orders are among the three fastest ones in 75\% of the experiments. The original paper has different results on that matter: RCM and ChDFS are the best alternatives as well, but they are always 10 to 20\% slower than Gorder.

\subsection{Comparison to the original paper}
Our purpose here is to detect if there are significant discrepancies in performance between the original paper and our replication study.

Figure~\ref{img-ranking} presents an aggregate view of the results grouped by ordering method.
%
For each series of experiments (\textit{i.e.} a given algorithm applied to a given dataset), we rank ordering methods from best to worst performance.
%
The figures report how many times each ordering has been ranked in each position. For instance Gorder is ranked first in 40 of our 81 replication series.

%%%%%%%%%%%%%
\begin{figure}[htb]
\centering
\begin{subfigure}{.48\textwidth}
\includegraphics[width=\linewidth]{img/img-ranking_vert.pdf}
\caption{\textbf{Rankings in our 81 experiments} (9 algorithms times 9 datasets). Random ordering was added and Metis was ignored. }\label{img-ranking-fab}
\end{subfigure}
\hspace{.02\textwidth}
\begin{subfigure}{.48\textwidth}
\includegraphics[width=\linewidth]{img/img-ranking-hao_vert.pdf}
\caption{\textbf{Rankings in \cite{gorder}} (72 experiments as \textit{epinion} is omitted). Rankings are inferred from Figure~9 of~\cite{gorder}: values above the factor 1.5 limit are considered equal.}\label{img-ranking-hao}
\end{subfigure}
\caption{\textbf{Rankings of ordering methods.} For each series of experiments, we rank the \runtime\ performance of the orderings. This figure shows how many times an ordering ranks best (thickest, lightest bar), second-best, \ldots, to worst (thinnest, darkest bar).}
\label{img-ranking}
\end{figure}
%%%%%%%%%%%%%

\subsubsection{Results for Gorder}
In both the original study and our replication, Gorder ranks first overall. This shows that this ordering is the best choice overall. However, our study shows that Gorder is outperformed by different orderings in half of the experiments, while it is only outranked once in the original paper. Figure~\ref{img-ranking-hao} thus leads us to think of Gorder as the perfect choice whereas Figure~\ref{img-ranking-fab} establishes RCM and ChDFS as relevant challengers, with 24 and 16 first places respectively.
%
This difference between the two papers is probably due to implementations: in our replication, ChDFS uses exactly the DFS algorithm. In particular, the nodes are visited in the same order, which leads to a quick execution of DFS. The original paper likely prevents this mechanism, for instance by shuffling the nodes at each step of the search.

\subsubsection{Ranking of other orders}
The three best orderings are evidently the same in both studies, but there are some nuances for the other ones. First, this visualisation does not always allow for exact ranking: in Figure~\ref{img-ranking-hao}, InDegSort has more second and third places than SlashBurn but fewer fourth and fifth places. There is no obvious way of deciding which is better, while Figure~\ref{img-ranking-fab} clearly indicates InDegSort. The same issue happens between Original and MinLogA: we can say that their rank in~\cite{gorder} is equal.

The last nuance comes for the slowest orderings: in our study, LDG is only better than Random while MinLA competes with MinLogA and Original. In~\cite{gorder} on the other hand, LDG is better than MinLA overall. Still, the limit at factor 1.5 makes the ranking unreliable for slowest orderings which can explain this difference.

In the end, both studies rank the orderings in a very similar way.

\subsubsection{Limits of visualisation}
The aggregate view of Figure~\ref{img-ranking} induces several approximations. First of all, there are 72 experiments in the original study and 81 experiments in ours, which adds \textit{epinion} dataset. This extra dataset is much smaller than the others and all its results in Figure~\ref{img-speedup} range in a 40\% factor, to be compared with more than 200\% for the biggest datasets. Yet, the ranking of ordering methods on \textit{epinion} is consistent with other datasets.

The original study does not test random orderings. This does not disturb the results as this method ranks last in most experiments. Similarly, our study omits Metis so we ignore it in Figure~\ref{img-ranking-hao} as well.
%
Moreover, the original paper hides precise information when a \runtime\ exceeds 1.5 times the \runtime\ of Gorder. We consider that all orderings above this bound are equal.

The main issue is that this visualisation only shows the rank and hides the extent of \runtime\ variations. This information is only visible in Figure~\ref{img-speedup}, where a rift separates two categories: faster orders with Gorder, RCM, ChDFS, InDegSort and SlashBurn, from slower orders with the other ones. However, Figure~\ref{img-ranking} is useful to grade ordering methods. If original ordering is taken as a limit between faster and slower orders, we find the same gap again.

\subsection{Cache miss}

A cache miss is a state of an execution when the data requested by the processor is not found in the cache memory. The program has to fetch the data in further cache levels or in main memory, which causes delays.
%
Gorder capitalises on the intuition that if we cluster nodes that are frequently accessed together, higher levels of cache will hold more relevant data and thus make algorithms run faster.

To prove that Gorder speedup is due to cache optimisation, we compute the proportion of the total computation time spent in data retrieval.
%
We use Unix \textit{perftools} with the wrapper \textit{ocperf}.
It provides various hardware metrics such as the number of CPU cycles, branch predictions, cache misses\ldots
%
\footnote{See \url{https://perf.wiki.kernel.org}. We select the following counters:
the total time \textit{task-clock}, \textit{cpu-cycles}, \textit{L1-dcache-loads} and \textit{L1-load-misses} to measure the efficiency of the first layer of data cache (we are not interested in instruction cache here), \textit{LLC-loads} and \textit{LLC-load-misses} to measure the efficiency of the last cache layer, and metrics specifically designed to measure the impact of cache misses such as \textit{cycles-l1d-pending} or \textit{cycles-l3-miss} in the cycle-activity category.}
%
Depending on the machine architecture, different metrics are available.
%
\begin{table}[bt]
\include{includes/table-cache}
\caption{
    \textbf{Cache statistics measured for PageRank algorithm.} L1-ref (references): number of times a piece of data was required by the processor and searched in level 1 of cache. L1-mr (miss-rate): proportion of data that was not found in L1. L3-ref: number of references to the third (lowest) level of cache after data was not found in levels 1 and 2. L3-r (ratio): proportion of data that was not found in L1 nor L2, then searched in L3. Cache-mr: proportion of data that was not found in cache (L1, L2 or L3) and had to be retrieved in main memory. Compare to Tables~3 and~4 in~\cite{gorder}.
}
\label{table-cache}
\end{table}

Table~\ref{table-cache}, just like the Tables~3 and~4 of the original paper, shows the cache-miss rates at different levels. The first column is the total number of L1-references which is the number of times a piece of data was required by the processor. A proportion of this data is not found (second column) and requested in intermediate levels of cache, until reaching L3 (third and fourth columns). The remaining data (last column) has to be retrieved in main memory. Note that each further level of cache roughly implies an additional factor 4 latency.

We observe that first-level cache references are similar for all orderings: the algorithms run in the exact same way so they need to access the same amount of data, regardless of the arrangement of nodes. However, the miss-rate in L1 reveals important variations: with Gorder, only 10\% of the data is not directly available in L1, while it reaches 20\% with Random or LDG orders.
%
The percentage of data requested in L3 is even more scattered, from 5\% with Gorder to 20\% with Random or LDG on \textit{sdarc}.
%
Finally, all the orderings have a low cache-miss rate (between 1.6 and 3.6\%) on \textit{flickr} and RCM has the smallest. The gap is more striking on \textit{sdarc} where Random and LDG have 9\% of cache-miss, three times as much as Gorder. This ratio is the proportion of data that had to be retrieved in main memory (RAM), which is about 60 times slower than the L1 cache\footnote{At 4GHz, a cycle is $1c=1/(4\cdot 10^9)s=0.25ns$, so latency is $4c=1ns$ for L1 and $42c+51ns\simeq 62ns$ for RAM. Values are taken from \url{https://www.7-cpu.com/cpu/Skylake.html}.}.

In general, the ranking for cache-miss rates matches the ranking for \runtime\ shown in Figure~\ref{img-ranking-fab}. Gorder has the best results and RCM and ChDFS are close behind. MinLA, MinLogA and Original orders have high cache-miss rates for all levels. This shows that the speedup is indeed due to cache-miss reduction.
%
When compared to Original order, Gorder reduces cache-miss rates to speed up the algorithms. Figure~\ref{img-cache} shows that the total \runtime\ is reduced by 15 to 50\% on \textit{sdarc}, but the CPU execution time is almost identical: it is the factor 3 reduction on cache stall that makes the algorithm faster.

\section{Discussion}\label{discussion}

Our experiments replicate the ones proposed in~\cite{gorder} but some aspects are not discussed in sufficient detail in the original paper to allow for immediate replication.
%
For instance, the algorithms NQ and DS only have a succinct description, which may explain why their performances reported in our Figure~\ref{img-cache} do not align perfectly with Figure~1 of \cite{gorder}.
Similarly, we were not able to tune the simulated annealing procedure correctly, which questions the relevance of our experiments with MinLA and MinLogA.
%
Nonetheless, most of these technical issues have been solved or circumvented thanks to the answers of Hao Wei to our questions.

Above all, this study replicates the main observation of the original paper: Gorder reduces cache latency significantly and is the best performer among all the ordering methods under study, as shown in Figure~\ref{img-ranking}. Its consistent efficiency on all algorithms and datasets suggests that it could speed up other graph algorithms as well.

The only important difference with the original paper is that RCM and ChDFS follow closely behind Gorder and even outperform it in half of the experiments. They are based on straightforward graph searches, which are simple to program and very quick to execute, as reported in Table~\ref{table-order-time}.
%
On the other hand, computing Gorder requires a complex procedure and a lot of time. It has been pointed out in~\cite{overhead} that this high overhead time can only be amortised if algorithms are run thousands of times. In the case where networks evolve and require constant recomputation of the node ordering, Gorder needs to be adapted to integrate the modifications without running the whole process again. A parallel version of Gorder could reduce this problem.

Beyond algorithm speed-up, the contribution of Hao Wei \textit{et al.} is an efficient framework that could be applied for other purposes. For example, graph compression also benefits from orderings that cluster nodes with high proximity~\cite{boldiv}. Gorder could be an input for such existing methods. It would also be interesting to investigate how different types of real-world datasets~\cite{milo} behave when a new ordering is applied.

\section{Conclusion}

The replication of paper \cite{gorder} shows that Gorder is an efficient cache optimisation for various standard algorithms.
%, though some orders are still faster for specific algorithms.
We confirm its superiority for networks ranging from 30 million to 2 billion edges, and the hardware measurement tools prove that this is due to reduced cache stall. However, orders such as DFS are among the best performers, and they are much simpler to design. Indeed, the computation of Gorder does not scale linearly, which makes it very time-consuming for bigger graphs. It is then a matter of balance between this long overhead time and the substantial speedup for subsequent graph algorithms.

%%%%%%%%%%%%
% \newpage
%%%%%%%%%%%%

\subsection*{Acknowledgements}

We warmly thank Hao Wei for replying to our questions about the original paper, which settled several technical hesitations relative to the implementation.

This work is funded by the ANR (French National Agency of Research) partly by the \href{http://bit.ly/LiMass}{LiMass JCJC project} (under grant ANR-19-CE23-0010) and partly by the \href{http://fit.complexnetworks.fr}{ANR FiT LabCom}.


\documentclass[10pt,a4paper]{article}
\title{Insert Algo Name}
\date{}

\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
% For algorithms
\usepackage[linesnumbered,ruled,lined,boxed,commentsnumbered]{algorithm2e}

\usepackage{titling}

\setlength{\droptitle}{-10em}

\begin{document}
\maketitle

\begin{algorithm}[H]
	\KwData{Input data here}
	\KwResult{Output here}
	\BlankLine
	\Begin {
		% Pseudo code over here using algorithm2e
	}
\caption{Insert Algo Name}
\end{algorithm}

\section{Proof of Correctness}
	\subsection{Invariant}

	\subsection{Initialization}

	\subsection{Maintenance}

	\subsection{Termination}
\end{document}