Log In Sign Up

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

by   Niel de Beaudrap, et al.
University of Oxford

The ZX-calculus is a graphical language for reasoning about quantum computation using ZX-diagrams, a certain flexible generalisation of quantum circuits that can be used to represent linear maps from m to n qubits for any m,n ≥ 0. Some applications for the ZX-calculus, such as quantum circuit optimisation and synthesis, rely on being able to efficiently translate a ZX-diagram back into a quantum circuit of comparable size. While several sufficient conditions are known for describing families of ZX-diagrams that can be efficiently transformed back into circuits, it has previously been conjectured that the general problem of circuit extraction is hard. That is, that it should not be possible to efficiently convert an arbitrary ZX-diagram describing a unitary linear map into an equivalent quantum circuit. In this paper we prove this conjecture by showing that the circuit extraction problem is #P-hard, and so is itself at least as hard as strong simulation of quantum circuits. In addition to our main hardness result, which relies specifically on the circuit representation, we give a representation-agnostic hardness result. Namely, we show that any oracle that takes as input a ZX-diagram description of a unitary and produces samples of the output of the associated quantum computation enables efficient probabilistic solutions to NP-complete problems.


page 3

page 7

page 9

page 11

page 15

page 17

page 18

page 19


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

We present a new circuit-to-circuit optimisation routine based on an equ...

Classifying Complexity with the ZX-Calculus: Jones Polynomials and Potts Partition Functions

The ZX-calculus is a graphical language which allows for reasoning about...

PBS-calculus: A Graphical Language for Quantum-Controlled Computations

We introduce the PBS-calculus to represent and reason on quantum computa...

LIMDD A Decision Diagram for Simulation of Quantum Computing Including Stabilizer States

Efficient methods for the representation of relevant quantum states and ...

A diagrammatic axiomatisation of fermionic quantum circuits

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

The rational fragment of the ZX-calculus

We introduce here a new axiomatisation of the rational fragment of the Z...

VyZX : A Vision for Verifying the ZX Calculus

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

1 Introduction

Quantum circuit notation is widely used in the field of quantum computing to denote computations to be executed on a quantum computer. While quantum circuits are a useful tool for representing computations on a quantum computer, they are somewhat inconvenient for reasoning about computations (such as proving equalities or doing simplifications); and for representing computations in alternative models like the one-way model of measurement-based quantum computation (MBQC) [37], or surface code lattice surgery [30].

ZX-diagrams are an alternative, more general representation of quantum computations, which allow complex operations to be described using a few simple generating operators. ZX-diagrams come with an equational theory, called the ZX-calculus [10], which allows one to perform many useful calculations graphically, without resorting to concrete matrix computations. While ZX-diagrams can be seen as an extension of circuits [11], they also readily admit encodings of the one-way model [22] and lattice surgery [19], and allow one to reason more easily about such procedures. There are several known complete axiomatisations of the ZX-calculus [35, 46], where any true equality of linear maps can be proved graphically. For a review on the ZX-calculus we refer to [44].

The ZX-calculus has been used in a variety of areas. It was used to optimise T-count [32, 17], braided circuits [28] and MBQC [4]; to find a new normal form for Clifford circuits [21]; to do more effective classical simulation using stabiliser decompositions [33]; and to reason about surface codes [25, 26], mixed-state quantum computations [8]

, natural language processing 

[9], condensed matter systems [13], counting problems [20, 41] and spin-networks [23].

As a strict extension of quantum circuit language, ZX-diagrams may express operations in a form that do not correspond directly to a quantum circuit. This added flexibility makes it easier to find novel strategies to simplify quantum circuits, but it comes at a cost: given a ZX-diagram representing a unitary linear map, it might be non-trivial to transform it back into a circuit of comparable size. Such a translation might however be necessary if, for instance, we want to run the computation described by a ZX-diagram on a gate-based quantum computer.

We refer to the above problem, as the circuit extraction problem: given a ZX-diagram which denotes a unitary operator , find a unitary circuit (i.e., a quantum circuit without measurements) that implements . In recent years, some progress has been made on this problem [21, 32, 4, 38, 31, 18]. However, all known methods for efficient extraction of circuits from ZX-diagrams rely on additional conditions, in particular requiring there to be some kind of flow on the diagram, a concept imported from MBQC [6]. Such conditions allow the diagram to be rewritten incrementally into a unitary circuit. Since many ZX-calculus rewrites preserve these conditions, it is possible to perform optimisation of quantum circuits using ZX-calculus rules and still recover circuits efficiently.

However, it is worth trying to generalise these conditions as much as possible, or even remove them. For instance, it was noted in [32] that a certain transformation of ZX-diagrams would decrease the T-count (an important metric for quantum circuit optimisation), but in the process broke the invariant (the existence of a gflow), preventing a circuit from being extracted efficiently using known techniques. Given all this it is then natural to wonder about the following question:

Is there some efficient procedure to translate any

unitary ZX-diagram into a quantum circuit?

In this paper we present strong evidence that there is no such efficient procedure, by showing that the circuit extraction problem is #P-hard in the worst case. The complexity class #P contains for instance the problem of strong simulation of quantum circuits, and counting the number of satisfying solutions to a Boolean formula, so #P-hard problems are expected to be intractable. We prove #P-hardness by giving an encoding of Boolean formulae into unitary ZX-diagrams in such a way that extracting a polysize circuit provides a solution to the associated #SAT instance. A consequence of our result is that if there were a polynomial time algorithm for circuit extraction, then .

