Chapter 5
Clifford circuits and diagrams

In the previous chapter we saw that there were already a lot of interesting things to say about phase-free ZX-diagrams. However, interesting as they are, because there are no phases, these diagrams don’t allow us to do many cool quantum computing things. In this chapter we will remedy this problem and introduce some phases back into the picture. Instead of immediately allowing all possible phases, we will expand our scope to the Clifford ZX-diagrams. These are ZX-diagrams whose angles are all integer multiples of π2. At first, this might seem somewhat artificial, but we’ll see that in this special setting, even huge diagrams can always be simplified all the way down to a compact canonical form, called GSLC form. It turns out this reduced diagram only has O(n) spiders in it and O(n2) wires, where n is the number of qubits. A couple of magical things happen as a consequence. In particular, virtually everything we would want to do with such a diagram is efficient, from computing single matrix elements to comparing two such diagrams for equality. Related to this: any circuit which can be translated into a Clifford ZX-diagram can be efficiently classically simulated. We call such circuits Clifford circuits, and this is (a version of) the famous Gottesman-Knill theorem. Just because we can efficiently reason about Clifford diagrams does not mean they are not useful, far from it! We will see that Clifford diagrams form the backbone in measurement-based quantum computing (Chapter 8) and quantum error correction (Chapter 11). In a standard textbook on quantum computing, Clifford circuits and the technique for efficiently classically simulating them would be introduced in the context of stabiliser theory, a powerful collection of tools based on group-theoretic properties of the Pauli group. These techniques are important and ubiquitous in the quantum information literature, and we’ll go through them in detail in Chapter 6. However, it is interesting to note that we also have a purely graphical bag of tricks based on the ZX-calculus that are extremely useful for working with Clifford circuits, and in fact already suffice to prove the Gottesman-Knill theorem. Thus, in this chapter, we’ll deal with Clifford circuits using just the ZX-calculus.

5.1 Clifford circuits and Clifford ZX-diagrams

In the previous chapter, we established a close correspondence between CNOT circuits and phase-free ZX-diagrams (see Section 4.2). Namely, we saw that any CNOT circuit translates into a phase-free ZX-diagram, and conversely any unitary phase-free ZX-diagram is equal to a CNOT circuit (Theorem 4.2.13). In this chapter we will see that a similar relationship exists if we generalise from only allowing the phase 0 to allowing phases from the set {0, π 2 ,π,π 2 }. On one side of this correspondence, we have the following family of ZX-diagrams.

Definition 5.1.1. A Clifford ZX-diagram is a ZX-diagram where all the phases on the spiders are integer multiples of π 2 .

On the other side, we have a certain family of circuits, which generalises CNOT circuits.

Definition 5.1.2. A Clifford circuit is a circuit constructed from the following gates:

We will also refer to unitaries that can be built by composing these gates as Clifford unitaries.

It immediately follows that any Clifford circuit yields a Clifford ZX-diagram (as the Hadamard can be decomposed into a series of π 2 rotations, see Eq. (3.81)). That any unitary Clifford ZX-diagram can be realised by a Clifford circuit is less obvious, and proving this will in fact be one of the primary goals of this chapter.

Exercise 5.1. A single-qubit Clifford circuit is constructed out of just Hadamard and S gates. Show that any single-qubit Clifford circuit can be rewritten to the form

for some integers a, b and c. Hint: We know that a single S or Hadamard can be brought to this form. So you just need to show that when you compose this normal form with an additional S or Hadamard gate that the resulting circuit also be brought to this normal form. You probably will want to make a case distinction on the value of b.

Definition 5.1.3. A Clifford state is a state which can be realised as U|00 for some Clifford unitary U.

Exercise 5.2. Show that the following states are Clifford states. I.e. construct a Clifford circuit C that when applied to |00 gives the desired state.

a)

|1.

b)

|+⟩.

c)

1 2(|00 + |11).

d)

1 2(|01 + |10).

e)

1 2(|000 + |111).

5.1.1 Graph-like diagrams

When dealing with phase-free diagrams it turned out to be useful to simplify our diagrams somewhat in order to work more easily with them: we fused all the spiders and got rid of self-loops and double edges to get diagrams that we called two-coloured (Definition 4.2.3). In this chapter it will be useful to introduce a variation on this that allows us to more easily work with Hadamards. This type of diagram only contains Z-spiders. This can be achieved by changing the colour of every X-spider using the Hadamard colour-change rule (cc). We can then cancel all double Hadamards that appear by the (hh) rule and fuse all connected Z-spiders using (sp). In the resulting diagram all connections of spiders will then go via a Hadamard. It will be useful to have a special name and notation for this.

Definition 5.1.4. When two spiders in a ZX-diagram are connected via a Hadamard, we can denote this using a blue dotted line:

(5.1)

We call such a connection a Hadamard edge.

Hadamard edges have a couple of useful properties. First, we only have to deal with at most a single Hadamard edge between a pair of spiders, since any parallel pair of Hadamard edges cancels.

Lemma 5.1.5.

Proof.

Second, we can always remove a “Hadamard edge self-loop.”

Lemma 5.1.6.

Proof. This is just Eq. (3.83). □

Now let’s give the definition of this special class of diagrams we are interested in.

Definition 5.1.7. We say a ZX-diagram is graph-like when

Every ZX-diagram can be efficiently reduced to an equivalent graph-like diagram.

Proposition 5.1.8. Let D be an arbitrary ZX-diagram. Then the following sequence of steps reduces D efficiently to an equivalent graph-like diagram.

1..

Convert all X-spiders to Z-spiders using the (cc) rule.

2..

Cancel all pairs of adjacent Hadamards using the (hh) rule.

3..

Fuse all spiders by applying the (sp) rule until it can no longer be applied.

4..

Remove parallel Hadamard edges using Lemma 5.1.5.

5..

Remove self-loops using Eq. (3.39), and remove Hadamard self-loops using Lemma 5.1.6.

6..

Introduce Z-spiders and Hadamards using (id) and (hh) in reverse, in order to ensure every input and output is directly connected to a Z-spider and no Z-spiders are connected to multiple inputs/outputs.

Proof. It is clear that after this procedure there are only Z-spiders, as all X-spiders have been converted. Every connection between spiders must be via a Hadamard edge, since if it were a regular connection, then the spiders would have been fused in step 3, and if there were multiple Hadamards on the connection, then pairs of them would be cancelled in step 2. There is at most one Hadamard edge between each pair of spiders because of step 4, and there are no self-loops because of step 5. It could now still be that we have input/output wires that are connected via a Hadamard to a Z-spider, or wires that are not connected to a spider at all. We take care of these cases as follows:

Similarly, if a Z-spider is connected to multiple inputs or outputs, we can introduce an extra Z spider and a pair of Hadamards to fix it up:

Each of the steps of this algorithm touches each vertex or edge at most once, and hence this is all efficient in the size of the diagram. □

Example 5.1.9. We demonstrate how an example ZX-diagram is transformed into a graph-like diagram below. In the last step we write down its underlying graph.

The reason we call these diagrams graph-like is because they are neatly described by a structure that we call an open graph, a graph with a specified list of inputs and outputs. We will have more to say about open graphs in Chapter 8. For now, let’s just note that we can view each spider in a graph-like diagram as a vertex, and every Hadamard as an edge.

Exercise 5.3.  

a)

Show that every two-coloured diagram (see Definition 4.2.3) is transformed into a graph-like diagram by changing all the X-spiders into Z-spiders using (cc), and then potentially introducing some more identities with (id) and (hh) to the input and output wires.

b)

Show that the converse is not true: find a graph-like ZX-diagram where it is not possible to rewrite it back into a two-coloured diagram using just (cc).

c)

Find a systematic way in which a graph-like diagram can be transformed into a two-coloured diagram.

5.1.2 Graph states

A particularly useful subset of graph-like diagrams are the graph states. We can either describe these diagrammatically as a restricted set of graph-like diagrams, or directly as a type of quantum state. We will give the description as a quantum state first. For each simple undirected graph G = (V,E), where V denotes the set of vertices of the graph, and E the set of edges, we can define its corresponding graph state |G as

|G := (v,w)ECZv,w|+|V |.

I.e. we prepare the |+⋯+⟩ state, where the number of qubits is equal to the number of vertices in the graph, and then for every edge in G we apply a CZ gate between the corresponding qubits (recall the CZ from Exercise 2.13). A |+⟩ state as a ZX-diagram is just a phase-free Z-spider with a single output. A CZ gate is a pair of Z-spiders connected via a Hadamard gate:

To go from a graph to a graph state represented as a ZX-diagram is then straightforward:

(5.2)

Here we get the diagram on the right by simply fusing all the spiders together. To go from a graph to the graph state represented as a ZX-diagram we see then that every vertex becomes a phase-free Z-spider with an output attached to it and each edge in the graph becomes a Hadamard edge between the corresponding spiders. With this description in hand we can also define a graph state as a particular type of graph-like diagram (spend some time convincing yourself that this definition is indeed equivalent to the description given above):

Definition 5.1.10. A graph-like diagram is a graph state when

Some useful quantum states are not exactly graph states, but are instead merely very close to being a graph state. For instance, the GHZ-state (cf. (3.40)), is not a graph state, but we can construct it by starting with a graph state and then applying some Hadamard gates on a couple of the qubits:

(5.3)

In the context of graph states, we refer to the application of single-qubit unitaries on some of its outputs as local unitaries. Imagine for instance some quantum protocol where we start with a bunch of qubits in one spot, which are then entangled to make a graph state. We then give each of the qubits of this graph state to a different person, who are then allowed to take their qubit very far away from the others. While each of these people can’t change the graph state by applying some operation on multiple qubits at once, they can still modify the qubit they have access to by applying a unitary on just that qubit. Hence why we refer to single-qubit operations as ‘local’. Note furthermore that the operation we had to apply in the case of the GHZ state was not just any unitary but specifically a Clifford unitary. This leads us to our next definition of a useful subclass of states and ZX-diagrams.

Definition 5.1.11. A graph state with local Cliffords (GSLC) is a graph state to which some single-qubit Clifford unitaries have been applied on its outputs.

We will often say a ZX-diagram is in GSLC form or (at the risk of sounding like the kind of people that say “ATM machine”) that a quantum state is a GSLC state. Every single-qubit Clifford unitary can be written as a composition of three phase gates where the phases are multiples of π 2 (cf. Exercise 5.1). So an example of a GSLC state would be a composition of the graph state of (5.2) with any Z(π 2 ) or X(π 2 ) phase gates:

Where here the Hadamard gate on the top qubit is a number of π 2 phase gates in disguise.

Exercise 5.4. Show that the graph state (5.2) is a Clifford state by finding a Clifford circuit that builds it when applied to |00.

Exercise 5.5. A graph state has no internal spiders, but a general graph-like diagram does. Show that any graph-like diagram with no inputs (i.e. a state) can be written as a graph-state where each internal spider becomes a post-selection by adapting the arguments from Section 3.4.1.

5.2 Simplifying Clifford diagrams

Now that we have all the tools we need, we will see how we can systematically simplify Clifford diagrams. Instead of rewriting arbitrary diagrams, we will work with graph-like diagrams. Thanks to Proposition 5.1.8, we can translate any ZX-diagram into a graph-like one, so we can do this without loss of generality. Because graph-like ZX-diagrams are pretty much just graphs with a bit of extra stuff, we can use some techniques from graph theory to simplify them. Before we do this in the general case, it pays to first look at the special case of GSLC states.

5.2.1 Transforming graph states using local complementation

When looking at a graph state it might seem at first glance that the presence or absence of an edge between two qubits determines whether those qubits are entangled. Considering again the scenario where we have prepared a graph state and sent each of the qubits far away from each other. This might then seem to mean that there is no way in which we can get any more entanglement between these qubits. However, the structure of entanglement in a graph state can be deceiving. It turns out that just applying local Cliffords can greatly affect the connectivity of the underlying graph. For instance, in Eq. (5.3) we saw that we can represent a GHZ state as a graph state with some local Cliffords. Because the GHZ is of course symmetric in all three qubits, that means we can do this in three equivalent ways, and hence the following graph states are all equal up to the application of some local Cliffords:

A natural question is then how we can find out when two graph states can be transformed into each other just using local Clifford operations. One important graph transformation we can do just by using local operations is the local complementation.

Definition 5.2.1. Let G be a graph, and u a vertex in G. The local complementation of G about u, which we write as G u, is the graph which has the same vertices and edges as G, except that the neighbourhood of u is complemented. In other words, two neighbours v and w of u are connected in G u if and only if they are not connected in G.

Example 5.2.2. Consider the graph G below with vertices a,b,c,d. In G a we see that the neighbourhood of a, consisting of the vertices b,c,d is complemented. So because b and c are not connected in G, they are connected in G a, and because b and d are connected in G, they are not in G a. In (G a) b we see that the connection between c and d is not affected, as d is not a neighbour of b.

To transform a graph state so that its underlying graph is locally complemented about a vertex (i.e. qubit) u, we only need to apply a X(π 2 ) gate on u, and a Z(π 2 ) gate on each of its neighbours:

(5.4)

Here N(u) denotes the neighbourhood of u. In the remainder of this section we will prove that (5.4) indeed holds. To do this it will be helpful to introduce the family of fully connected ZX-diagrams.

Definition 5.2.3. We define Kn to be the fully connected ZX-diagram on n qubits, defined recursively as:

(5.5)

When we fuse all the spiders in Kn we see that they indeed give totally-connected graphs of Hadamard edges:

Using this definition of Kn we can state the equality that will allow us to do local complementations:

Lemma 5.2.4. The following holds in the ZX-calculus for all n :

(5.6)

Before we prove this, see Example 5.2.5 for a demonstration of how this is related to doing local complementations. The crucial point is that the introduction of a fully connected graph by Eq. (5.6) makes a parallel Hadamard edge if there was already a Hadamard edge present, which is then subsequently removed by Lemma 5.1.5.

Example 5.2.5. Let us take the graph G from Example 5.2.2, but now seen as the graph state |G.

We indeed end up with |G a (up to local Cliffords).

For the proof of Lemma 5.2.4 we will need the following base case.

Exercise 5.6. Prove the following using the ZX-calculus.

(5.7)

Hint: Push the rightmost Hadamards to the right and decompose the middle Hadamard using one of the versions of the Euler decomposition from Exercise 3.12 to reveal a place where you can apply strong complementarity.

And now we can prove the general case.

Proof of Lemma 5.2.4. Note that for n = 0 and n = 1 this equation becomes:

Exercise 5.6 shows n = 2. We prove the other cases by induction. For our induction hypothesis, assume (5.6) holds for some fixed n 2, which we indicate as (ih) below. Then, for n + 1 we calculate:

Exercise 5.7. We say two n-qubit quantum states |ψ1 and |ψ2 are equivalent under local operations when U|ψ1 = |ψ2 for a local quantum circuit U = U1 U2 Un consisting of just single-qubit gates. Show that the following two graph states are equivalent under local operations.

Hint: Use the fact that a local complementation can be done using just local unitaries.

5.2.2 Pivoting

It turns out that it is often useful to not just do a single local complementation, but to do a particular sequence on a pair of connected vertices.

Definition 5.2.6. Let G be a graph and let u and v be a pair of connected vertices in G. We define the pivot of G along uv, written as G uv, as the graph G u v u.

Note that in this definition, the ordering of u and v does not matter.

Exercise 5.8. Show that for any graph G and connected pair of vertices u and v in G we have G u v u = G v u v.

On a graph, pivoting consists in exchanging u and v, and complementing the edges between three particular subsets of the vertices: the common neighbourhood of u and v (i.e. NG(u) NG(v)), the exclusive neighbourhood of u (i.e. NG(u) (NG(v) {v})), and exclusive neighbourhood of v (i.e. NG(v) (NG(u) {u})). Schematically:

As a pivot is just a series of local complementations, it can also be performed on a graph state by the application of a particular set of local Cliffords. Indeed, in terms of ZX-diagrams, we have:

(5.8)

I.e. we can perform a pivot on the graph state by applying a Hadamard to the vertices we pivot along, and applying a Z gate to the vertices in their common neighbourhood.

Exercise 5.9. Prove Eq. (5.8) by decomposing the Hadamards into sequences of π 2 phase gates and then applying a sequence of local complementations using Eq. (5.4).

It turns out we can prove (5.8) more directly by using strong complementarity.

Lemma 5.2.7. Eq. (5.8) holds in the ZX-calculus.

Proof. For clarity, let us first assume that the set of vertices connected to both u and v is empty.

(5.9)

We see that u ends up connected to whatever v was connected to and vice versa, and that the neighbourhoods of u and v are now fully connected, so that if there were connections they will get complemented in the same way as described in Example 5.2.5. Now, if there are spiders that are connected to both u and v, then we can unfuse spiders in a clever way to reduce it to the previous case:

For clarity we have only drawn the Hadamard edges that stay within the joint neighbourhood of u and v in the bottom two diagrams. We see that we end up with parallel Hadamard edges that can be removed using Lemma 5.1.5. The Hadamard self-loops are simplified to Z(π) phases using Lemma 5.1.6, which indeed gives the expected result. □

5.2.3 Removing spiders in Clifford diagrams

In Sections 5.2.1 and 5.2.2 we saw that we can apply the graph operations of local complementation and pivoting on graph states by introducing some local Cliffords. It turns out that we can use some variations on these rules to greatly simplify graph-like diagrams. As this chapter deals with Clifford diagrams, we will focus here on the variations that are useful to simplify these diagrams, but later on we will introduce some additional variations that can also simplify generic graph-like diagrams. The rules we introduce in this section all serve to remove one or more spiders from a Clifford diagram. By repeatedly applying these rules we then get smaller and smaller diagrams until there are no longer any spiders to remove using these rules. For these rewrite rules it will be useful to introduce a distinction between two classes of spiders in graph-like diagrams (see also Definition 4.2.5).

Definition 5.2.8. Let D be a graph-like diagram. We say a spider in D is internal if it is not an input or output spider (i.e. it is not connected to any input or output wire). Conversely, we say a spider is a boundary spider when it is connected to at least one input or output wire.

Our first simplification rule is based on the local complementation rule (5.6).

Lemma 5.2.9. The following local complementation simplification hold:

(5.10)

Proof. We pull out all of the phases via (sp) then apply the local complementation rule (5.6) (from right to left) on the vertex marked by (∗):

