Log In Sign Up

Graph-theoretic Simplification of Quantum Circuits with the ZX-calculus

We present a new circuit-to-circuit optimisation routine based on an equational theory called the ZX-calculus. We first interpret quantum circuits as ZX-diagrams, a flexible, lower-level language for describing quantum computations graphically. Then, using the rules of the ZX-calculus, we derive a terminating simplification procedure for ZX-diagrams inspired by the graph-theoretic transformations of local complementation and pivoting. Finally, we use the preservation of a graph invariant called focused gFlow to derive a deterministic strategy for re-extracting a (simpler) quantum circuit from the resultant ZX-diagram. This procedure enables us to temporarily break the rigid quantum circuit structure and "see around" obstructions (namely non-Clifford quantum gates) to produce more simplifications than naive circuit transformation techniques alone.


page 1

page 2

page 3

page 4


Circuit Extraction for ZX-diagrams can be #P-hard

The ZX-calculus is a graphical language for reasoning about quantum comp...

Software science view on quantum circuit algorithms

We show that, on the abstraction level of quantum circuit diagrams, quan...

A diagrammatic axiomatisation of fermionic quantum circuits

We introduce the fermionic ZW calculus, a string-diagrammatic language f...

Kindergarden quantum mechanics graduates (...or how I learned to stop gluing LEGO together and love the ZX-calculus)