Alternatively, since there is an evident translation from a ZX-diagram into a quantum circuit with postselection, this result can equivalently be seen as expressing the hardness of translating a postselected circuit that is promised to be proportional to a unitary into a circuit without postselection. While intuitively this seems likely to be hard, particularly in light of Aaronson’s landmark result that  [1]

, our hardness result seems to be quite different in nature due to the unitarity promise. In particular, the postselection does not seem to be the ‘source of power’ in our proof: the measurement outcomes corresponding to the post-selections in our circuits occur with some bounded probability, independent of the problem size.

One could ask how much our hardness result is tied to the fact that we require a procedure that produces quantum circuits from ZX-diagrams. Especially, when considering that in most cases we are not interested in the circuit itself, but instead we simply want to sample the output of the quantum computation. Perhaps one could find some other procedure to “program” a quantum computer using a ZX-diagram describing a unitary and obtain samples of measurement outcomes. We show that an efficient such procedure is unlikely to exist for arbitrary ZX-diagrams, by finding that such a procedure allows you to probabilistically solve NP-hard problems. So if there were some way to generically translate unitary ZX-diagrams into procedures which could be realised in polynomial time on a quantum computer, it would follow that the entire polynomial hierarchy is in BQP, and in particular that .

The paper is structured as follows. We start by covering preliminaries on quantum circuits, ZX-diagrams and the necessary complexity theory in Section 2. Then in Section 3 we formally define the circuit extraction problem and prove it is hard. Section 4 considers several variations on circuit extraction, and in Section 5 we find some upper bounds on the hardness of circuit extraction. We end with some concluding remarks in Section 6.

2 Preliminaries

2.1 Quantum circuits

Since we wish to extract ‘a circuit’ from a ZX-diagram, it will be helpful to first consider what we actually mean by a circuit.

In quantum computational theory, a ‘circuit’ is a description of a computational process consisting of operations which may be decomposed as a sequence of primitive ‘gates’ and ‘measurements’, which act on one or more qubits to change the states of those qubits. The state-space of a qubit is identified with the finite-dimensional Hilbert space ; the state of

qubits in parallel is described by the tensor product

. A ‘gate’ is an operation which is applied to one or more qubits and implements a unitary transformation on the associated state space. A ‘measurement’ is an operation which transforms a state to some state where is a set of projections that sum up to the identity operator , the gives the probability of observing that particular measurement outcome and is given by , and the index provides the classical ‘outcome’ indicating which transformation occurred. A gate or measurement acting on a small number of qubits can be applied to a larger set of qubits by taking the tensor product with an appropriate number of identity operators. A ‘circuit’ is then a composition of such gates and measurements on some number of qubits, acting in sequence or in parallel, to describe more complex (and in general, non-deterministic and irreversible) transformations of a quantum state-space. For the purposes of using quantum circuits to define a reasonable model of computation, one usually elaborates the above with a description of how one would specify a circuit as part of a family of unitary operators, acting on inputs of various sizes (see Appendix A for details). For our purposes, it will suffice to require that the coefficients of the gates be efficiently computable, and in particular provided explicitly in some representation which suffices to approximate them to bits of precision in time for an qubit circuit.

It will be convenient to refer to one specific such gate-set — an infinite set of gates, consisting of the single-qubit gates for arbitrary angles , the single-qubit Hadamard gate and the two-qubit gate CNOT:


This gate set forms a universal gate set, meaning that a unitary acting on any number of qubits can be written as a circuit consisting of these gates [36]. Other universal gate-sets exist, but so long as one considers gate sets whose parameters are efficiently computable from some input parameters and which act only on a bounded numbers of qubits (e.g., at most two or three qubits), the size of a circuit to represent a given unitary operator can only vary by a constant factor, so that for the purpose of complexity theory, the details of the specific gate set chosen are not important.

A circuit which contains no measurements, and therefore consists entirely of unitary gates, is called a ‘unitary circuit’. A unitary circuit is reversible, and ‘deterministic’ in the sense that an idealised realisation of such a circuit will transform the state-space in the same way each time. As this is a convenient feature for the design and analysis of quantum algorithms, much of the literature on quantum algorithms concerns itself with unitary circuits, and much of the design of quantum computers is concerned with how to reliably implement unitary circuits.

2.2 ZX-diagrams

We provide a brief overview of ZX-diagrams. For a review see [44], and for a book-length introduction see Ref. [12].

