Chapter 8
Measurement-based quantum computation

Up to this point, whenever we talked about a quantum computation, we were talking about the circuit model. In this model of computation you start with a simple state, usually |00, which is then inserted into a quantum circuit, i.e. a collection of simple unitaries that combine to make something more complex. At the end we measure the qubits in some fixed basis, and the outcome of these measurements is the outcome of our computation. This model of quantum computation is inspired by classic logic circuits. It is a universal model, meaning that we can in fact present arbitrary quantum computations in this way. This however does not mean that this is always the best way to think of a quantum computation, or the one that matches the most closely to how a real-world quantum computer would function. There are more ways to implement a computation on a quantum state than just by directly performing a unitary on it. If we have some entangled state, then measurement of one part of the state induces an action on the other part. Depending on the entanglement and the measurement this action could be unitary or non-unitary. Let’s take for example a slight modification of the teleportation example of Section 3.3.2 that we also saw in Section 6.5:

(8.1)

In this example of gate teleportation we have some maximally entangled state |ψ, which we entangle with the qubit we want to do a computation on using a CNOT. By then measuring some qubits, the resulting state has a unitary U and a Pauli applied to it. The Pauli we apply however is determined by the measurement outcome. This is an inevitable feature of using measurements to do computations: measurement non-determinism. Since we don’t control which Pauli gets applied, and it is ‘stuck’ behind the U, this seems like it would prevent us to control which computations get executed. However, it turns out that for smart choices of measurements and smart choices of U, we can feed-forward the Pauli errors. In this way we can make the non-determinism ‘deterministic enough’ to work for us. There are various degrees of how much we can use measurements to do computations for us. On one end of the spectrum we don’t use measurements at all, performing all computations with unitary gates. Moving a bit further along the spectrum we can decide to implement only certain types of gates using gate teleportation (like in Eq. (8.1)), or using its closely related cousin of state injection. Even further along the spectrum we can let all multi-qubit dynamics be taken care of by measurements, which is the case in lattice surgery or fusion-based computation. We will have a lot more to say about lattice surgery in Chapter 11. On the extreme end of the measurement-based scale is the one-way model, where arguably all computation is done by measurements. In the one-way model we start with a large entangled graph state, and then we perform single-qubit measurements in different rotated bases. The choice of which qubit to measure and in what basis it is measured is informed by the computation you want to do and what the previous measurement outcomes were, while the starting graph state (apart from its given size) usually doesn’t depend on the particular computation. In this model all computation is done by measurements. Such a computation might for instance look like the following:

(8.2)

Here we start with a four qubit graph state, and then we measure each of these in different bases. The Boolean variables a, b, c and d represent each of the measurement outcomes and are the output of this computation. In this example we have pre-determined measurement planes, i.e. whether the measurement takes place in a (rotated) Z or X basis, but some adaptive measurement angles. I.e. while the top qubit is always measured in a basis with angle π 2 , the third qubit has a measurement angle (1)aπ 4 , meaning that whether we measure it in the angle π 4 or π 4 depends on the measurement outcome of the qubit a. This means there is an order fixed on the measurements of these qubits, with qubit a having to be measured before qubit c. Collectively, we call models of quantum computation using measurements measurement-based quantum computing (MBQC). While the circuit model is inspired by classical circuits, MBQC has no classical counterpart. There are various reasons why we might want to consider MBQC as opposed to quantum circuits:

In this chapter we will look in detail at the one-way model. It turns out that graph-like diagrams can naturally be understood as measurement patterns. In this way we can see that we can indeed do universal quantum computation in the one-way model. We will also see more broadly how we can determine when a computation can be made deterministic. We do this by studying generalised flow, or gflow for short, which tells us how to feed-forward Pauli errors. It turns out that any deterministic measurement pattern with gflow can be efficiently transformed back into a quantum circuit. This gives us a triangle of translations, from quantum circuits, to ZX-diagrams, to measurement patterns, and back to quantum circuits. Because we can rewrite ZX-diagrams, this gives us a unified way to think about circuit optimisation and measurement-pattern optimisation.

8.1 Measurement fragments

If we were to formally specify what a computation in the quantum circuit model is, it would be something like: prepare n qubits in the |0 state, apply a series of unitary gates G1,,Gk, then measure all n qubits in the computational basis, giving some bit string x, and finally post-process this with some output function p(x) giving the final outcome. In contrast, we might formally specify a one-way computation as follows.

Definition 8.1.1. A one-way model computation consists of the following data:

To execute it, we prepare the graph state |G, and measure the qubits one by one in the order f(1),f(2), giving outcomes x1,x2,. They are measured in the plane λ(f(k)) with angle αk(x1,,xk1). The final outcome of the computation is p(x).

Note that we will talk about what these ‘measurement planes’ are in more detail later, for now you can think of the XY plane as corresponding to Z-spiders and the Y Z plane as corresponding to X spiders.

Remark 8.1.2. In Definition 8.1.1 we are not allowing the measurement-plane to depend on previous measurement outcomes. This is just for our convenience, and because this model is already universal.

Definition 8.1.1 specifies a complete calculation from beginning to end where all qubits end up measured. If we represent it as a ZX-diagram it hence corresponds to a scalar ZX-diagram, i.e. a diagram with no inputs or outputs. This is no different from the circuit model, where for a full computation we also have to fix an input state and end by measuring all qubits. However, just as it is useful in the circuit model to think of just a part of a computation which has some input and output qubits, it is also useful to think of ‘fragments’ of a measurement-based computation that can be composed together to create more complicated computations. These fragments have inputs and outputs just like a quantum circuit would. For instance, a measurement fragment that implements a CNOT gate is given by the following diagram:

(8.3)

Here the top qubit is both an input and an output and hence isn’t measured. The third qubit is an input, but is not an output and hence is measured. The fourth qubit is an output and hence also isn’t measured. The second qubit is ‘internal’ and is hence prepared and measured as part of this fragment. The fragment (8.3) implements a CNOT gate up to a known Pauli error that depends on the measurement outcomes a and b. We can calculate this Pauli error by simplifying the diagram:

(8.4)

Hence we end up with the circuit (Zb (ZbXa)) CNOT. Since the error is a known Pauli, later measurements can be adapted to absorb these errors so that the overall effect of this measurement fragment is the application of a CNOT gate. We call this process of pushing Pauli errors outside of the pattern into the future feed-forward. Let’s give a bit more formal definition of a measurement fragment. For that we need the concept of an open graph.

Definition 8.1.3. An open graph (G,I,O) is a graph G = (V,E) together with a list of inputs I and outputs O. These lists consists of vertices of G, where repetition of vertices is allowed, and the order is relevant.

Definition 8.1.4. A stand-alone measurement fragment consists of

The reason we call this a ‘stand-alone’ fragment is because this definition doesn’t deal with fed-forward Pauli errors. To prevent making this too complicated for now, we postpone that discussion until later. This definition is maybe a lot to take in, but the corresponding ZX-diagrammatic picture should make things more clear. We construct the ZX-diagram corresponding to a measurement fragment as follows. For every vertex in V we add a Z-spider, and for every edge in E we add a Hadamard edge between them. Then we add an input wire on a spider if it is in I and an output wire if it is in O. This so far gives us a graph-like diagram and an open graph (where the graph-like diagram is phase-free). However, now we also add an additional output wire to every non-output spider, to get a diagram that looks something like this:

(8.5)

Now on each of those additional output wires, we are going to plug in a measurement effect, corresponding to the measurement plane and angle of that vertex:

(8.6)

Here the αk denotes the measurement angle of the pattern, and the bk is a Boolean variable denoting the outcome of the measurement. Note that αk is actually a function of the variables b1,,bk1 representing the outcomes of the previous measurements. These names XY , XZ and Y Z come from the fact that these effects lie on those corresponding planes of the Bloch sphere:

We see then that if in the fragment (8.5) we choose XY for the measurement-plane of both qubits and we simply set the measurement angles to 0 that we get precisely the measurement fragment (8.3) implementing the CNOT gate. We can also construct a fragment that implements an arbitrary single-qubit unitary. Recall that we can use the Euler decomposition of such a unitary to write it as a sequence of a Z phase gate, and X phase gate, and then another Z phase gate: . Let’s try to write down a measurement fragment that implements this, by putting each of the phases α,β and γ into the measurement angle of a qubit:

(8.7)

This is not exactly correct. There are a couple of things we need to fix. For one thing, there is a Pauli error at the end: an X gate depending on b + d and a Z error depending on a + c. We will learn how to deal with such errors later. But there is also a problem with the phases. We want the phases to be α, β and γ, but we see that depending on the measurement outcomes we might have actually gotten β or γ. This is where the condition of Definition 8.1.4 comes in that measurement angles are allowed to depend on previous measurement outcomes. To make this fragment do what we want it to do, we need to make it adaptive. We first measure the qubit labelled by the measurement outcome a. If a = 0, we measure the qubit b in the angle β, which gives what we want. Otherwise we measure it in the angle β. Hence, the measurement angle is (1)aβ. Rerunning the calculation (8.7) with β replaced by (1)aβ, we see that we get the final phase of (1)a(1)aβ = β, so that now the final angle no longer depends on the measurement outcome! We can do the same with γ, letting the measurement angle instead be (1)bγ. With these changes the measurement fragment becomes:

(8.8)