This paper is a `spiritual child' of the 2005 lecture notes Kindergarten...

Relating Measurement Patterns to Circuits via Pauli Flow

The one-way model of Measurement-Based Quantum Computing and the gate-ba...

VyZX : A Vision for Verifying the ZX Calculus

Optimizing quantum circuits is a key challenge for quantum computing. Th...

1 Introduction

Quantum circuits provide a de facto ‘assembly language’ for quantum computation, in which computations are described as the composition of many simple unitary linear maps called quantum gates. An important topic in the study of quantum circuits is quantum circuit optimisation

, whereby quantum circuits which realise a given computation are transformed into new circuits involving fewer or simpler gates. While some strides have already been made in this area, the field is still in its infancy. Most approaches to quantum circuit optimisation are based on only a handful of techniques: gate substitutions, computation of small (pseudo-)normal forms for special families of circuits 

[1, 26, 24], optimisation of phase polynomials [3, 20], or some combination thereof [2, 28].

This paper lays a theoretical foundation for a completely new quantum circuit optimisation technique based on the ZX-calculus [9]. A key point of departure of our technique is that we break the rigid structure of quantum circuits and perform reductions on a lower-level, string-diagram based representation of a quantum circuit called a ZX-diagram. These diagrams are more flexible than circuits, in that they can be deformed arbitrarily, and are subject to a rich equational theory: the ZX-calculus. The core rules of the ZX-calculus give a sound and complete [5] theory for Clifford circuits, a well-known class of circuits that can be efficiently classically simulated. More surprisingly, it was shown in 2018 that modest extensions to the ZX-calculus suffice to give completeness for families of circuits that are approximately universal [21] and exactly universal [18, 22, 30] for quantum computation.

Since ZX-diagrams provide a more flexible representation of a quantum computation than a circuit, we can derive many new simplifications from the rules of the ZX-calculus that have no analogue for quantum circuits. However, this added flexibility comes at a price: while any quantum circuit can be interpreted as a ZX-diagram by decomposing gates into smaller pieces, the converse is not true. For a generic ZX-diagram corresponding to a unitary, there is no known general-purpose procedure for efficiently recovering a quantum circuit. Hence, an important part of our optimisation procedure is keeping enough information about the quantum circuit structure to get a circuit back at the end. Schematically:


Until recently, this extraction step was poorly understood, and the only techniques for doing circuit-to-circuit translation with the ZX-calculus did so without departing from the overall structure of the original quantum circuit [17], avoiding the extraction problem altogether. In this paper we adopt a more ambitious approach. First, building on prior work of two of the authors [14, 15, 16], we use the rules of the ZX-calculus to derive a sound, terminating simplification procedure for ZX-diagrams. The key simplification steps involve the graph-theoretic transformations of local complementation and pivoting [25, 7], which allow certain generators to be deleted from ZX-diagrams one-by-one or in pairs, respectively. When applied to Clifford circuits, the diagram resulting from the simplification procedure is represented in the form of a graph-state with local Cliffords (GS-LC) [19]

, a pseudo-normal form for representing Clifford circuits whose size is at most quadratic in the number of qubits. Hence, one side effect of our simplification procedure is that it gives a simple, graph-theoretic alternative to the normalisation of a ZX-diagram to GS-LC form proposed by Backens 

[5]. For non-Clifford circuits, the simplified ZX-diagram represents a ‘skeleton’ of the circuit we started with, consisting only of generators arising from non-Clifford phase gates and their nearest neighbours. Although this is no longer a canonical form, it can still be significantly smaller than the input circuit, especially when there is a relatively low proportion of non-Clifford gates. We then show that, even though this simplification breaks the circuit structure, it preserves a graph-theoretic invariant called focused gFlow [8, 27], from which we can derive an efficient circuit extraction strategy. We demonstrate the full simplify-and-extract procedure by means of a running example, which is also available online as a Jupyter

In the case of Clifford circuits, this procedure will produce circuits comparable in size to those described by standard techniques [1, 29]. In the non-Clifford case, this can already find more simplifications than naïvely ‘cutting’ the circuit and simplifying purely-Clifford sections. Additionally, this simplify-and-extract setup provides a new framework for implementing further simplifications on the ‘skeleton’, e.g. for -count reduction. We will comment on the latter point—and its implementation in a tool called PyZX [23]—as a topic of future work.

The paper is organised as follows. After giving a brief introduction to the ZX-calculus in Section 2, we will introduce graph-like ZX-diagrams in Section 3. This mild restriction to the family of all ZX-diagrams will enable us to speak more readily about graph-theoretic properties of the diagram, like the existence of a focused gFlow. In Section 4 we will show that both local complementation and pivoting preserve focused gFlow. Then in Section 5 we will derive a simplification routine using these graph-theoretic notions. We will show how the diagrams produced by this routine can be extracted into a circuit in Section 6, and finally, in Section 7 we conclude and discuss future work.

2 The ZX-calculus and quantum circuits

We will provide a brief overview of the ZX-calculus. For an in-depth reference see Ref. [10].

The ZX-calculus is a diagrammatic language similar to the familiar quantum circuit notation. A ZX-diagram consists of wires and spiders. Wires entering the diagram from the left are inputs; wires exiting to the right are outputs

. Given two diagrams we can compose them by joining the outputs of the first to the inputs of the second, or form their tensor product by simply stacking the two diagrams.

Spiders are linear maps which can have any number of input or output wires. There are two varieties: spiders depicted as green dots and spiders depicted as red dots.222If you are reading this document in monochrome or otherwise have difficulty distinguishing green and red, spiders will appear lightly-shaded and darkly-shaded. Written explicitly in Dirac ‘bra-ket’ notation, these linear maps are:

A ZX-diagram with intput wires and output wires then represents a linear map built from spiders (and permutations of qubits) by composition and tensor product of linear maps. As a special case, diagrams with no inputs and

outputs represent vectors in

, i.e. (unnormalised) -qubit states.

We can immediately write down some simple state preparations and unitaries in the ZX-calculus:

In particular we have the Pauli matrices:

It will be convenient to introduce a symbol – a yellow square – for the Hadamard gate. This is defined by the equation:


We will often use an alternative notation to simplify the diagrams, and replace a Hadamard between two spiders by a blue dashed edge, as illustrated below. blue-edge-def Both the blue edge notation and the Hadamard box can always be translated back into spiders when necessary. We will refer to the blue edge as a Hadamard edge.

Two diagrams are considered equal when one can be deformed to the other by moving the vertices around in the plane, bending, unbending, crossing, and uncrossing wires, so long as the connectivity and the order of the inputs and outputs is maintained. Furthermore, there is an additional set of equations that we call the rules of the ZX-calculus; these are shown in Figure 1. Equal diagrams correspond to equal linear maps333We will consider linear maps and to be “equal” if they satisfy for some non-zero . Backens [6] presents a version of the ZX-calculus where equality is “on the nose”..


Figure 1: A convenient presentation for the ZX-calculus. These rules hold for all , and due to and all rules also hold with the colours interchanged.

The ZX-calculus is universal in the sense that any linear map can be expressed as a ZX-diagram. Furthermore, when restricted to Clifford ZX-diagrams, i.e. diagrams whose phases are all multiples of , the version we present in Figure 1 is complete. That is, for any two Clifford ZX-diagrams that describe the same linear map, there exists a series of rewrites transforming one into the other. Recent extensions to the calculus have been introduced which are complete for the larger Clifford+T family of ZX-diagrams [21], where phases are multiples of , and for all ZX-diagrams [18, 22, 30].

Quantum circuits can be translated into ZX-diagrams in a straightforward manner. We will take as our starting point circuits constructed from the following universal set of gates:

We fix this gate set because they admit a convenient representation in terms of spiders:

CNOT (2)

Note that the green spider is the first (i.e. control) qubit of the CNOT and the red spider is the second (i.e. target) qubit. Other common gates can easily be expressed in terms of these gates. In particular, , and:

CZ (3)

For our purposes, we will define quantum circuits as a special case of ZX-diagrams.

A circuit is a ZX-diagram generated by compositions and tensor products of the ZX-diagrams in equation (2).

Important subclasses of circuits are Clifford circuits, sometimes called stabilizer circuits, which are obtained from compositions of only CNOT, , and gates. They are efficiently classically simulable, thanks to the Gottesman-Knill theorem [1]. Local Clifford circuits are Clifford circuits on a single qubit, i.e. circuits consisting only of and gates.

The addition of gates yields Clifford+T circuits, which are capable of approximating any -qubit unitary to arbitrary precision, whereas the inclusion of gates for all enables one to construct any unitary exactly.

3 Graph-like ZX-diagrams

Before starting our simplification procedure, we transform ZX-diagrams into the following, convenient form.

A ZX-diagram is graph-like when:

  1. All spiders are Z-spiders.

  2. Z-spiders are only connected via Hadamard edges.

  3. There are no parallel Hadamard edges or self-loops.

  4. Every input or output is connected to a Z-spider and every Z-spider is connected to at most one input or output.

A ZX-diagram is called a graph state if it is graph-like, every spider is connected to an output, and there are no non-zero phases. This corresponds to the standard notion of graph state from the literature [19]. Hence, graph-like ZX-diagrams are a generalisation of graph states to maps where we allow arbitrary phases and some interior spiders, i.e. spiders not connected to an input or output.

Every ZX-diagram is equal to a graph-like ZX-diagram.


Starting with an arbitrary ZX-diagram, we apply to turn all red spiders into green spiders surrounded by Hadamard gates. We then remove excess Hadamards via . Any non-Hadamard edge is then removed by fusing the adjacent spiders with . Any parallel Hadamard edges or self-loops can be removed via the following 3 rules:


which we prove in Appendix B.1. Finally, we can apply the rules and from right-to-left until the last condition is satisfied. ∎

A useful feature of graph-like ZX-diagrams is that much of its structure is captured by its underlying open graph.

An open graph is a triple where is an undirected graph, and is a set of inputs and a set of outputs. For a ZX-diagram , the underlying open graph is the open graph whose vertices are the spiders of , whose edges correspond to Hadamard edges, and whose sets and are the subsets of spiders connected to the inputs and outputs of , respectively.


Figure 2: A circuit, an equivalent graph-like ZX-diagram, and its underlying open graph.

Note that, because of Definition 3, the sets and in will always be disjoint. When discussing open graphs we will use the notation and for the non-inputs and non-outputs respectively. The set of neighbours of a vertex will be denoted by . We are now ready to define a graph-theoretic condition that will be instrumental in our circuit extraction procedure.

[27] Given an open graph , a focused gFlow on consists of a function and a partial order on the vertices of such that for all ,

where is the odd neighbourhood of .

Generalised flow (gFlow) techniques were introduced in the context of measurement-based quantum computing [12, 13]. Focused gFlow is a special case of the standard notion of gFlow [8], where the latter allows other vertices in the set , provided they are in the future of (i.e. ). However, as a property of graphs, the two notions are equivalent: an open graph has a gFlow if and only if it has a focused gFlow. We will rely on this equivalence in Appendix B.2 to prove the following Lemma.

If is a graph-like ZX-diagram obtained from a circuit by the procedure of Lemma 3, then admits a focused gFlow.


See Appendix B.2. ∎

4 Local complementation and pivoting

Local complementation is a graph transformation introduced by Kotzig [25]. Let be a graph and let be a vertex of . The local complementation of according to , written as , is a graph which has the same vertices as , but all the neighbours of are connected in if and only if they are not connected in . All other edges are unchanged.

Local complementations according to the vertices and are given by:

A related graph-theoretic operation is pivoting, which takes place at a pair of adjacent vertices. Let be a graph, and let and be a pair of connected vertices in . The pivot of along the edge is the graph . On a graph, pivoting consists in exchanging and , and complementing the edges between three particular subsets of the vertices: the common neighbourhood of and (i.e. ), the exclusive neighbourhood of (i.e. ), and exclusive neighbourhood of (i.e. ):

Our primary interest in local complementation and pivoting is that each corresponds to a transformation of ZX-diagrams. In the special case where a ZX-diagram is a graph-state, it is possible to obtain a diagram where by applying an gate on the spider corresponding to and on all of the spiders in :


This is a well-known property of graph states, and a derivation using the rules of the ZX-calculus was given in [14]. Similarly, it was shown in [16] that a pivot can be introduced by applying Hadamard gates on and and gates on :


Note that the swap on the RHS comes from the vertices and being interchanged by the pivot.

The following theorem will prove pivotal in our extraction routine. It shows that the existence of a focused gflow is preserved by local complementation (resp. pivoting) followed by the deletion of the vertex (resp. the pair of vertices) on which the transformation is applied:

Let be an open graph that admits a focused gFlow,

  1. for , setting

  2. for , setting

where is the graph obtained by deleting the vertices in and any adjacent edges.


The two cases are proved in Appendix B.3, Lemmas B.3.1 and B.3.2 respectively. ∎

5 A simplification strategy for circuits

We now have all the necessary machinery to introduce our simplification routine. The general idea is to use local complementation and pivoting based rewrite rules to remove as many interior spiders as possible. A spider is called interior when it is not connected to an input or an output, otherwise it is called a boundary spider.

We call a spider Pauli if its phase is a multiple of , and Clifford if its phase is a multiple of . If the phase of a Clifford spider is an odd multiple of (and hence non-Pauli), we call this a proper Clifford spider.

The graph-like ZX-diagram resulting from the translation of a Clifford circuit contains only Clifford spiders, since the only time the phase changes on a spider is during a spider-fusion step, in which case the phases are added together.

We will show that our procedure is able to eliminate all interior proper Clifford spiders and all Pauli spiders adjacent either to a boundary spider or any interior Pauli spider. In particular, for Clifford circuits, we will obtain a pseudo-normal form which contains no interior spiders (cf. Section 6).

The main rewrite rules we use are based on local complementation and pivoting. The first one allows us to remove any interior proper Clifford spider while the second one removes any two connected interior Pauli spiders. The following rule holds in the ZX-calculus:


where the RHS is obtained from the LHS by performing a local complementation at the marked vertex, removing it, and updating the phases as shown. The following rule holds in the ZX-calculus:


where the RHS is obtained from the LHS by performing a pivot at the marked vertices, removing them, and updating the phases as shown. The proof of these lemmas can be found in Appendix B.4.

We can additionally apply (8) to remove an interior Pauli spider that is adjacent to a boundary spider. To do this, we first turn the boundary spider into a (phaseless) interior spider via the following transformation, which follows from the rules , , and :


After this transformation, we can perform (8) on the two spiders labelled to remove them. For our purposes, we can then treat as a boundary spider, and save the single-qubit unitaries to the right of separately.

There exists a terminating procedure which turns any graph-like ZX-diagram into a graph-like ZX-diagram (up to single-qubit unitaries on inputs/outputs) which does not contain:

  1. interior proper Clifford spiders

  2. adjacent pairs of interior Pauli spiders

  3. interior Pauli spiders adjacent to a boundary spider

In particular, if only contains Clifford spiders, then contains no interior spiders.


Starting with a graph-like ZX-diagram, mark every interior Clifford spider for simplification. Then repeat the steps below (followed by (4) to remove parallel edges), until no rule matches:

  • apply (7) to remove a marked proper Clifford spider

  • apply (8) to remove an adjacent pair of marked Pauli spiders

  • apply (9) to a boundary adjacent to a marked Pauli spider and immediately apply (8)

All 3 rules remove at least 1 marked node, so the procedure terminates. Since none of these rules will introduce non-Clifford spiders, if contains only Clifford spiders so too does . Since the only possibilities for interior spiders in are covered by cases 1-3, contains no interior spiders. ∎

For and the ZX-diagrams from Theorem 5, if admits a focused gFlow, then so too does .


It was shown in Theorem 4 that the transformations (7) and (8) preserve focused gFlow. The transformation (9) acts as an input/output extension on . That is, for , , it adds a new vertex and an edge , and sets . It was shown in [27] that these transformations preserve focused gflow. ∎

This simplification procedure is very effective, especially for circuits with few non-Clifford gates. We can see this in the following example:


The circuit above has 195 gates, with 4 non-Clifford gates. If we apply the simplification procedure, we obtain a small ‘skeleton’ of the circuit, containing 12 spiders:


Note the non-Clifford phases now clearly appear on the 4 interior spiders. In general, the interior spiders will either be non-Clifford or be Pauli with all non-Clifford neighbours. Any other possibilities will be removed.

6 Circuit extraction

As described in the previous section, when a Clifford circuit is fed into our simplification routine, no interior spiders will be left, and hence the diagram is in GS-LC form (graph-state with local Cliffords). It is straightforward to extract a Clifford circuit from a GS-LC form. First, we unfuse spiders to create CZ gates and local Cliffords on the inputs and outputs, then apply the rule to the spiders on the right side of the resulting bipartite graph:


The part of the diagram marked now has the form of a classical parity circuit. That is, it is a permutation of computational basis states where the output basis is given in terms of parities of the inputs, e.g. Such a unitary can always be realised via CNOT gates, using standard techniques based on Gaussian elimination over (see e.g. [26]). Hence, we obtain a Clifford circuit with 6 layers of gates:

Local Cliffords + CZs + CNOTs + Hadamards + CZs + Local Cliffords (11)

This is similar to the 11-layer pseudo-normal form for Clifford circuits given in [1] and the slightly more compact version in [29]. The reason we obtain fewer layers is we allow CZ gates in the decomposition, rather than expanding them in terms of CNOT and local Cliffords.

If a Clifford+T circuit – or a more general circuit containing gates or for – is fed into our simplification routine, there might still be interior spiders left, and hence the diagram will not be in GS-LC form.

Our general strategy for extracting a circuit from a diagram produced by our simplification routine is to progress through the diagram from right-to-left, consuming vertices to the left and introducing quantum gates on the right. For an -qubit circuit, we maintain a layer of vertices called the frontier between these two parts. The goal is therefore to progress the frontier from the outputs all the way to the inputs, at which point we are left with an extracted circuit. We will see that the existence of a focused gFlow guarantees we can always progress the frontier leftward in this manner.

Much like in the Clifford case, our extraction procedure relies on applying (a variant of) Gaussian elimination on the adjacency matrix of a graph. Hence, we first establish a correspondence between primitive row operations and CNOT gates.

For any ZX-diagram , the following equation holds:



where describes the biadjacency matrix of the relevant vertices, and is the matrix produced by starting with and then adding row 2 to row 1, taking sums modulo 2. Furthermore, if the diagram on the LHS has a focused gFlow, then so does the RHS.


See Appendix B.4. ∎

We can now start describing our extraction procedure. To start, let the frontier consist of all the output vertices. If a vertex of the frontier has a non-zero phase, unfuse this phase in the direction of the output. Whenever two vertices of the frontier are connected, unfuse this connection into a CZ gate. If the diagram started out having a gFlow, then the resulting diagram still has a gFlow since we only affected output vertices. Let be the gFlow of the diagram. We push the frontier onto new vertices in the following way:

  1. Find an unextracted vertex such that . Such a vertex always exists: take for instance any non-frontier vertex that is maximal in the gFlow order.

  2. We know that Odd hence we can pick a designated vertex such that is connected to .

  3. Write the biadjency matrix of and their neighbours to the left of the frontier (‘the past’). Because Odd we know that the sum of all the rows in this matrix modulo 2 is an all-zero vector except for a 1 corresponding to . Hence, if we apply row operations with as the target from every other vertex in we know that will have only a single vertex connected to it in its past, namely . Do these row operations using Proposition 6. As a result, CNOT gates will be pushed onto the extracted circuit. By that same proposition, the diagram will still have a gFlow.

  4. At this point it might be that is still connected to vertices of that are not . For each of these vertices , do a row operation from to by adding the corresponding CNOT to the extracted diagram in order to disconnect from . At this point ’s only connection to is via . We can therefore conclude that the gFlow of the resulting diagram is such that the only vertex that has is .

  5. The vertex has arity 2 and since it is phaseless we can remove it from the diagram by . Remove from the frontier, and replace it by . By the remarks in the previous point the resulting diagram still has a gFlow. Unfuse the phase of as a phase gate to the extracted part.

  6. If there is any vertex in that is not connected to an input, go back to step 1, otherwise we are done.

After all vertices have been extracted by the above procedure, we will have some permutation of the frontier vertices to the inputs. The extraction is finished by realising this permutation as a series of SWAP gates.

For a pseudocode description of the extraction algorithm, see Appendix C in the Appendix. For a fully worked-out example we refer to Appendix A.

An interesting thing to note is we do not actually need a pre-calculated focused gFlow for this algorithm: knowing that one exists is enough. In step 3, it suffices to apply primitive row operations until a row with a single 1 appears in the biadjacency matrix. If this is possible by some set of row operations (i.e. if there exists a focused gFlow), such a row will always appear in the reduced echelon form, so we can simply do Gauss-Jordan elimination. This is how we describe this step in the pseudocode presented in Appendix C.

Picking up our example from the previous section, we can apply this procedure to the skeleton of the circuit in equation (10) and we obtain a new, extracted circuit: big-example-extract2 The circuit has been reduced from 195 gates to 41 gates, going via an intermediate representation as a ZX-diagram with 12 spiders. As mentioned in the introduction, this example is available as a Jupyter notebook ‘ demos/example-gtsimp.ipynb’ in the PyZX [23] repository on GitHub.

7 Conclusions and Future Work

We have introduced a terminating rewrite strategy for ZX-diagrams that simplifies Clifford circuits to GS-LC form using the graph-theoretic notions of local complementation and pivoting. We have shown how the diagrams produced by the rewrite strategy applied to non-Clifford circuits can be turned back into a circuit using the fact that our rewrites preserve focused gFlow.

The question of how a circuit can be extracted from a general ZX-diagram is still open. We speculate that this problem is not tractable in the general case, as it seems to be related to the problem of finding an ancilla-free unitary from a circuit containing ancillae. This observation does however not preclude finding larger classes of rewrites and ZX-diagrams such that we can efficiently extract a circuit.

The next step for optimising quantum circuits using ZX-diagrams is to find additional rewrite rules that allows one to produce smaller diagrams, while still being able to extract the diagrams into a circuit. An approach based on replacing non-Clifford phase gates with certain ZX-diagrams called phase gadgets during the simplification procedure has shown some promise. These phase gadgets enable phases to propegate non-locally through the circuit, much like they do in phase-polynomial approaches to quantum circuit optimisation [20, 4, 3]. However, unlike those approaches, the framework we described in this paper (with the addition of phase gadgets) applies to arbitrary circuits, rather than only

circuits. Various heuristics involving phase gadgets have been implemented in the circuit optimisation tool PyZX, however a detailed description of these techniques and analysis of their performance is a topic of future work.

A second avenue of future work is to adapt the circuit extraction procedure to work in constrained qubit topologies. Many near-term quantum devices only allow interactions between certain pairs of qubits (e.g. nearest neighbours in some fixed planar graph). A notable feature of the circuit extraction procedure described in Section 6 is that we have some freedom in choosing which CNOTs to apply in reducing the bi-adjacency matrix of the ZX-diagram. We are currently exploring techniques by which this extraction can be constrained to only apply CNOTs in ‘allowed’ locations to produce circuits suitable for hardware with topological constraints.

Acknowledgements. SP acknowledges support from the projects ANR-17-CE25-0009 SoftQPro, ANR-17-CE24-0035 VanQuTe, PIA-GDN/Quantex, and LUE / UOQ. AK and JvdW are supported in part by AFOSR grant FA2386-18-1-4028.


  • [1] Scott Aaronson and Daniel Gottesman. Improved simulation of stabilizer circuits. Physical Review A, 70(5):052328, 2004.
  • [2] Nabila Abdessaied, Mathias Soeken, and Rolf Drechsler. Quantum circuit optimization by hadamard gate reduction. In International Conference on Reversible Computation, pages 149–162. Springer, 2014.
  • [3] Matthew Amy, Dmitri Maslov, and Michele Mosca. Polynomial-time T-depth optimization of Clifford+ T circuits via matroid partitioning. IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems, 33(10):1476–1489, 2014.
  • [4] Matthew Amy and Michele Mosca. T-count optimization and Reed-Muller codes. 2016. arXiv:1601.07363.
  • [5] Miriam Backens. The zx-calculus is complete for stabilizer quantum mechanics. New Journal of Physics, 16(9):093021, 2014.
  • [6] Miriam Backens. Making the stabilizer zx-calculus complete for scalars. In Chris Heunen, Peter Selinger, and Jamie Vicary, editors, Proceedings of the 12th International Workshop on Quantum Physics and Logic (QPL 2015), volume 195 of Electronic Proceedings in Theoretical Computer Science, pages 17–32, 2015. arXiv:1507.03854, doi:10.4204/EPTCS.195.2.
  • [7] André Bouchet. Graphic presentations of isotropic systems. J. Comb. Theory Ser. A, 45:58–76, July 1987. URL:
  • [8] Daniel E Browne, Elham Kashefi, Mehdi Mhalla, and Simon Perdrix. Generalized flow and determinism in measurement-based quantum computation. New Journal of Physics, 9(8):250, 2007. URL:
  • [9] B. Coecke and R. Duncan. Interacting quantum observables: categorical algebra and diagrammatics. New Journal of Physics, 13:043016, 2011. arXiv:quant-ph/09064725.
  • [10] B. Coecke and A. Kissinger. Picturing Quantum Processes. Cambridge University Press, 2014.
  • [11] V. Danos and E. Kashefi. Determinism in the one-way model. Phys. Rev. A, 74(052310), 2006. doi:10.1103/PhysRevA.74.052310.
  • [12] V. Danos, E. Kashefi, and P. Panangaden. The Measurement Calculus. April 2007. arXiv:0704.1263.
  • [13] Vincent Danos, Elham Kashefi, Prakash Panangaden, and Simon Perdrix. Extended Measurement Calculus. Semantic Techniques in Quantum Computation, 2010.
  • [14] R. Duncan and S. Perdrix. Graph states and the necessity of Euler decomposition. Mathematical Theory and Computational Practice, pages 167–177, 2009.
  • [15] R. Duncan and S. Perdrix. Rewriting measurement-based quantum computations with generalised flow. In Proceedings of ICALP, Lecture Notes in Computer Science, pages 285–296. Springer, 2010.
  • [16] Ross Duncan and Simon Perdrix. Pivoting makes the ZX-calculus complete for real stabilizers. In Proceedings of the 10th International Workshop on Quantum Physics and Logic (QPL), volume 171 of Electronic Proceedings in Theoretical Computer Science, pages 50–62. Open Publishing Association, 2014. doi:10.4204/EPTCS.171.5.
  • [17] Andrew Fagan and Ross Duncan. Optimising Clifford Circuits with Quantomatic. In Proceedings of the 15th International Conference on Quantum Physics and Logic (QPL), volume 287 of Electronic Proceedings in Theoretical Computer Science, pages 85–105. Open Publishing Association, 2019. doi:10.4204/EPTCS.287.5.
  • [18] Amar Hadzihasanovic, Kang Feng Ng, and Quanlong Wang. Two complete axiomatisations of pure-state qubit quantum computing. In Proceedings of the 33rd Annual ACM/IEEE Symposium on Logic in Computer Science, LICS ’18, pages 502–511, New York, NY, USA, 2018. ACM. doi:10.1145/3209108.3209128.
  • [19] Marc Hein, Wolfgang Dür, Jens Eisert, Robert Raussendorf, M Nest, and H-J Briegel. Entanglement in graph states and its applications. 2006. arXiv:quant-ph/0602096.
  • [20] Luke E Heyfron and Earl T Campbell. An efficient quantum compiler that reduces T count. Quantum Science and Technology, 4(015004), 2018. doi:10.1088/2058-9565/aad604.
  • [21] Emmanuel Jeandel, Simon Perdrix, and Renaud Vilmart. A Complete Axiomatisation of the ZX-Calculus for Clifford+T Quantum Mechanics. In Proceedings of the 33rd Annual ACM/IEEE Symposium on Logic in Computer Science, LICS ’18, pages 559–568, New York, NY, USA, 2018. ACM. doi:10.1145/3209108.3209131.
  • [22] Emmanuel Jeandel, Simon Perdrix, and Renaud Vilmart. Diagrammatic Reasoning Beyond Clifford+T Quantum Mechanics. In Proceedings of the 33rd Annual ACM/IEEE Symposium on Logic in Computer Science, LICS ’18, pages 569–578, New York, NY, USA, 2018. ACM. doi:10.1145/3209108.3209139.
  • [23] Aleks Kissinger and John van de Wetering. PyZX: A circuit optimisation tool based on the ZX-caculus.
  • [24] Vadym Kliuchnikov and Dmitri Maslov. Optimization of Clifford circuits. Phys. Rev. A, 88:052307, Nov 2013. doi:10.1103/PhysRevA.88.052307.
  • [25] Anton Kotzig. Eulerian lines in finite 4-valent graphs and their transformations. In Colloqium on Graph Theory Tihany 1966, pages 219–230. Academic Press, 1968.
  • [26] Ketan Markov, Igor Patel, and John Hayes. Optimal synthesis of linear reversible circuits. Quantum Information and Computation, 8(3&4):0282–0294, 2008.
  • [27] Mehdi Mhalla, Mio Murao, Simon Perdrix, Masato Someya, and Peter S Turner. Which graph states are useful for quantum information processing? In Conference on Quantum Computation, Communication, and Cryptography, pages 174–187. Springer, 2011.
  • [28] Yunseong Nam, Neil J Ross, Yuan Su, Andrew M Childs, and Dmitri Maslov. Automated optimization of large quantum circuits with continuous parameters. npj Quantum Information, 4(1):23, 2018.
  • [29] Maarten Van Den Nest. Classical simulation of quantum computation, the gottesman-knill theorem, and slightly beyond. Quantum Information & Computation, 10(3):258–271, 2010.
  • [30] Renaud Vilmart. A Near-Optimal Axiomatisation of ZX-Calculus for Pure Qubit Quantum Mechanics. 2018. arXiv:1812.09114.

Appendix A Example derivation

In this section we will work through a complete example of our simplification algorithm.

Let us start with the following circuit: compl-example1 This has 5 two-qubit gates and 19 single-qubit gates. Using the procedure of Lemma 3 to get it in graph-like form we get: compl-example2

We see that we have multiple interior Pauli and proper Clifford phases and hence we must do local complementations and pivots. We start by doing a sequence of local complementations. The locations of these operations are marked by a red star. compl-example3 We now have two internal Pauli vertices left, but they are not connected. Hence we must use equation (9), to be able to get rid of them: compl-example4 Applying the pivots to the designated vertices gives us: compl-example5 Note that in the bottom qubit we end up where we started before doing the pivots, but now we have marked the vertex as a local Clifford, and hence the vertex now counts as a boundary vertex. This means the simplification procedure has ended. The final step is extracting a circuit: compl-example6a Here the frontier is marked by the box. We first unfuse the phases onto gates. Then we want to extract new vertices. These are marked by a red star. Since the three marked vertices have no other connections to the frontier, and the frontier vertices have only these single neighbours, we can extract these by simply putting them onto the frontier. The next step is to extract the bottomleft vertex, but in this case there is a connection too many which we must extract as a CNOT: compl-example6b We now simply repeat this procedure until the entire circuit is extracted. compl-example6c

The extracted circuit has 4 two-qubit gates and 18 single-qubit gates. Applying some final cancellations between Hadamards on the inputs and outputs gets the number of single-qubit gates down to 14: compl-example7

Appendix B Proofs

b.1 Derived Rules in the ZX-calculus

The antipode rule, hopf-rule is derivable in the ZX-calculus.


To derive the rule we take advantage of the freedom to deform the diagram as shown below. hopf-proof The final equation is simply dropping the scalar. ∎

The -copy rule, picopy-rule is derivable in the ZX-calculus.


To derive the rule we use the rule first to split the -labelled vertex, and the and rules do the bulk of the work as shown below: picopy-proof ∎

Self-loops can be removed in the ZX-calculus:


The first one follows by applying from right to left and then using . For the second one we do:

The first step is simply the definition of the Hadamard box, and in the last step we implicitly drop the scalar X spider that we are left with. ∎

Parallel Hadamard edges can be removed in the ZX-calculus: par-edge-rem


b.2 Circuits and focused gFlow

To show that graph-like ZX-diagrams arising from circuits admit a focused gFlow, we introduce a simpler sufficient condition.

[11] Given an open graph , a causal flow on consists of a function and a partial order on the set satisfying the following properties:

  1. if then

where means that and are adjacent in the graph.

Like focused gFlow, causal flow is a special case of a more general property called gFlow:

Given an open graph , a generalised flow, or gFlow consists of a pair such that for any :

  1. if , then

  2. if and , then

In the case where all of the sets are singletons, the conditions above are equivalent to the causal flow conditions. Hence, if a graph admits a causal flow, it also admits a gFlow by letting . It was furthermore show in [27] that any gFlow can be systematically transformed into a focused gFlow. Combining these two facts, we obtain the following theorem.

If an open graph admits a causal flow , then it also admits a focused gFlow.

The following proof of Lemma 3 shows that the diagrams produced by making a circuit graph-like according to the procedure outlined in Lemma 3 have causal flow and hence a focused gFlow.

Proof of Lemma 3.

Let denote the circuit, and let denote the diagram produced by applying the procedure of Lemma 3 to .

In order to prove that has a focused gFlow, it suffices to show that it admits a causal flow, by Theorem B.2.

With every spider of the circuit we associate a number specifying on which ‘qubit-line’ it appears. We also associate a ‘row-number’ specifying how ‘deep’ in the circuit it appears. Suppose now that in . If they are on the same qubit, so , then necessarily . Conversely, if they are on different qubits, , then they must be part of a CZ or CNOT gate, and hence .

In the diagram resulting from Lemma 3, every spider arises from fusing together adjacent spiders on the same qubit line from the original diagram. For a spider in we can thus associate two numbers , and , where is the lowest row-number of a spider fused into , and is the highest. Spider fusion from only happens for spiders on the same qubit-line, and hence also inherits a from all the spiders that got fused into it. Any two spiders and in with must have been produced by fusing together adjacent spiders on the same qubit-line, and hence we must have or , depending on which of the spiders is most to the left. If instead and , then their connection must have arisen from some CNOT or CZ gate in , and hence the intervals and must have overlap, so that necessarily and .

Now we let be the set of spiders connected to an output, and the set of spiders connected to an input in . For all we let be the unique connected spider to the right of on the same qubit-line. We define the partial order as follows: if and only if or . It is straightforward to check that this is indeed a partial order.

By construction and the property , follows from discussed above, so let us look at the third property of causal flow.

Suppose . We need to show that . If this is trivial so suppose . First suppose that (which is also equal to ). has a maximum of two neighbours on the same qubit-line, and since one of them is , this can only be if and hence , and we are done. So suppose that . By the discussion above, we must then have and . Since we also have we get so that indeed . ∎

b.3 Preservation of focused gFlow

Throughout this section, we will rely extensively on the symmetric difference of sets: . This extends to an -ary operation in the obvious way. By convention, we assume these binds are far to the right as possible, i.e.

b.3.1 Local complementation

The following lemma will be needed in the other proofs, it shows how the odd neighbourhood of a set evolves under local complementation: Given a graph , and ,


First notice that is linear: , . Moreover , the neighbourhood of in . As a consequence, .

The local complementation is acting as follows on the neighbourhoods:

As a consequence,

Notice that iff . Hence, if , . Otherwise, if , .

If is a focused gFlow for then is a focused gFlow for where is inductively defined as

where .


If is a focused gFlow for then is a focused gFlow for where is inductively defined as

where .

First of all, can indeed be defined inductively by starting at the maximal elements in the partial order, since for any , so that , and similarly when , so implies hence . That preserves the order, i.e. , follows similarly. Moreover, it is easy to show that , . It remains to show that , or equivalently, where .

First notice that for any , , so, according to Lemma B.3.1, and using the linearity of and the distributivity of over ,

Moreover, , so

(Lemma B.3.1)

As a consequence,

Now, we prove that by induction on starting at maximal elements in the order.

Let be maximal for i.e. , . By maximality we must have and hence . If , it implies that . If , then , so is maximal, so and , as a consequence is also equal to in this case.

By induction, for any ,

  • If ,

  • If ,

If is a focused gFlow for then is a gFlow for where is defined as

Notice that is not necessarily a focused gFlow.

b.3.2 Pivoting

The action of the pivoting on the odd-neighbourhood can be described as follows: Given a graph , , , and ,


where and are the closed neighbourhood and the closed odd neighbourhood respectively.


The pivoting acts as follows on neighbourhoods:

As a consequence,

Notice that iff , and similarly for . Hence we obtain (13) by case distinction.∎

If is a focused gFlow for then is a focused gFlow for where , .


If is a focused gFlow for then is a focused gFlow for where is defined as follows:

It remains to show that