ZX-diagrams form a diagrammatic language similar to the familiar quantum circuit notation. A ZX-diagram (or simply 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 [10, 11].

Spiders are linear operations 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:


Note that if you are reading this document in monochrome or otherwise have difficulty distinguishing green and red, spiders will appear lightly-shaded and darkly-shaded. The diagram as a whole corresponds to a linear map built from the spiders (and permutations) by the usual composition and tensor product of linear maps. As a special case, diagrams with no inputs represent (super-normalised) state preparations. Note that when , we will not write the phase on the spider.

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


We can also represent the effects that are dual to the states above using spiders:


In the diagrams above we write explicit scalars to represent a proportionality constant. In this paper (non-zero) scalar factors will not be important. However, do note it is always possible to represent any scalar as an explicit ZX-diagram (of constant size). For this reason, our results will also apply to other proposed normalisations of the ZX generators, such as those in Refs. [16, 13, 23].

It is often convenient to introduce a symbol — a yellow square — for the Hadamard gate. This is defined by the equation:


The CNOT gate also has a straightforward representation as a ZX-diagram:


Seeing as can represent , and CNOT gates as ZX-diagrams, we see that we can in fact represent any unitary as a ZX-diagram. The above demonstrates that ZX-diagrams can be used as an alternative representation for quantum circuits. However, ZX-diagrams are also more versatile than unitary circuits. Consider for example the following construction of the CZ gate as a ZX-diagram:

CZ (7)

The right-hand-side demonstrates a different diagrammatic construction for CZ, that does not immediately look circuit-like, with the Hadamard-box representing some sort of interaction of two qubits rather than the evolution of a single qubit.

In fact, this versatility is reflected in the property that ZX-diagrams are universal for all linear maps between any number of qubits. To see this, note that we can represent states as in Eq. (3). By composing tensor products of these states with some unitary we can write down any quantum state. By the map-state duality of quantum theory (i.e. the Choi-Jamiołkowski isomorphism), we can then also write every linear map, see for instance [44] for the details.

The universality of the gate-set and of the ZX-calculus means that any unitary operator on some fixed number of qubits may be represented by some ‘gadget’ in the ZX calculus, consisting of some fixed diagram of finite size — though as the example of CZ in Eq. (7) shows, there may also be ‘gadgets’ which represent a unitary operator which do not consist of sequential and parallel composition of diagrams from Eq. (2). Indeed, even the representation of the CNOT is by a simple ‘gadget’ of two nodes, which is not describable as a composition of the other single-node ‘gadgets’. In this respect, ZX-diagrams represent a more versatile notation than a conventional circuit notation. This raises the question of how, given a representation of some unitary as a ZX-diagram, one might find another representation of which consists of just compositions from the universal gate-set . This is the problem that this paper is concerned with.

ZX-diagrams are more than just a notation for unitary circuits (and non-unitary operators more generally): they may be used to perform computations. Specifically, ZX-diagrams come with a set of graphical rewrite rules, which may be used to find equivalent diagrams which represent the same state or operator, just as one might manipulate an algebraic expression. This rewrite system is complete [35, 46]: unlike other circuit diagrams, one may show that two equivalent ZX-diagrams are equivalent though transformations of diagrams alone. The possible advantage of this is that ZX-diagrams can often concisely represent operators which have a very large number of non-zero coefficients, and so that this reasoning can be done efficiently while it could not be done using the matrices directly. For instance, one of the rewrite rules we will use in this paper is spider fusion:

These rules say that we can fuse together adjacent spiders of the same colour.

While these rewrite rules are not immediately relevant to our results, the fact that it is possible to compute with ZX-diagrams is the motivation for considering this particular representation of unitary circuits, and also motivates the concept of considering different ZX-diagrams which represent the same unitary transformation. We refer the interested reader to [44] for an overview.

2.3 Circuit extraction

In the above section we saw that we can get ZX-diagrams directly from quantum circuits. We can also get ZX-diagrams from considering measurement patterns in the one-way model [37]. In the one-way model of quantum computation we start with a large graph state, on which we then do subsequent measurements, where the choice of measurement angle and axis may depend on previous measurement outcomes. This leads to another universal model of quantum computation. The one-way model can be straightforwardly represented in the ZX-calculus [22, 4].

An important property of a one-way computation is that we can perform a computation deterministically, so that we perform the same overall computation regardless of individual measurement outcomes. A sufficient property for ensuring that deterministic processes are possible on a given resource state is that its underlying graph has a property known as gflow [6]. This is an efficiently verifiable combinatorial condition on the entangled resource.

When we represent a one-way computation with gflow as a ZX-diagram, the gflow ensures that certain ‘local’ parts of the diagram correspond to individual unitary gates, in a way which can be iteratively translated into an actual unitary circuit. In this case we can hence extract a unitary quantum circuit from the ZX-diagram that represents the one-way computation. See for instance [21, 4, 38] for several variations on this idea.

Measurement-based quantum computation like the one-way model is a type of non-unitary quantum computation. Another type of non-unitary model is given by doing lattice surgery in the surface code [29, 19]. A lattice surgery procedure can also be represented as a ZX-diagram [19]. Just as in the one-way model, there is a flow condition that ensures such a calculation is deterministic, and that the resulting ZX-diagram can be step-by-step rewritten into a unitary circuit [18].

We see that there are several quantum computational models that can be written in terms of ZX-diagrams, which can be rewritten into a unitary quantum circuit efficiently when they satisfy some condition. The type of flow condition required for these procedures ensures that the diagram can’t get ‘too wild’ in the middle, so that we can stepwise rewrite the diagram into something that looks more like a circuit. A natural question to ask then is how much we can weaken such additional conditions, and in particular if we can transform a ZX-diagram into a circuit efficiently in the most general setting, where the only condition we require of the ZX-diagram is that it is proportional to a unitary. The main result of this paper is that such a general efficient procedure most likely does not exist.

2.4 Background on computational complexity

Finally, we provide some background on computational complexity. We assume knowledge of P, the boolean satisfiability problem , oracle machines, NP

and nondeterministic Turing machines (NTMs) in general. Our results concern

Cook reductions (in fact, usually Cook[1] reductions). A Cook reduction from a problem to another problem is an algorithm for solving using a deterministic Turing machine which halts in polynomial time, but which may query an oracle (in the case of a Cook[1] reduction, exactly once) for . This implies that, modulo some polynomial-time computation, the problem is at least as hard as ; and that if , we also have . In symbols we may write . Our results will generally concern problems related to ZX-diagrams and problems which are at least NP-hard (i.e., they suffice to solve ).

Quantum circuits (specifically: uniform circuit families, as described in Appendix A) form a model of computation, which may be considered to generate random outcomes through measurement operations. The class BQP consists of decision problems which can be decided with bounded error (with error probability less than , say) by such circuit families, and represents the decision problems that can be practically solved by an (idealised) quantum computer. It is not expected that either of NP or BQP contain the other. So if we can reduce in polynomial time (by many-to-one or oracle reductions) an NP-complete problem to some problem , then we expect to be intractable for quantum computers. Certain modifications of the quantum computational model do allow for more difficult problems to be solved, however. For instance, PostBQP is the class of problems which may be solved with bounded error by a uniform quantum circuit family, conditioned on some other measurement yielding a specific outcome (which occurs with non-zero probability). This ‘conditioning’ restriction is known as postselection, and appears to be operationally very powerful, as PostBQP coincides with the class PP, of decision problems for which a ‘yes’ instance is accepted on more than half of the branches of some NTM halting in polynomial time.

The class P is closed under oracles: a deterministic Turing machine equipped with an oracle for some problem in P cannot decide more problems in polynomial time than a normal Turing machine, so that . The same is true for BQP: any decision problem solvable (with bounded error) by a uniform family of quantum circuits, can also be solved (with bounded error) by some other family of quantum circuits without oracle access, so that . The same is not true, however, for NP: it is not known whether (the class of decision problems, for which there is an NTM with an oracle for a problem in NP, halts in polynomial time and accepts in some branch precisely for ‘yes’ instances) is equal to NP. It is widely conjectured that , and indeed that , and so forth. The union of for all , defines the class PH, called the polynomial hierarchy [39].

The hardness results which we are most concerned with involve problems in #P: the class of problems which may be reduced to counting the number of accepting branches of some NTM on a given input. In particular, we are interested in the problem #SAT, of counting the number of ‘solutions’ to an instance of SAT, presented as a formula for a function , where a ‘solution’ satisfies . The problem #SAT is #P-complete [43], as is tensor contraction over the natural numbers [14], and ‘strong simulation’ (i.e.

, precise estimation of explicit measurement probabilities) of uniform quantum circuit families 

