# ZX-calculus : measurement and output probabilities

I'm discovering ZX-Calculus, and it seems to be much easier to do computations on circuit that would take much more time with the usual formalism. However, I can't find a nice way to represent measurements (instead of post-selection) and compute the output probabilities. I have the feeling that normalisation and adding variables to a "one-leg" spiders could help, but I'm not yet convinced that it's the good way to go.

And for example, can ZX-calculus deal with "impossible"/not normalisable circuits, like "create a plus state and project it on minus" ?

Thanks!

• @NieldeBeaudrap No, I had accidentally flagged the wrong post earlier. I rescinded the flag but forgot that it automatically generates that comment. Sorry. Feb 6, 2020 at 0:45

In the ZX calculus, the closest thing to a graph that measures an observable is a graph that post-selects that observable to be in its $$+1$$ eigenbasis.

If you are attempting to understand a surface code lattice surgery computation in terms of a ZX graph this is kind of annoying. You need to be able to figure out which postselections are just shorthands for unitary effects, and which ones are actual measurements of the inputs. The best way that I know of to do that is to perform Gaussian elimination on the table of things that are post-selected by each individual spider. The eliminated table then tells you the external observables that are postselected. Any observable that is input-only or output-only indicates the presence of a measurement. • Thanks a lot. So measurements are only the stabilizers that apply only on the output nodes after Gaussian elimination ? So any real unitary should have zero stabilisers that works only on the output ? Interesting… Do you have any references for more details ? And also this does not give any probability distribution. Does that mean that for a given graph I have no better way to compute the outcome distribution than trying to calculate the underlying circuit and then just manually compute the state? Then what's the point of normalisation? Thanks! Feb 2, 2020 at 13:33
• @tobiasBora No, the measurements are the stabilizers that apply only to the input. When the number of qubits is preserved, there will be a redundant stabilizer on the output when there is a stabilizer on the input. For stabilizer graphs you don't think in terms of probabilities/amplitudes, you think using the Gottesman-Knill theorem (i.e. in stabilizers). For some complicated graphs there's no substitute for just computing the tensor directly. Feb 2, 2020 at 23:50
• On the input? I'm not sure to understand why. And also, in your graph you wrote on the last line, corresponding to "X . X" on D and E (where one is input one is output, but they are denoted in this table as output): "Output state is stabilized by X.X (there is a measurement present)". What do you mean by this? And if you have any nice reference feel free to share. Thanks! (and too bad for the distribution probability...) Feb 3, 2020 at 15:26
• Note that this paper seems to propose an actual graphical way to derive measurement probabilities with the stabilizer fragment of ZX-calculus, which is proven to be complete in this axiomatisation arxiv.org/pdf/1507.03854.pdf Feb 3, 2020 at 16:33
• And I've the feeling that this paper pretends to have the same result for the "full" Cliford+T fragment (which is more or less universal), but then I'm not sure to see the link with that answer. Feb 3, 2020 at 16:40

So, in order to clarify what I wrote in the comments I'll write an answer here. I found a convincing approach by adding variables to nodes and combining it to ZX-Calculus with scalars (scalars are like normalization factors, see for example this paper). Indeed, a red node labelled with $$0$$ means "project on 0" and the red node labeled with $$\pi$$ means "project on $$1$$". That way, I can write directly a red node labelled $$a\pi$$, which is equivalent to saying that I measured an $$a$$.

This approach is equivalent to writing two diagrams, one with a red node $$0$$ and one with a red node $$\pi$$, and rewrite it until you get simple scalars (that's why you need ZX-Calculus with scalars), and this scalar will be equal to the probability of measuring $$0$$ or $$1$$. The addition of variables is just a nice trick to make sure that you just write a single diagram, which is much quicker to write, especially when you add several measurements. This idea is used (introduced?) for example in this paper. Note however that you need to extend the rules a bit, in order to add rules that apply for nodes with variables. But usually it's not very hard to see which rule you need to apply: just see for each rule what happens when $$a=0$$ and when $$a=1$$, and here you go!

This approach is so great that now I never write any matrix to check math statements/circuits/...: I just write a small ZX diagram, and I can check what happens very easily!

Sorry, I don't have time right now to give examples, but I'm planning to write a blog post at some point... Will come back when I do so. In the meantime, feel free to ask questions in comments!

• It's great you found the solution you are looking for. I just wanted to add that there is another way to represent measurement in the ZX-calculus, which requries the use of 'thick' wires and spiders to represent quantum processes and 'thin' wires and spiders to represent classical processes/measurement. I explain this in my recent review paper arxiv.org/abs/2012.13966 (see Section 10)
– John
Feb 22, 2021 at 13:25
• Thanks a lot. Your review is really nice, I discovered it recently and I love it. Now, I don't even need to write my blog post since you already present nice examples using the method I explain above in section 5.4. Great job! Feb 22, 2021 at 13:55