Apart from the Pauli error at the end that we still need to deal with, this implements the unitary we want. Note that in the fragment implementing the CNOT (8.3), the measurement angles didn’t depend on each other, so that the order of measuring the qubits wasn’t important. In (8.8) however, the measurement angles of some of the qubits depend on the measurement outcomes of other qubits, so that those qubits have to be measured first. This gives us a ‘direction of time’ on the pattern. It makes sense that we need to have some kind of adaptivity or dependency in our calculation. If we could do universal computation without such dependencies, then we could measure all qubits simultaneously, and do computations in constant time! So now we have a measurement fragment implementing a CNOT and another one implementing arbitrary single-qubit unitaries. Hence, if we can combine these then we can implement arbitrary unitaries. However, now we get to why we called these measurement fragments ‘stand-alone’: there is the problem of the Pauli errors. Let’s see what we can do with them. If a fragment with a Pauli error occurs at the end of our computation this is easy enough to deal with. At the end, we measure all the qubits in the computational basis anyway. This means that these errors just change how we should interpret the measurement outcomes:

So if we were feedforwarding an X error, i.e. x = 1 above, then this changes how we should interpret the measurement outcome we got. If we observe the measurement outcome a then this is actually a = a x. So to get the ‘actual’ measurement outcome a, we just take a x = a x x = a. A Z error (z = 1) doesn’t change the measurement outcome when we measure in the computational basis, so we can ignore those in this setting. A Y error, i.e. where both a Z error and an X error occurred, we can treat the same as an X error here. In general though, the measurement fragment will happen somewhere in the middle of the computation so that the errors will not change the final measurement outcomes, but change how we should run the next fragments in the sequence. For instance, let’s see what would have happened if a Pauli error had happened on the input qubit prior to executing the measurement fragment (8.8):

(8.9)

We see that we can push these errors to the output of the fragment, at the cost of changing the angles in the unitary to potentially have minus signs, and additionally changing our output Pauli error. But these Pauli errors we have on the input arise from measurements we have done before, so we know what this error is. This means we can decide the measurement angle of our measured qubits based on this input Pauli error, in the same way we also change it based on the measurement outcomes of the qubits internal to the fragment. The full pattern that can also deal with incoming errors then becomes:

(8.10)

This still gives us a Pauli error at the end, but this is fine since we now know how to deal with this. In the definition of a stand-alone measurement fragment Definition 8.1.4 we only allowed the measurement angles to depend on previous measurement outcomes, and not on Pauli errors being fed-forward into it. Now that we know that we need this kind of adaptivity, we can give a definition of the kind of fragment we need.

Definition 8.1.5. A measurement fragment consists of

Note that we take it as part of the definition of a measurement fragment to specify what the output errors are. By specifying what we consider ‘errors’ we are at the same time specifying what our desired outcome is, and hence what the linear map we are trying to implement is. We also need this error information as it needs to be fed-forward into the fragments following it.

Example 8.1.6. Translating the diagram (8.10) into the language of Definition 8.1.5, we see that G is a chain of five vertices, let’s call them a,b,c,d,o to match with the variables in (8.10). Then I = {a} and O = {o}. We have m = 4, ni = no = 1. The measurement order f just goes down the chain: f(1) = a,f(2) = b,f(3) = c,f(4) = d (although actually qubit d can be measured whenever as nothing else in the fragment depends on this outcome). The measurement-plane λ is XY for every measured qubit. The measurement-angle functions are then

f1(z,x) = (1)xα, f2(z,x,a) = (1)a+zβ, f3(z,x,a,b) = (1)b+xγ, f4(z,x,a,b,c) = 0

where here α, β and γ are pre-determined phases corresponding to the unitary we wish to implement. Finally, the Pauli error functions are fZ(z,x,a,b,c,d) = a + c + z and fX(z,x,a,b,c,d) = b + d + x.

Exercise 8.1. Do the same type of analysis of the Pauli errors as was done for (8.9), but for the CNOT measurement fragment (8.3). Do the measurement angles in this pattern have to depend on the incoming Pauli errors? What are the resulting Pauli errors on the output? Translate all this information into the form of a measurement fragment as in Definition 8.1.5.

Now that our definition of a measurement fragment can specify how incoming Pauli errors should change the measurement angles, and how the resulting errors should be fed-forward, we can actually compose these fragments together. We will not formally define how to do so, as this is quite tedious, but one can visualise it as just connecting the associated ZX-diagrams together and pushing the internal Pauli errors to the end.

Remark 8.1.7. The example fragments we have considered so far, (8.10) and (8.3), implement a linear map that is independent of the measurement outcomes in the pattern (up to a known Pauli error that is being fed-forward). We call such a fragment deterministic, because if we zoom out and consider the fragment as a single unit, it just implements a fixed unitary. Our definition of measurement fragment doesn’t require the fragments to be deterministic, but in practice we will restrict ourselves to deterministic ones. We will have a lot more to say about determinism in the one-way model in Section 8.2.

8.1.1 Universal resources

We have described a measurement fragment to implement a CNOT gate and one that can implement an arbitrary single-qubit unitary. As CNOT gates and single-qubit unitaries form a universal gate set, we see then that we can construct a measurement fragment for any unitary we would want to implement. Hurray! Note however that the resulting graph state we need will depend on the specific unitary we want to implement. There is then still some ‘information’ about the computation that is present in the starting resource state. This then raises an interesting question: can we implement arbitrary unitaries using a measurement fragment that has a fixed graph state? We need to be a bit careful about how to formally state this question, because there are unitaries that are really hard to implement, and so we would expect them to require a large resource state to prepare (put simply: if we only have k measurements, we could represent at most a k-dimensional subset of all unitaries, but the space of all unitaries scales exponentially with the number of qubits). We hence shouldn’t consider a fixed resource, but rather a family of resource state that is allowed to scale with the cost of the unitary. A more formal version of the question would hence be something like:

Does there exist a family of open graphs Gk where Gk consists of poly(k) vertices, such that for any n-qubit unitary U with m gates, we can find a measurement pattern implementing U which uses the open graph Gk where k = poly(n,m)?

Maybe perhaps surprisingly, the answer to this is yes! There exist universal resource states which allow you to implement arbitrary quantum computations up to some size. A particularly nice example of a family of universal resource states are the 2D cluster states:

I.e. the graph is just a big square grid. The trick to seeing why this is universal, is that we can use measurements in the Y Z plane to strategically cut holes into the grid:

This allows us to shape the grid into whatever pattern we need it to be to perform the computation we want.

8.2 Determinism and gflow

We have now seen that we can do universal computation using the one-way model. An important part in getting there was knowing how to deal with the wrong measurement outcomes by finding ways to feed them forward. So far we have done this essentially by trial and error: we construct a simple fragment, observe that we get the wrong phases sometimes, and then change them to correct for this. In this section we will find a more systematic way to think about correcting errors and when we can see that a measurement fragment can be made deterministic. But first: let’s look at the connection between measurement fragments and graph-like diagrams.

8.2.1 Graph-like ZX-diagrams as measurement fragments

It turns out that if we take the ZX representation of a measurement pattern, ignore the adaptivity needed to correct for ‘wrong’ measurement outcomes, and fuse some spiders, that we get a graph-like diagram. For instance, doing this for the fragment (8.7), we get:

(8.11)

This graph-like diagram is then a representation of the ‘post-selected’ measurement fragment, where all the measurement outcomes where what we wanted them to be. It turns out the converse is also true: any graph-like diagram can be seen as a post-selected measurement fragment, just by unfusing some phases and introducing some identities:

(8.12)

If we were to actually try to run this as a measurement fragment, we would of course usually get some of the ‘wrong’ measurement outcomes. So this fragment is only useful if we know how to deal with all measurement outcomes, so that we can make the pattern deterministic. Can we do this somehow? This is not just a niche question we are asking because we like diagrams. We can write any quantum circuit as a graph-like diagram, so if we could do this then this would give us an easy way to translate a circuit into a deterministic measurement fragment. It turns out that it is in general not possible to turn graph-like diagrams into deterministic measurement fragments. This is for the simple reason that we can write down ZX-diagrams that are not isometries. For instance, consider the following graph-like diagram:

(8.13)

By doing some colour changing and identity removals, we see that this is just a 2-input, 2-output Z-spider, which is a projection and is not unitary. If we could deterministically perform such a projection, we could do non-unitary quantum computation! Or even more simply, consider the graph-like diagram diagram of bra-plus. If we could implement this ZX-diagram deterministically, we would be doing post-selection. So it is not always possible to turn a graph-like diagram into a deterministic measurement fragment. But can we at least somehow determine when we can do so? As it turns out: yes. For a particularly strong type of deterministic measurement pattern there is a one-to-one correspondence to graph-like ZX-diagrams with a property called gflow.

8.2.2 The measurement correction game

To understand when we can implement a correction strategy for measurement errors on a graph-like ZX-diagram, let’s consider a small toy diagram to see what we can do:

(8.14)

This is of course not a realistic diagram that we would expect to encounter when doing MBQC, but it will serve to demonstrate the principle of correction. Here our goal is to get rid of the π phase. We can do this by changing the spider with the β phase:

(8.15)

Hence, as long as we measure the qubit with phase β after the one with α, an error at α can be corrected by changing the measurement angle of the β qubit to be β. Here we could have also chosen to change γ in order to correct the error at α. Finding the right correction was easy here, because the β spider was only connected to α and nothing else. Let’s consider a slightly more complicated diagram:

(8.16)

In this case, changing the phase of β does still remove the error at α, but it also changes the phases at the other spiders:

(8.17)

Now if we can run the pattern such that the qubits with the γ and δ phase can be measured after the α qubit, then this is fine, since we can still decide to measure them with a different phase to correct for the additional π phase they have. But if we suppose that we have already measured the qubit with the γ phase, then this would not be possible. In that case however, we see that we can apply the same ‘π-pushing’ trick with δ to remove the additional phase γ got:

(8.18)

This gave us an additional π phase at β as well, but that is fine as we are already considering changing the phase at β. Hence, to correct the error at α, we can decide to change the phase at β and δ, and this leaves the phase at γ invariant. Let’s try to formalise what is happening here. We see that the trick of pushing out an X(π) phase affects the phases on all the neighbours of this vertex, and that if we affect the phase of a vertex twice, that this then cancels out the effect. The qubits will be measured in some order, so we must make sure that whatever qubits we affect the phase of must be measured after the qubit we are trying to correct an error at. We can capture this behaviour in a little game: you are given an open graph with vertices V where every vertex is labelled with either the presence or absence of an error (a 1 or 0). You are allowed to do the operation flipv for a vertex v V , which flips the value of the error on all the neighbours of v (but not at v itself). The goal is to move all the 1’s (the errors) to the output vertices. For example:

(8.19)

For some open graphs and configurations of errors, this task might be impossible. For example, there is no solution for the following graph:

Which makes sense, because if we were to try to build a one-way model computation on this open graph, it would map two qubits to one qubit, so there is no way we could do such a computation deterministically. The question then is, for which graphs can you always win this game, regardless of where the errors occur? We can see that a winning strategy is the following: first, find an ordering of vertices which give a direction of ‘time’ going from inputs to outputs, and find for each non-output vertex u, a correction set g(u) V of vertices in the future of u (with respect to the ordering  ) such that applying flipv for all v g(u) flips the bit on u, and potentially also flips some other bits, as long as those bits all belong to vertices that are in the future of u (again, with respect to ). Now, for any instance of the game we can apply the following strategy: find a minimal vertex u (w.r.t.  ) which has an error. Then apply flipv to all v g(u). This removes the error on u, and only introduces new errors on vertices in the future of u. Then find a new minimal vertex with an error and repeat until all the errors are moved all the way to the end at the outputs. This game describes the property of g(u) in terms of the flip operation, but we can actually make the description a bit simpler and more natural to graph-theory language. Namely, we see that a vertex w get its bit flipped by applying flipv for all v g(u) precisely when it is connected to an odd amount of vertices in g(u). This is because if it is connected an even amount of times to vertices in g(u), then it gets its bit flipped twice, so that nothing happens. Let’s capture this in a definition.

Definition 8.2.1. Let G = (V,E) be an (open) graph, and A V some subset of its vertices. We define the odd neighbourhood of A in G as OddG(A) := {w V ||NG(w) A| mod 2 = 1}. Here NG(w) denotes the regular neighbourhood of a vertex w, i.e. its set of neighbours.

Using odd neighbourhoods we can rephrase the condition we needed on the correction sets g(u): we need u OddG(g(u)) (applying flip for all vertices in g(u) results in a flip at u) and if v OddG(g(u)) then u v (if v gets flipped by the corrections for u, then v needs to be in the future of u). This is in fact exactly what we require, and allows us to give the definition of the central concept of this chapter: gflow.

Definition 8.2.2. Let G = (V,E,I,O) be an open graph. A gflow (,g) on G consists of a partial order on the vertices of G, and a correction set function g : V O (V I) that associates to every non-output vertex v V O a subset of non-input vertices g(v) V I, such that:

1..

The inputs are minimal in the partial order (meaning that if v i for some input i, then v = i) and conversely the outputs are maximal;

2..

For every u V O, we have that u v and uv for every v g(u), i.e. all the elements in the correction set are in the future of the vertex being corrected;

3..

For every u V O we have u OddG(g(u)), i.e. applying a correction at all the vertices in the correction set of u, results in a correction at u;

4..

For every u V O, if v OddG(g(u)), then u v. That is, if v is a vertex that ends up with a correction from the correction set of u, then v is in the future of u.

We say an open graph has gflow when at least one gflow can be defined on it.

With what we discussed above we see that if an open graph has gflow, that this gives us a winning strategy for the error correction game.

Remark 8.2.3. We have here only shown that the existence of gflow gives us a winning strategy for the error correction game, but not that there might also be other strategies. It turns out that the open graph of a deterministic measurement pattern has gflow if and only if it has a particularly well-behaved kind of determinism. See the References of this chapter for more.

Exercise 8.2. In the definition above we defined OddG(A) by checking all vertices in G. However, there is also an ‘intrinsic’ definition, given by OddG(A) = ΔvANG(v). Here Δ denotes the symmetric difference operation of sets, where for example {1,2,3}Δ {2,3,4} = {1,4}. Prove that this definition is equivalent to the one in Definition 8.2.1.

Exercise 8.3. Show that for any two sets of vertices A,B V of G = (V,E) that OddG(A Δ B) = OddG(A) Δ Oddg(B).

8.2.3 Diagrams with gflow are deterministic measurement patterns

We can use gflow to describe how to transform a graph-like ZX-diagram into a deterministic measurement pattern. Let’s assume we have a graph-like ZX-diagram D such that its corresponding open graph G has a gflow (,g). We see from Definition 8.1.5 that to describe a measurement fragment, we need to supply a number of data to fully define it. The first parts are easy enough to specify:

But now comes the hard part: we need to describe the measurement angles, and more importantly, how they are affected by the measurement outcomes. In practice, what this means is that we have a standard measurement angle α that comes from the angle we had in the ZX-diagram D. But then this α gains either a + π phase or a negation depending on whether it appears in any correction sets, or odd neighbourhoods of correction sets of measured qubits that require a correction. Let’s write αu for the phase that the spider u has in the original diagram D and au for the measurement outcome when the spider u is measured. Hence, if all the measurement outcomes au are 0, then the measurement angles we want to measure every qubit in is just αu. We will change these αu to functions αu that may depend on the av of qubits v that have been measured before u. Let’s first consider an input u I, which has to deal with a fed-forward Pauli X error, but no other corrections from inside the pattern:

We see that we should change our initial choice of measurement αu to a function αu(z,x) = (1)xα + in order to account for the error being fed-forward into the spider. This doesn’t fully capture the incoming Pauli error though, as we see that the X error has to be further fed-forward into the neighbours of u. All this does is change the measurement angle of that neighbour by , so we will ignore this detail. While this deals with the incoming Pauli error, it does not deal with the measurement error av that it produces itself. To correct this we need the gflow condition. This procedure is the same regardless of whether the spider is an input or not, so let’s just take u V O to be any measured qubit now. We then have a set of correction qubits g(u) = {v1,,vk} and a set of ‘corrected’ qubits OddG(g(u)) = {u,w1,,wl}. We then see that by changing the measurement angles at the correction and corrected qubits, we can remove the measurement error at u:

Here for simplicity we have assumed that each vi and wj is not an output, as we will deal with that case later. We have given every qubit in this diagram an additional output wire to denote that it can also be connected to some other spiders. The last application of (π) does not affect these additional qubits, precisely because they are not in the odd neighbourhood of the correction set. So for every v g(u) we set αv(au) = (1)auαv and for every w OddG(g(u)) with wu we set αw(au) = αw + auπ. In general, a spider could of course be part of multiple correction sets and odd neighbourhoods of correction sets. It will be useful to give these a name:

S1(v) := {u V O|v g(u)} S2(v) := {u V O|v OddG(g(u)){u}}

Then the actual measurement angle, as a function of the previous measurement outcomes, is

αv({a u|u v}) = (1) uS1(v)au αv + ( uS2(v)au) π.

We are now almost done! The above tells us how to change measurement angles to correct errors when the correction sets g(u) and corrected sets OddG(g(u)) only contain non-outputs. When instead an output qubit o is in such a set, then we don’t change the measurement angle of o (which we can’t do since o is not measured), but we change the Pauli error that is being fed-forward. If o g(u), then we get a Pauli X error of auπ, and if o OddG(g(u)), then we get a Pauli Z error auπ. In general then, the output Pauli that gets forwarded at output o is (z,x) = ( uS2(o)au, uS1(v)au). We have now specified what all the measurement angles of the qubits should be, based on the fed-forward errors and the internal measurement outcomes, and we have specified what the outgoing fed-forward errors will be based on the measurement outcomes. This then indeed gives us a measurement pattern. By how we constructed the pattern, we see that it implements the ZX-diagram we started out with regardless of the internal measurement outcomes (up to the fed-forward Pauli error at the end). We have then proved the following result.

Theorem 8.2.4. Let D be a graph-like diagram, and G = (V,E,I,O) its corresponding open graph consisting of a vertex for every spider and edge for every Hadamard edge, and suppose that G has gflow. Then we can efficiently construct a deterministic measurement fragment from D and the gflow which has the same underlying open graph and implements the same linear map as D.

Remark 8.2.5. The trick we applied here, introducing Pauli X’s to cancel a Pauli Z at a different location, might have seemed a bit familiar. This is because it is actually based on the stabilisers of the underlying graph state (see Example 6.3.8). Applying the flipv operation is like introducing the graph-state stabiliser Sv consisting of an X at v and a Z at all its neighbours. The correction set g(u) then says that to correct the error at u, we need to introduce the stabiliser vg(u)Sv.