[45]. The #P-completeness here means that a Cook reduction from any of these problems to some problem , establishes that there is a Cook reduction from any problem to . in this case we say then that is “#P-hard”. The computational power of #P is considered to be significantly greater than that of NP. In particular, Toda [40] showed that .

3 Proof of hardness of Circuit extraction

We now present the central problem of our work.

Input: A ZX-diagram with inputs and outputs and at most wires and/or spiders, and a set of unitary gates (each acting on at most qubits).
Promise: The operator denoted by is proportional to a unitary.
Output: Either (a) a -size circuit , expressed as a sequence of gates from and expressing an -qubit unitary that is proportional to the operator denoted by , if such a circuit exists; or (b) a message that no such circuit exists, if that is the case.

Note that here we make no assumptions on the specific gate set , apart from the computability of the coefficients as described in Section 2.1, and that the number of qubits which is bounded by some constant. One might object to the requirement that the output list of gates must be polynomially related to the size of the input ZX-diagram: however, as we are interested in whether the extraction problem can be solved efficiently, the restriction on the size of follows from the time required to represent it as a list of gates.

The above problem can of course also be stated for any related graphical language for quantum operations, such as the ZH-calculus [3] or the ZW-calculus [27]. Since such diagrams can be efficiently translated into one another, these problems are of equivalent hardness. There are some other reasonable variations we can consider of CircuitExtraction that we will discuss in the next section.

We will now show that CircuitExtraction is #P-hard. We do this by building a diagram that is proportional to a unitary based on a SAT instance, and showing that the resulting matrix the diagram represents is uniquely determined by the number of solutions of the instance.

Let be a Boolean formula with terms. We say a bit string is a solution to when . The first step will be to build a ZX-diagram that implements the linear map that takes qubits to qubit by . We can of course represent as a tree of AND and NOT operations so that to construct it suffices to find linear maps that implement AND and NOT on .

We may consider ZX diagrams for “quantum” versions of the boolean logical AND gate and NOT gate, i.e., linear operators such that , , and . These operations can be represented (up to a constant factor) by the following ZX-diagrams:

The NOT gate is just an gate, but the AND is more complicated. It is based on the 4 -gate representation of the CCZ gate from [33].

By combining these diagrammatic gadgets for NOT and AND we can build the operation as a ZX-diagram using spiders. Now, note that:


where is the number of solutions of , is the number of ‘non-solutions’ of , and we set and for . The resulting state is not normalised: to normalise it we should multiply both sides by .

We use the ‘state’ described in Eq.  (8) as the input of a controlled operation. By choosing the controlled operation appropriately, we will be left with something proportional to a unitary. We may for instance consider the following diagram:


To see this is unitary first recall that a rotation over an angle applied to gives . Hence the state of Eq. (8), when properly normalised, can be written as for . We can then calculate:


In the above, we use the relation , and some simple ZX-calculus rewrites. Hence, the diagram of Eq. (9) is proportional to an rotation where is uniquely determined by the number of solutions to . Note that this operation can be easily represented (with at most three gates) using a gate-set such as , in which the set of values of allowed angles include those that may arise in the diagram of Eq. (10) for some number of solutions to the formula ; such an operation will be representable using other gate-sets as well.111Note that the gate-set described here cannot be a single, finite gate set for all values of . However, the angles arising out of instances of satisfiability in this way can be specified in bits, precisely by characterising them in the way that we have as being related to some integer ranging in via inverse trigonometric functions. For remarks on what can be achieved with finite gate-sets, the reader may be interested in our remarks on the related problem ApproxCircuitExtraction, in Section 4.

CircuitExtraction is #P-hard.


#SAT is a #P-complete problem, so it suffices to show that we can count the number of solutions to a Boolean formula using a call to an oracle which solves CircuitExtraction. Given a Boolean formula with terms, construct the diagram of Eq. (9). The diagram here for uses of the diagrammatic gadgets for NOT and AND, and hence the complete diagram consists of spiders, each of which may be restricted to having at most wires. We may apply the CircuitExtraction oracle on this diagram subject to a suitable gate set that can exactly generate the possible X-rotations which may arise. As is a single-qubit circuit with at most gates, we can calculate the unitary it implements, up to any required precision , in polynomial time. We know that the operation realised is of the form , so to determine the value of , it suffices to estimate the entries of the resulting to within an error of . Determining the value of to bits of precision is more than sufficient to do this. ∎

If there is a polynomial time algorithm for CircuitExtraction, then . In particular, the polynomial hierarchy collapses to the first level: .


If CircuitExtraction can be done in polynomial time, then the above shows that we can solve #SAT in polynomial time, and hence . ∎

Our construction of the diagram we use to prove our result might seem somewhat arbitrary. To motivate it some more, first realise that instead of the function , we could have used the standard unitary quantum oracle for a Boolean function which acts on qubits via . We can get out of by post-selecting the top qubits to . Using the language of post-selection, we may then present a circuit version of Eq. (9):


The top part is calculating the number of solutions, while the bottom part ensures that this information is fed into a qubit in such a way that the overall operation is proportional to a unitary. The choice of is for the sake of simplicity: any unitary that satisfies would also suffice, such as or .

Even though we can view the diagram as a post-selected circuit, this does not seem to be where the power of the procedure comes from, as it is for instance in Aaronson’s [1] characterisation PostBQP = PP. The probability of observing the ‘correct’ outcome is bounded from below by a constant, and does not depend on . This means in particular that by doing repeat-until-success we could with high probability implement the circuit Eq. (11) on a quantum computer. However, this does not allow you to solve #SAT, as adjacent possibilities of the rotation angle are exponentially close. So rather, the power of the procedure comes from getting an explicit description of the circuit which allows us to exactly calculate the rotation angle.

4 Variations on extraction

There are several variations on circuit extraction which we can consider, all of which also turn out to be hard.

The essential trick we used in our proof is that our resulting circuit has just one qubit, and hence a description of a unitary on it can easily be transformed into the actual unitary it implements by just multiplying all the resulting matrices. But of course the same statement remains true if we have slightly more than one qubit, say a logarithmic amount in the size of the SAT instance. We also see that it then doesn’t matter if our circuit contains auxiliary qubits, measurements, or classically-controlled corrections. All of these can be efficiently calculated as long as the number of qubits is small enough. Therefore, let’s define the following variant of circuit extraction.

Input: A ZX-diagram with inputs and outputs and at most wires and/or spiders, and a set of unitary gates (each acting on at most qubits).
Promise: The operator denoted by is proportional to a unitary.
Output: Either (a) a deterministic -qubit circuit implementing the unitary of the input ZX-diagram, described as a length list of gates, auxiliary qubit preparations, measurements, and classical corrections, with at most auxiliary qubits; or (b) a message that no such circuit exists, if that is the case.

AuxCircuitExtraction is #P-hard.


We construct the same diagram as in the proof of Theorem 3 to solve a #SAT instance, except that we can no longer assume that the final circuit will act only on a single qubit: instead it may act on up to qubits, including the operations on the auxiliary qubits. The size of the matrices involved when trying to calculate the resulting unitary is , where here is the size of the input diagram. We may then still multiply the matrices together in polynomial time to obtain sufficiently precise estimates of the coefficients. ∎

One might also object that requiring the output unitary to exactly represent the ZX-diagram is too strong — in particular, impossible in general even with an approximately universal, finite gate set — and wish for an approximate output instead. We say that a unitary operator is an -approximation of another unitary for some , if for some global phase . Here, denotes the operator norm of

: the largest singular value of


Input: A ZX-diagram with inputs and outputs and at most wires and/or spiders, a set of unitary gates (each acting on at most qubits), and a precision parameter .
Promise: The operator denoted by is proportional to a unitary.
Output: Either (a) a -size circuit , expressed as a sequence of gates from and expressing an -qubit unitary which is an -approximation to either the operator denoted by , or some operator proportional to it; or (b) a message that no such circuit exists, if that is the case.

ApproxCircuitExtraction is #P-hard.


For a given SAT instance we again construct the same diagram as in the proof of Theorem 3 which denotes a unitary  , where allows us to determine the number of solutions to . This diagram has spiders. Set for some large enough constant . Then applying ApproxCircuitExtraction gives rise to a circuit, which has gates. We can hence just multiply out the matrices in order to determine the unitary it implements. This unitary approximates to degree . Since the top left entry of is real, we can first multiply by the appropriate global phase to ensure it is also real. If we have picked large enough then the entries of are then within of that of so that we can determine by rounding to the nearest allowed value. ∎