Using Eq. (3.84), the topmost spider in the right-hand side above becomes an X-spider, with phase π2, which combines with the phase below it into an phase, where a = 0 if we started with π2 and a = 1 if we had started with π2. The resulting X-spider copies and fuses with the neighbours:

In words we can describe this rule as follows: if we have a spider (here marked on the left-hand side by a ) with a ±π 2 phase in a graph-like diagram that is internal, i.e. that is not connected to inputs or outputs but only to other spiders, then we can remove it from the diagram by complementing the connectivity on its neighbourhood and changing some phases. The reason we complement the neighbourhood, is because in Lemma 5.2.9 we get a fully connected graph on the right-hand side, but if there were already edges present between some of the spiders, then the resulting double edges would be removed by Lemma 5.1.5, so that we indeed complement the edges in the neighbourhood. For the remainder of this chapter, when we say we ‘apply’ Lemma 5.2.9 we mean that we apply it from left to right on some chosen vertex, and that we immediately follow it by Lemma 5.1.5 in order to cancel the introduced parallel edges, so that we are still left with a graph-like diagram.

Remark* 5.2.10. In this rule we ignored non-zero scalar factors (like we always do). However, when we applied Eq. (3.84), the actual equation with the correct scalar, Lemma 3.6.8, introduces an additional scalar diagram of fracpi2 spider. So in this sense, Lemma 5.2.9 is not really removing the ±π 2 spider, as it is just interchanging it for a ±π 2 spider that is not connected to any other spider, and hence is just a simple scalar. This is important for when we discuss completeness in Section 5.5.

In a Clifford diagram each spider has a phase kπ 2 for some k . Using the rule above repeatedly on a graph-like Clifford diagram we can remove all internal spiders with a ±π 2 phase. Hence, the only internal spiders that remain are those that have a 0 or π phase. Most of these internal spiders can also be removed, by using a variation on the pivot rule (5.8).

Lemma 5.2.11. The following pivot simplification holds:

Proof. We pull out all of the phases via (sp) and apply the pivot rule Lemma 5.2.7:

We then apply the colour-change rule to turn the Z-spiders with phases and into X-spiders. They can then be copied, colour-changed again and fused with their neighbours:

Note that the dangling scalar diagram appears because we copy twice and the vertices are connected. We simply ignore this non-zero scalar. □

Here, the marked spiders on the left-hand side are internal connected spiders with a 0 or π phase. On the right-hand side, these spiders are removed, at the cost of complementing their neighbourhood in the manner described by the pivot rule, and introducing some phases (again, the complementation happens because fully connected bipartite connectivity is introduced, and parallel edges are then removed using Lemma 5.1.5).

Exercise 5.10. Simplify the following circuit to a diagram that has no internal spiders with a ±π 2 phase or pairs of internal spiders with a 0 or π phase.

5.3 Clifford normal forms

These simplification lemmas allow us to remove many of the spiders in a Clifford diagram. In fact, so many that the resulting types of diagrams deserve to be called normal forms for Clifford diagrams. In this section we will see two types of normal forms. The first is what you get if you just keep applying the local complementation and pivoting simplifications. The second requires an additional type of pivot operation that removes the final internal spiders.

5.3.1 The affine with phases normal form

Lemma 5.2.9 removes those internal spiders with a phase of ±π 2 so that if we started with a Clifford diagram, the only phases left on internal spiders are 0 are π. Then Lemma 5.2.11 can apply to any remaining internal spider that is connected to at least one other internal spider. Hence, once we are done applying Lemmas 5.2.9 and 5.2.11 on a Clifford diagram the only remaining internal spiders are then those that carry a 0 or π phase and are connected only to boundary spiders. These diagrams turn out to be rather useful, so let’s give them a name.

Definition 5.3.1. We say a graph-like Clifford diagram is in affine with phases form (AP form) when:

1..

every boundary spider is connected to exactly one input or output,

2..

every internal spider has a phase of 0 or π, and

3..

no two internal spiders are connected to each other.

Our previous summary of the simplification procedure can then be summarised as follows.

Proposition 5.3.2. We can efficiently rewrite any Clifford diagram into an equivalent AP form.

In an AP form we have two groups of spiders. We have the boundary spiders and we have the internal spiders. The boundary spiders can be connected to any other spider (via a Hadamard edge) and carry any phase, but the internal spiders are only connected to the boundary spiders and can only have a phase of 0 or π.

Example 5.3.3. An example AP form:

for bj {0,1} and kj {0,1,2,3}.

Thanks to condition 1 of Definition 5.3.1, AP forms don’t treat inputs and outputs differently. Thus, from hence forth we will primarily study states in AP form. Here, we implicitly use the fact that we can treat arbitrary AP form maps as states by ‘bending wires’ to turn inputs into outputs. For example, the map from Example 5.3.3 can be treated as a state as follows:

Why do we call these diagrams ‘affine with phases’? To answer this we need to look at what types of states they encode. There are a couple of different things going on here, so for simplicity we’ll start with just the ‘affine’ part of AP forms then build up to the general case. Recall from Section 4.3.2 that a phase-free X-Z normal forms give us a state defined by a system of linear equations:

Importantly, S is always defined by a homogeneous system of linear equations, meaning the right-hand side of every equation is 0. Equivalently, it is the set of bit vectors x satisfying Mx = 0 for some 𝔽2-matrix M. We can generalise this form by additionally allowing the X spiders to carry 0 or π phases. This gives us almost the same thing, except now S can be defined by an inhomogeneous system of linear equations. Each X spider with a 0 phase gives us an equation with a 0 on the right-hand side, whereas an X spider with a π phase gives us an equation with a 1 on the right-hand side. For example:

(5.11)

That is, we get the set of vectors x satisfying Mx = b for some fixed matrix M and vector b. In the example above, its:

M = ( 1 1 1 1 0 1 )b = ( 1 0 )

Whereas the set of all solutions to a system of homogeneous linear equations always gives us a linear subspace of 𝔽2n, the solutions to an inhomogeneous system will, in general, form an affine subspace. Intuitively, an affine subspace is like a linear subspace that has been shifted away from the origin by some fixed amount.

Definition 5.3.4. An affine subspace A 𝔽2n is either:

Just like in the case of linear spaces, we have two equivalent representations for an affine subspace, either in terms of a spanning set of vectors or a system of equations. As before, these correspond to Z-X normal forms and X-Z normal forms, respectively. In both cases, the extra data needed to define an affine space (as opposed to a linear one) is included by introducing π phases on to some of the X spiders.

(5.12)

As before, we have decorated spiders with vectors to mean that there is an edge to the j-th spider if the j-th entry of the associated vector is 1. Note the second row is a general form for (5.11), since wiT x gives the XOR of the variables xj for which (wi)j = 1. Equivalently, the vectors wi correspond to the rows in a matrix M such that A = {x|Mx = b}.

Exercise 5.11. The bit strings appearing in the superposition in an AP state are described by the solutions to the affine system of equations Mx = b. When we do row operations on M and b (as in a Gaussian elimination of the linear system) this does not change the solutions, and so this transformed system (M,b) should still describe the same state. As the matrix M corresponds to the connectivity of the internal spiders to the boundary spiders, show that these row operations can be implemented diagrammatically:

If we colour-change the X spiders, we see that we’re most of the way to an AP form:

(5.13)

Hence, if we do not have phases on the outputs or Hadamard edges between them, an AP form can always be described by an affine subspace. For a generic AP form, by spider (un)fusion, we can split off the affine part from the rest, which we’ll call the ‘phase’ part:

The reason for the name is that the ‘phase’ part always forms a diagonal unitary, which means all it will do to the state is introduce some phases on the computational basis states |v from (5.13). By unfusing some spiders, we can see that this phase part is generated by S gates, which introduce π2 phases to individual outputs, and CZ gates, which introduce Hadamard edges between outputs. We can see that each of these gates affects the phase in a way that depends on the computational basis state:

We can describe the action of unitaries built out of these gates using certain polynomials, called phase polynomials. For example:

whereϕ(x1,x2,x3) := x1 + 2x2 + 2x1x2 + 2x1x3

Here, each single-qubit gate (i.e. the S gate on the first qubit and the S2 = Z gate on the second) contributes a linear term to ϕ, whereas each two-qubit CZ gate contributes a quandratic term, whose coefficient is always even. Note that, even though these polynomials can contain products of variables, they are always linear in each argument individually. For that reason, we call these phase polynomials in multilinear form. In Chapter 7 we will see phase polynomials in XOR-form, and in Chapter 9, we will see how these two forms are related. By applying a diagonal Clifford unitary to an affine state, the phase is applied to each of the terms in the same. So, if we combine the example above with (5.13) we get:

where { A := {(x1,x2,x3)|x1 x2 x3 = 1,x1 x3 = 0} ϕ(x1,x2,x3) := π 2 (x1 + 2x2 + 2x1x2 + 2x1x3)
(5.14)

Exercise 5.12. Reduce the following diagram to AP-form:

What is its parity matrix and its phase polynomial?

5.3.2 GSLC normal form

In a diagram in AP form there are still some internal spiders. It turns out that we can actually also get rid of these. However this does come at a cost: we must then allow Hadamards on input and output wires, so that the diagram is not what we have defined to be a ’graph-like diagram’. Just as it was useful to define a ‘graph state with local Cliffords’, it will be useful here to define a diagram that is graph-like up to Hadamards on the boundary wires.

Definition 5.3.5. We say a diagram is graph-like with Hadamards when it satisfies all the conditions for being graph-like (Definition 5.1.7), except that inputs and outputs are also allowed to be connected to Z-spiders via a Hadamard.

Note that a graph-like diagram with Hadamards can be easily transformed into a graph-like diagram by introducing some additional Z-spiders using the (id) rule. So how do we get rid of the final internal spiders in a Clifford diagram? Note that each of those spiders has a 0 or π phase and is only connected to boundary spiders (in particular, it is connected to at least one boundary spider, since otherwise it would just be a floating scalar we can ignore). The first step is to introduce some dummy Hadamards and identity spiders to make this boundary spider into an internal spider:

(5.15)

The diagram is now no longer just graph-like, but graph-like with Hadamards and the spider with the γ phase has become internal. Then we make two case distinctions. If γ = 0 or π, we have an internal pair of 0/π spiders, and we can remove them using the pivot simplification Lemma 5.2.11. If γ = ±π 2 , then we can first remove that spider using the local complementation Lemma 5.2.9. As a result of this, the phase of the spider with the phase becomes π 2 so that its phase is also ±π 2 . We can then also remove this spider using local complementation. In both cases we see that we can remove both spiders, and hence that we get rid of the original internal spider. Note that in the second case, when γ = ±π 2 , the other spiders it is connected to also gain a π 2 phase, so that this might also give some additional opportunities to remove internal spiders using local complementation. We can repeat this procedure for any remaining internal spider. This might result in multiple Hadamards appearing on the same input or output wire. In that case we can of course cancel these Hadamards using (hh). Combining the simplifications so far we see that we can hence actually remove all internal spiders in a Clifford diagram. Let’s give a name to such a type of diagram.

Definition 5.3.6. We say a Clifford diagram is in GSLC form when it is graph-like with Hadamards and has no internal spiders.

As before, GSLC here stands for graph state with local Cliffords. This is a fitting name, because states in GSLC form are graph states with local Cliffords as defined in Definition 5.1.11. Indeed, if we have a state, so a diagram with no inputs, that is in GSLC form, then every spider must be connected to an output, possibly via a Hadamard, so after unfusing the phases on the spiders, we see that it is indeed a graph state followed by some single-qubit Clifford unitaries:

Let’s summarise what we have shown in a proposition.

Proposition 5.3.7. Any Clifford diagram can be efficiently rewritten to an equivalent diagram in GSLC form.

As a consequence of this, all Clifford states, those states that can be produced from applying a Clifford unitary to |00, must be equal to graph states with local Cliffords.

Theorem 5.3.8. Let U a Clifford unitary (i.e. a circuit consisting of CNOTs, Hadamards and S gates). Then U|00 is a graph state with local Cliffords.

Proof. We can easily represent U|00 as a Clifford diagram. Proposition 5.3.7 shows it can be reduced to GSLC form. Unfusing the phases then transforms this into a graph state with local Cliffords. □

In fact, we have something even stronger: we can apply the Clifford circuit to |00, and then also post-select some outputs to be 0| (or 1|, ⟨+| or ⟨−| for that matter), and still have a graph state with local Cliffords.

Proposition 5.3.9. Let |ψ be a state produced by applying a Clifford unitary U to |00, and then post-selecting some qubits to 0|. Then |ψ is (proportional to) a graph state with local Cliffords.

Proof. The rewrite strategy to bring the diagram to GSLC form works regardless of how we produced the Clifford ZX-diagram, so we can still apply it in this setting. □

This means that allowing Z-basis measurements on Clifford states doesn’t give us something more general or powerful: we get exactly the same class of states. Finally, let us write down an equivalence between two different notions of Clifford states.

Proposition 5.3.10. Let D be a Clifford diagram without inputs (i.e. a state). Then D is equal to a Clifford state U|00 for some Clifford unitary U.

Proof. Rewrite D to GSLC form so that it is a graph state with local Cliffords, and then build U as the circuit that transforms |00 into that graph state plus the local Cliffords. □

5.3.3 Normal form for Clifford circuits

In the previous section we saw that if we simplify a Clifford state, that we get a graph state with local Cliffords. What happens if we simplify a Clifford unitary in the same manner? Again, there are no internal spiders in the diagram, so each spider must be connected to at least one input or output. By introducing some dummy spiders we can ensure that each spider is connected to exactly one input or output. The diagram will then look something like the following:

We have possible Hadamards on the inputs and outputs as our reduced diagram is graph-like with Hadamards. Each spider can carry a phase, and each spider is connected to exactly one input or output, so that we have two layers of spiders. There are no further (obvious) restrictions for how the spiders can be connected via Hadamard edges. We will now investigate how we can make diagrams like this look more like circuits. First, note that we can unfuse the phases on both sides so that the Hadamards and the phases form a layer of local Cliffords:

Second, we can unfuse the connections between the spiders in the same layer. This reveals those connections to be CZ gates:

It remains to see what is happening in the middle-part of the diagram. This should become clear once we change the colour of the layer of spiders on the right:

(5.16)

We recognise this middle part of the diagram as a parity normal form (Definition 4.2.2)! So far, all the steps we have done on this GSLC diagram work regardless of whether the diagram is unitary. However, when the diagram is unitary, then this parity normal form must represent a unitary matrix itself, and hence by Proposition 4.2.12, it is equivalent to a CNOT circuit. Summarising this analysis of GSLC unitary diagrams we see that we can represent any Clifford unitary as a particular sequence of gates.

Theorem 5.3.11. Let U be a Clifford unitary. Then U can be written as a circuit consisting of 8 layers of gates in the following order:

Had S CZ CNOT Had CZ S Had

This is really surprising! For one thing, before we started this chapter you might think there are an infinite number of different unitaries you can build from the Hadamard, S and CNOT gate, as you can just make longer and longer circuits, but this result shows that we can always reduce such a long circuit to one consisting of just a few layers of gates. In particular, we need at most a quadratic number of gates in terms of the number of qubits.

Proposition 5.3.12. Any n-qubit Clifford unitary can be represented by an equivalent circuit consisting of at most 4n(n + 32) 1 Hadamard, S and CNOT gates.

Proof. A layer of Hadamard gates contains at most n gates, and there are three of those. Each layer of S gates has at most 3 gates per qubits, corresponding to an S, Z or S gate, and there are again two of those layers. Hence, the single-qubit gates contribute at most 9n gates. A circuit of CZ gates contains at most n(n 1)2 CZ gates (corresponding to all possible pairs of qubits there can be a CZ between). A CZ gate can be constructed from a CNOT and two Hadamards, and hence each CZ layer, of which there are two, contributes at most 3 n(n 1)2 gates. The number of CNOTs needed in the CNOT circuit corresponds to how many Gaussian elimination row operations are needed to fully reduce the associated parity matrix. It is a little exercise to show that you need at most n2 1 row operations to fully reduce any matrix. The total number of needed Hadamard, S and CNOT gates is then:

9n + 2 3 n(n 1)2 + n2 1 = 6n + 4n2 1 = 4n(n + 32) 1.

Corollary 5.3.13. For any given number of qubits, there are only a finite number of different Clifford unitaries.

Exercise 5.13. Using Theorem 5.3.11, give an upper-bound on the number of different n-qubit Clifford unitaries for any n. Hint: See Section 4.5.1 for how you can count this.

We can also conclude another interesting fact from this extraction of a circuit from a GSLC normal form. The simplification procedure to get to this GSLC normal form works for any Clifford ZX-diagram, i.e. any ZX-diagram whose phases are multiples of π2, not just those coming from a Clifford circuit. If such a diagram happens to be unitary, then we can use the procedure above to transform it into a Clifford circuit. Hence, the following proposition immediately follows.

Proposition 5.3.14. Any unitary Clifford ZX-diagram is equal to a Clifford circuit.

Exercise 5.14. Show that any Clifford ZX-diagram of an isometry V can be transformed into a Clifford circuit with some ancilla qubits in state |0. That is, there exists come Clifford circuit U such that V = U(I |0...0), or graphically:

Hint: See Exercise 4.6.

Exercise 5.15. In Theorem 5.3.11 we had three layers of Hadamards. It turns out we only need two, because we can get rid of either the first or last one by doing some additional rewriting before extracting a circuit. To start, let’s assume we have a unitary Clifford ZX-diagram in GSLC form. We are going to progressively remove Hadamards on its input wires.

a)

Suppose we have an input spider with a Hadamard on it, and that the phase of the spider is . Show that we can remove this Hadamard by doing a regular, non-vertex-removing, pivot (5.8) between this input and an output it is connected to. Why will it always be connected to an output? Argue that this does not introduce any Hadamards on other inputs.

b)

Suppose we have an input spider with a Hadamard on it, and that the phase of the spider is ±π 2 . Show that you can remove the Hadamard by using a Euler decomposition and removing the resulting X(π 2 ) phase using a regular local complementation (5.4). Show that you can rewrite the diagram back into GSLC form, but now with one fewer Hadamard on an input wire.

c)

Argue that if you do these steps for all the inputs with Hadamards on them, that you get a GSLC form diagram where extracting a circuit does not give any Hadamards in the first layer.

5.4 Classical simulation of Clifford circuits

