Tranversal gates in permutation-invariant codes and CSS codes

Let $S_n$ be the group of permutations of the $n$-element set $[n]:=\{1 , 2, \dots, n\}$, and let $\pi\in S_n$. Define the unitary $U_\pi: (\mathbb{C}^2)^{\otimes n}\mapsto(\mathbb{C}^2)^{\otimes n}$ by
\[
U_\pi(\ket{\varphi_1}\otimes\cdots\otimes\ket{\varphi_n})=\ket{\varphi_{\pi^{-1}(1)}}\otimes\cdots\otimes\ket{\varphi_{\pi^{-1}(n)}}
\]
for all product states $\ket{\varphi_1}\otimes\cdots\otimes\ket{\varphi_n}$ (and extended linearly to all of $(\mathbb{C})^{\otimes{n}}$). Denote by $(i j)$ the transposition of $i,j\in[n]$ for $i\neq j$, and define the subspace
\[
Q_n=\{\ket{\Psi}\in(\mathbb{C})^2)^{\otimes{n}} \mid U_{(i j)}\ket{\Psi}=\ket{\Psi} \  \text{for all} \ i\neq j \}.
\]

 Let $\vec{b}=b_1b_2\dots b_n \in\{0,1\}^n$ with $b_i\in\{0,1\}$, and let $\ket{\vec{b}}\in(\mathbb{C}^2)^{\otimes n}$ be a $n$-qubit computational basis state. More explicitly, $\ket{\vec{b}}=\bigotimes_{i=1}^{n}\ket{b_i}$, describes the $n$-qubit state where each qubit is either in the state $\ket{0}$ or $\ket{1}$. Now define the map
 \[
  \omega: \{0,1\}^n\to \{0,1,\dots,n\} \ \ \text{given as} \ \  \omega(\vec{b})=\SUM{i=1}{n}b_i,
  \]
  which simply counts the number of $1$s appearing in the bit string $\vec{b}$, and call $\omega(\vec{b})$ the \emph{weight} of $\vec{b}$.
 
It was shown in a previous post that a basis of $Q_n$ is given by the $n+1$ states of the form
 
  \[
  \ket{\omega_k}=\frac{1}{\sqrt{\binom{n}{k}}}\SUM{ \ \ \vec{b} \  : \  \omega(\vec{b})=k}{}\ket{\bar{b}},
    \]
   
  where each basis state $\ket{\omega_k}$, for $k\in\{0,1,\dots, n\}$, consists of an equally weighted superposition of the $\binom{n}{k}$ computational basis states $\ket{\vec{b}}$ with weight $\omega(\vec{b})=k$.


 Consider the two dimensional subspace of $Q_n$ which is spanned by the following two states:
 \[\begin{align*}
 \ket{\overline{0}}&:=\ket{\omega_0}=\TENSOR{i=1}{n}\ket{0}=\ket{\vec{0}}, \\
 \ket{\overline{1}}&:=\frac{1}{\sqrt{2^n-1}}\SUM{k=1}{n}\sqrt{\binom{n}{k}}\ket{\omega_k} \\
 &=\frac{1}{\sqrt{2^n-1}}\SUM{\vec{b}\neq\vec{0}}{}\ket{\vec{b}},
 \end{align*}  \]
 and note that $\ip{\overline{0}}{\overline{1}}=0$. Moreover, since each of $\ket{\overline{0}}$ and $\ket{\overline{1}}$ are given by superpositions of basis states of $Q_n$ each state is left invariant under the action of $U_{(ij)}$ for any transposition $(ij)\in S_n$. Therefore, the two dimensional subspace spanned by $\ket{\overline{0}}$ and $\ket{\overline{1}}$ is a valid subcode of $Q_n$. 

  Now, observe the action of the transversal Hadamard gate applied to each of the $n$ qubits of the state $\ket{\overline{0}}$

\[ \begin{align*}
 H^{\otimes n}\ket{\overline{0}}&= H^{\otimes n}\ket{\vec{0}} \\
  &=\frac{1}{\sqrt{2^n}}\SUM{\vec{b}\in\{0,1\}^n}{}\ket{\vec{b}} \\
  &=\frac{1}{\sqrt{2^n}}\ket{\vec{0}}+\frac{1}{\sqrt{2^n}}\SUM{\vec{b}\neq \vec{0}}{}\ket{\vec{b}} \\
  =&\frac{1}{\sqrt{2^n}}\ket{\vec{0}}+\frac{\sqrt{2^n-1}}{\sqrt{2^n}}\left(\frac{1}{\sqrt{2^n-1}}\SUM{\vec{b}\neq \vec{0}}{}\ket{\vec{b}}\right) \\
  &=\sqrt{2^{-n}}\ket{\overline{0}}+\sqrt{1-2^{-n}}\ket{\overline{1}}. \\
 \end{align*}\]

 Instead, observe the action of $H^{\otimes n}$ on the state $\ket{\overline{1}}$:
\[  \begin{align*}
 H^{\otimes n}\ket{\overline{1}}&= \frac{1}{\sqrt{2^n-1}}\SUM{\vec{b}\neq\vec{0}}{}H^{\otimes n}\ket{\vec{b}} \\
 &= \frac{1}{\sqrt{2^n-1}\sqrt{2^n}}\SUM{\vec{b}\neq\vec{0}}{}\SUM{ \ \vec{c}\in\{0,1\}^n}{}(-1)^{\vec{b}\cdot\vec{c}}\ket{\vec{c}} \\
 &= \frac{1}{\sqrt{2^n-1}\sqrt{2^n}}\SUM{\vec{b}\neq\vec{0}}{}(-1)^{\vec{b}\cdot\vec{0}}\ket{\vec{0}} + \frac{1}{\sqrt{2^n-1}\sqrt{2^n}}\SUM{\vec{b}\neq\vec{0}}{}\SUM{ \ \vec{c}\neq\vec{0}}{}(-1)^{\vec{b}\cdot\vec{c}}\ket{\vec{c}}  \\
  &= \frac{2^n-1}{\sqrt{2^n-1}\sqrt{2^n}}\ket{\vec{0}} + \frac{1}{\sqrt{2^n-1}\sqrt{2^n}}\SUM{\vec{b}\neq\vec{0}}{}\SUM{ \ \vec{c}\neq\vec{0}}{}(-1)^{\vec{b}\cdot\vec{c}}\ket{\vec{c}}  \\
  &= \sqrt{1-2^{-n}}\ket{\vec{0}} + \frac{1}{\sqrt{2^n-1}\sqrt{2^n}}\SUM{\vec{b}\neq\vec{0}}{}\SUM{ \ \vec{c}\neq\vec{0}}{}(-1)^{\vec{b}\cdot\vec{c}}\ket{\vec{c}}  \\
 &= \sqrt{1-2^{-n}}\ket{\vec{0}} + \frac{1}{\sqrt{2^n-1}\sqrt{2^n}}\SUM{\vec{c}\neq\vec{0}}{}\left(\SUM{ \ \vec{b}\neq\vec{0}}{}(-1)^{\vec{b}\cdot\vec{c}}\right)\ket{\vec{c}}  \\
  &= \sqrt{1-2^{-n}}\ket{\vec{0}} + \frac{1}{\sqrt{2^n}}\frac{1}{\sqrt{2^n-1}}\SUM{\vec{c}\neq\vec{0}}{}\left(-1\right)\ket{\vec{c}}  \\
    &= \sqrt{1-2^{-n}}\ket{\overline{0}} - \sqrt{2^{-n}}\ket{\overline{1}}.  \\
 \end{align*}\]

 Thus, in summary the action of $H^{\otimes n}$ on $\ket{\overline{0}}$ and $\ket{\overline{1}}$ is given by:
 \[\begin{align*}
 \ket{\overline{0}}&\overset{H^{\otimes n}}\mapsto \sqrt{2^{-n}}\ket{\overline{0}}+\sqrt{1-2^{-n}}\ket{\overline{1}} \\
  \ket{\overline{1}}&\overset{H^{\otimes n}}\mapsto \sqrt{1-2^{-n}}\ket{\overline{0}}-\sqrt{2^{-n}}\ket{\overline{1}},
 \end{align*}\]

 which is given by the logical operation $\overline{U}$ given by the matrix expressed in the logical basis as
 \[
 \overline{U}=\begin{pmatrix}
 \sqrt{2^{-n}} & \sqrt{1-2^{-n}}\\
  \sqrt{1-2^{-n}}&-\sqrt{2^{-n}} \\
 \end{pmatrix}.
 \]