8.2.4 From circuits to measurement patterns

We started out this section with the goal of understanding how we can systematically create measurement fragments that are deterministic. We have seen that we have one powerful tool for ensuring determinism: the existence of a gflow. What we have however not yet done is finding a good source of measurement fragments that have gflow. As it turns out, if we take a unitary circuit consisting of Clifford and phase gates, and then turn it into a graph-like diagram by fusing all spiders and colour changing to Z-spiders as described in Proposition 5.1.8, the resulting diagram has gflow.

Proposition 8.2.6. Let D be the diagram of some quantum circuit, and D the graph-like diagram produced from D using Proposition 5.1.8. Then D has a gflow.

Proof. The idea will be to set g(u) = {v} where v is the spider directly to the right of u on the same qubit line, and for the partial order to encode ‘is that spider to the left of me?’ For every spider v of the circuit D we associate a number qv specifying on which ‘qubit-line’ it appears. We also associate a ‘column-number’ cv 0 specifying how ‘deep’ in the circuit it appears. Hence, each spider has ‘xy coordinates’ (cv,qv):

Suppose that v and w are connected in D, v w. If they are on the same qubit, so qv = qw, then necessarily rvrw, since they can’t share the same space. Conversely, if they are on different qubits, qvqw, then they must be part of a CZ or CNOT gate, and hence rv = rw. In D, every spider arises from fusing together adjacent spiders on the same qubit line from the original diagram (apart from the additional identity spiders introduced in the last step, which we will ignore for now):

For a spider v in D we can thus associate two numbers sv, and tv, where sv is the lowest column-number of a spider fused into v, and tv the highest. For instance, for the second spider on the second qubit, we have s = 3 and t = 5. Spider fusion in D only happens for spiders on the same qubit-line, and hence v also inherits a unique qv from all the spiders that got fused into it. An identity spider v created by the last step of the translation, must be attached to either an input or an output. If it is attached to an input, we set sv = tv = 0. If it is attached to an output we set sv = tv = + (or any value bigger than the largest value of tv in the diagram). For this proof we can treat these spiders the same way as the others. We define a partial order on D as follows: v w if and only if v = w or tv < tw. It is straightforward to check that this is indeed a partial order. Now for any u in D that is not an output, set g(u) = {v} where v is the unique neighbour to the right of u on the same qubit-line. We claim (g,) is a gflow. By construction u Odd(g(u)) = N(v). We need u v. The spiders of D that got fused into the same spider in D must have all been adjacent. Hence, for the distinct spiders u and v in D on the same qubit we must have tv < sw, as they couldn’t have overlap in the spiders that got merged into them. Hence, tu < sv < tv so that u v. Suppose w Odd(g(u)) = N(v) so that w v. We need to show that u w. If u = w this is trivial so suppose vw. First suppose that qw = qv (which is also equal to qu). We know v has a maximum of two neighbours on the same qubit-line (one to the left, and one to the right), and since the one to the left is u, w must be to the right, so u v w. If instead qvqw then their connection must have arisen from some CNOT or CZ gate in D, and hence the intervals [sv,tv] and [sw,tw] must have overlap, so that necessarily sw tv and sv tw. Since we also have tu < sv we get tu < sv tw so that indeed u w. □

Remark 8.2.7. A gflow like we get here, where each correction set only contains a single element, is known as a causal flow, or just a flow. This is the kind of flow that gflow is generalising.

There are also some simple modifications we can make to an open graph that preserve the existence of a gflow. Like adding new vertices after an output or adding and removing connections between output vertices.

Exercise 8.4. Let G = (V,E,I,O) be an open graph with a gflow (,g) and suppose that outputs oi,oj O are connected. Show then that (,g) is also a gflow for the open graph G = (V,E,I,O) where E = E{(oi,oj)}, i.e. the graph where we removed an edge between two outputs. Similarly, show that adding an edge between two outputs also preserves gflow.

Exercise 8.5. Let G = (V,E,I,O) be an open graph with a gflow (,g) and let o O be some chosen output. Define G = (V ,E,I,O) by V = V {u}, O = {u} O{o} and E = E {(o,u)}. That is: G is just G but with another vertex u after o that becomes the new output. Show that (,g) is a gflow for G where is just the transitive closure of with the additional relation o u, and g(o) = {u}, and g(v) = v for every other vertex.

Note that these results only talk about creating a new pattern that also has a gflow. We are not defining an actual measurement pattern, and hence we are not saying anything about whether this new pattern implements the same linear map or not. In Section 8.3 we will prove that some more elaborate ways in which we can change graphs also preserve the existence of a gflow.

8.2.5 Focussed gflow

The definition of a gflow allows the correction set g(u) to also induce corrections on other vertices, as long as those other vertices are in the future of u. That is, OddG(g(u)) can contain more than one vertex. It turns out that we can modify a gflow to just allow u to be corrected and no other measured vertex (this turns out to be useful later).

Definition 8.2.8. We say a gflow (,g) on an open graph G = (V,E,I,O) is focussed when for every u V O, the corrected vertices v OddG(g(u)) are either v = u or v O. That is, OddG(g(u))O = {u}.

Exercise 8.6. Let G = (V,E,I,O) be an open graph with a gflow (,g). Pick some vertex u V O. Let A V be some set of vertices such that for any v A and v OddG(A) we have u v and uv. Show then that the function g defined by g(u) = g(u) Δ A and g(w) = g(w) for all wu also defines a gflow (,g) on G.
Hint: Use Exercise 8.3.

Exercise* 8.7. Show that if an open graph has a gflow, then it also has a focussed gflow.
Hint: if you have some u for which OddG(g(u)) contains some vertex v it shouldn’t, then v has to be in the future of u. Argue that A = g(v) satisfies the conditions of the previous exercise. Proceed to modify g(u) with A. What has now changed about OddG(g(u))?

8.3 Optimising deterministic measurement patterns

In Chapter 5 we saw two rewrites that proved very useful for optimising Clifford diagrams: local complementation and pivoting. These rewrites allowed us to remove internal spiders from a graph-like diagram. As we’ve seen in this chapter, we can view graph-like diagrams as measurement patterns, and then internal spiders become measured qubits. Hence, these rewrites now offer ways to optimise the number of qubits we need to measure in the pattern. Of course, this is only useful if it preserves our ability to deterministically implement the measurement pattern, i.e. if it preserves the existence of a gflow. That is precisely what we will prove in this section. While we tried to present the proofs here in as simple a way as possible, it still requires some stamina to process all the odd-neighbourhood acrobatics. So perhaps on a first read-through you might want to just read the statements of Proposition 8.3.2 and 8.3.5 and then move on to the next section to see what we will use these results for. Recall that for a graph G, we defined G u to be the graph where we locally complemented about u. In this graph the neighbourhoods have been updated as follows for any v V :