Note that, even for exponentially small angles as might arise when has few solutions, circuits of polynomial size do exist for when is an approximately universal gate-set: using the Solovay–Kitaev algorithm [34, 15] or any of its many refinements (see e.g. Ref. [5] and references therein), we may synthesise circuits approximating to any precision in time scaling polynomially in . The difficulty of ApproxCircuitExtraction stems from determining which angle to approximate.

Let us consider one final variation on extraction. One could argue that the reason that we end up with a hard problem in these instances, is because requiring the output to be some kind of circuit is too restrictive. The ultimate goal of circuit extraction is that we wish for the ZX-diagram to be run on a quantum computer, to obtain some probability distribution over outcomes; but the complexity of

CircuitExtraction and its variations seems to arise from the complexity of finding a precise description of the procedure to do so. Cutting out the middle-man, we may consider any process which takes as input a unitary ZX-diagram, and produces bit strings as output whose distribution conforms with the one we expect from the unitary.

Input: A ZX-diagram with inputs and outputs and at most wires and/or spiders.
Promise: The operator denoted by is proportional to some unitary .
Output: A sample from a probability distribution, given by (or sufficiently close to) .

It is clear that UnitaryZXSampling is at least as hard as BQP: we could just input a ZX-diagram that directly represents a quantum circuit, in which case this problem is equivalent to simulating that circuit. The reason we write here that the probabilities just have to be ‘sufficiently close’ is because the exact number doesn’t matter for the theorem below. To be concrete we could for instance allow the probability to additively deviate by  from the true value.

There is a randomised polynomial reduction from NP to UnitaryZXSampling. In other words: with access to a PromiseUnitaryZXSampling oracle—which produces the expected output if the input diagram is unitary and arbitrary output otherwise—we can with high probability solve NP-complete problems.


SAT is an NP-complete problem. To randomly reduce NP it however suffices to consider the problem USAT by the Valiant–Vazirani theorem [42]. USAT asks us to determine whether a Boolean formula is satisfiable, given the promise that it has at most one solution. Using the randomised reduction from SAT to USAT, we consider how to solve USAT using a PromiseUnitaryZXSampling oracle.

Let be a Boolean formula that has at most one solution. Construct the diagram Eq. (9) as in the previous proofs: as a unitary this implements the identity iff is not satisfiable, and for some fixed angle when is satisfiable. In the latter case, the value of is exponentially small, but known precisely, as has exactly one solution in this case. So we can say the circuit implements where encodes whether is satisfiable or not.


be the one-qubit (non-unitary) matrix that maps

and , so that in particular . By universality of ZX-diagrams we can find some (constant sized) diagram to represent . We can then calculate:


Hence, the ZX-diagram on the left in Eq. (12) implements either the identity, or an operation (that is to say, a NOT operation), depending on whether is satisfiable. When we feed this ZX-diagram to an oracle for PromiseUnitaryZXSampling, we get either the output 0 or 1, where a 0 indicates with high probability that the circuit is the identity, and a 1 indicates that the circuit is a NOT operation. We can repeatedly call the oracle to get additional samples to increase our confidence in the result.

Now suppose is a general instance of , which may have more than one solution. Using the Valiant–Vazirani reduction multiple times we probabilistically produce different Boolean formulae . If is not satisfiable, then none of the will be satisfiable either and this is what the PromiseUnitaryZXSampling will tell us as well. If is satisfiable, then a significant fraction of the will have a unique solution, so that our oracle tells us they are satisfiable. For the other the oracle will return some arbitrary output. So by picking large enough there will with high probability be some that will be uniquely satisfiable, and so we can conclude that is satisfiable as well.

Hence, we can determine with arbitrary high probability whether a SAT instance is satisfiable using enough calls to PromiseUnitaryZXSampling. ∎

If we knew that the number of solutions to the SAT instance was some other fixed number, then we could pick a different matrix to boost the state up to gate as above. If we pick ‘slightly wrong’, then the resulting diagram will just be close to . One might think that we could use such a procedure to try and determine the number of solutions to by doing binary search on the number of solutions, and so boost the power of UnitaryZXSampling to #P. However, the problem with this is that the resulting diagrams are not proportional to a unitary most of the time. There might be some way around this issue, so that UnitaryZXSampling is still #P-hard: we leave this as an open problem.

Note that if we were to consider a version of UnitaryZXSampling, without the promise of unitarity, such an oracle would be as powerful as PostBQP, since we can represent any ZX-diagram as a post-selected quantum circuit. In our case, the power again comes not so much from postselection, as being able to take advantage of the versatility of ZX-diagrams to gain access, in some way, to extract very precise information regarding a #P problem.

5 Upper bounding the complexity of CircuitExtraction

Given that CircuitExtraction is #P-hard, one might ask whether or not the problem is #P-complete (or more precisely: -complete), in the sense that a Turing machine with access to a #P oracle would be able to solve it, for some given polynomial upper bound on circuit size and some given gate-set (perhaps with suitable restrictions), in polynomial time. We have not managed to prove such a completeness result. We will however present the following upper bounds on decision problem versions of circuit extraction, relying on techniques from [2] (which we describe in Appendix B).