In the previous sections we saw that we can use two simple rewrites, local complementation and pivots, to reduce Clifford states to graph states with local Cliffords, and Clifford circuits to a normal form consisting of just a few layers of gates. There is a third class of relevant Clifford diagrams that we can simplify using these rewrite rules: scalars. Recall that a scalar diagram is any ZX-diagram that has no inputs or outputs. The reason we care about scalar diagrams is because they can represent amplitudes of a quantum computation. If we start with the basis state |00, then apply a unitary U, and finally wish to know the amplitude of the state U|00 with respects to some computational basis effect x1xn| we get the scalar x1xn|U|00. In our case we are interested in U’s that are Clifford unitaries, so that the resulting scalar ZX-diagram is also Clifford. So what happens if we feed a scalar Clifford diagram to the simplification procedure described in Section 5.2? Remember that the procedure allowed us to remove any internal Clifford spider. However, in a scalar Clifford diagram, all spiders are internal and Clifford, so after we are done simplifying there will be no spiders left! The diagram will have been simplified away completely. What does this mean? The empty diagram evaluates to the scalar 1. However, remember that all our rewrites also introduce some scalar factors, which in the case of Clifford diagrams are always multiples of 12 and eiπ 4 . So the end result is just a number, which is equal to the amplitude we were calculating. Let’s summarise all this in a proposition.

Proposition 5.4.1. Let U be a Clifford circuit, and let x1xn| for x 𝔽2n be any computational basis effect. Then we can efficiently calculate the amplitude x1xn|U|00.

This is really surprising! Clifford circuits contain essentially all the features we would expect from a quantum computation—entanglement, superpositions, and negative and complex amplitudes—and we can use Clifford circuits to realise many truly quantum protocols such as quantum teleportation or quantum key distribution, and yet, such circuits offer no computational benefit over classical computers. This result is known in the literature as the Gottesman-Knill theorem.

Gottesman-Knill theorem: A Clifford computation can be efficiently classically simulated.

Why is this the case? Well, on the surface we see it’s because we can just rewrite the corresponding diagrams very well. But why is it that we can do that? A hint is given by the affine with phases normal form of Clifford states. Apparently, Clifford circuits can only produce quantum states that are uniform superpositions of computational basis states that are efficiently described by an affine subspace of bit strings. This means there is a limit to how much we can actually use the complex amplitudes and entanglement present in Clifford states. There is for instance no way in which we can iteratively repeat a procedure to slowly add more and more amplitude to certain states like is done in Grover’s algorithm: the amplitudes are always distributed equally.

5.4.1 Simulating Cliffords efficiently

In Proposition 5.4.1 we said we could simulate a Clifford amplitude efficiently, but how efficient are we talking? The entire ‘simulation’ just consists of diagram simplification operations, so the complexity of the method, how expensive it is to actually calculate an amplitude, comes down to how hard it is to find the correct rewrite rule to apply, the number of rewrites we need to do, and how hard these rewrites are to perform. The first two of these questions are easily answered. First, how hard is it to find the correct rewrite rule to apply? Well, local complementation applies to any spider with a ±π 2 phase, so we simply have to loop over the spiders of the diagram until we encounter a spider with the correct phase. When we are done doing local complementations, any spider will have a 0 or π phase left, so all the spiders are suitable for a pivot, and we only need to look at any neighbour, so that finding a place where we can apply a rewrite rule is quite trivial in this setting: we can do it anywhere. The second question, how many rewrite rules need to be applied, is also easily answered. Each of the rewrite rules, local complementation and pivoting, removes at least one spider, so that the number of rewrite rules applied is bounded by the number of spiders. Finally, how hard is it actually to change the diagram based on the rewrite rules? We will measure this in terms of the number of elementary graph operations we need to perform: vertex and edge additions or removals. When we do a local complementation, we remove a single vertex, and we toggle the connectivity of all its neighbours. In the worst case, the spider we wish to remove is connected to pretty much all other spiders. In this case we end up changing the connectivity of the entire graph. So if there are N spiders, then this could cost N2 edge additions and removals. A similar cost estimation holds for pivoting: we remove two spiders, and we toggle connectivity between three groups of spiders that could also pretty much encompass the entire graph, so that it also costs N2 graph operations to implement a pivot. So a single simplification costs about N2 elementary graph operations in the worst case, and as we’ve seen, we will need about N rewrite rules to fully simplify the graph, which means we will need N N2 = N3 graph operations in the worst case. In comparison to this, the cost of finding the right rewrite rules to apply is negligible (adding at most an O(N) cost to the application of every rewrite rule). We can now state a more detailed version of Proposition 5.4.1.

Proposition 5.4.2. Let D be a scalar Clifford diagram containing N spiders. Then we can calculate the value of D in time O(N3). In particular, we can calculate amplitudes of a Clifford circuit containing k gates in time O(k3).

Proof. The first claim follows from the discussion on the complexity of rewriting above. For the second claim we simply note that each gate in a Clifford circuit can be translated into a fixed small number of spiders, so that the ZX-diagram corresponding to the amplitude to be calculated has O(k) spiders. □

Now, O(N3) is not too bad, but it does mean that once we start dealing with diagrams with, say, millions, of spiders, that we run into trouble. Can we do better? As it turns out: yes! With a more clever simplification strategy, we can actually obtain a significantly better upper bound. The reason we got this N3 scaling, is because we weren’t telling the simplifier which spiders to target, so that we couldn’t limit the number of wires that end up in the diagram. There is a better strategy that we can use to simplify the diagram, which works when we know that the diagram came from a circuit. The idea is that once we have a GSLC diagram that we can very efficiently ‘absorb’ a Clifford gate and rewrite the whole thing as another GSLC diagram. So suppose we have a Clifford circuit consisting of CZ, Hadamard and S gates (if your circuit contains CNOTs, then these can be converted into CZ gates surrounded by Hadamards). Now when we write this circuit as a ZX-diagram, it will only contain Z-spiders, so that it already looks a bit like a graph-like diagram. However, we will not actually reduce it to graph-like form like we did with our previous simplification algorithm. Instead we will keep the circuit structure intact. Now we will introduce some dummy spiders and Hadamards in order to insert a GSLC form diagram at the start of the circuit:

(5.17)

We will now consume gates one by one from the circuit and absorb them into the GSLC part of the diagram, transforming it into a different GSLC diagram, while not affecting the other parts of the diagram. Depending on the gate and on the specific configuration the GLSC part of the diagram is in, we will need to do different things. The easiest gate to deal with is the Hadamard. This is simply absorbed as part of the GSLC if there is no Hadamard already on that qubit, or cancelled if there is one:

(5.18)

For S gates and CZ gates the situation is more complicated. If there are no Hadamards on the qubits they act on, then we can also absorb them as part of the GSLC:

(5.19)

For the CZ gate, as always, if there was already a Hadamard edge present between the spiders, then we simply toggle the connectivity. Now, if there is a Hadamard in the way then we can’t just fuse the S or CZ gate into the GSLC. Instead, we will need to resort to our old friends, the local complementation and pivot. The reason we can use these, is because if there is a Hadamard in the way, with an S or CZ gate on the right-hand side, then the spider that is part of the GSLC is ‘internal’ in the sense that all its connections are to other spiders via a Hadamard edge. Now, if this spider has a ±π 2 phase, this is straightforward enough: we just apply a local complementation on it to remove it. This connects the spider of the S or CZ gate to all the neighbours of this internal spider, so that the S or CZ spider takes its place in the GSLC diagram:

(5.20)

Now, if the spider we wish to remove has a 0 or π phase, then we need to apply a pivot to get rid of it. The spider must be connected to at least one input spider (since the diagram is unitary), so that we can apply the standard non-spider-removing pivot rule of (5.8). The end result is that the output Hadamard disappears, so that the spider of the gate can be fused and become part of the GSLC diagram. Combining these different options we see that we can always absorb a gate into the GSLC portion of the diagram. We can hence simplify the entire circuit into a GSLC diagram.

Exercise 5.16. Reduce the following Clifford circuit to GSLC form using the algorithm described in this section.

Crucially, the connectivity change resulting from these local complementations and pivots is now restricted to just the other spiders of the GSLC diagram and the spider corresponding to the gate to be absorbed, instead of potentially involving the entire diagram. Letting q denote the number of qubits, there are 2q qubits in the GSLC diagram, so that this requires toggling at most (2q)2 edges. We need to do such a rewrite potentially for every gate we absorb, so that the entire simplification costs O(Nq2) elementary graph operations where N is the number of gates in the circuit. Compare this to our previous method that required O(N3) elementary graph operations. The number of gates is generally a lot more than the number of qubits, so this is a significant savings. Indeed, from Proposition 5.3.12 it follows that to represent an arbitrary Clifford unitary we need O(q2) gates, so taking N = q2 we see that we have improved the complexity from O(q6) to O(q4).

Proposition 5.4.3. Let U be a q-qubit Clifford circuit with N CNOT, Hadamard and S gates. Then we can reduce it to GSLC form using O(Nq2) elementary graph operations. Furthermore, assuming that N q, we can also write U in the layered normal form of Theorem 5.3.11 in O(Nq2) time.