Transitioning now into the setting of CSS codes, let $H_1, H_2$ be parity check matrices such that $Q=CSS(H_1,H_2)$ is a $[[n,k,d]]$-CSS code. The matrix of stabilizers for this code is given by the binary symplectic matrix
  \[
 S= \left(\begin{array}{c | c}
  0&H_1 \\
  H_2 & 0
  \end{array}\right)
  \]
 
  The action of conjugation by a transversal Hadamard applied to the symplectic matrix $S$ transforms it to 
    \[
 S'=H^{\otimes n}SH^{\otimes n \dagger} \left(\begin{array}{c | c}
  0&H_2 \\
  H_1 & 0
  \end{array}\right)
  \]
 
  Suppose that $H^{\otimes n}$ preserves the code space so that $H^{\otimes n}Q=Q$. This action must send codewords of $Q$ to codewords of $Q$ and only permute the set of stabilizers of the code.  Since $H^{\otimes n}$ effectively turns $X$-type generators into $Z$-type generators, then it must be the case that any row $r_i$ of $H_1$ lies in the span of the rows of $H_2$, and likewise that any row $r'_i$ of $H_2$ lies in the span of the rows of $H_1$. That is, $Row(H_1)\subseteq Row(H_2)$ and $Row(H_2)\subseteq Row(H_1)$, which is equivalent to the condition that
  \[
  Row(H_1)=Row(H_2),
  \] 
  where $row(H_i)$ represents the space spanned by rows of $H_i$.
 
  Now, suppose instead that $Row(H1)=Row(H_2)$. This implies that a row of $H_1$ (or $H_2$) can be expressed in terms of the rows of $H_2$ (or $H_1$). Then after the action of a transversal Hadamard $H^{\otimes n }$, each $X$-type (or $Z$-type) stabilizer will be transformed into a $Z$-type ($X$-type) stabilizer that can be generated by the original set of $Z$-type ($X$-type) stabilizers. Hence, the action of $H^{\otimes n}$ preserves the codespace: $H^{\otimes n}Q=Q$.
 
Therefore, the condition that $Row(H_1)=Row(H_2)$ is both a necessary and sufficient condition for $H^{\otimes n}Q=Q$. If $H_1=H_2$, then trivially $Row(H_1)=Row(H_2)$ so that $H^{\otimes n}Q=Q$.


Suppose that $H=H_1=H_2$ and $n$ is odd. Let $Row(H)$ be the space spanned by the rows of $H$, and assume that $|v|=\sum_{j=1}^{n}=0 \ (mod \ 2)$ for every $v\in Row(H)$. Note that this implies that $\vec{1}\in Row(H)^\perp\backslash Row(H)$, where $\vec{1}=(1,\dots,1)$ ($n$ times).

Therefore, the operators given by $X^{\otimes n}$ and $Z^{\otimes n}$ are in the normalizer of the stabilizer for $Q$, because each stabilizer will commute with $X^{\otimes n}$ and $Z^{\otimes n}$ as the size of the intersection of the supports of any stabilizer with either $X^{\otimes n}$ and $Z^{\otimes n}$ is even. Moreover, $X^{\otimes n}$ and $Z^{\otimes n}$ are not in the stabilizer since every stabilizer acts nontrivially only on an even number of physical qubits whereas $X^{\otimes n}$ and $Z^{\otimes n}$ acts on all $n$ qubits (where $n$ is odd). Hence, the operators $X^{\otimes n}$ and $Z^{\otimes n}$ yield a logical operation on $Q$ on some encoded qubit. Without loss of generality associate these logical operations to act on the first encoded qubit:
\[\begin{align*}
\overline{X}_1&=X^{\otimes n} \\
\overline{Z}_2&=Z^{\otimes n}
\end{align*}\]

Consider then the logical basis states for the $1$st encoded qubit: $\ket{\overline{0}}_1$ and $\ket{\overline{1}}_1$. In this basis, these states can be expressed as:
\[\begin{align*}
\ket{\overline{0}}_1\bra{\overline{0}}_1&=\frac{I+\overline{Z}}{2} \\
\ket{\overline{1}}_1\bra{\overline{1}}_1&=\frac{I-\overline{Z}}{2}.
\end{align*}\]

Then since $HXH^\dagger=Z$ and $HZH\dagger=X$, this implies that $H^{\otimes n}\overline{X}H^{\otimes n \dagger}=\overline{Z}$ and $H^{\otimes n}\overline{Z}H^{\otimes n \dagger}=\overline{X}$. Therefore,
\[\begin{align*}
H^{\otimes n}\left(\frac{I+\overline{Z}}{2}\right)H^{\otimes n \dagger}&=\frac{I+\overline{X}}{2}=\ket{\overline{+}}_1\bra{\overline{+}}_1 \\
H^{\otimes n}\left(\frac{I-\overline{Z}}{2}\right)H^{\otimes n \dagger}&=\frac{I-\overline{X}}{2}=\ket{\overline{-}}_1\bra{\overline{-}}_1,
\end{align*}\]
  where $\ket{\overline{+}}=\frac{1}{\sqrt{2}}(\ket{\overline{0}}_1+\ket{\overline{1}}_1)$ and $\ket{\overline{-}}=\frac{1}{\sqrt{2}}(\ket{\overline{0}}_1-\ket{\overline{1}}_1)$. Hence, the action of $H^{\otimes n}$ on the logical computational basis of the first encoded qubit is given by a logical Hadamard on that encoded qubit:
\[  \begin{align*}
  \ket{\overline{0}}&\overset{\overline{H}}\mapsto\ket{\overline{+}},\\
  \ket{\overline{1}}&\overset{\overline{H}}\mapsto\ket{\overline{-}}.
  \end{align*}\]
 
  In regards to the action of $H^{\otimes n}$ on the rest of the $k-1$ encoded qubits, recall that $H^{\otimes n}$ preserves the code space. Therefore, $H^{\otimes n}$ merely permutes the individual stabilizers. More generally, $H^{\otimes n}$ is in the Clifford group $C_n$. Thus, it must be the case that $H^{\otimes n}=\overline{H}\otimes \overline{C}$, where $\overline{C}$ is some logical Clifford operation since $H^{\otimes n}$ is a Clifford operation.    
 

Probabilistic implementation of gates by cyclic permutation and measurement