First, consider the following decision problem: given a ZX-diagram, and a circuit, determine whether the circuit implements a unitary which is proportional to that represented by the ZX-diagram (whether by a factor of for some angle , or a more general complex number). The complement of this problem is in . To sketch why this is, consider a circuit representing a unitary , and a ZX diagram representing an operator . If and are two non-zero coefficients from , and and are the corresponding (non-zero) pair of coefficients from the matrix represented by , then only if either for all possible such pairs. (We compare pairs instead of single coefficients, to deal with the fact that they might only represent the same matrix up to some non-zero scalar.) We also require that for any coefficient in which is zero, the corresponding coefficient of is also zero. Taken together, this implies that for all corresponding pairs of coefficients of and , . A #P oracle allows one to calculate coefficients222In this case, it is not necessary to compute complete information about , , , and : it suffices to compute information about individual components of the products and

, where these are regarded as vectors over

. (See the closing remarks of Appendix B.) of ZX-diagrams and circuits: if , an NTM with access to a #P oracle can non-deterministically find a witness that these two operators are not in fact proportional to one another. Thus, determining whether a circuit does not represent a unitary which is denoted (up to scalar factors) by a ZX-diagram, is in .

The above result has a simple corollary: the property of a ZX-diagram being proportional to a unitary, itself belongs to the complement of . We may see this by the fact that a ZX-diagram denoting an operator , which is proportional to a unitary, satisfies . We may represent by composing the diagram with its adjoint (which is the left-to-right mirror image of , with all phase angles negated). This composite diagram may easily be computed, at which point we may ask whether the operator it represents is distinct from the identity (even modulo non-zero scalar factors). As we note above, this problem is in .

Finally, using these ideas, we may consider the decision problem of determining, for a ZX-diagram which denotes an operator proportional to a unitary, and given some (approximately universal) gate set and polynomial length bound , whether there exists a circuit of at most gates over which implements . This problem is in : for an NTM with access to an oracle, it suffices to make a nondeterministic guess at a circuit of length (where each gate may be the identity operator, or some gate acting on a non-deterministically chosen set of qubits) and then query the oracle to determine whether the circuit approximately realises . A deterministic Turing machine, with access to an oracle for this problem, could then solve ApproxCircuitExtraction in polynomial time using standard techniques, using the oracle to facilitate a search for a circuit to realise .

These observations represent the most straightforward approach to determining an upper bound for the circuit extraction problem, and seem to place it at a level of complexity significantly higher than . If we conceive of #P as broadly representing the complexity of evaluating a tensor network, a superficial analogy between CircuitExtraction and boolean circuit minimisation [24, 7] would seem to suggest that CircuitExtraction is likely to be hard for some complexity class higher than (barring some collapse of complexity classes).

6 Conclusion

In this paper we studied the problem of extracting a quantum circuit description from a unitary ZX-diagram. We’ve shown that this problem is #P-hard by reducing #SAT to an application of circuit extraction. We’ve also studied some variations where we allow auxiliary qubits, classical control, and/or approximate synthesis of the desired unitary, and have shown that these problems are also #P-hard. In addition, we studied the hardness of a machine that takes in a unitary ZX-diagram and outputs measurement samples from that ZX-diagram, and have shown that such a machine allows one to probabilistically solve NP-hard problems.

A conclusion to be drawn from our results is that if we want some efficient procedure to transform a unitary ZX-diagram into a quantum circuit, then we will have to have some additional information about the structure of the ZX-diagram. In the known procedures for efficient circuit extraction [4, 38, 18], this additional information takes the form of a kind of ‘flow’ on the diagram that prevents parts of the diagram from becoming too unwieldy. An immediate question then is if there are other types of, more general, promises on the structure of the diagram which then allow you to extract a circuit from it.

Aaronson showed that sampling from a post-selected quantum circuit is hard [1]. Our results imply that some other tasks surrounding unitary post-selected circuits (that is, circuits which perform a unitary transformation conditioned on some post-selection) are hard. However, this hardness seems to stem not from the post-selection itself, as the post-selections can be simulated with high probability in our case. Rather, the hardness seems to stem from a hypothetical ability to find an equivalent, deterministic way to realise the same operation — which implies an ability to extract difficult-to-access information about the input diagram.

A question related to circuit extraction from ZX-diagrams is circuit extraction from deterministic measurement patterns (in for instance the one-way model or lattice surgery). When we have a deterministic measurement pattern, we can represent each branch of the computation by a ZX-diagram denoting a unitary. Our hardness proof does however not immediately translate to this setting, as it might be that the fact that all of these ZX-diagrams are branches of the same measurement pattern forces some kind of structure on the diagrams that might make it easier to rewrite them into circuits. The diagrams we used to show hardness of circuit extraction are as far as we are aware not representable as branches of some deterministic measurement pattern, so that we can’t use the same proof. We leave it for future work to determine the hardness of extracting unitary circuits from deterministic measurement patterns.

JvdW is supported by an NWO Rubicon personal fellowship.


Appendix A Quantum circuits as a computational model

In order to describe a model of computation with bounded computational power, one usually imposes further constraints on ‘quantum circuits’, as follows.

As with the study of boolean circuits as a model of computation, one often considers a quantum circuit to be described by some polynomial-time computable procedure (a sort of ‘effective blueprint’), which for a given requires time to produce a circuit taking inputs of size . While this constraint is not essential when considering a single circuit on its own (the description of the circuit itself is a finite specification), this constraint prevents us from considering what might otherwise seem like ‘quantum algorithms’ for uncomputable problems (in the same way that one must for boolean circuits).