Proof. The reduction to GSLC form in O(Nq2) time follows from the algorithm described above. To rewrite a GSLC diagram into the layered Clifford normal form requires a Gaussian elimination of the central parity diagram (5.16). This takes O(q3) time for a total cost of O(Nq2 + q3). As long as N q, this reduces to O(Nq2). □

Proposition 5.4.4. Let U be a q-qubit Clifford circuit with N q CNOT, Hadamard and S gates. Then we can calculate any amplitude x1xn|U|00 in O(Nq2) time. If U is given as a GSLC diagram then this reduces to O(q3).

Proof. We first reduce U to GSLC form using the algorithm described above. This takes O(Nq2) time. Then we compose the diagram with the ZX-diagrams for |00 and x1xn|. This adds O(q) spiders, so that the total diagram has O(q) spiders. Using the standard simplification algorithm on this diagram then requires O(q3) graph operations. Assuming N q the total cost is then O(Nq2) for fully reducing the diagram to a scalar. If U were already given as a GSLC diagram, then only the final set of simplifications is necessary, requiring just O(q3) graph operations. □

Exercise* 5.17. The O(N3) bound on calculating amplitudes in Proposition 5.4.2 is just an upper-bound. In practice it might turn out not to be so bad. Implement a benchmark of random Clifford circuits with an increasing number of gates and/or qubits and measure what the actual exponent is more like. Does the exponent stay the same for different number of qubits? Can you find a different strategy for targeting spiders to remove that leads to better scaling?

5.4.2 Weak vs strong simulation

In the previous sections we discussed how to calculate the amplitude corresponding to observing a particular effect on a Clifford state and we called this ‘simulating’ a Clifford computation. But this is not entirely correct. In order to truly say we are simulating a quantum computation we should be getting the same types of outcomes that we would get when we would actually run the quantum circuit. These outcomes come in the form of measurement samples. Namely, we would prepare a quantum state, execute quantum gates on it, and finally measure each qubit. The outcome is then a bit string specifying which measurement outcome we got for each qubit. By running the experiment many times we will see a particular distribution of bit strings as outcomes. To simulate a quantum computation is then to be able to generate a series of bit strings that have a similar distribution of outcomes.

Definition 5.4.5. Let U be some unitary, and write

P(x1,,xn) = |x1xn|U|00|2

for the probabilities of observing the outcome |x1xn when applying U to the input state |00. We then say a probabilistic algorithm weakly simulates U when it produces bit strings y 𝔽2n according to a distribution suitably close to P.

In this definition ‘suitably close’ can be made exact, but that won’t be necessary for us for now. With what we have seen up to now, it is not obvious how we can actually efficiently weakly simulate Clifford unitaries. We are however quite close to being able to strongly simulate Clifford circuits.

Definition 5.4.6. Let U be some unitary, and let P(x1,,xn) be its associated probability distribution as above. Then we say an algorithm strongly simulates U when it can calculate (or closely approximate) any marginal probability of P.

Let’s explain this definition. Recall that a marginal probability distribution is one where we don’t care about the outcome of one or more of the variables of the distribution. For instance, if we have a distribution P(x1,x2,x3) of three variables, then we can marginalise x3 to get the distribution P(x1,x2) := x3P(x1,x2,x3). When P(x1,x2,x3) corresponds to the probabilities of observing particular measurement outcomes in a 3-qubit circuit, then this marginal P(x1,x2) tells us the probability of observing x1 on qubit 1 and x2 on qubit 2, when we don’t measure qubit 3 at all. The reason we require the ability to determine any marginal probability in the definition of strong simulation, is that if we can only calculate the non-marginal probabilities, then it will generally take exponential resources to determine marginal probabilities. Consider for instance an n-variable distribution P(x1,,xn) of Boolean variables. Then to calculate the marginal P(x1) we have to sum the values of n 1 variables P(x1) = x2,,xnP(x1,x2,,xn), and this summation contains O(2n) terms. Okay, so now that we understand what the definition says, it might be helpful to answer why we call this ‘strong’ simulation as opposed to ‘weak’ simulation. First of all, note that being able to weakly simulate doesn’t seem to easily imply the ability to calculate the value of the probabilities: it might be that some probability P(x1,,xn) is exponentially small (in n), and hence we would need to sample at least exponentially many bit strings using weak simulation to get an estimate of its value. But the converse is true: if we can strongly simulate a unitary, then we can also weakly simulate it. To see how to do this, we need to recall the concept of conditional probabilities. A conditional probability distribution tells us the probability of observing some outcome conditional on some other variables taking particular values. For instance P(x1,x2|x3 = 1), the probability of observing the particular values x1 and x2 given that x3 = 1, is equal to P(x1,x2,1)P(x3 = 1). Hence, since strong simulation allows us to calculate any marginal probability, we can then also calculate any conditional probability. So how do we use marginal and conditional probabilities to generate a sample bit string y with the correct distribution? We do this by determining the value of each bit of y in turn. First we ask for the probability p1 = P(x1 = 0), the marginal probability that we observe qubit 1 to give a value of 0. We then decide with probability p1 to set y1 = 0 and otherwise we set y1 = 1. We then calculate p2 = P(x2 = 0|x1 = y1) and set y2 = 0 with probability p2 and otherwise y2 = 1. This means that we have chosen y1 and y2 with probability

P(y2|x1 = y1) P(y1) = P(y1,y2) P(y1) P(y1) = P(y1,y2)
(5.21)

which is the correct distribution. We carry on and calculate p3 = P(x3 = 0|x1 = y1,x2 = y2) and repeat the procedure until we have determined the entire bit string y1yn. Repeating the argument of Eq. (5.21) we see that we will have chosen this specific bit string with probability P(x1 = y1,x2 = y2,,xn = yn) so that we are indeed sampling correctly from this distribution. To summarise:

So how do we actually do strong simulation of Clifford circuits with the ZX-diagram simplification strategies we have discussed in this chapter? Well, we have seen how to calculate an amplitude x1xn|U|00 which allows us to calculate a non-marginal probability P(x1,,xn) = |x1xn|U|00|2. But how do we calculate a marginal probability? To see this it first helps to expand P(x1,,xn) in a way that allows us to more easily represent it as a diagram. Recall that for a complex number z we have |z|2 = zz where z is the conjugate. The conjugate of the inner product x1xn|U|00 is 00|U|x1xn. We can represent each of these by ZX-diagrams, and as they are scalar diagrams, their multiplication is implemented just by putting them next to each other:

(5.22)

We get these scalar factors of 12 because the X-spiders only represent |0 and |1 up to a scalar. Note that these middle pairs of spiders correspond then (up to scalar) to operators |xixi|. Now if we want to calculate a marginal probability then this corresponds to a sum of such diagrams where we vary the values of some of the xi. Remember that x|xx| = I, hence on the diagram we can implement this summation by replacing the middle spiders by an identity wire:

(5.23)

Using this diagrammatic representation of a marginal probability allows to calculate the marginals of a Clifford computation.

Proposition 5.4.7. Let U be a q-qubit Clifford circuit with N q gates. Then we can calculate any marginal probability of U using O(Nq2) graph operations. If U is given in GSLC form then it takes only O(q3) operations.

Proof. First reduce U to GSLC form using O(Nq2) operations (see Proposition 5.4.3). Then construct the diagram as in (5.23) to represent the desired marginal probability. This diagram has O(q) spiders, so fully simplifying it requires O(q3) graph operations. As N q we see that the total number of steps taken is O(Nq2). □

Since we can now calculate any marginal probability, we have also found a way to sample measurement outcomes from the Clifford circuit.

Proposition 5.4.8. Let U be a q-qubit Clifford circuit with N gates. Then we can sample k bit strings from its measurement distribution using O(Nq2 + kq4) graph operations.

Proof. We first reduce U to GSLC form, which requires O(Nq2) operations. Now in order to sample a bit string from its distribution (i.e. to perform weak simulation), we can use the method described above, which requires us to calculate q marginals, each of which takes O(q3) operations to calculate. So sampling a single bit string requires O(q4) operations. We need to do this k times, so the total cost is O(Nq2 + kq4). □

It is perhaps a bit unsatisfying that the weak simulation seems to be more expensive than the so-called strong simulation. However, it turns out that there is a smarter way to perform weak simulation of Clifford circuits. To do this, we also need to simplify our unitary U using ZX-calculus rewrites, but now instead of reducing to GSLC form, we want to reduce it to the affine with phases form (AP form) of Section 5.3.1. We can do this with the same order of graph operations as it takes to reduce to GSLC form. We can see this in two ways. Either we first reduce to GSLC form using Proposition 5.4.3, and then we do some final rewrites to reduce it to AP form. Or, we modify the algorithm used in Proposition 5.4.3 so that instead of absorbing gates into a GSLC part of the diagram, we absorb gates into an AP form diagram. We hence have the following.

Proposition 5.4.9. Let U be a q-qubit Clifford unitary with N gates. Then we can write both U and U|00 in AP form using O(Nq2) operations.

Recall from Eq. (5.14) that a state in AP form can naturally be written as

U|00 = 1 2N x𝔽2q Ax=b if(x)|x

for some phase function f, parity matrix A and bit string b. This state is an equal superposition of those |x for which Ax = b. Hence, if we measure all the qubits then the outcomes will correspond to one of those bit strings x for which this parity condition Ax = b is satisfied (the phase function is irrelevant for the outcomes). So we see that sampling from the distribution of U boils down to being able to uniformly randomly select vectors that satisfy such parity conditions.