NGu(v) = { NG(v) Δ NG(u) Δ {v}if v NG(u) NG(v) otherwise
(8.20)

We will also need to know how the odd neighbourhood of a set changes when you apply a local complementation.

Lemma 8.3.1. Given a graph G = (V,E), A V and u V ,

OddGu(A) = { OddG(A) Δ (NG(u) A)if uOddG(A) OddG(A) Δ (NG(u) A) if u OddG(A)

Proof. Using the fact that OddG(A) = Δ vANG(v), we calculate:

OddGu(A) = Δ vANGu(v) =(8.20) (Δ vANG(u)NG(v) Δ NG(u) Δ {v})Δ (Δ vANG(u)NG(v)) = (Δ vANG(v)) Δ (Δ vANG(u)NG(u)) Δ (Δ vANG(u){v})

Here in the last step we simply regrouped the terms: we used the fact that the NG(v) term appears in both the terms above it so that we can combine them into Δ vANG(v), and we separated out the other terms. We then see that the first term is precisely OddG(A), while the last term is just a union of all the {v} in A NG(u). This expression hence simplifies to

OddGu(A) = OddG(A) Δ (Δ vANG(u)NG(u)) Δ (A NG(u))

It remains to simplify the middle expression. This is just a symmetric difference of NG(u) with itself a number of times. This term hence only appears when |A NG(u)| 1 mod 2. This is precisely the case when u OddG(A). Hence, if uOddG(A), OddGu(A) = OddG(A) Δ (A NG(u)). Otherwise, if u OddG(A), we get OddGu(A) = OddG(A) Δ NG(u) Δ (A NG(u)). We can simplify this expression by using the property B Δ (A B) = B A (convince yourself that this is true). The expression for OddGu(A) then becomes exactly what we wanted to prove. □

Proposition 8.3.2. Let G = (V,E,I,O) be an open graph with a gflow (,g) and let u V (I O) be an internal vertex. Then G := (G u) {u}, the open graph we get by doing a local complementation about u and then removing u, also has gflow.

Proof. By Exercise 8.7 we may assume that the gflow g of G is focussed, i.e. that OddG(g(w)) only contains {w} and outputs of G for any w. We then claim that the function g : V (O {u}) (V (I {u})) defined by

g(w) := { g(w) if ug(w) g(w) Δ {u}Δ g(u)otherwise
(8.21)

gives a gflow (,g) on (G u) {u}. We haven’t changed the partial order, so we just need to check the different conditions that g has to satisfy. First, note that it is well-defined: none of the g(w) contain u. In the first case this is true by construction, and in the second case we know that u g(w), so that g(w) Δ {u} = g(w) {u}. Now we have to check three things:

1..

All the elements of g(w) are in the future of w.

2..

All the elements of OddGu(g(w)), except for w itself are in the future of w.

3..

OddGu(g(w)) contains w.

For the first point, note that if ug(w), that then g(w) = g(w), in which case all of g(w) is definitely in the future of w (since we haven’t changed the partial order ). Otherwise u g(w), and hence w u, so that all the elements of g(u) are in the future of w. Hence g(w) = g(w) Δ {u}Δ g(u) only contains elements in the future of w. Then for the second and third point. Because g is focussed and u is not an output, we know that uOddG(g(w)) if wu. This means that when we use Lemma 8.3.1 to calculate OddGu(g(w)) the first case applies and we get OddG(g(w)) Δ (NG(u) g(w)). So now let’s again make the case distinction on whether u g(w). If this is not the case, then g(w) = g(w), and hence

OddGu(g(w)) = Odd Gu(g(w)) = OddG(g(w)) Δ (NG(u) g(w)).

Both the elements of OddG(g(w)) and (NG(u) g(w)) g(w) are certainly in the future of w, so that this odd neighbourhood lies in the future of w. Additionally, OddG(g(w)) contains w, while g(w) does not, so that w OddGu(g(w)). Hence, points 2 and 3 are satisfied for those w where ug(w). It then remains to check OddGu(g(w)) for the w that satisfy u g(w). To calculate this set it will be useful to first calculate OddGu(g(u)). As u OddG(g(u)), the second case of Lemma 8.3.1 applies. We hence get

OddGu(g(u)) = OddG(g(u)) Δ (NG(u) g(u)).

Then using the definition of g(w) in Eq. (8.21) and the linearity property of odd neighbourhoods, OddG(A Δ B) = OddG(A) Δ OddG(B), we calculate:

OddGu(g(w)) = Odd Gu(g(w)) Δ OddGu({u}) Δ OddGu(g(u)) = OddGu(g(w)) Δ NG(u) Δ OddG(g(u)) Δ (NG(u) g(u)) = OddGu(g(w)) Δ OddG(g(u)) Δ (g(u) NG(u))

Here in the last step we used the property A Δ (A B) = B A where A = NG(u) and B = g(u). We have already seen that every element of OddGu(g(w)) is in the future of w. Since we are assuming u g(w), we have w u, and hence both g(u) NG(u) g(u) and OddG(g(u)) are in the future of w. It remains to verify that w OddGu(g(w)), but this follows because w OddGu(g(w)). We hence see that g is indeed a gflow. Note that while we started with a focussed gflow g, the new gflow g is not necessarily focussed. □

Proving that pivoting preserves gflow is done quite similarly. Just like how we needed a lemma that told us how odd neighbourhoods evolved under application of a local complementation, we need one that tells us what happens when a pivot happens. For this it will be helpful to introduce a little bit of extra notation.

Definition 8.3.3. We define the closed neighbourhood of a vertex u as NG[u] := NG(u) Δ {u} = NG(u) {u}. Similarly we define the closed odd neighbourhood of a set A as OddG[A] := Δ uANG[u] = OddG(A) Δ A.

Let u and v be some vertices of G, and write G uv for the graph where we pivoted along uv. Then for any w we have:

NGuv(w) = { NG(w) Δ NG[u] Δ NG[v]if w NG[u] NG[v] NG(w) Δ NG[v] if w NG[u] NG[v] NG(w) Δ NG[u] if w NG[v] NG[u] NG(w) otherwise
(8.22)

Exercise 8.8. Calculate using this equation, that when w = u we get NGuv(u) = (NG(v) {v}) {u} as we expect (since u and v essentially just swap places in the graph).

Lemma 8.3.4. Given a graph G = (V,E), A V , u V , and v NG(u),

OddGuv(A) = { OddG(A) if u,vOddG[A] OddG(A) Δ NG[v] if u OddG[A],vOddG[A] OddG(A) Δ NG[u] if uOddG[A],v OddG[A] OddG(A) Δ NG[u] Δ NG[v]if u,v OddG[A]
(8.23)

Exercise* 8.9. Prove Lemma 8.3.4.
Hint: You will need the same tricks that were used to prove Lemma 8.3.1.

Proposition 8.3.5. Let G = (V,E,I,O) be an open graph with a gflow (,g) and let u,v V (I O) be connected internal vertices. Then G := (G uv) {u,v}, the open graph we get by doing a pivot along uv and then removing u and v, also has gflow.

Proof. Again we will assume that g is focussed. We then define a gflow g for G uv {u,v} as follows: for every w V (O {u,v}) set g(w) := g(w) {u,v}. Every condition needed for g to be a focused gflow then follows immediately except for checking that OddGuv{u,v}(g(w)) contains w and lies in the future of w. Note that OddG[g(w)] = OddG(g(w)) Δ g(w) {w} O g(w) by the focussed property, so that u OddG[g(w)]u g(w) and similarly for v. Now, to look at the odd neighbourhoods of the correction sets we will make a case distinction on w based on whether u g(w) or v g(w).

We hence see that we can indeed do the spider-removing version of local complementation and pivoting while preserving the existence of gflow. You might at this point wonder whether we couldn’t just do the local complementation without removing the spider, and whether this preserves gflow. It in fact does not, but that is because we aren’t using the right notion of gflow for this: the spider-preserving version of local complementation (Lemma 5.2.4) introduces a X(π 2 ) phase on the spider being pivoted on. This makes it so that we can no longer interpret this spider as being measured in the XY plane. The solution to this is to treat it as a qubit measured in a different type of plane. We will see how to do this in Section 8.5.

Remark 8.3.6. Propositions 8.3.2 and 8.3.5 are results about open graphs, not measurement patterns. Hence, we can in general apply these to make new kinds of measurement patterns, which might not implement the same linear map as before. If we want to apply these in a way that preserves the linear map the pattern is implementing, we also need to consider the specific measurement angles the pattern must have and how these get updated by the rewrite. For this we would need to reference the ZX local complementation and pivot simplifications of Lemma 5.2.9 and 5.2.11.

8.4 From measurement patterns to circuits

Starting with a quantum circuit, we can transform it into a graph-like diagram which has gflow (Proposition 8.2.6), and hence we can turn this circuit into a deterministic measurement pattern. We have also seen several ways in which we can change a measurement pattern while preserving gflow. These patterns we get don’t necessarily look very circuit-like any more, so it is not obvious any more how the connections and measurements in this pattern correspond to unitaries acting on an input state. In this section we will see that nevertheless we can transform an arbitrary deterministic measurement pattern with gflow back into a circuit that implements the same linear map. Since these patterns are deterministic, we can represent the linear map they implement just as a graph-like ZX-diagram, like we did in Section 8.2.1. The input of our algorithm will be a graph-like diagram whose underlying open graph has a gflow, and the output should be an equivalent quantum circuit. We call this process circuit extraction. The basic idea will be similar to the CNOT circuit extraction algorithm we saw way back in Chapter 4, but instead of doing one round of Gaussian elimination to get a circuit out, we will be doing ‘a little bit’ of row elimination in order to extract a single internal spider from the pattern. We repeat this until the diagram contains no more internal spiders. We then have a diagram looking very similar to the Clifford GSLC normal form of Section 5.3.3, which we know how to turn into a circuit. Since our algorithm doesn’t work with measurement patterns directly, but with ZX-diagrams, we can let the input be any graph-like diagram whose underlying open graph has gflow. Such a diagram will then look something like this:

(8.24)

We put some phases on the spiders for concreteness, but as our only consideration is whether the diagram has gflow, these are pretty much irrelevant to the steps we need to do to extract a circuit out of a diagram. So let’s start trying to make this diagram more circuit like. As in Section 5.3.3, we first observe that the spiders on the boundary already directly correspond to quantum gates: either single-qubit gates or two-qubit CZ gates:

(8.25)

Here we mark the two parts of the diagram by ‘unextracted’ and ‘extracted’ to denote that we are done with the part on the right. This part already looks like a circuit now, so we don’t have to do anything with that anymore. We will refer to the spiders on the boundary of the extracted and unextracted part as the frontier. We will be applying operations to the frontier in such a way that we can move frontier spiders to the extracted part and internal spiders onto the frontier. The reason we start at the end of the diagram instead of at the beginning is because it will be easier to show that such operations preserve the existence of a gflow on the remaining diagram. The extraction algorithm is only guaranteed to work if the diagram has gflow, so it is important that all the steps change the diagram in ways which preserve the existence of a gflow. For instance, in Eq. (8.25) the underlying graph of the unextracted part only changed in having no more connections between the output vertices. This is exactly the transformation that we showed in Exercise 8.4 preserves gflow. In the case of the GSLC normal form of Section 5.3.3, we realised that the internal connectivity of the diagram corresponds to a CNOT circuit. Here we can do something similar, but instead of rewriting the entire diagram to a CNOT circuit directly, we can ‘extract’ a single CNOT in order to change the connectivity of the diagram:

Proposition 8.4.1. For any graph-like diagram D, the following equation holds:

where M describes the biadjacency matrix of the relevant vertices, and M is the matrix produced by starting with M and then adding row 1 to row 2, taking sums modulo 2. Furthermore, if the diagram on the left has gflow, then the graph-like part on the right also has gflow.

Proof. For clarity we will not draw the entire diagram, but instead we focus on the relevant part. First of all we note that we can add CNOTs in the following way while preserving equality:

(8.26)

Now let A denote the set of vertices connected to the top vertex, but not to the vertex beneath it, B the set of vertices connected to both, and C the vertices connected only to the bottom one. Further restricting our view of the diagram to just these two lines, we see that we can apply a pivot:

Looking at the connectivity matrix, it is straightforward to see that the matrix M has now been changed in exactly the way described. To see that these operations preserve the existence of a gflow, note first that we can view the rewrite of Eq. (8.26) as adding some identity spiders to the outputs of a diagram, and adding connections between these outputs. Hence, by Exercises 8.4 and 8.5 the resulting diagram still has gflow. We then do a pivot, which also preserves gflow by Proposition 8.3.5, and finally we consider the last CNOT as no longer being part of the graph-like diagram, which on the level of the underlying open graph looks like removing some output spiders, which can also be shown to preserve gflow. □

To demonstrate how we can use this, let us write down the biadjacency matrix from the frontier to the other spiders in our example diagram:

(8.27)

We see that if we add the fourth row to the third row that there will be only a single 1 on the third row. This means that the third frontier spider is only connected to a single internal spider, and hence corresponds to an identity spider that can be removed:

(8.28)

We now have one less spider in the unextracted part. We can again unfuse the phase of the frontier spider into the extracted part, and the same for the connections between the frontier spiders. We then rinse and repeat, extracting the spiders one by one. But why can we always do this? This is where gflow comes into play. Using gflow we can show that the biadjacency matrix always has this property that we can reduce at least one of the rows to contain a single 1 using row operations: Suppose we have a graph-like diagram D and that its underlying open graph G has a gflow (,g). Pick now the vertex u that is maximal according to the partial order in the set V O. That is, u corresponds to the last measured qubit. Now we know that g(u) and OddG(g(u)){u} only contain vertices in the future of u. So in this case they must only contain outputs. So let o1,,ok be the outputs that form g(u). Their sets of neighbours N(oj) then correspond to rows of the biadjacency matrix we wish to simplify. We are assuming we have already gotten rid of any connections between outputs, so that there are no outputs in the set N(oj). We know that OddG(g(u)) O {u} and furthermore OddG(g(u)) = N(o1) Δ Δ N(ok) (Exercise 8.2). So in fact OddG(g(u)) = {u}. Now here comes the kicker: Taking the symmetric difference of sets follows exactly the logic of addition in 𝔽2! If we ‘add’ two sets A Δ B, then if there is an s with s A and s B, then sA Δ B, exactly how 1 1 = 0. All the other cases are checked similarly. So when we were adding together rows in the biadjacency matrix, what we were really doing was calculating the symmetric difference of the neighbourhoods. So since N(o1) Δ Δ N(ok) = {u}, that means if we add together the rows of the biadjacency matrix corresponding to the outputs oj, then the resulting row has just a single 1, which corresponds to u. Hence, gflow tells us exactly which rows we can add together, and hence which CNOTs we need to place, in order to make progress. As we can do row operations on our biadjacency matrix using Proposition 8.4.1 and this preserves gflow, we will have after extracting a vertex still a diagram which has gflow. And hence when we repeat this procedure we will always be able to find some rows in the biadjacency matrix that combine together to form a row with a single 1, whose spider can then be extracted. Note that this is a similar procedure to how we extracted a circuit from a CNOT+Phase diagram in Section 7.2: there we did column operations in order to reduce a column to contain just a single 1. Because we are extracting from the right here, we are doing row operations instead. At some point we will have removed all internal spiders, in which the case the remaining diagram is like the GSLC normal form of the previous chapter, except that the phases on the spiders can be arbitrary. This final bit can then also be transformed into a circuit using a variation on the procedure described in Section 5.3.3 and then we are done. We can then conclude with the following theorem.

Theorem 8.4.2. Let D be a graph-like diagram whose underlying open graph has a gflow and which has the same number of inputs as outputs. Then we can efficiently extract a unitary circuit that implements the same linear map as D.

In Exercise 7.8 we saw that extracting a circuit from a ZX-diagram is in general a very hard problem. But now we see that if the diagram has gflow, that this ‘smooths’ it out enough so that it becomes much easier to extract a circuit from it. Since any measurement pattern corresponds to a graph-like ZX-diagram with some additional information on how the measurement outcomes should be propagated, we can also use this result to conclude that any measurement pattern with gflow must be unitary.

Theorem 8.4.3. A deterministic measurement fragment with gflow and the same number of inputs as outputs implements a unitary.

8.5 Measurements in three planes

So far we have restricted all our thinking on determinism and gflow to measurements all occurring in the same plane, namely the XY plane. With some small modifications we can also make it work for measurement patterns where the measurements occur in all three planes. Before we see how that works, let’s answer an important question first: why bother? We’ve seen that we can do universal computation with measurement patterns where all measurements are in the XY plane, and that any circuit can be transformed into a single-plane measurement pattern. So why should we even talk about measurements in other planes. There are a couple of reasons. First, in our discussion on universal resource states in Section 8.1.1 we saw that cluster states can be used to perform arbitrary computations. This however crucially depends on ‘carving out’ paths by doing strategic measurements in the Y Z plane. It is possible to do it without this feature, but it makes it harder and less intuitive. Second, in the previous chapter we’ve seen how useful phase gadgets are. Phase gadgets are however not compatible with single-plane gflow. Consider the following simple diagram containing a phase gadget connected to just one spider:

(8.29)

This diagram is of course unitary, and if we were to simplify the gadget to a phase gate, the diagram would definitely have gflow. So what about this diagram itself? Consider the following two facts about gflow that we know: the phases of spiders are not important for having gflow or not; and if you have gflow, the diagram must be unitary. Combining these facts we see that if the diagram (8.29) were to have gflow, then the following diagram would also have gflow, and hence would need to be unitary for all α and β:

(8.30)

But if we pick α = β = π 2 , we can show that the diagram disconnects, and so it is not unitary. So what is the issue here? We see that the problem with unitarity arises when we put a non-zero phase on the ‘base’ of the gadget. Doing this stops it from being a phase gadget, and makes it just a stack of two spiders with some phase. Instead, we should be treating the two spiders of the gadget as a single ‘unit’ where we can’t change the phase of the base. We can do this by treating a phase gadget as a qubit measured in a different basis than a regular spider. This then necessitates using multiple measurement axes. The final reason for considering multiple measurement planes, closely related to allowing for phase gadgets, is that it allows us to be more efficient about our computations. It turns out we can do the same computations with fewer measured qubits. So with all this in mind, let’s see how we should think about measurements happening in all three principal planes of the Bloch sphere. Recall first that these measurement bases have a nice representation in the ZX-calculus:

(8.31)

Here, as before, αk denotes the measurement angle of this specific effect, and the bk is a Boolean variable denoting the outcome of the measurement. The XY and Y Z plane measurements correspond to natural structures in a graph-like diagram: ‘regular’ internal spiders, and phase gadgets. We can view the ‘regular’ internal spiders of a graph-like diagram as qubits measured in the XY plane:

(8.32)

If we instead have a phase gadget, then we can view this as a qubit measured in the Y Z plane:

(8.33)

Measurements in the XZ plane don’t naturally occur in the graph-like diagrams we consider, because the π 2 phase on the spider would have meant it would’ve been removed by applying a local complementation. Another ‘explanation’ to why we don’t need XZ-plane measurements, is that we see that XY measurements correspond to Z-spiders, while Y Z measurements correspond to X-spiders. Hence, XZ-plane measurements correspond to ‘Y -spiders’, which we also don’t need to use.

Remark 8.5.1. It might be a bit confusing to remember that XY measurements correspond to Z spiders and so on for the other types of effects. The trick is to remember that the type of spider is the letter that does not appear in the name. So for XY , the corresponding spider is Z, and for Y Z it is X.

We see then that to view a graph-like diagram as a measurement pattern, we need to interpret phase gadgets as qubits measured in the Y Z plane, while every other non-output spider is treated as a qubit measured in the XY plane. Now, let’s consider what the corresponding notion of gflow should be for a 3-plane measurement pattern. To do so, let’s go back to the examples we looked at at the start of Section 8.2. There we considered an XY vertex that had an error:

We could then correct this by pushing out an X(π) phase from the XY vertex with phase β. When we push this X(π) phase, it becomes a Z(π) at the location we want it:

We captured the more general version of this idea with the gflow correction sets g(u). Here the set g(u) tells us where we have to extract out X(π) phases in order to get a Z(π) at the desired location. In particular, we get Z(π) phases at all the vertices in OddG(g(u)). The conditions on g(u) for u an XY vertex are hence that u OddG(g(u)) and ug(u) (since we can’t extract out an X(π) phase from u itself). We see then that we interpret g(u) as the vertices where we need to push out an X(π) and OddG(g(u)) where we need to push out a Z(π). The properties of an XY -plane measured vertex u tell us what the relations to g(u) and OddG(g(u)) need to be. Let’s now consider the same example, but with a Y Z vertex instead:

We see then that now we need to correct an X(π) error instead of a Z(π) error. Still treating g(u) as the ‘set of vertices where we push out an X(π)’ we see then that now we do need u g(u) to correct this error, as pushing out another X(π) from u corrects the error present. Analogously, we now do not want a Z(π) to appear at u, so we must have uOddG(g(u)). Putting it succinctly: g(u) are the X-corrections, while OddG(g(u)) are the Z-corrections. The measurement plane of the vertex determines which correction its measurement outcome needs. Note that there is no restriction on what types of vertices can appear in g(u) or OddG(g(u)), as it is possible to extract both Z(π) phases and X(π) phases from a vertex used in a correction set, regardless of which measurement plane that vertex has. In order to give a formal definition of a gflow on multiple measurement planes we need to work with a labelled open graph, where each non-output vertex u is labelled by its type t(u). We take this type to be a set that is either {X,Y },{Y,Z} or {X,Z} (defining it as a set likes this makes the following definition nicer).

Definition 8.5.2. Let G = (V,E,I,O,t) be a labelled open graph with types t. A 3-plane gflow (,g) on G consists of a partial order on the vertices of G, and a correction set function g : V O (V I) that associates to every non-output vertex u V O a subset of non-input vertices g(u) V I, such that for every non-output vertex u the following conditions hold:

1..

The inputs are minimal in the partial order (meaning that if v i for some input i, then v = i) and conversely the outputs are maximal;

2..

We have u v for every v g(u) and v OddG(g(u)), i.e. corrections lie in the future of u.

3..

u OddG(g(u)) if and only if X t(u),

4..

u g(u) if and only if Z t(u).

We say an open graph has 3-plane gflow when at least one 3-plane gflow can be defined on it.

This definition might look a bit weird, but we can check that this gives the correct behaviour for all three types of measurement plane. If t(u) = {X,Y }, then we see that condition 3 gives u OddG(g(u)), while condition 4 gives ug(u). This is because condition 4 is an ‘if and only if’. Hence, as we do not have X t(u), we also do not have u g(u). In the same way we can check that for t(u) = {Y,Z} we get uOddG(g(u)) and u g(u) as we expect. For the final type t(u) = {X,Z} we see that we get the conditions u OddG(g(u)) and u g(u). This means that to correct an error at u, we should get both an X(π) and a Z(π) there. We can check that this is indeed what is necessary:

(8.34)

We indeed see that the wrong measurement outcome in a XZ-plane measured vertex requires both a Pauli X and Z to correct it. With this discussion we see then that 3-plane gflow allows us to correct the wrong measurement outcome in every measured vertex. We can then write down a 3-plane version of Theorem 8.2.4. As the fully-correct adaptation is a bit technical to write down, we will instead give a more informal description.

Theorem 8.5.3. Let D be a graph-like ZX-diagram and let (G,I,O,t) be its underlying labelled open graph, where t is a choice of measurement planes ‘compatible’ with D (e.g. the plane is XY for a ‘regular’ spider and Y Z for a phase gadget). Then if its associated labelled open graph has a 3-plane gflow, we can efficiently construct a deterministic measurement pattern from D that implements the same linear map as D.

Remark 8.5.4. The reason we write ‘compatible with’ above, is because in general there are multiple measurement planes that we can associate to a spider. This happens when the spider has a Clifford phase, or more generally when the diagram is an isometry instead of a unitary.

We can see something nice in Definition 8.5.2 that simplifies our life somewhat: each 3-plane gflow is compatible with exactly one choice of types. This is because conditions 3 and 4 are if-and-only-if. Just by inspecting whether u OddG(g(u)) and u g(u) we can exactly determine which of the three types t(u) is. Hence, if we are given a labelled open graph with a 3-plane gflow, we don’t actually need to know the labels as we can recover them from the gflow itself. With slight abuse of notation we will hence just say that an (unlabelled) open graph has a 3-plane gflow, and that the label of a vertex is determined by the properties of its correction set.

8.5.1 Rewriting 3-plane gflow

Measurement patterns with 3-plane gflow allow some rewrites that have no counterpart in the single measurement-plane model. For instance, we can actually remove any vertex that is not measured in the XY plane.

Exercise 8.10. Let G be an open graph with 3-plane gflow (g,). Let u be a non-output, with u g(u), i.e. t(u){X,Y }. Show that then u can be removed from G while preserving the existence of a 3-plane gflow and that furthermore, this gflow can be chosen in such a way to preserve the measurement plane of all vertices. Hint: On the new graph with u removed, define a new gflow g as g(v) = g(v) if ug(v) and g(v) = g(v)Δg(u) otherwise.

While it might be surprising at first that we can just remove qubits while preserving gflow, note that these Y Z and XZ measurements we can remove are essentially phase gadgets. When we set the phase of a phase gadget to zero, they do not contribute to the linear map. Since determinism must hold regardless of the measurement angle, the determinism must hence not ‘depend’ on the phase gadget’s existence. In Proposition 8.3.2 we showed that we can do the spider-removing version of local complementation while preserving single-plane gflow. It turns out that we can split this up into its component parts: local complementation, and spider removing. Exercise 8.10 already shows how to remove a spider while preserving existence of gflow.

Proposition 8.5.5. Let (g,) be a 3-plane gflow for an open graph (G,I,O), and let u be an internal vertex. Then the local complementation of G about u, written G u has a 3-plane gflow (g,) where g is defined by

g(u) := { g(u) if t(u) = {Y,Z} g(u)Δ{u}else g(v) := { g(v) if uOddG(g(v)) g(v)Δg(u)Δ{u}if u OddG(g(v))

where v is any non-output vertex not equal to u.

The proof of this proposition is similar to that of Proposition 8.3.2, though with more case distinctions for all the different measurement planes u and v can have. We leave the proof to the particularly motivated reader.

Exercise* 8.11. Prove Proposition 8.5.5.

In Proposition 8.5.5 we didn’t write out the measurement planes of the of the vertices in G u. But it is important to keep in mind that these do change. Way back in Section 5.2.1 we saw that we can perform a local complementation on a graph state by adding some local Cliffords. In particular, on u we add an X(±π 2 ) phase, while all of its neighbours get a Z(π 2 ) phase. These π 2 phases change the measurement planes of u and its neighbours. For instance, suppose that t(u) = {X,Y }. Then when its spider gains an X(π 2 ) phase, we see that:

(8.35)

Hence, it becomes a spider measured in the XZ plane. This gives us a new perspective on the spider-removing version of local complementation: the local complementation changes the measurement plane from XY to XZ, and then Exercise 8.10 shows us that we can remove a spider measured in the XZ plane without losing the existence of gflow. A pivot along the edge between vertices u and v is just a triple of local complementations on u, then v, and then u again. Hence, we see that a (regular, non-spider-removing) pivot also preserves gflow! As we saw in Section 5.2.2, the spiders being pivoted on gain (or lose) a Hadamard on their output wire:

In our setting of measurement planes, this again means that their measurement planes will change. In particular, the Z-spider of an XY measurement, becomes the X-spider of an Y Z measurement. This again allows us to decompose the preservation of gflow under the spider-removing pivot as a sequence of two operations: first we pivot to change the XY vertices into Y Z vertices, and then we remove these vertices while preserving gflow using Exercise 8.10. This also immediately gets us the gflow preservation of variations on the pivot we’ve seen. In particular, the gadget pivot of Lemma 7.6.1 we can see as doing a regular pivot on a pair of XY vertices, where we then only remove the resulting vertex corresponding to the Pauli spider:

The new phase gadget we get is the second spider of the pivot, which transforms from XY to Y Z. As pivoting preserves gflow, we see that the gadget pivot (which we now see is just a regular pivot followed by a vertex removal) also preserves gflow. Hence, we can introduce phase gadgets while preserving the existence of a 3-plane gflow!

Exercise 8.12. Prove that local complementation and pivoting have the following effects on measurement planes:

We said at the start of this section that 3-plane patterns can be more efficient in the number of qubits measured. We can now see why. In Section 7.6 we observed that local complementation and pivoting do not necessarily remove all internal Pauli spiders. In order to do so, we had to turn them into the base of a phase gadget. While this does not decrease the total number of spiders in the diagram, when viewing the diagram as a measurement pattern, the two spiders of a phase gadget correspond to a single qubit measured in the Y Z plane. If the phase gadget has a Clifford phase, we can remove it, so we observed that every internal spider either has a non-Clifford phase, or is part of a phase gadget with a non-Clifford phase. Phrasing this in terms of measurement patterns, we see that these rewrite rules allow us to remove all non-input qubits that are measured in a Clifford angle. Since all steps preserve gflow, the resulting compact pattern can still be deterministically implemented.

Theorem 8.5.6. For every 3-plane measurement fragment containing k non-Clifford non-input measured qubits, we can efficiently find an equivalent measurement fragment that contains at most k non-input measured qubits.

8.5.2 Circuit extraction, now phase gadget compatible

It turns out we can also extract circuits from 3-plane patterns. To do this we need to slightly modify the algorithm we described in Section 8.4. First, let’s see how that algorithm will go wrong when we have measurements not in the XY plane. Let’s consider the following example where we have a phase gadget (i.e. a Y Z plane measurement) connected to the frontier:

(8.36)

Looking at the connectivity matrix we see there is no way to do row operations to reduce any row to just have a single one. So our strategy for extracting spiders one-by-one fails here. But remember that we introduced phase gadgets into our diagrams by doing pivots (Lemmas 7.6.1 and 7.6.2). So if a pivot got us into this mess, perhaps another pivot can get us out of it:

(8.37)

Success! Looking at the connectivity matrix we see that a single row operation from qubit 2 to qubit 1 gives us the right connectivity to extract the spider with the α phase. In general, the way we do circuit extraction is as follows. First, we need to make sure our pattern only contains XY and Y Z measurements, no XZ measurements allowed (we describe how to do this later). Then, as long as we have XY vertices we can extract, we extract them. When we get stuck, it must be because there are Y Z vertices in the way. We do a pivot on them to change them into XY vertices, and then we continue the process. Since all steps preserve gflow, this procedure works and allows us to extract the full diagram. So how do we get rid of the XZ measurements? We can do this by doing a series of smart pivots and local complementations to change the measurement planes in useful ways (see Exercise 8.12). First, if a XZ is connected to a Y Z, we do a pivot on them. This transforms the Y Z to XY , but keeps the XZ as is. Once this is done to all XZ vertices, they are only connected to XY vertices and other XZ vertices. Then for each XZ vertex, we do a local complementation on them. This changes it into an XY vertex. Neighbouring XY vertices stay the same, but neighbouring XZ turn into Y Z. Hence, each application reduces the number of XZ vertices, so that we can get rid of all of them. All of these steps preserve gflow and don’t increase or decrease the number of measurements (although they do change the connectivity of the pattern).

Theorem 8.5.7. We can efficiently turn a graph-like diagram with 3-plane gflow into an equivalent quantum circuit.

8.6 There and back again

Let’s summarise some of the things we have seen in this chapter. We introduced a new way to perform quantum computations: using measurements. This lead us to the notion of a measurement pattern, where we describe a set of inputs, outputs, measurements and corrections. This model is also universal for quantum computing, as we can implement arbitrary single-qubit gates and CNOTs and compose these together. If we consider a single branch of a measurement fragment (where we fix all the measurement outcomes), this can be represented directly as a graph-like ZX-diagram. Conversely, a graph-like ZX-diagram can be easily understood as a branch of a measurement fragment. In this sense, graph-like diagrams and measurement fragments are ‘the same thing’. This misses an important detail though: determinism. A measurement fragment is deterministic when we can perform the desired computation regardless of the observed measurement outcomes, by applying the appropriate corrections. If our measurement fragment is not deterministic it is considerably less useful, as it doesn’t allow us to always calculate what we want. In that case we would need to post-select, i.e. keep running the computation until we get the desired measurement outcomes, to perform the correct calculation. We introduced a useful tool for thinking of determinism: gflow. Gflow is not a property of a specific measurement fragment, but rather of the underlying graph structure, and is agnostic to the specific measurement angles in the pattern. To specify a full deterministic measurement pattern we have to describe how all the measurement angles change depending on the observed measurement outcomes. If instead we know the pattern has gflow, then this is already sufficient, as this allows us to construct a correction strategy. Instead of deterministic measurement patterns we can hence consider the weaker notion of graph-like diagram with gflow: the graph-like diagram tells us what the map should be when we get the ideal outcomes, and the gflow tells us how to correct when we get the wrong outcomes. This notion is weaker, because there might also be other correction strategies that do not correspond to a gflow strategy, or even measurement patterns that do not have gflow but are still deterministic for ad-hoc reasons. When we have such a graph-like diagram with gflow, we can efficiently convert this back into a measurement-free (i.e. ancilla-free) quantum circuit. Conversely, when we have a unitary quantum circuit, we can write this as a graph-like diagram with gflow. By using ZX-diagrams as an intermediary, we can translate back-and-forth between representing a computation as a circuit vs a deterministic measurement fragment:

In Chapters 5 and 7 we saw strategies for optimising ZX-diagrams, and in particular to remove spiders from the diagram. In this chapter we have seen that these rewrites based on local complementation and pivoting preserve the existence of gflow on the underlying open graph. This allows us to think of these rewrites not just as spider-removing simplifications on ZX-diagrams, but as ‘qubit-removing’ (or ‘measurement-removing’) simplifications on deterministic measurement patterns. Essentially, these rewrites, even a variant like the gadget pivot, can be seen as ways to get rid of qubits measured in a Clifford angle. This is yet another way in which we can think of the Clifford operations as being ‘easy’: when we measure a qubit in a Clifford angle, we can find an equivalent pattern where that qubit wasn’t necessary in the first place.

8.7 Summary: What to remember

1..

In measurement-based quantum computing we use quantum measurements as an integral part of the computation, instead of just using them at the end to get the result out of the final computation.

2..

There are many different variants on measurement-based quantum computing, but one particularly well-studied model that lies on the extreme end of doing all computations via measurements is the one-way model.

3..

In the one-way model you start by preparing a graph-state. Then single-qubit measurements are performed in rotated bases in order to do computations. Later measurement angles are allowed to depend on previous measurement outcomes.

4..

Just like how a quantum circuit is built out of gates, we can view a one-way model computation as being built out of measurement fragments.

5..

An important consideration for a measurement fragment is whether it is deterministic, meaning that regardless of all the intermediate measurement outcomes, the overall linear map that is performed is the same.

6..

One particular strategy for ensuring a fragment is deterministic is for the underlying open graph to have a property called gflow.

7..

We can view measurement fragments as graph-like ZX-diagrams, and vice versa we can interpret a graph-like ZX-diagram as a measurement fragment without a specified order of measurement.

8..

There is an efficient strategy to translate a circuit into a measurement fragment with gflow.

9..

There is an efficient strategy to translate a measurement pattern with gflow, or equivalently a ZX-diagram with gflow, back into a circuit.

10..

While the one-way model with just measurements in the XY plane is already universal, allowing measurements in all three principal planes allows for more compact patterns. There is a notion of gflow that works for measurements in all three planes, and the circuit extraction algorithm can be adapted to work for that.

11..

The ZX rewrite strategy of Chapter 7 preserves the existence of 3-plane gflow.

8.8 References and further reading

The one-way model The one-way model was originally proposed by [196], where they also immediately showed how the cluster state can be used as a universal resource for quantum computation. The cluster state itself was introduced by the same authors in a paper earlier that year [40]. In a paper the following year they formalised the model underlying the one-way model more, and they showed that a Clifford computation can be performed in a single time-step [198]. These authors revisit computing on cluster states in more detail in [199] which also coins the term ‘measurement-based quantum computing. The authors together with several others review all the progress made on the one-way model some years later [39].

Measurement patterns and fragments The notion of a measurement pattern was formalised in [70], and how to compose these together as fragments and ‘normalise’ them into a standard format where we first do all state preparations and only then do measurements in [71]. How to represent these patterns in ZX was first described by [91].

Flow and determinism The notion of causal flow was introduced by [69]. This was later extended to generalised flow, or gflow, by [43], where they show that certain graph states do not allow causal flow, but do allow gflow. This paper defined both the single-plane gflow and three-plane gflow, though our presentation of three-plane gflow is a bit simplified. Furthermore, [43] showed that a measurement pattern has a gflow if and only if the pattern is uniformly, strongly and stepwise deterministic. Uniformity means that the determinism holds for any choice of measurement angle. Strong determinism means that every measurement outcome happens with equal probability. The stepwise determinism means that we retrieve a deterministic pattern after every single measurement. Or in other words, that the necessary corrections depend only on a single previous outcome. Hence, while there are deterministic patterns that do not have gflow, when they are sufficiently ‘regular’ and the reason for their determinism ‘not too complex’, it will have a gflow. Finally, [43] also introduced Pauli flow, which can deal with patterns where some qubits are designated to be measured in a Clifford angle. Hence, the uniformity condition doesn’t apply to these qubits. Because measurements in a Clifford angle essentially belong to two principal planes of the Bloch sphere at the same time, they can be corrected, and be part of correction sets, in more ways than general measurements, so that their gflow conditions can be less strict.

Circuit extraction An algorithm for extracting a circuit without ancilla from a measurement pattern with single-plane gflow was given by [181]. This was based on finding a path-cover of the open graph, and then resolving ‘acausal’ CZ gates by pushing them through other gates until they were acting at the same point in time on the two qubits. Independently, a different algorithm phrased in the language of ZX was given in [88]. This was then extended to work for three-plane gflow in [23]. The procedure we show in this chapter is based on that article.

Rewriting measurement patterns How a local complementation changes a graph state was noted in [94], and specifically for pivots in [178]. That these operations preserve gflow was shown in [88], that they preserve 3-plane gflow in [23] and that they preserve Pauli flow in [213]. This chapter is based on [88] and [23].

Other measurement-based models The one-way model is not the only way to do measurement based quantum computing. We can also do universal computation using AKLT states [236], a state based on phase gadgets [145], or generalisations of graph states known as hypergraph states, that are built using multi-qubit controlled-Z operations [180220]. For a ZX perspective on hypergraph states, see [163]. We can also view the lattice surgery operations we will explore in Chapter 11 as a measurement-based model, see [76].

Applications of MBQC There are several suggested applications of MBQC that don’t make sense when just talking about circuits. Representing a circuit by a measurement pattern allows you to parallelise more operations, creating a less deep, but more wide computation [42], in some cases even being able to reduce a computation from linear depth to logarithmic depth. The notion of blind quantum computation [41] was also demonstrated using MBQC. In blind computation, a client which only has the ability to prepare single-qubit states and transmit them, can delegate a computation to a server in such a way that the server does not know what it is computing. Hence, in this way you can do quantum computations ‘on the cloud’ without you having to share your data or what you are trying to compute. MBQC is ideally suited for such a scheme, because the qubits sent by the client either generate or block entanglement when the server tries to make a graph state with them. Finally, MBQC is also a natural framework for understanding computations with photons as the qubits. Photons are then non-deterministically entangled using ‘fusion’ operations (which are not the same as spider fusions, though they are related [76]), which results in a resource state which has some random structure. By analysing average case behaviour, deterministic computations can still be run on such a ballistic state [184108].