Given an $n$- qubit Pauli operator $P=P_1\otimes \cdots \otimes P_n$, with $P_j\in\{I,X,Y,Z\}$, let $\eta(P)=P_2\otimes P_3\otimes\cdots\otimes P_n\otimes P_1$ be the Pauli operator obtained by cyclically permuting the factors. Let $S$ be a stabilizer with generators $\{M_j\}_j$, and let $\{\overline{X}_l,\overline{Z}_l\}_l$ be generators of $N(S)/S$. Consider the stabilizer $\eta(S)$ defined by generators $\{M'_j:=\eta(M_j)\}_j$, and the associated generators $\{\overline{X}'_l=\eta(\overline{X}_l), \overline{Z}'_l=\eta(\overline{Z}_l)\}_l$ of $N(\eta(S))/\eta(S)$.
Consider the following process:
  1. Start with some encoded state $\ket{\overline{\Psi}}$ for $S$.
  2. Measure all the stabilizer generators of $\eta(S)$.
  3. Output `success' and the post-measurement state if all outcomes are $+1$.

Let $S$ be the stabilizer of the $[[5,1,3]]$-code, and let $\ket{\overline{\Psi}}\in\mathcal{T}(S)$ be an arbitrary encoded state.

The stabilizer generators $S=<M_1,M_2,M_3,M_4>$ for this 5-qubit code, are given by
\[\begin{align*}
M_1=&X \ Z \ Z \ X \ I \\
M_2=& I \ X \ Z \ Z \ X \\
M_3=& X \ I \ X \ Z \ Z \\
M_4=& Z \ X \ I \ X \ Z ,
\end{align*}\]
and so the resulting generators for $\eta(S)=<M'_1,M'_2,M'_3,M'_4>$ are given by
\[\begin{align*}
M'_1=&Z \ Z \ X \ I \ X \\
M'_2=&X \ Z \ Z \ X \ I \\
M'_3=& I \ X \ Z \ Z \ X \\
M'_4=& X \ I \ X \ Z \ Z. \\
\end{align*}\]

Observe that $M'_2=M_1$, $M'_3=M_2$, $M'_4=M_3$, and that $M'_1=M_1M_2M_3M_4$. Thus, each of the generators $M'_j$ can be expressed in terms of the generators of $S$, which implies that $\eta(S)=S$. Since each $M\in S=\eta(S)$ satisfies $M\ket{\overline{\Psi}}=\ket{\overline{\Psi}}$, measuring the stabilizer generators $M'_j$ will always yield an outcome corresponding to $+1$, and the state will be left invariant as $\ket{\overline{\Psi}}$.  In regards to the procedure outlined above, the success probability will be $1$, and the post-measurement state will be $\ket{\overline{\Psi}}$.


Consider the set of stabilizers $S=<M_1,M_2>$ and generators of $N(S)/S=<\overline{X}_1,\overline{Z}_1,\overline{X}_2,\overline{Z}_2>$ given by
\[\begin{align*}
M_1=&X \ X \ X \ I  \\
M_2=& I \ Z \ Z \ I  \\
\overline{X}_1=& I \ X \ X \ I \\
\overline{Z}_1=& Z \ I \ Z \ I   \\
\overline{X}_2=& I \ I \ I \ X \\
\overline{Z}_3=&I \ I \ I \ Z.
\end{align*}\]

Then the stabilizer generators of $\eta(S)=<M'_1,M'_2>$ are given by
\[\begin{align*}
M'_1=&X \ X \ I \ X  \\
M'_2=& Z \ Z \ I \ I.  \\
\end{align*}\]
It is readily seen that $\{M'_1,M_i\}=0$ and $[M'_2,M_i]=0$, for $i=1,2$, implying that $M'_1\notin N(S)$, and that $M'_2\in N(S)$ but $M'_2\notin S$.


Consider the set of stabilizer generators of $S=<M_1,M_2>$ and generators of \\ $N(S)/S=<\overline{X}_1,\overline{Z}_1,\overline{X}_2,\overline{Z}_2>$ given by
\[\begin{align*}
M_1 =& X \ X \ X \ I \\
M_2 =& I \ Z \ Z \ I \\
\overline{X}_1=& I \ X \ X \ I \\
\overline{Z}_1=& Z \ I \ Z \ I \\
\overline{X}_2=& I \ I \ I \ X \\
\overline{Z}_2=& I \ I \ I \ Z, \\
\end{align*}\]

and the generators of $\eta(S)$ and $N(\eta(S))/\eta(S)$ given by

\[\begin{align*}
M'_1 =& X \ X \ I \ X \\
M'_2 =& Z \ Z \ I \ I \\
\overline{X}'_1=& X \ X \ I \ I \\
\overline{Z}'_1=& I \ Z \ I \ Z \\
\overline{X}'_2=& I \ I \ X \ I \\
\overline{Z}'_2=& I \ I \ Z \ I. \\
\end{align*}\]

Suppose the initial state is an encoded state $\ket{\overline{\Psi}}=\ket{\overline{+}}_1\otimes\ket{\overline{0}}_2$. Here, $\ket{\overline{+}}_1$ is interpreted as an encoded state of $3$ physical qubits, and the other encoded state $\ket{\overline{0}}_2$ in the tensor product is an encoded state represented by a single qubit.

More explicitly, consider the state $\frac{1}{\sqrt{2}}(\ket{000}+\ket{111})$ and observe that
\[
\overline{X}_1\frac{1}{\sqrt{2}}(\ket{000}+\ket{111})=\frac{1}{\sqrt{2}}(\ket{011}+\ket{100}),
\]
 which suggests the encoded basis is given by
 \[
\ket{\overline{0}}_1= \frac{1}{\sqrt{2}}(\ket{000}+\ket{111}) \ \ \text{and} \ \ \ket{\overline{1}}_1=\frac{1}{\sqrt{2}}(\ket{011}+\ket{100}).
 \]
 For the second encoded qubit, it must be that $\ket{\overline{0}}_2=\ket{0}$ and $\ket{\overline{1}}_2=\ket{1}$.

 Hence, the intitial encoded state is of the form
\[ \begin{align*}
 \ket{\overline{\Psi}}=&\ket{\overline{+}}_1\ket{\overline{0}}_2 \\
 =&\frac{1}{\sqrt{2}}(\ket{\overline{0}}_1+\ket{\overline{1}}_1)\ket{\overline{0}}_2 \\
 =&\frac{1}{\sqrt{2}}(\ket{000}+\ket{111}+\ket{011}+\ket{100})\ket{0} \\
 =&\frac{1}{\sqrt{2}}(\ket{0000}+\ket{1110}+\ket{0110}+\ket{1000}).
 \end{align*}\]

Consider the two permuted stabilizer $M'_1$ and $M'_2$. Note that $M'_1$ anticommutes with all of the logical Pauli operators in $N(S)/S$ so that $M'_1\notin N(S)$.  On the contrary, note that $M'_2$ does commute with all generators of $N(S)/S$, yet is not in the stabilizer $S$ since it cannot be generated by $M_1$ and $M_2$. Therefore, $M'_2\in N(S)\backslash S$, and can be expressed as a logical operation as $M'_2=\overline{Z}_1M_2$.

 Now suppose the operator $M'_2$ is measured on the encoded state $\ket{\overline{\Psi}}$. Since $M'_2=\overline{Z}_1M_2$ has the effect of applying a logical $Z$ operation on the first encoded qubit, which is in the state $\ket{\overline{+}}$, the probability of observing a $+1$ eigenvalue is $1/2$. In this case, the state after measuring $M'_2$ can be determined by applying the projector into the $+1$ eigenstate of $M'_2$:
\[ \begin{align*}
 \frac{1}{2}(I+M'_2)\ket{\overline{\Psi}}=&\frac{1}{2}(I+\overline{Z}_1M_2)(\ket{\overline{+}}_1\ket{\overline{0}}_2)\\
 =&\frac{1}{2}(\ket{\overline{+}}_1\ket{\overline{0}}_2+\ket{\overline{-}}_1\ket{\overline{0}}_2) \\
 =&\frac{1}{2}\ket{\overline{0}}_1\ket{\overline{0}}_2
\end{align*} \]

Thus, after renormalization the resulting state is given by $\ket{\overline{0}}_1\ket{\overline{0}}_2$.

Now, consider measuring $M'_1$. Since $M'_1\notin N(S)$, it commutes with exactly half of the Paulis and anticommutes with the other half. This gives a $1/2$ probability of measuring a $+1$ eigenvalue. Hence, the overall success probability of measuring a $+1$ outcome for both operators $M'_1$ and $M'_2$ is given by $1/4$.

Moreover, the resulting state after this second measurement is made is determined via the projector:
\[ \begin{align*}
 \frac{1}{2}(I+M'_1)\ket{\overline{0}}_1\ket{\overline{0}}_2=&\frac{1}{2\sqrt{2}}(I+M'_1)(\ket{000}\ket{0}+\ket{111}\ket{0}) \\
 =&\frac{1}{2\sqrt{2}}(\ket{000}\ket{0}+\ket{111}\ket{0}+\ket{110}\ket{1}+\ket{001}\ket{1})\\
 \rightarrow& \ \frac{1}{2}(\ket{000}\ket{0}+\ket{111}\ket{0}+\ket{110}\ket{1}+\ket{001}\ket{1}),
\end{align*} \]
 where the resulting state has been normalized accordingly.

 In the context of the permuted stabilizer $\eta(S)$, the $2$nd encoded qubit now appears physically in the $3$rd register of the system. Then by effectively permuting the qubits cyclically, the final state can be expressed in the form
  \[\begin{align*}
\ket{\psi_{final}}=& \frac{1}{2}(\ket{000}\ket{0}+\ket{011}\ket{1}+\ket{111}\ket{0}+\ket{100}\ket{1}) \\
=&\frac{1}{2}((\ket{000}+\ket{111})\ket{0}+(\ket{011}+\ket{100})\ket{1})\\
=&\frac{1}{2}(\ket{\overline{0}}_1\ket{\overline{0}}_2+\ket{\overline{1}}_1\ket{\overline{1}}_2),
 \end{align*}\]
 showing that the state is entangled between logical qubits.

Clifford circuits for stabilizer codes

 Consider the quantum code $T(S)$ defined by the encoding circuit shown below:



The initial state is of the form $\ket{\psi}\ket{0}\ket{+}$, where $\ket{\psi}$ is an arbitrary single qubit state to be encoded. Two stabilizers $M_1$ and $M_2$ acting on the three qubits can be associated to this initial state such that $\ket{0}$ is a $+1$ eigenstate of $M_1$ and $\ket{+}$ is a $+1$ eigenstate of $M_2$. Since $Z\ket{0}=\ket{0}$ and $X\ket{+}=\ket{+}$, then $M_1=IZI$ and $M_2=IIX$. The ``logical" Pauli operators in this case are simply $\overline{X}=XII$ and $\overline{Z}=ZII$.

When passing through some gate $U$ in an encoding circuit the stabilizer generators and logical Pauli operators after the action of the gate $U$ can be updated to new stabilizer generators $M'_1, M'_2$ and new logical Paulis $\overline{X}', \overline{Z}'$ given by conjugation by $U$:
\[
M'_1=UM_1U^\dagger , M'_2=UM_2U^\dagger, \overline{X}'=U\overline{X}U^\dagger, \overline{Z}'=U\overline{Z}U^\dagger.
\]

In the table shown below, such an updating procedure is shown for every gate in the encoding circuit. The following relations were used throughout
\[\begin{align*}
&HXH=Z, \ \  HZH=X , \ \ \ \  RXR^\dagger=Y, \ \  RZR^\dagger=Z \\
&CNOT(X\otimes I)CNOT=X\otimes X, \  \  CNOT(I\otimes X)CNOT=I\otimes X \\
&CNOT(Z\otimes I)CNOT=Z\otimes I, \ \  CNOT(I\otimes Z)CNOT=Z
\otimes Z
\end{align*}\]



Therefore, the stabilizer generators of $S$ are $M_1=-YZY$ and $M_2=-XXY$, and the logical Pauli operators corresponding to generators of $N(S)/S$ are $\overline{X}=IYX$ and $\overline{Z}=-XXY$.


Let $\delta$ be an $n\times n$ matrix and $S$ a $2n\times 2n$ matrix given as
\[
S=\begin{pmatrix}
0 & \delta \\
\delta & 0
\end{pmatrix},
\]
where here $0$ is an $n\times n$ matrix. By definition, $S$ is symplectic if and only if $J=S^TJS$, where
\[
J=\begin{pmatrix}
0 &I \\
I & 0
\end{pmatrix}.
\]
Then since
\[
\begin{pmatrix}
0 &I \\
I & 0
\end{pmatrix}=\begin{pmatrix}
0 &\delta^T \\
\delta^T & 0
\end{pmatrix}\begin{pmatrix}
0 &I \\
I & 0
\end{pmatrix}
\begin{pmatrix}
0 &\delta \\
\delta & 0
\end{pmatrix}
=\begin{pmatrix}
0 &\delta^T\delta \\
\delta^T\delta & 0
\end{pmatrix},
\]
in order for $S$ to be a symplectic matrix it must be the case that $I=\delta^T\delta$. Let the columns of the matrix $\delta$ be given by $\vec{r}_i\in\mathbb{Z}^n_2$ for $i\in\{1,\dots,n\}$. Then the condition $I=\delta^T\delta$ can then be interpreted as requiring each row $\vec{r}_i$ to have unit norm, $\vec{r}_i\cdot\vec{r}_i=1 (mod \ 2)$, and also that distinct rows be orthogonal, $\vec{r}_i\cdot\vec{r}_j=0 (mod \ 2)$ for $i\neq j$.

Now let the matrix $\delta=(d_{a,b})_{a,b}$ be given by
\[
d_{a,b}=
\left\{
\begin{array}{ll}
1 \ \ \text{for} \ \ a \neq b\\
\\
0\ \ \text{for} \ \ a=b\\

\end{array}
\right.
\]

Then the condition $\delta^T\delta=I$, implies that  $\delta^T\delta=\delta^2=(\sum_{i=1}^{n}d_{a,i}d_{i,b})_{a,b}=(\delta_{a,b})_{a,b}=I$. Therefore, $\sum_{i=1}^{n}d_{a,i}d_{i,a}=\sum_{i=1}^{n}d^2_{a,i}=n-1(mod 2)=1$ and $\sum_{i=1}^{n}d_{a,i}d_{i,b}=n-2(mod 2)=0$, which implies that $n$ must be even. Hence the matrix
\[
S=\begin{pmatrix}
0 & \delta \\
\delta & 0
\end{pmatrix},
\]
is symplectic if and only if $n$ is even.

Consider the case $n=4$ with $\delta$ defined as above. Then
\[
S=\begin{pmatrix}
0 &0 & 0& 0 & 0 & 1 & 1&1 \\
0 &0 & 0& 0 & 1 & 0 & 1&1 \\
0 &0 & 0& 0 & 1 & 1 & 0&1 \\
0 &0 & 0& 0 & 1 & 1 & 1&0 \\
0 &1 & 1& 1 & 0 & 0 & 0&0 \\
1 &0 & 1& 1 & 0 & 0 & 0&0 \\
1 &1 & 0& 1 & 0 & 0 & 0&0 \\
1 &1 & 1& 0 & 0 & 0 & 0&0 \\
\end{pmatrix}
\]
The objective here will be to find symplectic matrices $V_{L,k},V_{R,k}\in\{H, CNOT\}$ such that
\[
\left(\PROD{k=1}{g_L}V_{L,k} \right)S\left(\PROD{k=1}{g_R}V_{R,k} \right)=I.
\]
This would then imply that
\[
\left(\PROD{k=g_l}{1}V^\dagger_{L,k} \right)\left(\PROD{k=g_R}{1}V^\dagger_{R,k} \right)=S,
\]
giving a decomposition of $S$ in terms of $H$ and $CNOT$ gates alone. Actually, in what follows, only matrices acting from the left will be considered, so that $g_R=0$ and
\[
\left(\PROD{k=1}{g_L}V_{L,k} \right)S=I \ \ \text{so that} \ \ \left(\PROD{k=g_L}{1}V^\dagger_{L,k} \right)=S
\]
In general, for a symplectic matrix in the block form:
\[
U=\begin{pmatrix}
A & B \\
C & D
\end{pmatrix},
\]
the action of multiplying on the left by $H_i$ has the effect of switching the $i$th rows of $(A | B )$ and $(C | D )$. The action of $CNOT_{i,j}$ has the effect of adding the $i$th row of $(A |B)$ to the $j$th row of $(A | B )$, and adding the $j$th row of $( C | D ) $ to the $i$th row of $(C|D)$.

Consider the following sequence of transformations:
\[\begin{align*}
S=\begin{pmatrix}
0 &0 & 0& 0 & 0 & 1 & 1&1 \\
0 &0 & 0& 0 & 1 & 0 & 1&1 \\
0 &0 & 0& 0 & 1 & 1 & 0&1 \\
0 &0 & 0& 0 & 1 & 1 & 1&0 \\
0 &1 & 1& 1 & 0 & 0 & 0&0 \\
1 &0 & 1& 1 & 0 & 0 & 0&0 \\
1 &1 & 0& 1 & 0 & 0 & 0&0 \\
1 &1 & 1& 0 & 0 & 0 & 0&0 \\
\end{pmatrix}
\overset{CN_{4,1}CN_{3,1}CN_{2,1}}\rightarrow&
\begin{pmatrix}
0 &0 & 0& 0 & 1 & 1 & 1&1 \\
0 &0 & 0& 0 & 1 & 0 & 1&1 \\
0 &0 & 0& 0 & 1 & 1 & 0&1 \\
0 &0 & 0& 0 & 1 & 1 & 1&0 \\
0 &1 & 1& 1 & 0 & 0 & 0&0 \\
1 &1 & 0& 0 & 0 & 0 & 0&0 \\
1 &0 & 1& 0 & 0 & 0 & 0&0 \\
1 &0 & 0& 1 & 0 & 0 & 0&0 \\
\end{pmatrix}
\\
\overset{CN_{1,4}CN_{1,3}CN_{1,2}}\rightarrow&
\begin{pmatrix}
0 &0 & 0& 0 & 1 & 1 & 1&1 \\
0 &0 & 0& 0 & 1 & 0 & 0&0 \\
0 &0 & 0& 0 & 0 & 0 & 1&0 \\
0 &0 & 0& 0 & 0 & 0 & 0&1 \\
1 &0 & 0& 0 & 0 & 0 & 0&0 \\
1 &1 & 0& 0 & 0 & 0 & 0&0 \\
1 &0 & 1& 0 & 0 & 0 & 0&0 \\
1 &0 & 0& 1 & 0 & 0 & 0&0 \\
\end{pmatrix}
\\
\overset{CN_{4,1}CN_{3,1}CN_{2,1}}\rightarrow&
\begin{pmatrix}
0 &0 & 0& 0 & 1 & 0 & 0&0 \\
0 &0 & 0& 0 & 0 & 1 & 0&0 \\
0 &0 & 0& 0 & 0 & 0 & 1&0 \\
0 &0 & 0& 0 & 0 & 0 & 0&1 \\
1 &0 & 0& 0 & 0 & 0 & 0&0 \\
0 &1 & 0& 0 & 0 & 0 & 0&0 \\
0 &0 & 1& 0 & 0 & 0 & 0&0 \\
0 &0 & 0& 1 & 0 & 0 & 0&0 \\
\end{pmatrix}
\\
\overset{H_{1}H_{2}H_{3}H_{4}}\rightarrow&
\begin{pmatrix}
1 &0 & 0& 0 & 0 & 0 & 0&0 \\
0 &1 & 0& 0 & 0 & 0 & 0&0 \\
0 &0 & 1& 0 & 0 & 0 & 0&0 \\
0 &0 & 0& 1 & 0 & 0 & 0&0 \\
0 &0 & 0& 0 & 1 & 0 & 0&0 \\
0 &0 & 0& 0 & 0 & 1 & 0&0 \\
0 &0 & 0& 0 & 0 & 0 & 1&0 \\
0 &0 & 0& 0 & 0 & 0 & 0&1 \\
\end{pmatrix}=I
\end{align*}\]

Recalling that $H^\dagger=H$ and $CNOT^\dagger=CNOT$, and reversing the order of the operations used above then yields a sequence of operations that implements $S$ (the rightmost operation is applied first) :

\[
S=CN_{2,1}CN_{3,1}CN_{4,1}CN_{1,2}CN_{1,3}CN_{1,4}CN_{2,1}CN_{3,1}CN_{4,1}H_{4}H_{3}H_{2}H_{1}.
\]

A circuit diagram depicting this sequence is shown below:




CSS codes and the 9-qubit Shor code

In the 9-qubit Shor code, the stabilizer $S$ is generated by the following operators

\[\begin{align*}
S_1=& Z_1Z_2 \\
S_2=&Z_2Z_3 \\
S_3=&Z_4Z_5 \\
S_4=&Z_5Z_6 \\
S_5=&Z_7Z_8 \\
S_6=&Z_8Z_9 \\
S_7=&X_1X_2X_3X_4X_5X_6 \\
S_8=&X_4X_5X_6X_7X_8X_9. \\
\end{align*}\]
 Thus, the the dimension of the code space is $2^{9-8}=2$, which implies that the code only encodes one logical qubit. In this case, $\hat{N}(S)/S\cong \hat{P}_1$, so $\hat{N}/S$ will be generated by some elements $\overline{X}, \overline{Z}\in\hat{N}(S)\backslash S$, satisfying the usual Pauli commutation relations:
 \[
\overline{X}^2=\overline{Z}^2=\overline{I}, \  \text{and} \  \overline{X} \ \overline{Z}=-\overline{Z} \ \overline{X}
 \]
 In this regard, let
\[\begin{align*}
 \overline{Z}=&X_1X_2X_3X_4X_5X_6X_7X_8X_9 \\
  \overline{X}=& Z_1Z_2Z_3Z_4Z_5Z_6Z_7Z_8Z_9 \\
\end{align*}\]
 which satisfy the commutation relations described above. Moreover, $\overline{Z}\in\hat{N}(S)\backslash S$. To see this, note that
\[ \begin{align*}
 [\overline{Z},S_i]=0&, \ \text{for} \  i=7,8 \\
  [\overline{X},S_i]=0&, \ \text{for} \  i=1,2,3,4,5,6 \\
 \end{align*}\]
 because each of these ease either a product of only $X$ operators or only $Z$ operators. The less trivial relations
 \[ \begin{align*}
 [\overline{Z},S_i]=0&, \ \text{for} \ i=1,2,3,4,5,6  \\
  [\overline{X},S_i]=0&, \ \text{for} \ i=7,8  \\
 \end{align*}\]

also hold, because the intersection of the supports of $\overline{Z}$ and $S_i$ ( for $ i=1,2,3,4,5,6 $) is always an even number of qubits. Likewise, the intersection of the supports of $\overline{X}$ and $S_i$ ( for $ i=7,8 $) is also always an even number of qubits. Thus, $\overline{X},\overline{Z}\in \hat{N}(S)$.

 Now, to see that $\overline{X},\overline{Z}\notin S$ observe that the product$S_7S_8=X_1X_2X_3X_7X_8X_9\neq\overline{Z}$, which implies $\overline{Z}\notin S$. For $\overline{X}$, it is impossible to even generate an operator that contains all the factors $Z_1Z_2Z_3$ since the only stabilizers that even have nontrivial support on these first three qubits are $S_1$ and $S_2$, but yet  $S_1S_2=Z_1Z_3\neq Z_1Z_2Z_3$. Therefore, $\overline{X}\notin S$.


Consider the binary matrix
\[
\delta=\begin{pmatrix}
1&1&1&0&0 \\
0&0&1&1&1\\
1&1&0&1&1 \\
1&1&1&0&0 \\
0&0&1&1&1\\
\end{pmatrix}.
\]
 Associate to each row $j$ an $X$-type stbilizer
 \[
 M_j=\PROD{l=1}{5}X_l^{\delta_{jl}},
 \]
 and to each column a $Z$-stabilizer
 \[
  N_j=\PROD{l=1}{5}Z_l^{\delta_{lj}}.
 \]
 The product of the matrix $\delta$ with itself (modulo $2$) effectively computes products of  all the $M_j$ operators with all the $N_j$ operators. The $i,j$th coefficient in the matrix of $\delta^2$,  has a value of $0$ if $M_iN_j$ commute and has a value of $1$ if $M_iN_j$ anticommute. In fact, since $\delta^2$ gives the matrix with all coefficients $0$, each $M_i$ commutes with each $N_j$. Therefore, the set $Q$ generated by all such products of $M_j$ and $N_i$ forms an abelian subgroup of the Pauli group $\hat{P}_5$. Moreover, since each $M_j$ and $N_j$ square to $+I$, it is necessarily the case that $-I\notin Q$. Hence, $Q$ actually defines a stabilizer group. By choosing linearly independent operators $M_j$ and $N_i$, it is seen that the stabilizer $Q$ can be generated by $\{M_1,M_2,N_1, N_4\}$.


Let $C_1$ and $C_2$ be a classical linear codes with parity check matrices $H_1$ and $H_2$ given by

  \[
 H_1=\begin{pmatrix}
 1&0&1&1&0 \\
 0&1&1&0&1
 \end{pmatrix}
  \ \ \text{and} \  \
  H_2=\begin{pmatrix}
 1&1&1&0&0 \\
 0&0&1&1&1
 \end{pmatrix}.
 \]

Notice that $H_1$ consists of the two $Z$-type stabilizer generators $N_1$ and $N_4$, and $H_2$ consists of the two $X$-type stabilizer generators $M_1$ and $M_2$ defined in (2) that together generate the stabilizer group $Q$. In this way, $Q$ is the CSS code $CSS(H_1,H_2)$. Here, $Q=<S_1\cup S_2>$, where $S_1$ and $S_2$ are the stabilizer groups generated by the $Z$-type and $X$-type operators, respectively.  Namely,
  \[
 S_1=\begin{pmatrix}
  0&0&0&0&0 \\
 1&0&1&1&0 \\
 0&1&1&0&1 \\
  1&1&0&1&1
 \end{pmatrix}
  \ \ \text{and} \  \
 S_2=\begin{pmatrix}
  1&0&1&1&0 \\
 1&1&1&0&0 \\
 0&0&1&1&1\\
  1&1&0&1&1 \\
 \end{pmatrix}.
 \]

Let $G_1$ and $G_2$ be corresponding generator matrices of the codes $C_1$ and $C_2$, respectively. For each code, since there are $5$ physical bits and $3$ encoded bits ($H_1$ and $H_2$ are $2 \times 5$ matrices), both generator matrices have dimensions $3\times 5$. These generators must satisfy the constraints
\[
G_iH_i^T=0 \  \ \text{and} \ \ H_iG_i^T=0.
\]
for $i=1,2$. The constraints form a set of $k$ non-singular equations on $n$ bits. It can be checked that the following two particular matrices satisfy these constraints:
\[
 G_1=\begin{pmatrix}
 1&0&0&1&0 \\
 1&1&0&1&1 \\
  0&1&1&1&0
 \end{pmatrix}
  \ \ \text{and} \  \
G_2=\begin{pmatrix}
 1&0&1&0&1 \\
 1&1&0&0&0 \\
  0&1&1&1&0
 \end{pmatrix}.
\]

The rows of $G_1$ and $G_2$ form a basis of the code spaces $C_1$ and $C_2$, respectively. Hence, the span of each generates the entire code spaces. The elements of these code spaces are then
\[
 C_1=\begin{pmatrix}
 0&0&0&0&0 \\
 1&0&0&1&0 \\
 1&1&0&1&1 \\
  0&1&1&1&0 \\
 0&1&0&0&1 \\
  1&0&1&0&1 \\
   1&1&1&0&0 \\
    0&0&1&1&1
 \end{pmatrix}
  \ \ \text{and} \  \
C_2=\begin{pmatrix}
 0&0&0&0&0 \\
 1&0&1&0&1 \\
 1&1&0&0&0 \\
  0&1&1&1&0 \\
   1&0&1&1&0 \\
    0&1&1&0&1 \\
     1&1&0&1&1 \\
      0&0&0&1&1 \\
 \end{pmatrix}.
\]

By associating a $Z$-type (or $X$-type) operator $\overline{Z}$ (or $\overline{X}$) to each row of $C_2$ (or $C_1$), and demanding that $\overline{Z}\notin S_1$ (and $\overline{X}\notin S_2$) and also that $\overline{Z} \ \overline{X}=-\overline{X} \ \overline{Z}$, then the pair $(\overline{X},\overline{Z})$ can be made to correspond to a logical operation on a logical qubit. In this case, since there is only $1$ logical qubit a single pair satisfying these properties is all that is needed. In this regard, choose
\[
\overline{X}=X_1X_4 \ \ \text{and} \ \ \overline{Z}=Z_1Z_3Z_5
\]
corresponding to the second rows of $C_2$ and $C_1$. Then indeed, $\overline{X}\notin S_2$ and $\overline{Z}\notin S_1$, and $\overline{Z} \ \overline{X}=-\overline{X} \ \overline{Z}$. Therefore, the pair $(\overline{X},\overline{Z})$ function as logical operators on the encoded qubit, and hence generate $\mathcal{N}(S)/S\cong P_1$.


In the classical linear code context, the distances of codes $C_1$ and $C_2$ are both given by $d_1=d_2=2$, which can be seen by examining the elements of $C_1$ and $C_2$ and finding the minimum weight of any non-identity codeword. For $CSS(H_1,H_2)$, the distance of the code $Q$ must satisfy $d\geq min\{d_1,d_2\}=2$. In this context, the distance of $Q$ will be the minimum weight of an operator in $\mathcal{N}(S)\backslash S$, which by inspection is seen to be $d=2$.


In what follows, an algorithm will be described which begins with two parity check matrices $H_1$ and $H_2$ of a general CSS code, and computes a set of generators for $\hat{\mathcal{N}}(S)/S$ grouped into pairs $\{(\overline{X}_i,\overline{Z}_i)\}$.

First, using $H_1$ and $H_2$ (matrices with dimensions $(n-k)\times n$ construct generator matrices $G_1$ and $G_2$ (of dimensions $k\times n$) satisfying the constraints $G_iH_i^T=0$ and $H_iG^T=0$ for each $i=1,2$. Moreover, the rows of such $G_i$ should be linearly independent. Such a procedure can be done in general using the Gram-Schmidt process.

Next, consider the codes paces $C_i$ defined as the span of the rows of $G_i$, and also the stabilizer spaces $S_i$ defined as the span of the rows of $H_i$. Then to find generators of $\hat{\mathcal{N}}(S)/S$, it suffices to choose pairs $(\overline{X}_l,\overline{Z}_l)$ with $\overline{Z}_l\in C_1\backslash S_1$ and $\overline{X}_l\in C_2\backslash S_2$, such that $\overline{X}_l$ and $\overline{Z}_l$ anti commute, and all pairs $(\overline{X}_l,\overline{Z}_l)$ and$(\overline{X}_l',\overline{Z}_l')$ with $l\neq l'$ commute. For $k$ encoded qubits, there will be $k$ many many pairs, corresponding to the logical operations applied to each of the $k$ logical qubits.


Graph states


Let $G=(V,E)$ be a undirected graph with no self-loops. That is, for all $v,v'\in V$, $(v,v)\notin E$, and  if $(v,v')\in E$ then also $(v',v)\in E$. Associate a qubit to each vertex in $V$. When necessary, the vertices will be indexed as $v_i$ with $i\in\{1,\dots, N\}$ where $|V|=N$. Let $I_N=I^{\otimes N}$ be the identity operator on all $N$ qubits, where $I$ is the identity operator on a single qubit. For some single qubit unitary $U$, write $U_{v_i}=I\otimes\cdots\otimes I\otimes U\otimes\cdots\otimes I$ to denote the operator on the $N$-qubit space which applies the single qubit unitary $U$ to the qubit associated to vertex $v_i$. Now, define the operators
\[
M_v=X_v\PROD{v':(v,v')\in E}{} Z_{v'}
\]
for $v\in V$, where $X_v$ and $Z_v$ are the single qubit $X$ and $Z$ operators acting on the qubit associated to vertex $v$.


 For compatible operators $A$ and $B$, let $[A,B]=ABA^{-1}B^{-1}$. If $[A,B]=I$, then $A$ and $B$ \emph{commute}, and if $[A,B]=-I$ then $A$ and $B$ \emph{anticommute}. Now observe the following commutation relations:
\[
\begin{align*}
\text{for any} \ v_i,v_j\in V:& \ \ \ [I_N,X_{v_i}]=[I_N,Z_{v_i}]=[X_{v_i},X_{v_j}]=[Z_{v_i},Z_{v_j}]=I_N\\
\text{if} \  v_i\neq v_j:& \ \ \ [X_{v_i},Z_{v_j}]=I_N\\
\text{if} \ v_i=v_j:& \ \ \ [X_{v_i},Z_{v_j}] =-I_N.
\end{align*}
\]
These then imply the following commutation relations:
\[
\begin{align*}
\text{for any} \ v_i,v_j\in V:& \ \ \ \left[\PROD{v':(v_i,v')\in E}{} Z_{v'} \ , \ \PROD{v':(v_j,v')\in E}{} Z_{v'}\right]=I_N \\
\text{if} \ (v_i,v_j)\notin E:& \ \ \ \left[X_{v_i} \ , \ \PROD{v':(v_j,v')\in E}{} Z_{v'}\right]=I_N \\
\text{if} \ (v_i,v_j)\in E:& \ \ \ \left[X_{v_i} \ , \ \PROD{v':(v_j,v')\in E}{} Z_{v'}\right]=-I_N.
\end{align*}
\]

Trivially, for any graph $G$ and $v\in V$, the operator $M_v$ commutes with itself since $M_v^2=I_N$ as $M_v$ is only comprised of $X$ and $Z$ terms which satisfy $X^2=I$ and $Z^2=I$.  Therefore, consider graphs $G$ with more than one vertex so that $|V|\geq 2$. For any two $M_{v_i}, M_{v_j}\in \{M_v\}_{v\in V}$ such that $v_i\neq v_j$, there are two cases two consider: either $(v_i,v_j)\notin E$ or $(v_i,v_j)\in E$.

Suppose first that $(v_i,v_j)\notin E$. Then $ Z_{v_j}$ does not appear in $M_{v_i}$, and likewise $Z_{v_i}$ does not appear in $M_{v_j}$. Then in the product $M_{v_i}M_{v_j}$, the pairs of operators that act on any particular qubit all commute. Therefore, $M_{v_i}M_{v_j}=M_{v_j}M_{v_i}$ so that $M_{v_i}$ and $M_{v_j}$ commute as well in this case.

Instead, suppose that $(v_i,v_j)\in E$. In this case, $ Z_{v_j}$ does appear in $M_{v_i}$, and likewise $Z_{v_i}$ appears in $M_{v_j}$. Then in the product $M_{v_i}M_{v_j}$ there are two pairs of operators that anticommute--namely,  $X_{v_i}Z_{v_i}$  and $Z_{v_j}X_{v_j}$. Then since $X_{v_i}Z_{v_i}=-Z_{v_i}X_{v_i}$ and $Z_{v_j}X_{v_j}=-X_{v_j}Z_{v_j}$, the two resulting $-1$ factors will cancel. Hence, that $M_{v_i}M_{v_j}=M_{v_j}M_{v_i}$ implying that $M_{v_i}$ and $M_{v_j}$ commute. To see this more explicitly, consider the calculation shown below, which makes use of the nontrivial commutation relations given above:
\[
\begin{align*}
M_{v_i}M_{v_j}=&\left(X_{v_i}\PROD{v':(v_i,v')\in E}{} Z_{v'} \right)\left(X_{v_j}\PROD{v':(v_j,v')\in E}{} Z_{v'} \right)\\
&=(-1)X_{v_i}X_{v_j}\PROD{v':(v_i,v')\in E}{} Z_{v'}\PROD{v':(v_j,v')\in E}{} Z_{v'} \\
&=(-1)X_{v_j}X_{v_i}\PROD{v':(v_j,v')\in E}{} Z_{v'}\PROD{v':(v_i,v')\in E}{} Z_{v'} \\
&=(-1)(-1)X_{v_j}\PROD{v':(v_j,v')\in E}{} Z_{v'}X_{v_i}\PROD{v':(v_i,v')\in E}{} Z_{v'} \\
&=\left(X_{v_i}\PROD{v':(v_i,v')\in E}{} Z_{v'} \right)\left(X_{v_j}\PROD{v':(v_j,v')\in E}{} Z_{v'} \right)\\
&=M_{v_j}M_{v_i}.
\end{align*}
\]
It has now been shown that all operators in the set $\{M_v\}_{v\in V}$ commute with one another.

Since each operator $M_v$ contains the operator $X_v$, and any other $M_{v'}$ with $v\neq v'$ contains a different $X_{v'}$ operator, $M_v$ cannot be generated as a product of other $M_{v'}$ operators. Thus, the set $\{M_v\}_{v\in V}$ forms an independent set of commuting Pauli operators. Then the group $S_G:=<M_v>_{v\in V}$ generated by all $M_v$ forms a valid stabilizer group.

The stabilizer group $S_G=<M_v>_{v\in V}$ defines the code space
\[
T(S_G):=\{\ket{\Psi}\in(\mathbb{C}^2)^{\otimes n} \mid M_v\ket{\Psi}=\ket{\Psi}, \ \text{for all} \ v\in V \}.
\]
Furthermore, since are $|V|=N$ qubits and also $r=N$  independent generators, the number of encoded qubits expressed in $T(S_G)$ is given by $2^{N-r}=2^{0}=1$. Therefore, every graph $G$ can be associated to a unique (up to phase) state $\ket{\Psi_G}\in T(S_G)$ which encodes one logical qubit.



Suppose $G=C_n=(V,E)$ is the $n$-cycle graph with $n> 4$. Here, $V=\{v_1,v_2,\dots,v_n\}$ and $E=\{(v_a,v_b)\mid a\equiv b (mod \ n)\}$. Let $\ket{\Psi_{G}}\in T(S_G)$ be the associated graph state. Let $\mathcal{M}_{\bar{b}}\in S_G$,  Then the projection onto $T(S_G)$ satisfies
 \[
 \ket{\Psi_G}\bra{\Psi_G}=\frac{1}{2^n}\SUM{U_a}{}U_a,
 \]
 since $T(S_G)$ is one dimensional. Denote by $Tr_{(i-1,i,i+1)}(\ket{\Psi_G}\bra{\Psi_G})$, the reduced density operator that results by tracing out all qubit registers except for those associated to neighboring registers $i-1, i$, and $i+1$ (where addition is taken $mod \ n$). Then
 \[
 Tr_{(i-1,i,i+1)}(\ket{\Psi_G}\bra{\Psi_G})=\frac{1}{2^n}\SUM{U_a}{}Tr_{(i-1,i,i+1)}(U_a).
 \]
 Hence, consider $Tr_{(i-1,i,i+1)}(U_a)$ for an arbitrary $U_a\in S_G$. Each $U_a$ is a product of some $M_v$ operators. If  $U_a$ contains some $M_v$ which has nontrivial support on some vertex other than $v_{i-1},v_i$, or $v_{i+1}$, then $Tr_{(i-1,i,i+1)}(U_a)=0$, because the trace of any Pauli operator  is $0$.  Hence, the only nonzero contribution comes from $U_a=I$ and $U_a=M_{v_i}$ so that
\[\begin{align*}
 Tr_{(i-1,i,i+1)}(\ket{\Psi_G}\bra{\Psi_G})=&\frac{1}{2^n}\SUM{U_a}{}Tr_{(i-1,i,i+1)}(U_a)\\
 =&\frac{1}{2^n}\left(Tr_{(i-1,i,i+1)}(I)+Tr_{(i-1,i,i+1)}(M_{v_i})\right)\\
 =&\frac{1}{2^{3}}\left(I+M_{v_i}\right) \\
 =&\frac{1}{2^{3}}\left(I+X_{v_i}Z_{v_{i-1}}Z_{v_{i+1}}\right).
 \end{align*}\]


 Let $G=(V_G,E_G)$ and $G'=(M_{G'},E_{G'})$ be graphs and suppose $G'$ is obtained from $G$ by adding a vertex $v'$ which has no edges. Then $V_{G'}=V_G\cup\{v'\}$, and $E_{G'}=E_G$. Let $\ket{\Psi_G}\in T(S_G)$ and $\ket{\Psi_G'}\in T(S_{G'})$ be the associated graph states of $S_G$ and $S_{G'}$, respectively. In terms of $\ket{\Psi_G}$, the state $\ket{\Psi_{G'}}$ can be expressed as
 \[
 \ket{\Psi_{G'}}=\ket{\Psi_G}\otimes\ket{\varphi},
 \]
 where $\ket{\varphi}$ is a yet to be determined single qubit state.

 In this case, the set of stabilizer generators for $G'$ is given by $\{M_v\}_{v\in V_G}\cup \{M_{v'}\}$, where $M_{v'}=X_{v'}$. All of the operators in $S_G$ act trivially on the state $\ket{\varphi}$ of $\ket{\Psi_{G'}}$, and the operator $M_{v'}$ acts trivially on all registers of the state $\ket{\Psi_{G'}}$ except for the qubit in the state $\ket{\varphi}$. However, since it must be the case that $M_v\ket{\Psi_{G'}}=\ket{\Psi_{G'}}$ for any $M_v\in S_{G'}$, then $\ket{\varphi}$ must be a $+1$ eigenstate of $M_{v'}=X_{v'}$. Therefore, $\ket{\varphi}=\ket{+}:=\frac{1}{\sqrt{2}}(\ket{0}+\ket{1})$ as
 \[
 X\ket{+}=\frac{1}{\sqrt{2}}(X\ket{0}+X\ket{1})=\frac{1}{\sqrt{2}}(\ket{1}+\ket{0})=\ket{+},
 \]
  which shows that $\ket{+}$ is the unique $+1$ eigenstate of $X$. Hence, the associated graph state of $S_{G'}$ is given by
 \[
 \ket{\Psi_{G'}}=\ket{\Psi_G}\otimes\ket{+}.
 \]
 
  Now suppose $G'=(V_{G'},E_{G'})$ is obtained from $G=(V_{G},E_{G})$ by adding an edge $(v_1,v_2)$, where $(v_1,v_2)\notin E_{G}$, so that $E_{G'}=E_{G}\cup\{(v_1,v_2)\}$ and $V_{G'}=V_{G}$. Let $S_G=<M^G_v>_{v\in V_G}$ and $S_{G'}=<M^{G'}_v>_{v\in V_{G'}}$ be the stabilzer groups generated by the operators $M^G_v$ and $M^{G'}_v$, respectively. Then all  of the operators in $S_{G'}$ and $ S_{G}$ are the same, except the operators $M^{G'}_{v_1},M^{G'}_{v_2}\in S_{G'}$ differ from those in $S_{G}$, by including additional $Z_{v_2}$ and $Z_{v_1}$ terms, respectively. That is,
\[
M^{G'}_{v_i}=
\left\{
\begin{array}{ll}
M^{G}_{v_i} \ \ \text{if} \ \ v_i \neq v_1, v_2 \\
\\
M^{G}_{v_i}Z_2\ \ \text{if} \ \ v_i=v_1\\
\\
M^{G}_{v_i}Z_1\ \ \text{if} \ \ v_i=v_2.\\
\end{array}
\right.
\]


 Consider $\ket{\Psi_{G}}\in T(S_{G})$, and let $\ket{\Phi}=CZ_{z_1,z_2}\ket{\Psi_G}$, where $CZ_{z_1,z_2}$ is the two qubit phase gate applied to the qubits associated to vertices $v_1$ and $v_2$ given by
\[
 CZ=\begin{pmatrix}
 1 & 0 & 0 & 0 \\
 0 & 1 & 0 & 0 \\
 0 & 0 &1 & 0  \\
 0 & 0 & 0 & -1
 \end{pmatrix}.
\]
 Since $M^{G'}_{v_i}=M^{G}_{v_i}$ for $v_i\neq v_1, v_2$, and neither $X_{v_1}$ nor $X_{v_2}$ appear as factors in any of the operators  $M^{G'}_{v_i}$ in this case, then each  $M^{G'}_{v_i}$ commutes with $CZ_{z_1,z_2}$. Therefore,
\[
 M^{G'}_{v_i}\ket{\Phi}=M^{G'}_{v_i}CZ_{z_1,z_2}\ket{\Psi_G}=CZ_{z_1,z_2}M^{G'}_{v_i}\ket{\Psi_G}=CZ_{z_1,z_2}\ket{\Psi_G}=\ket{\Phi},
\]
  in the case where $v_i\neq v_1, v_2$.
 
  For the other cases, first observe that $X_{v_1}Z_{v_2}CZ_{v_1,v_2}=CZ_{v_1,v_2}X_{v_1}$. Now suppose $v_i=v_1$, then
\[\begin{align*}
M^{G'}_{v_1}CZ_{z_1,z_2}=&M^{G}_{v_1}Z_{v_2}CZ_{z_1,z_2} \\
=&M^{G}_{v_1}X_{v_1}X_{v_1}Z_{v_2}CZ_{z_1,z_2} \\
=&M^{G}_{v_1}X_{v_1}CZ_{z_1,z_2}X_{v_1}\\
=& CZ_{z_1,z_2}M^{G}_{v_1}X_{v_1}X_{v_1} \\
=&CZ_{z_1,z_2}M^{G}_{v_1}.
 \end{align*}  \]
 Hence,  $M^{G'}_{v_1}\ket{\Phi}=M^{G'}_{v_1}CZ_{z_1,z_2}\ket{\Psi_G}=CZ_{z_1,z_2}M^{G}_{v_1}\ket{\Phi_G}=CZ_{z_1,z_2}\ket{\Psi_G}=\ket{\Phi}$. Therefore, for all $v_i\in V_{G'}$, it follows that $M^{G'}_{v_1}\ket{\Phi}=\ket{\Phi}$, implying that $\ket{\Phi}=CZ_{z_1,z_2}\ket{\Psi_G}\in T(S_{G'})$ is the encoded graph state of $S_{G'}$.

 The consequences just shown can be applied to construct the graph state $\ket{\Psi_{C_4}}$ for the cycle graph $C_4$. In this approach, a Hadamard gate is applied  to each of the four qubits (that all begin in the $\ket{0}$ state) which puts each qubit into the $\ket{+}$  state. Then a controlled phase $CZ_{v_i,v_j}$ for each pair of adjacent vertices is applied. The resulting state produced by this circuit will then be $\ket{\Psi_{C_4}}$.