Proposition 5.4.10. Let U be a q-qubit Clifford unitary with N gates. Then we can sample k bit strings from its measurement distribution using O(Nq2 + q3 + kq2) operations.

Proof. First write U|00 in AP form using Proposition 5.4.9, which requires O(Nq2) operations, and let A and b denote the parity matrix and bit string determining the AP form. Now we need to uniformly randomly return k bit strings x that satisfy Ax = b. First find a single z for which Az = b. This takes O(q3) operations as A is of size O(q), and Gaussian elimination takes cubic time. Now do another Gaussian elimination of A to find a basis x1,,xr for the kernel of A, i.e. of those xi for which Axi = 0. This also takes O(q3) time. Now to determine a uniformly random bit string x satisfying Ax = b we simply generate uniformly random bits c1,cr and output x = z + c1x1 + + crxr (this is indeed uniformly random as each bit string in the kernel of A can be written in a unique way as a combination of the basis vectors). Hence, each additional sample just requires generating some random bits and summing together O(q) bit strings of length O(q) for a total cost of O(q2) per sample. □

Instead of casting this algorithm in terms of Gaussian elimination, we can also view it as a diagram rewriting exercise. In Eq. (5.12) we saw that we can relate the affine part of an AP form diagram, a X-Z normal form, to a different Z-X form:

From this latter type of diagram we can easily read of which computational basis states |x are part of the superposition making it up: each Z-spider represents a basis vector xj of the kernel of A, where xij is 1 precisely when the Z-spider is connected to output spider i. While the spiders give the solution to Ax = 0, the π phases on the output transform this into solutions to Ax = b.

5.5 Completeness of Clifford ZX-diagrams

We have seen in this chapter that we can prove a lot about Clifford circuits using the ZX-calculus, but can we actually prove everything? In the previous chapter we saw that the phase-free ZX-calculus is complete, meaning we can prove all equations between phase-free ZX-diagrams using the rules of the phase-free ZX-calculus. It turns out the same is true for Clifford diagrams, when we use the Clifford rewrite rules. In this section we will adopt the scalar-accurate rewrite rules of Section 3.6.2. We will then show that these rewrite rules are complete for the Clifford fragment, meaning that if we can represent a linear map by a Clifford diagram, then any two ways to do so can be rewritten into one another. We show completeness in two steps. First we study scalar Clifford diagrams and show that these can be reduced to a form that uniquely encodes the number they are equal to. Hence, any two scalars representing the same number are reduced to the same diagram, which shows that we have completeness for these scalar diagrams. Then we show that we can refine the AP normal form so that every Clifford diagram can be reduced to a unique normal form. This means that if two diagrams represent the same linear map, that they will be reduced to the same normal form, and hence we have a path of rewriting from one to the other.

5.5.1 A normal form for scalars

First let’s show that we can correctly deal with scalar Clifford diagrams, so that we are then again free to ignore them. For this we will use the results of Section 3.6.2, and hence we use the rules of Figure 3.0 there. We’ve seen in Proposition 3.6.5 that when the diagram contains a zero scalar diagram of pi, that the entire diagram can be reduced to a simple unique form. Hence, we may assume our scalar diagram is non-zero. Our strategy will be to simplify an arbitrarily complicated scalar Clifford diagram to a diagram that consists of small disconnected bits and pieces that can each be dealt with individually. It is straightforward enough to check that with the rules of Figure 3.0 we can prove all the rules of Figure 3.0 up to some scalar diagrams that contain at most two spiders. Hence, everything we have proven so far using the rules of Figure 3.0 remains true using our scalar-accurate set of rules, except that we might acquire some additional small scalar diagrams. This means that in particular our simplification strategy for Clifford diagrams still works, except for some small modifications. We can still use the local complementation simplification Lemma 5.2.9, but as noted in Remark 5.2.10, now it doesn’t actually remove the spider we complement on. Instead, the spider remains as an unconnected scalar. Hence, if we were to apply this rewrite to an unconnected spider (so where n = 0 in that lemma), it would not remove the spider. In order for the simplification strategy to work we must then only apply this lemma to spiders with a ±π 2 phase that are connected to at least one other spider. The same consideration holds for the pivot simplification Lemma 5.2.11, where we should only apply it if at least one of the spiders being pivoted on is connected to some other spider. In Section 5.4 it was noted that if we apply the simplification strategy to a scalar Clifford diagram, that the entire diagram is simplified away. With our scalar-accurate calculus we see that this now becomes slightly different. We can still remove most connections between spiders, but there will generally be some small scalar subdiagrams left.

Proposition 5.5.1. Any scalar Clifford diagram can be rewritten to be a product of the following scalar subdiagrams:

Proof. First rewrite the ZX-diagram to graph-like form, except that we can’t remove the triple set of wires in diagram of scalar-sqrt2inv . We leave those subdiagrams as is. Then apply the scalar-accurate version of the local complementation Lemma 5.2.9 to any spider with a ±π 2 phase that is connected to at least one other spider. After doing this, any connected spider must have a phase of 0 or π. Apply the pivot Lemma 5.2.11 to any such pair where at least one of the spiders has connections to other spiders. Hence, after we are done there can only be connections between pairs of spiders that aren’t connected to anything else. By simply enumerating the possibilities (and applying some colour-changes using (cc)) we see that the only possible connected subdiagrams are then the ones listed above, diagram of sqrt2-scalar-pi , and diagram of Z-scalar . The first of these can be rewritten to diagram of sqrt2-scalar-3 using Lemma 3.6.4, and diagram of Z-scalar can be decomposed into a pair of diagram of sqrt2-scalar-3 ’s using Lemma 3.6.1. □

Now, if our scalar diagram contains a diagram of pi then it can already be rewritten to a normal form, so let’s assume it does not contain that subdiagram. Then our diagram is a composition of five different types of diagrams. By applying (s) we can ensure that the diagram does not contain both a diagram of sqrt2-scalar-3 and a diagram of scalar-sqrt2inv (as they are each others inverses). What other relations hold between these scalars? Using Lemma 3.6.7 we see that there can be at most one subdiagram of diagram of scalar-min1 and using Lemma 3.6.9 we can make it so that there is at most one spider with a ±π 2 phase in our diagram.

Theorem 5.5.2. We can rewrite any non-zero scalar Clifford diagram D to a unique normal form D1k D2 D3 where k , diagram of sqrt2-scalar-1, diagram of scalar-min1-1 and diagram of scalar-i.

Proof. Apply Proposition 5.5.1 to rewrite the diagram to a product of pairs of spiders. Apply Lemma 3.6.9 so that the diagram contains at most one spider with a ±π 2 phase. If this one diagram with a π 2 is diagram of scalar-min-i then apply Lemma 3.6.6 in reverse with α = π and β = π 2 , so that the π 2 diagram is then diagram of scalar-i-3 . Apply Lemma 3.6.7 so that there is at most one instance of diagram of scalar-min1 . Finally, cancel all pairs of diagram of sqrt2-scalar-3 and diagram of scalar-sqrt2inv using (s). It is then straightforward to verify that the diagram must be of the form specified. To see this is a unique representation of the scalar let s denote the value of the scalar the diagram represents. The type of D3 tells us whether Re(s) = Im(s) (diagram of fracpi2-3), Re(s) = Im(s) (diagram of fracpi2-4), Re(s) = 0 (diagram of scalar-i-1) or Im(s) = 0 (D3 = = 1). As s0 by assumption D3 must then be the same for any diagram representing s in this normal form. Similarly D2 tells us whether the real part of s is positive (or the imaginary part in case diagram of scalar-i-2), since D2 either represents 2 or 1, so that this must also be the same diagram for every representation of s. Finally, D1 being diagram of sqrt2-scalar-2 or diagram of scalar-sqrt2inv-1 together with the value of k tells us the magnitude of Re(s) (or Im(s)), and hence is also uniquely determined by s. □

This theorem tells us that we can always rewrite any two scalar Clifford ZX-diagrams into one another if they represent the same scalar, since they can both be rewritten into this unique normal form.

5.5.2 A unique normal form for Clifford diagrams

The previous section settled the question of completeness for scalar Clifford diagrams. In this section we will do the same for non-scalar Clifford diagrams. Since the question of scalars is now settled, we will again revert back to not caring about these scalar subdiagrams. As before, we will write when we are denoting an equality up to a non-zero scalar factor. We will just work with states in this section, so diagrams that don’t have any inputs. Once we have completeness for states, completeness for all diagrams follows easily just by bending some wires (like we did in Theorem 4.3.6). What we will show in this section is that we can refine the AP form, rewriting it into something more canonical. We will then show that this reduced normal form is unique. In particular, we will rewrite our diagrams to the following form.

Definition 5.5.3. A non-zero diagram in AP-form defined by the triple A,b,ϕ is in reduced AP-form when:

1..

A is in reduced row echelon form (RREF) with no zero rows,

2..

ϕ only contains free variables from the system Ax = b.

3..

all the coefficients of ϕ are in the interval (1,1].

Recall that the first non-zero element in a row of a matrix A in RREF is called a pivot (no relation to the pivot graph rewrite rule). The variable xi is called a free variable if the ith column of A does not contain a pivot, otherwise it is called a bound variable. The utility of looking at the reduced AP-form is the following theorem.