Furthermore, to prevent unbounded computational power from being hidden elsewhere in the description of a quantum circuit, one often imposes constraints on the gates and measurements allowed in a circuit. One common convention is to require that the unitary gates be drawn from a finite set of unitary operators, and to require that all measurements are of single qubits, with projectors . This is frequently relaxed, to permit arbitrary single-qubit operations, or Z-rotations and X-rotations by arbitrary angles, and to allow one or two particular two-qubit gates, such as CNOT or CZ, and single-qubit measurements in an arbitrary basis; one then requires that the parameters of any such gates or measurements be efficiently computable.

Appendix B Counting complexity upper bounds on quantum simulation

In order to consider how we may obtain containments for quantum computing using counting complexity, we give an outline of the known techniques for relating quantum computation to counting complexity, and the (mild) technical constraints on coefficients of gates and of ZX-diagrams which this involves.

We are frequently interested in unitary circuits whose gates have coefficients which are irrational. However, in practise, the (finite) gate-sets of most interest involve only algebraic coefficients: that is to say, complex numbers (e.g. and for integers ) which satisfy , for some polynomial with integer coefficients. As such coefficients are dense in the complex numbers, and in particular are also dense in the subset of the complex numbers which have unit modulus, coefficients of this sort are appropriate to (approximately) represent gates which we may normally think of as being drawn from continuous, single-parameter families of gates such as and . This motivates a restriction to gates, whose coefficients are represented by algebraic numbers.

We refine this constraint as follows. By virtue of a circuit having only finitely many gates , the coefficients of the gates can in principle be drawn from a common algebraic number field , where each is a root of some (irreducible) polynomial as above and where . (For a finite gate-set, will in fact be a constant independent of .) We adopt the requirement on the representation of a circuit, that the coefficients for its gates be explicitly represented in a form

for some constant and for some choice of integer coefficients , where for each . (Following Ref. [2], for a finite gate-set, this does not limit the computational power of unitary circuits either for exact or for bounded-error quantum computation.) A product of such coefficients, may be represented in a similar form, but with a leading factor of rather than ; sums of such products may be represented in the same way by collecting terms together. For two numbers represented in this form, we may put them into normal form by comparing each of the terms (for some fixed sequence of powers ), and testing equality of each integer coefficient. The significance of this, is that a circuit with gates, where the individual gates satisfy such conditions, represent unitary transformations whose coefficients take this form. This provides us with a way in which the coefficients of operators given as unitary circuits, may be represented in such a way that we can efficiently perform equality comparisons in principle;333It is in principle possible to extend this representation in some ways, to allow equality comparisons between coefficients which are not algebraic; but this is not practically important to us. the question is then how we bound the complexity of doing so.

Using the techniques of Ref. [2], we may represent the coefficients of a unitary operator indirectly, using the number of accepting paths of nondeterministic Turing machines with various strings written on the tape to represent the integers of an algebraic number as above.444To be more precise: we may represent such an integer as a difference , where each is itself the number of accepting branches on the nondeterministic Turing machine, with slightly different contents of its tape. Then, with access to a #P oracle, a deterministic Turing machine would be able to evaluate any one coefficient . Furthermore: the techniques of Ref. [2] are not specialised in any particular way to unitary matrices, or indeed to square matrices, and can be applied to a matrix of any shape (or indeed, any tensor network) with algebraic coefficients. In particular, we may use these techniques to similarly represent the coefficients of linear operators which are represented by ZX-diagrams — assuming again that the coefficients arising from each generator is algebraic. The coefficients of the operators described in Eq. (2) are either , , or of the form or for various phase angles and integers . For these to all be algebraic, it suffices that the phase angles of the ZX-diagrams are rational multiples of (though other values of would also satisfy this constraint).555Technically, for any rational multiple described in the diagram, we also require that a prime factorisation of is provided. (This is an implicit requirement for the representation described above of elements of a number field .) For the purposes of practical numerical computation, this can be fulfilled by taking for a sufficiently large value of . Alternatively, if one were to use such a representation within a model of computation with access to a #P oracle, one might simply factorise by making use of the #P oracle to facilitate a binary search for factors of . We may also consider the coefficients which arise from multiplying the matrix represented by a ZX-diagram, by the matrix represented by a unitary circuit; this requires only that we represent the coefficients of each in a consistent way in terms of a common algebraic number field . From representations of the gates and of the coefficients of the ZX-generators, this would not be difficult to compute.

The above suffices to describe, in outline, how we may describe the coefficients of a linear operator — described by a unitary circuit, a ZX-diagram, or compositions of these representations — by counting the number of accepting branches of non-deterministic Turing machines. In particular, for any one coefficient , a deterministic Turing machine with a #P oracle can evaluate any particular integer . If the degree666A number field such as we have considered, can be interpreted as a vector space over the rational numbers , with a ‘basis’ described by the monomials for various integers . The degree is then the dimension of as a vector space over , and may be computed as the product of the degrees of the irreducible polynomials . of the field extension is ‘small’ (i.e., a constant, or more generally bounded by a polynomial in the size of the description of as a composition of simpler operators), we may simply query each such integer to obtain complete information of a single coefficient of . (If the degree is not ‘small’ in this sense, one might consider subtler strategies to obtain information about them; absence any particular promises or structure, complete information about the matrix coefficients would likely be inaccessible in polynomial time, even with recourse to a #P oracle.)