1

Although I mentioned ZX-calculus, looking back I realise that very little of my question involves ZX-diagrams at all. I believe that many quantum people on this forum can help, not just people in this subfield :) After all the example in my question is a quantum circuit.


First off, I am a total beginner at anything quantum. I suspect I am totally confusing two adjacent concepts, hence this question.

My question is about ZX-calculus, in particular about how to compute the linear map (either the tensor notations or an explicit matrix) of the CNOT gate.

I know (ref) that the following is a CNOT gate:

enter image description here

It "feels" to me like I can just draw this because the green spider is the identity map from my computation.

enter image description here

(Question 1: Is this a "well-formed" ZX-diagram or no?)


I also know that the matrix of enter image description here is $\begin{pmatrix} 1 & 0 & 0 & 1 \\ 0 & 1 & 1 & 0 \end{pmatrix}$, where the columns are indexed by $|00\rangle, |01\rangle, |10\rangle, |11\rangle$ (input) and the rows are indexed by $|0\rangle, |1\rangle$ (output). It can also be expressed as ${\color{red}{|+\rangle\langle++|}} + \color{red}{|-\rangle\langle--|}$.

Of course, the CNOT gate is now just also outputting the first input bit untouched, so I have computed the matrix for enter image description here being $\begin{pmatrix} 1 & 1 & 0 & 0 \\ 0 & 0 & 1 & 1 \end{pmatrix} = I_2 \otimes \begin{pmatrix} 1 & 1 \end{pmatrix}$ so I just write as $\color{blue}{\sqrt{2}I_2 \otimes \langle +|}$.

Edit: After receiving Peter-Jan's comment, I have also computed the matrix of the $1 \to 2$ green spider with an extra input enter image description here as $\begin{pmatrix} 1 & 0 \\ 0 & 0 \\ 0 & 0 \\ 0 & 1 \end{pmatrix} \otimes \begin{pmatrix} 1 & 1 \end{pmatrix} = \begin{pmatrix} 1 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 1 \end{pmatrix}$, or equivalently the expression $\color{green}{\sqrt{2}(|00\rangle\langle 0+| + |11\rangle\langle 1+|)}$, which comes from the expression for a $1 \to 2$ green spider and adding an extra lane does nothing.

Question 2: How can the matrix / linear map for the CNOT gate be expressed from these two matrices / two tensor expressions? Simply stacking them on top would give the correct dimensions but is clearly incorrect: $CNOT(|00\rangle)$ is the basis state $|00\rangle$ not a superposition state. Another option I considered is some tensor product between the two matrices, but (1) this doesn't give the correct dimension matrix (2) CNOT cannot be expressed as a tensor product (otherwise it's separable.) Also, I believe the correct matrix is $\begin{pmatrix} I_2 & 0 \\ 0 & X \end{pmatrix}$ where $X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}$.

Question 3: What about the tensor product expression? How do I combine the red and blue expressions into an expression for CNOT?

Question 4: Is my approach applicable in general? In other words, for more complicated ZX-circuits, can I also slice the circuit into layers and track the action of each spider?

Question 5: Does this work if my ZX-diagram isn't a circuit? AFAIK ZX-diagrams form a strict superset of quantum circuits so surely there are some diagrams that aren't circuits right, how do they work?

Thank you in advance for reading this horribly written question.

ketsi
  • 131
  • 5

2 Answers2

2

It "feels" to me like I can just draw this because the green spider is the identity map from my computation.

The green spider is the identity map if it has two legs and phase 0. Here it has three legs. Getting rid of one of the legs as you have done is not permitted by the rules of ZX.

(Question 1: Is this a "well-formed" ZX-diagram or no?)

The two diagrams above Question 1 are not equal.

Your rewrite would work if the input to the top wire is a green spider: ZX rewrites

Peter-Jan
  • 2,373
  • 9
  • 30
2

After several more hours and $4$ pages of computations and thinking, I have gotten an answer. As mentioned by Peter-Jan's answer, my decomposition / rewrite of the diagram is incorrect, for example because the green spider has three legs, not two.

But this can still be fixed. The correct method is to not "merge" the output of the green spider directly into the input of the red spider, but instead keep it as a separate output. I can't explain it well, but look at this picture:

a decomposition of the graph with 2 -> 3 -> 2 qubits, and a green and red spider respectively

Each of these are proper ZX-diagrams (zxlive agrees to let me start a proof.) Now we can compute the linear maps desired. The computation is much more straightforward because we're doing the right thing.

For the left graph, we recall that a $1 \to 2$ green spider is $Z_2^1 = |00\rangle\langle 0| + |11\rangle\langle 1|$. To add an "identity" wire we just tensor with the identity $I$ (I'm not entirely sure how this works but we can take $I = |0\rangle\langle 0| + |1\rangle\langle 1|$ for example.) So the left graph is

$$ Z_2^1 \otimes I = |000\rangle\langle 00| + |001\rangle\langle 01| + |110\rangle\langle 10| + |111\rangle\langle 11| $$

Pause! Let's do a sanity check. If we apply $|10\rangle$ to the left diagram, what do we get? Our expression tells us $(Z_2^1 \otimes I)|10\rangle = |110\rangle$, which is what we expect, as the first bit is duplicated and the second bit is copied. In fact, $(Z_2^1 \otimes I)|b_1b_2\rangle = |b_1b_1b_2\rangle$ for all $b_1, b_2 \in \{0, 1\}$. Indeed, our expression just describes the action ofJust as we expected!

For the right graph we do the same thing, it is $I \otimes X_1^2 = I \otimes (|+\rangle\langle ++| + |-\rangle\langle--|)$. For computational purpose we can write out $|+\rangle\langle ++| + |-\rangle\langle --| = \frac{1}{\sqrt{2}}\left(|0\rangle(\langle 00|+\langle 11|) + |1\rangle(\langle 01|+\langle 10|)\right)$, so the tensor computes to be

$$ I \otimes X_1^2 = \frac{1}{\sqrt{2}}\left[ |00\rangle(\langle 000| + \langle 011|) + |01\rangle(\langle 001| + \langle 010|) \atop + |10\rangle(\langle 100| + \langle 111|) + |11\rangle(\langle 101| + \langle 110|) \right] $$

Now to combine them, we just multiply these together (how I see it is that they are just linear maps, so of course composition is multiplication.) So we get

$$ (I \otimes X_1^2)(Z_2^1 \otimes I) $$

Notice that here the first expression is the tensor of a $1 \to 1$ circuit (identity) with a $2 \to 1$ circuit (red spider), while the second expression is the tensor of a $1 \to 2$ circuit (green spider) with a $1 \to 1$ circuit (identity). In other words, the $I$ doesn't "match up" with $Z_2^1$. This got me confused for a while. (I believe in category theory language (categorical QM) there's an implicit associator between these morphisms in the monoidal category, but I know absolutely nothing about it.)

More sanity check: the paragraph above tells us that we can't just e.g. write the output as $Z_2^1 \otimes X_1^2$. This makes sense as CNOT is not a "separable gate"(?) - it creates entangled states

Now we compute! Copying my pen-and-paper results we get

$$ \frac{1}{\sqrt{2}}\left(|00\rangle\langle 00| + |01\rangle\langle 01| + |11\rangle\langle 10| + |10\rangle\langle 11|\right) $$

Again, as expected.

This approach fixes my Question 1, which then answers Question 2 and Question 3 directly.

Getting the matrix from this is straight forward.

ketsi
  • 131
  • 5