Theorem 5.5.4. For any non-zero state |ψ, there is at most one triple (A,b,ϕ) satisfying the conditions of Definition 5.5.3 such that:

|ψ x,Ax=beϕ|x

Proof. Since |ψ0, the set A = {x|Ax = b} is non-empty. Hence, there is a unique system of equations in RREF that define A (why?). From this it follows that A and b are uniquely fixed. Now, for any assignment {xi1 := c1,,xik := ck} of free variables, there exists |xA such that xiμ = cμ (this is why we call these variables ‘free’, they can be chosen without restrictions while still satisfying the constraints given by A). Hence:

x|ψ = λeiπϕ(c1,,ck)

for some fixed constant λ0. From this it follows that, by inspection of |ψ, we can determine the value of ϕ at all inputs (c1,,ck) 𝔽2k, modulo 2. This is enough to compute each of the coefficients of ϕ, modulo 2. (Q: How?) Since we require the coefficients of ϕ to be in the interval (1,1], we can drop the “modulo 2” and conclude that ϕ is uniquely fixed by |ψ. □

Our goal then will be to show that we can rewrite any Clifford diagram into reduced AP-form. We already know that we can rewrite the diagram to AP form using Proposition 5.3.2. Such a diagram is then fully described (up to scalar) by a parity matrix A, a bit string vector b and a phase function ϕ. We fully Gaussian eliminate the pair (A,b) and do the corresponding transformation on the diagram as in Exercise 5.11, to bring it to RREF. If the Gaussian elimination shows that there is no solution to the affine system, then this corresponds to a scalar X-spider with phase π appearing, which is equal to the scalar 0. In this case, we can bring the diagram to the zero normal form of Proposition 3.6.5. So let’s suppose that this is not the case, and the affine system is not inconsistent. We remove all the zero rows of A (which correspond to scalar spiders). So now each row of A is a linear independent bit string. The affine part of the diagram is then unique. It then remains to show that we can rewrite the phase part so that the phase function ϕ only depends on free variables. To do this it will be useful to introduce some notation. Each of the internal spiders in the diagram defines a parity set Pj containing the spiders it is connected to. Since we have fully reduced the matrix A, each Pj contains a pivot spider pj Pj that does not appear in any other parity set. We then need to rewrite the diagram so that the pivot spiders pj does not interact at all with ϕ. This means it must not have any phase, and not be involved with any CZs. First, if a pivot spider has a phase of π, then this can be pushed to the other spiders of its parity set:

If instead its phase is ±π 2 then we can remove it by applying a local complementation type rewrite rule. We start by applying the local complementation Lemma 5.2.9 in reverse:

Here in the last step we also implicitly got rid of the scalar spiders that result after applying the copy rule (sc). Now that all pivot spiders have no more phase, we will remove all the Hadamard edges that pivot spiders are involved in. First, we remove all the Hadamard edges from a pivot to a spider within its own parity set. We can do this by repeating the following rewrite:

After every such rewrite the number of Hadamard edges from a pivot strictly decreases, so that the procedure terminates. Finally, we can use a variation of this rewrite rule to remove Hadamard edges from a pivot to a spider outside its parity set:

Note that this rewrite can introduce new Hadamard edges to the pivot of the other parity set, namely when we apply the rewrite rule to two pivots that are connected to each other. However, the rewrite rule either decreases the total number of edges that are connected to a pivot or it decreases the number of pivots that are connected to each other, so that we can always keep applying it and it will always reduce one of these metrics, so that the procedure does terminate. In the end when we can no longer apply the rewrite rule anywhere, it must mean that there are no Hadamard edges attached to a pivot in the diagram.

Remark 5.5.5. The previous phase-removal and edge-removal rewrites also apply when the pivot spider is the only spider in its parity set, but then these rewrites become quite trivial:

We conclude then that we get a diagram in reduced AP form.

Proposition 5.5.6. Any diagram in AP form can be transformed to reduced AP form.

Theorem 5.5.7. The ZX-calculus is complete for Clifford diagrams.

Proof. Suppose we have two diagrams D1 and D2 that represent the same linear map. Without loss of generality we may assume that they are states by bending all the wires to the right. We can rewrite the diagrams to reduced AP forms D1, respectively D2. The diagrams represent the same linear map and Theorem 5.5.4 shows that this linear map has a unique reduced AP form associated to it, so that D1 and D2 must be the same diagram. Furthermore, by reducing the scalars in the diagrams to a unique normal form (Theorem 5.5.2), we see that the scalar parts of the diagram are also equal. We then indeed have a set of rewrites from D1 to D2: first go from D1 to D1, which is equal to D2, and then do rewrites in reverse to go from D2 to D2. □

Remark 5.5.8. The reader familiar with stabiliser theory might be wondering how it is that we get a unique normal form for Clifford states, as there is no really ‘canonical’ way to do this. The trick is that we fully Gaussian eliminate the parity matrix. This procedure makes a distinction between the qubits: the first qubit is much more ‘likely’ to be a pivot than the last qubit. A state that is symmetric in the qubits hence would not necessarily be reduced to a symmetric unique normal form (try to construct for instance the reduced AP form of the GHZ state).

You might wonder how these reduced AP forms relate to graph states. We have already seen that we can transform a state in AP form to one in GSLC form by doing some boundary pivots. If the diagram is in reduced AP form, the translation is even simpler: since for every internal spider we have a pivot spider that does not have a phase, it’s Z-spider is actually an identity, and we can do some identity removal and colour change to turn it into a GSLC state:

We see that that every internal spider in AP form translates into a Hadamard on the output of its corresponding pivot in the resulting graph state.

5.6 Summary: What to remember

1..

Clifford circuits are circuits consisting of CNOT, Hadamard and S gates. Clifford states are the quantum states that can be produced by starting with |00 and then applying a Clifford circuit to it.

2..

Clifford circuits are represented by ZX-diagrams where all the phases are multiples of π 2 . We call these diagrams Clifford diagrams.

3..

Any Clifford diagram that is unitary can be written as a Clifford circuit.

4..

We can efficiently simplify Clifford diagrams by the graph-theoretic operations of local complementation and pivoting.

5..

This allows us to

a)

reduce each Clifford circuit to a normal-form consisting of just a few layers of Hadamard, S, CNOT and CZ gates,

b)

write each Clifford state in the affine with phases form,

c)

write each Clifford state as a graph state with local Cliffords,

d)

efficiently calculate amplitudes of Clifford states,

e)

efficiently calculate marginal probabilities of Clifford states (strong simulation),

f)

efficiently sample measurement outcomes from a Clifford state (weak simulation).

6..

This scalar-accurate set of rewrites of the ZX-calculus is complete for Clifford ZX-diagrams, meaning that any two Clifford diagrams representing the same linear map can be rewritten into each other using these rewrite rules.

7..

This follows from the existence of a unique normal form for Clifford states that we call the reduced AP form.

5.7 References and further reading

Classical simulation Clifford circuits were first shown to be efficiently classically simulable by [113], using what he called the Heisenberg representation, which is now more commonly called the stabiliser representation or stabiliser tableau. We will go into detail on this structure in Chapter 6. Notably, the classical simulation theorem itself appears in this single-author paper by Gottesman as “Knill’s theorem”, crediting Knill with the idea. These days it is called the Gottesman-Knill theorem.

Circuit normal forms The first Clifford circuit synthesis algorithm was given by [1], which produced a circuit with 11 layers of distinct gate types. This was subsequently improved to more compact forms [79226170]. The shallowest decompositions, at the time of this writing, are due to [171] have a 2-qubit gate depth of 2n + O(log2n).

Graph states with local Cliffords The GSLC form for Clifford ZX diagrams is based on a result by [227], who showed that any stabiliser state, i.e. any state prepared from |00 using a Clifford circuit, can be expressed as a graph state with local Cliffords. The definition of GSLC form for ZX diagrams is due to [19], who used it to prove completeness of the Clifford ZX calculus. The reduction of an arbitrary diagram to GSLC form is from [88].

Local complementation Local complementation, as a purely graph-theoretic concept, goes back to [158]. It’s relevance to quantum computing originates with [225], who showed that two graph states are equal up to local Cliffords if and only if one graph can be transformed into the other via local complementations. [94] showed that, furthermore, this sequence of local complementations can be found efficiently. The local complementation rule was proved in the ZX-calculus by [90]. A more accessible proof is provided in Ref. [62, Prop. 9.125]. The pivoting rule was introduced for ZX diagrams by [92], where it was used to show completeness of the “real stabiliser” fragment of the ZX-calculus, i.e. for ZX diagrams generated by phase-free spiders and the Hadamard gate. The simplification-versions of local complementation and pivot rules (i.e. the ones that delete spiders) were introduced by [88] to simplify non-Clifford circuits, and with some additional variations on the pivoting rule, they were used in [23] to simplify MBQC patterns (though note that the idea that ’a pivot deletes vertices’ was also present in [178]).

AP normal form The AP form and reduced AP form were introduced in a preprint of this book in 2022 to give, among other things, a simplified proof of Clifford completeness. It first appears in published form in [192] for the case of odd-prime-dimensional qudits. A circuit decomposition for Clifford state preparations, which is closely related to the AP normal form, appears more than ten years earlier, in a classical simulation paper by [226].