Improved classical simulation of quantum circuits dominated by Clifford gates
Abstract
The Gottesman-Knill theorem asserts that a quantum circuit composed of Clifford gates can be efficiently simulated on a classical computer. Here we revisit this theorem and extend it to quantum circuits composed of Clifford and gates, where is the single-qubit phase shift. We assume that the circuit outputs a bit string obtained by measuring some subset of qubits. Two simulation tasks are considered: (1) computing the probability of a given output , and (2) sampling from the output probability distribution. It is shown that these tasks can be solved on a classical computer in time and respectively, where is the number of -gates, is the total number of gates, and is the number of qubits. The proposed simulation algorithms may serve as a verification tool for medium-size quantum computations that are dominated by Clifford gates. The main ingredient of both algorithms is a subroutine for approximating the norm of an -qubit state which is given as a linear combination of stabilizer states. The subroutine runs in time , where is the relative error. We also develop techniques for approximating tensor products of “magic states” by linear combinations of stabilizer states. To demonstrate the power of the new simulation methods, we performed a classical simulation of a hidden shift quantum algorithm with qubits, a few hundred Clifford gates, and nearly -gates.
I Introduction
The path towards building a large-scale quantum computer will inevitably require verification and validation of small quantum devices. One way to check that such a device is working properly is to simulate it on a classical computer. This becomes impractical at some point because the cost of classical simulation typically grows exponentially with the size of a quantum system. With this fundamental limitation in mind it is natural to ask how well we can do in practice.
Simulation methods which store a complete description of an -qubit quantum state as a complex vector of size are limited to a small number of qubits . For example, a state-of-the art implementation has been used to simulate Shor’s factoring algorithm with 31 qubits and roughly half a million gates [1]. For certain restricted classes of quantum circuits it is possible to do much better [2, 3, 4, 5, 6]. Most significantly, the Gottesman-Knill theorem allows efficient classical simulation of quantum circuits composed of gates in the so-called Clifford group [2]. In practice this allows one to simulate such circuits with thousands of qubits [3, 1]. It also means that a quantum computer will need to use gates outside of the Clifford group in order to achieve useful speedups over classical computation. The full power of quantum computation can be recovered by adding a single non-Clifford gate to the Clifford group. A simple choice is the single-qubit gate; the Clifford+ gate set obtained in this way is a natural instruction set for small-scale fault-tolerant quantum computers based on the surface code [7, 8], and has been at the centre of a recent renaissance in classical techniques for compiling quantum circuits [9, 10, 11].
In this paper we present two new algorithms for classical simulation of quantum circuits over the Clifford+ gate set. The runtime of the algorithms is polynomial in the number of qubits and the number of Clifford gates in the circuit but exponential in the number of gates, or -count. This exponential scaling is sufficiently mild that we anticipate a classical simulation of Clifford+ circuits with a few hundred qubits and -count can be performed on a medium-size computer cluster. Thus our algorithms may serve as a verification tool for small quantum computations dominated by Clifford gates. Such computations arise naturally if a logical quantum circuit is realized fault-tolerantly using some stabilizer code. The first demonstrations of logical quantum circuits using the surface code are likely to be dominated by Clifford gates due to a high implementation cost associated with logical -gates [12, 13].
To describe our results let us fix some notation. A Clifford+ quantum circuit of length acting on qubits is a unitary operator , where each is a one- or two-qubit gate from the set where is the Hadamard gate and . We shall write , where is the number of Clifford gates () and is the number of -gates also known as the -count. Applying to the initial state and measuring some fixed output register in the -basis generates a random bit string of length . A string appears with probability
| (1) |
where projects onto the basis state and acts trivially on the remaining qubits.
Our first result is a classical Monte Carlo algorithm that approximates the probability for a given string with a specified relative error and a failure probability . The algorithm has runtime
| (2) |
where is a constant that depends on the implementation details. For example, assuming that and are some fixed constants and , the runtime becomes
Our second result is a classical algorithm that allows one to sample the output string from a distribution which is -close to with respect to the -norm. The sampling algorithm has runtime
| (3) |
where the notation hides a factor logarithmic in and , and
| (4) |
is a constant that depends on the implementation details. We expect the sampling algorithm to be practical when is small and is not too small. For example, assuming that the circuit outputs a single bit (), is a fixed constant, and , the runtime becomes
Both algorithms can be divided into independent subroutines with a runtime each and thus support a large amount of parallelism. We provide pseudocode for the main subroutines used in the algorithms and a timing analysis for the MATLAB implementation 11 1 The MATLAB implementation of the sampling algorithm is available upon request to the authors. in the Supplemental Material.
Since the simulation runtime is likely to be dominated by the terms exponential in , one may wish to minimize the exponents , in Eqs. (2,3). These exponents are related to the stabilizer rank [15] of a magic state
Recall that a -qubit state is called a stabilizer state if it has the form , where is a quantum circuit composed of Clifford gates. Stabilizer states form an overcomplete basis in the Hilbert space of qubits. Let be the smallest integer such that can be approximated with an error at most by a linear combination of stabilizer states (here the approximating state should satisfy ). The runtime scaling in Eq. (2) holds for any exponent such that for all sufficiently large . Using the results of [15] one can choose . Stronger upper bounds on the stabilizer rank could improve the runtime scaling in Eq. (2). Likewise, the runtime scaling in Eq. (3) holds for any exponent such that for any constant and all sufficiently large . For simplicity here we assumed that the precision parameter in Eq. (3) is a constant. In this paper we propose a systematic method of finding approximate stabilizer decompositions of which yields an upper bound , where , see Eq. (4). We conjecture that this upper bound is tight.
We implemented our classical sampling algorithm in MATLAB and used it to simulate a class of benchmark quantum circuits on qubits, with a few hundred Clifford gates, and -count . Specifically, we simulated a quantum algorithm which solves the hidden shift problem for non-linear Boolean functions [16]. An instance of the hidden shift problem is defined by a pair of oracle functions and a hidden shift string . It is promised that is a bent (maximally non-linear) function, that is, the Hadamard transform of takes values . It is also promised that is the Hadamard transform of the shifted version of , that is,
| (5) |
Here stands for the bit-wise XOR. The goal is to learn the hidden shift by making as few queries to and as possible. The classical query complexity of this problem is known to be linear in , see Theorem 8 of Ref. [16]. In the quantum setting, and are given as diagonal -qubit unitary operators and such that and for all . A quantum algorithm can learn by making a single query to each of these oracles, as can be seen from the identity [16]
| (6) |
This hidden shift problem is ideally suited for our benchmarking task for two reasons. First, the algorithm produces a deterministic output, i.e., the output is a computational basis state for some -bit string . Because of this we achieve the most favorable runtime scaling in Eq. (3) since each bit of can be learned by calling the sampling algorithm with a single-qubit output register () and a constant statistical error . Second, the -count of the algorithm can be easily controlled by choosing a suitable bent function. Indeed, the non-oracle part of the algorithm consists only of Hadamard gates. We show that for a large class of bent functions (from the so-called Maiorana-McFarland family) the oracles and can be constructed using Clifford gates and only a few gates, see the Supplemental Material for details.
The numerical simulations were performed for two randomly generated instances of the hidden shift problem with qubits. For each of these instances we simulated the quantum circuit for the hidden shift algorithm, i.e., the circuit implementing the unitary described above. The -counts of the two simulated circuits are and respectively. Since the hidden shift is known beforehand, we are able to verify correctness of the simulation. Our results are presented in Fig. 1. As one can see from the plots, the output probability distribution of each qubit has most of its weight at the corresponding value of the hidden shift bit. Only the output probabilities for qubits are shown because our algorithm perfectly recovered the first half of the hidden shift bits . This perfect recovery occurs due to the special structure of the chosen bent functions, see the Supplemental Material for further details.
The rest of the paper is organized as follows. In Section II we give an overview of our main techniques. In Section III we summarize some basic facts concerning stabilizer states. We present our classical simulation algorithms for Clifford+ circuits in Section IV. Finally, we show how to approximate tensor products of magic states by linear combinations of stabilizer states in Section V. In the Supplemental Material we provide pseudocode for the main subroutines used in our algorithms, and we discuss further details of the simulations reported in Fig. 1.
II Sketch of techniques
Following Ref. [15], we simulate a Clifford+ circuit classically using three basic steps. First, each -gate in the original circuit is replaced by a certain gadget that contains only Clifford gates and a -measurement. The Clifford gates may be classically controlled by the measurement outcome. The gadget consumes one copy of the magic state . This gives an equivalent ‘gadgetized’ circuit acting on a non-stabilizer initial state that contains copies of . We show how to remove all intermediate measurements from the gadgetized circuit by replacing the outcomes of these measurements by random uniform postselection bits. Accordingly, we replace the classically controlled Clifford gates by a suitable random ensemble of uncontrolled Clifford gates. Second, the initial magic state is represented (exactly or approximately) as a linear combination of stabilizer states. The action of the gadgetized circuit on each term in this linear combination can be efficiently simulated using the standard Gottesman-Knill theorem since the gadgetized circuit contains only Clifford gates. This allows us to represent the final state before the measurement of as a linear combination of stabilizer states. We simulate the measurement of on this final state independently for each term in the linear combination (we also have to simulate certain additional post-selective measurements introduced at the first step). This is possible due to the fact that -measurements map stabilizer states to stabilizer states. The final post-measurement state is a linear combination of at most stabilizer states. The third and the most time consuming step is computing the norm of the post-measurement state. This norm is simply related to the quantity of interest, such as the output probability . We show how to obtain a square-root speedup in this step compared with Ref. [15] reducing the runtime scaling from to . This is achieved using a novel subroutine for approximating the norm of a linear combination of stabilizer states. The subroutine has runtime , where is the number of terms in the linear combination, is the number of qubits, and is the relative error. We expect that this subroutine may find applications in other contexts. We achieve a further speedup compared with Ref. [15] by reducing the scaling to by developing techniques for approximate stabilizer decompositions of . Although in general the simulation algorithm based on approximate stabilizer decomposition cannot accurately compute individual probabilities of the output distribution, we show that it can be used for sampling from the output distribution with a small statistical error.
III Stabilizer formalism
Before moving further, let us state some facts concerning stabilizer groups and stabilizer states. Let be the -qubit Pauli group. Any element of has the form , where each factor is either the identity or a single-qubit Pauli operator and . An abelian subgroup is called a stabilizer group if . Each stabilizer group has the form for some generating set of pairwise commuting self-adjoint Pauli operators such that . The integer is called the dimension of and is denoted . A state is said to be stabilized by if for all . States stabilized by span a “codespace” of dimension . A projector onto a codespace has the form
| (7) |
A pure -qubit state is a stabilizer state iff for some Clifford unitary . Any stabilizer state is uniquely defined (up to the overall phase) by a stabilizer group of dimension such that is the only state stabilized by . Let be the set of all -qubit stabilizer states. This set is known to be a -design [17], that is,
| (8) |
where the integral is with respect to the Haar measure on the set of all normalized -qubit states .
Throughout the paper we assume that stabilizer states are represented in a certain standard form defined in Appendix B. In this representation, three basic tasks can be performed efficiently. First, one can compute the inner product between stabilizer states [3, 18, 15]. More precisely, consider stabilizer states . Then for some , integer and that can be computed in time , see Ref. [15]. Pseudocode for computing the inner product can be found in Appendix C. Secondly, a projection of any stabilizer state onto the codespace of any stabilizer code is a stabilizer state which is easy to compute. More precisely, suppose is a stabilizer group and . Then for some , some integer , and stabilizer state . One can compute in time as explained in Appendix E. Recall that . Finally, one can generate a random stabilizer state drawn from the uniform distribution on in time , see Appendix D.
IV Classical simulation algorithms
First consider the task of approximating the output probability . The algorithm described below consists of two stages with runtimes
and
The first stage computes a stabilizer group and an integer such that
| (9) |
We begin by replacing each -gate in the original circuit by the well-known gadget [19] shown in Fig. 2. The gadget implements the -gate by performing Clifford gates CNOT, , and a -measurement. Each measurement outcome appears with the probability . The gate is applied only if the outcome is ’1’. The gadget also consumes one copy of the magic state which is destroyed in the process.
Suppose we postselect the outcome ’0’ in each gadget, i.e. replace each measurement by a projector . This removes the classically controlled -gates such that each gadget adds a single CNOT to the original circuit . Let be the modified version of . By definition, acts on qubits and contains Clifford gates. Let us agree that the ancillary qubits initialized in the magic state are appended at the end of computational qubits such that the circuit acts on the initial state . Combining the final measurement projector with the projectors acting on the ancillary qubits gives a projector
acting on qubits such that
| (10) |
Here we noted that the postselection probability is . Obviously, for a stabilizer group of dimension . Namely, let be the -th qubit of . Generators of are for and for . Since the conjugation by maps Pauli operators to Pauli operators, we get , where is a stabilizer group of dimension generated by with . Assuming that the action of a single Clifford gate on a Pauli operator can be computed in time , one can compute each generator in time . Accordingly, can be computed in time .
Let be the subgroup of that includes all Pauli operators which act as or on each of the first qubits. Let . A generating set can be computed in time using standard linear algebra. We get
| (11) |
since . Define -qubit Pauli operators , . These operators pairwise commute since is abelian and commute with each other on the first qubits. If then there exists with and therefore
in which case and we are done. Let us now consider the case . In this case let be the stabilizer group generated by and . One can check the condition and compute in time . Without loss of generality, . Noting that must contain elements acting trivially on the last qubits yields . This proves Eq. (9) with and the stabilizer group defined above. Combining all the steps needed to compute gives the promised runtime .
The second stage of the algorithm computes the expectation value in Eq. (9) by decomposing into a linear combination of stabilizer states. Suppose
| (12) |
for some stabilizer states and some coefficients . For each compute , an integer and a stabilizer state such that
see Appendix E for details. As stated above, this computation takes time . Introducing new coefficients and using Eqs. (9,12) one gets
| (13) |
Here are -qubit stabilizer states. Below we describe a randomized algorithm that takes as input a -qubit state , a target error parameter and a failure probability . The algorithm computes a real number which, with probability at least , approximates the norm of with relative error . The running time of the algorithm is . The key idea is to approximate by computing inner products between and randomly chosen stabilizer states.
We shall first consider the special case where the failure probability is ; at the end we describe how to reduce it to a given value . Let be a random stabilizer state drawn from the uniform distribution. Define expectation values
Using Eq. (8) one can compute and by pretending that is drawn from the Haar measure. Standard formulas for the integrals over the unit sphere yield
| (14) |
Suppose are random independent stabilizer states. Define a random variable
| (15) |
From Eq. (14) one infers that the expected value of is and the standard deviation of is
For large one has . By the Chebyshev inequality, . Thus
| (16) |
with probability at least provided that .
Now let us discuss how to reduce the failure probability (from ) so that it is below a given value . To achieve this, we compute independent estimates using the above procedure and output the median of these values. It is a simple fact that this procedure reduces the failure probability to below using only estimates (see Lemma 6.1 of Ref. [20]). With this choice, the probability that Eq. (16) holds with replaced by is at least .
The inner product in Eq. (15) can be computed in time since and are stabilizer states of qubits. It follows that can be approximated in time , as promised.
Since the runtime grows linearly with , we would like to choose a stabilizer decomposition in Eq. (12) with a small rank . Clearly, the optimal choice is , where is the stabilizer rank defined in the introduction. Unfortunately, the exact value of is unknown. Using the identity
| (17) |
one can see that is a linear combination of two stabilizer states, that is, . By dividing qubits into pairs and applying the decomposition Eq. (17) to each pair one gets . The results of [15] give a slightly better bound with . This completes the analysis of the first algorithm.
Remark 1: If has a small dimension, namely, , it can be easier to compute directly from Eqs. (7,9) which yield . Clearly, each term in the sum can be computed in time , so the overall runtime becomes .
Remark 2: An alternative strategy to estimate the expectation value in Eq. (9) is to compute the inner products
for . Here are the stabilizer states defined in Eq. (12) and are random stabilizer states. The same arguments as above show that
This may be beneficial in the regime since one has to compute the action of only times rather than times.
Let us now describe the algorithm that allows one to sample from the distribution with statistical error . As before, we replace each -gate in the original circuit by the gadget shown on Fig. 2, prepare all magic states at the very first time step, and permute the qubits such that the initial state is . Let be the outcome of the measurement performed in the -th gadget and . Let be the Clifford circuit on qubits corresponding to measurement outcomes . Each gadget with contributes a CNOT gate to , whereas each gadget with contributes a CNOT and the -gate to . Thus contains gates. A composition of all gadgets and Clifford gates of implements a trace preserving completely positive (TPCP) map
Here is the -qubit identity operator and the sum runs over all -bit strings . Suppose first that is applied to a state . Then the final state of the computational qubits is regardless of and each appears with probability . Thus
| (18) |
Next suppose that is applied to a state , where is a linear combination of stabilizer states that approximates with a small error:
| (19) |
Here are some coefficients and we assume has unit norm. The error is sufficient to ensure that the output distribution of the overall simulation algorithm is -close to . From Eq. (19) one gets
| (20) |
By definition of ,
| (21) |
where
| (22) |
and are normalized -qubit states defined by
| (23) |
Clearly, is a normalized probability distribution on the set of -bit strings. The state is defined only for . Combining Eqs. (18,20,21) and tracing out the last qubits of and one infers that
| (24) |
Here we noted that TPCP maps do not increase the trace distance. Combining Eqs. (18,20,21) and tracing out the first qubits of and shows that the distribution satisfies , where is the uniform distribution on the set of -bit strings. Using this fact and Eq. (24) we arrive at
| (25) |
For each -bit string define a probability distribution . Below we give an algorithm which takes as input and and produces a sample from a distribution which satisfies
| (26) |
Our algorithm to approximately sample from has two steps. We first generate a random uniformly distributed -bit string and then we sample from . From Eqs. (25,26) we see that the distribution over outputs produced by this algorithm approximates within error in the trace norm.
We are now ready to describe how to sample from satisfying Eq. (26). We first describe how to compute an approximation to with relative error . Note that
| (27) |
Here we used Eqs. (22,23). Repeating the same arguments as in the derivation of Eq. (9) one gets
| (28) |
for some stabilizer groups and integers that can be computed in time . We already know a randomized algorithm which computes and with a relative error in time . Recall that is the probability that the algorithm does not achieve the desired approximation. Thus we can compute with a relative error in time .
Now consider the task of sampling from . Assume for simplicity that . For each define conditional probabilities
| (29) |
where . Suppose the bits have already been sampled (initially ). Then the next bit can be sampled by tossing a coin with bias . Things are complicated by the fact that we cannot exactly compute this conditional probability. We use the same simulation strategy except that at each step the conditional probability is replaced by an approximation . Here we require that with probability at least , both and approximate the conditional probabilities and respectively with relative error . Such an approximation can be computed in time using the procedure described above for approximating the probabilities on the right-hand side of Eq. (29). Indeed, first compute which, with probability at least , approximate and respectively with relative error . If then we set while if then we set .
We now analyze the resulting simulation algorithm and show that we can ensure Eq. (26) by choosing approximation error and failure probability . Let us first suppose that all probabilities computed by the algorithm achieve the desired approximation (i.e., no failures occur). Conditioned on this event we see that the output distribution produced by the algorithm approximates with relative error . This conditional probability distribution can therefore be made -close (say) to by choosing . It remains to show that by choosing we can ensure that the output distribution of the simulation algorithm is -close to the distribution conditioned on no failures. This follows because the algorithm computes probabilities in total and choosing we can ensure that all of them are computed to within the desired approximation error , with probability at least . With this choice we have where is the distribution conditioned on no failures, and thus as claimed.
The overall running time of this algorithm is , where and .
Remark: This algorithm can be modified slightly to handle certain Clifford+ circuits which use measurement and classical control. To see how, recall that in the -gate gadget from Fig. 2, a single qubit is measured in the computational basis (yielding both outcomes with equal probability) and a Clifford operation is classically controlled on the measurement outcome. In our simulation algorithm the measurement is replaced by a uniformly chosen postselection bit . Exactly the same strategy can be used for other simple gadgets which involve measurement and classical control. For example, the Toffoli gate can be implemented as a Clifford+ circuit with only four -gates if we allow two ancillas, measurement, and classical control [13](otherwise it requires seven -gates [21, 22]). Fortunately it is possible to use the less costly circuit with four -gates in the above simulation algorithm by including one additional postselection bit per Toffoli gate.
V Approximating magic states
In this section we show how to compute a decomposition Eq. (19) with , where satisfies Eq. (4). Define a state
We note that the magic state is equivalent to modulo Clifford gates and a global phase, . Thus it suffices to construct a state
| (30) |
such that ,
| (31) |
for all sufficiently small .
Our starting point is the identity
| (32) |
where , , and
The right-hand side of Eq. (32) is a uniform superposition of non-orthogonal stabilizer states labeled by elements of the vector space . We shall construct an approximation which is a uniform superposition of states over a linear subspace of .
Let be the set of all -dimensional linear subspaces . We will fix below. For each define a state
| (33) |
where
| (34) |
Using the identity , where , and the fact that is a linear subspace one can easily check that is a normalized state, . We take our approximation from Eq. (30) to be Eq. (33) for a suitably chosen subspace , which gives an approximate decomposition of using stabilizer states. How small can we hope to make ? Using the fact that we see that
| (35) |
From this we immediately get a lower bound on . Indeed, since we will need to achieve the desired approximation. Below we describe a randomized algorithm which outputs a subspace with . Thus for constant we achieve the best possible scaling of with . We will use the following fact about random subspaces of .
Lemma 1.
Let be chosen uniformly at random. Then
| (36) |
Proof.
By linearity, we have
| (37) |
where is the indicator function of . The expectation value with respect to for a fixed is . Thus we arrive at
∎
As a corollary, there exists at least one such that . We now fix to be the unique positive integer satisfying
| (38) |
Consider a subspace chosen uniformly at random. Using Markov’s inequality and Lemma 36 we get
For a given we may compute in time . By randomly choosing subspaces we obtain one satisfying
| (39) |
with constant probability. Plugging Eq. (39) into Eq. (35) we see that
where in the second line we used Eq. (38). The state obtained in this way therefore satisfies Eq. (31) with
| (40) |
This algorithm has running time , since we must check the condition Eq. (39) for each of the randomly sampled elements of (note that the time required to sample each element is ).
Remark: One may ask whether a stronger bound on can be obtained by truncating the expansion of in some other basis of stabilizer states. For example, consider the standard -basis of qubits. The expansion of in this basis is concentrated on basis vectors with Hamming weight . The number of such basis vectors scales as , where is the binary Shannon entropy function. Thus replacing the -basis by the -basis gives a significantly worse bound on .
As noted above, taking to be a constant our construction has the best possible scaling of any decomposition of the form Eq. (33). In fact, we prove the following lower bound on the stabilizer rank of .
Lemma 2.
Consider a state , where . Suppose and . Then , where .
Proof.
First, let us show that
| (41) |
The lower bound is obvious since . We shall use induction in to show that . Consider some fixed and let for some . Suppose we measure the first qubit of in the basis. Let be the probability of getting the outcome . It is well-known that for any stabilizer state . Consider three cases.
Case 1: . Then for some and .
Case 2: . Then for some and .
We conjecture that any approximate stabilizer decomposition of that achieves a constant approximation error must use at least stabilizer states.
VI Acknowledgments
DG acknowledges funding provided by the Institute for Quantum Information and Matter, an NSF Physics Frontiers Center (NFS Grant PHY-1125565) with support of the Gordon and Betty Moore Foundation (GBMF-12500028). SB thanks Alexei Kitaev for helpful discussions and comments.
Appendix A: Quadratic forms
The remaining sections provide more details on implementation of our algorithms. Appendix A presents some basic facts about quadratic forms over finite fields and describes a subroutine for computing certain exponential sums. The standard form of stabilizer states used in all our algorithms is defined in Appendix B. Then we present algorithms for computing the inner product between stabilizer states (Appendix C), generating a random uniformly distributed stabilizer state (Appendix D), and computing the action of Pauli measurements on stabilizer states (Appendix E). The three algorithms have running time , , and respectively, where is the number of qubits. We provide pseudocode for all algorithms and report timing analysis for a MATLAB implementation. Appendix F describes simulation of the hidden shift algorithm.
Below we consider functions that map binary vectors to integers modulo eight. We define a special class of such functions that are analogous to quadratic forms over the real field. The definition of -valued quadratic forms given below was proposed to us by Kitaev [23]. Analogous definitions and computations using -valued quadratic forms can be found in [24]. For a general theory of quadratic forms over a finite field see Ref. [25]. Throughout the rest of the paper arithmetic operations are performed modulo eight (unless stated otherwise), whereas addition of binary vectors modulo two is denoted . Elements of are considered as binary row vectors. A binary inner product between vectors will be denoted . A set of binary matrices of size is denoted . A transpose of a matrix is denoted .
Recall that a subset is a called an affine space of dimension iff for some -dimensional linear subspace and a shift vector . Note that uniquely determines , namely, . The shift vector however is not uniquely defined. Obviously, .
Definition 1.
Consider an affine space . A function is called a quadratic form iff there exists a function such that
| (42) |
for all and for all .
Informally, Eq. (42) demands that a discrete analogue of the second derivative evaluated at some point does not depend on , as it is the case for quadratic forms over the real field. The next lemma states properties of the function that follow from Eq. (42).
Lemma 3.
The function defined by Eq. (42) is a symmetric bilinear form that takes values . Namely, , , , and for all .
Proof.
As a corollary, one gets for all and for all . This can be checked by choosing in Eq. (42) and using the fact that .
Suppose is some fixed basis of , is some fixed shift vector, and . Then
We shall write to avoid confusion between a point and its coordinates. Applying Eq. (42) and Lemma 3 one can describe in a basis-dependent way as
| (43) |
where ,
| (44) |
| (45) |
We shall consider as a symmetric matrix. Although Eq. (43) depends only on off-diagonal matrix elements of , it will be convenient to retain the diagonal of . Combining Eqs. (42,43) one gets
| (46) |
A connection between quadratic forms and stabilizer states is established by the following lemma.
Lemma 4.
Any -qubit stabilizer state can be uniquely written as
| (47) |
where is an affine space of dimension and is a quadratic form.
Proof.
Next let us describe how the representation of transforms under various basis changes. Suppose is an invertible matrix. Consider a basis change
| (48) |
where . The shift vector remains unchanged. Applying Eq. (43) where is chosen as the -th row of , one can easily check that the coefficients transform according to ,
| (49) |
and
| (50) |
The matrix multiplications are performed in the ring . Next consider a basis change that alters the shift vector,
| (51) |
Using Eq. (44) one can easily check that the coefficients transform according to
| (52) |
| (53) |
and .
The above rules determine the representation of in any basis of . What is the cost of computing this representation ? Clearly, all updates can be expressed as a constant number of matrix-matrix (matrix-vector) multiplications with -valued matrices of size . Thus the updates have cost in the worst case. We shall often consider basis changes Eq. (48) such that the matrix is sparse. Let be the total number of non-zeros in . Using sparse matrix-matrix multiplication one can perform all updates in Eqs. (49,50) in time . Indeed, let be the number of non-zeros in the -th row of . One can update and for any fixed in time and respectively. Thus and can be updated in time . Since the updates Eq. (53,52) require time and , the overall time is . We conclude that computing the representation of in the new basis takes time
| (54) |
In the rest of this section we show how to compute certain exponential sums associated with quadratic forms, namely,
| (55) |
where is defined by Eq. (43). Of course, the addition in Eq. (55) is over the complex field. Our algorithm takes as input the data describing and outputs . The algorithm has running time . It will be used as a subroutine for computing the inner product between two stabilizer states, see Appendix C.
It will be convenient to consider a more general sum
| (56) |
where is an affine space and is a quadratic form on . Clearly, Eq. (55) is a special case of Eq. (56). Let us say that is a canonical basis of iff the set of basis vectors can be partitioned into disjoint subsets
| (57) |
such that
| (58) |
| (59) |
Assume that is already equipped with a canonical basis and show how to compute the sum . Suppose first . By repeatedly applying Eq. (43) and using Eqs. (58,60,61) one can check that
| (62) |
where is defined by
| (63) |
Examination of Eqs. (56,62,63) reveals that the sum factorizes into a product of terms such that each term can be computed in time . Specifically,
| (64) |
where
| (65) |
Consider now the remaining case . Since , we have for some . By repeatedly applying Eq. (43) and using Eqs. (58,60,61) one can check that
| (66) | |||||
where is defined by
| (67) |
We have , where
| (68) |
Examination of Eqs. (66,67) reveals that factorizes into a product of terms such that each term can be computed in time . Specifically,
| (69) |
where
| (70) | |||||
To transform an arbitrary basis of into the canonical form we shall use a version of the Gram-Schmidt orthogonalization. It involves at most basis changes Eq. (48) with sparse matrices such that . Computing the coefficients in the canonical basis thus takes time , see Eq. (54).
Recall that . Define a subset
If is non-empty, pick an arbitrary element . Perform a basis change for each . From Eq. (49) one gets for all and for all . Set . Now we can assume that for all for some subset such that . From Eq. (46) we infer
| (71) |
Let us say that a pair of basis vectors with is a dimer if it obeys Eq. (61), that is, and for all . Note that a basis vector can belong to at most one dimer. Let us say that a basis vector with is a monomer if it obeys Eq. (60), that is, for all . Partition the set of basis vectors into four disjoint sets,
| (72) |
such that is the union of all dimers, is the union of all monomers, and is the complement of . By definition, a basis has a canonical form iff is empty. Initially , are empty, and is the complement of . Suppose is non-empty. Pick any . If for all , move from to . Otherwise for some . Let us define a binary matrix corresponding to such that if and otherwise. Perform a basis change
| (73) |
Using Eq. (71) one can check that the new basis vectors obey for all . Thus we can move from to by creating a new dimer in Eq. (57). By repeating the above steps at most times one makes . Furthermore, the matrices corresponding to the basis change Eq. (73) are sparse since any row of contains at most three non-zero elements. Thus the original basis is transformed into the canonical form by basis changes Eq. (48) with sparse matrices such that . This has cost . We summarize the algorithm below.
function ExponentialSum() if then Pick any for do end for Update using Eqs. (49,50) end if Now for all while do Pick any if then Found a new monomer else Pick any for do end for Update using Eqs. (49,50) Now form a new dimer , end if end while if then Compute from Eq. (64) else Compute from Eq. (69) Set end if end function
Comments: The basis vectors only serve a notational purpose to describe the basis change matrix that must be used in the update formulas Eqs. (49,50). There are no actual data representing or operations performed with them. For example, the first for loop corresponds to a matrix , where is the binary vector with a single ‘’ at the -th position. As was shown in Ref. [15], the sum can be represented by a triple of integers , , and such that . Our implementation of the algorithm uses such representation for all intermediate sums to avoid roundoff errors. Timing analysis for a MATLAB implementation is reported in Table 1.
Appendix B: Standard form of stabilizer states
Suppose is a stabilizer state of qubits defined in Eq. (47). An affine space of dimension will be represented by a tuple
such that is spanned by the first rows of the matrix and , that is,
| (74) |
We shall write and for the -th row of and respectively. Thus and for . We shall refer to and as the primal and the dual basis vectors.
A quadratic form will be specified by a list of coefficients that describe in the basis of , see Eqs. (43,44,45), with the shift vector . Thus, a stabilizer state of qubits is described by the following data:
where , , and is a symmetric such that for all . A valid data must satisfy conditions Eq. (74) and Eq. (46).
We shall often use a subroutine that alters a stabilizer state by shrinking the affine space reducing its dimension by one. Namely, consider a vector and . Define
| (75) |
Clearly, is an affine space which is either empty, or , or has dimension . Below we describe an algorithm that takes as input a stabilizer state and computes the standard form of the state (or reports that is empty). Here it is understood that the form is restricted onto . The algorithm has runtime . First we note that
where . Let
One can compute in time . If and then is empty. If and then . Otherwise pick any element and remove from . Change the basis of according to
Change the dual basis according to
Now for all . The basis change requires time . Let us also swap the -th and the -th basis vectors. Updating the coefficients using Eqs. (49,50) takes time . Now basis vectors are orthogonal to and . Thus
where is the new shift vector. Update the coefficients using Eqs. (52,53), where . This takes time . Now restricting the form onto is equivalent to removing the -th row/column from the matrix and removing the -th element from . We obtained the standard form of the state . The entire algorithm is summarized below.
function Shrink() if and then return EMPTY end if if and then return SAME end if Pick any for do Update using Eqs. (49,50) end for Swap and . Swap and . Update using Eqs. (49,50) Update using Eqs. (52,53) Remove the -th row/column from Remove the -th element from return SUCCESS end function
To simplify notations, here we assume that the function SHRINK modifies the data describing the input state. The function reports whether the new affine space is empty or the same as the initial space. It reports SUCESS whenever the dimension of the affine space has been reduced by one. The function has runtime . Sometimes we shall use a “lazy” version of the function that does not update the coefficients of . We shall use the notation SHRINK∗ for such lazy version.
Appendix C: The inner product
Consider a pair of -qubit stabilizer states
with the standard forms . Below we describe an algorithm that computes the inner product
| (76) |
in time . First we note that iff
Thus iff is orthogonal to all dual basis vectors with . Here and below and denote the -th row of and respectively. Thus
One can compute the standard form of by calls to the function SHRINK defined in Appendix B with and for . This takes time
since we have to call SHRINK times.
Let be the standard form of and be the coefficients of restricted onto in the basis (as usual, is the -th row of ).
The next step so the compute coefficients of the form restricted to in the basis with the shift vector . We note that
One can compute in time and then compute the updated coefficients from Eqs. (52,53). This takes time . A simple algebra shows that , that is, for all . Define a matrix of size such that
Using the dual basis of one gets . One can compute the entire matrix in time . Then the coefficients in the basis can be computed from Eqs. (49,50) which takes time , see Eq. (54). (Here we used a slightly stronger version of Eq. (54) taking into account that is a rectangular matrix.) The runtime up to this point is
Now the restrictions of both forms onto are defined in the same basis and the same shift vector . Thus has coefficients , where , , and . We get
where is the exponential sum Eq. (55) that can be computed in time , see Appendix A. The overall running time is thus
We summarize the entire inner product algorithm below.
function InnerProduct() for to do SHRINK if EMPTY then return end if end for Now for to do for to do end for end for Update using Eqs. (52,53) with Update using Eqs. (49,50) with Now , are defined in the same basis return ExponentialSum end function
Comments: As before, we assume that the output is converted to a triple of integers such that . If both and are small, one can compute the intersection directly by solving a linear system
with variables and equations. This provides a shift vector and a basis for in time . Then one can compute the updated coefficients of and in the new basis in time . Thus the overall running time is
| (77) |
which is linear in provided that both . We note however that the vast majority of stabilizer states have , see Appendix D, so the above method provides no speedup in the generic case.
The timing analysis of the function InnerProduct reported in Table 1 was performed for inner products , where is drawn from the uniform distribution (as described in Appendix D), is a random uniformly distributed string, and , where and . This choice is justified since our simulation algorithm only requires inner products of the above form.
Appendix D: Random stabilizer states
Let us now describe an algorithm that generates a random uniformly distributed stabilizer state . The algorithm has average-case runtime and the worst-case runtime .
For each define a subset of stabilizer states
For example, includes all basis vectors, whereas includes stabilizer states supported on all basis vectors. Our algorithm first picks a random integer drawn from a distribution
| (78) |
and generates a random subspace of dimension . To compute we need the following fact.
Lemma 5.
| (79) |
for any and .
Proof.
Let . The number of -dimensional linear subspaces is known to be
For a given there are affine spaces such that for some shift vector . Finally, for a given affine space there are
quadratic forms . Here the three factors represent the number of choices for the coefficients in Eqs. (43,44,45) respectively (recall that the diagonal of is determined by , see Eq. (46)). It follows that , which gives Eq. (79). ∎
One can rewrite Eq. (78) as
| (80) |
where and
for . One can compute a lookup table for the function offline since it depends only on . Clearly, with high probability. Thus, the average-case online complexity of sampling from the distribution is .
We start by choosing the zero shift vector such that is a random linear space of dimension . We shall generate by repeatedly picking a random matrix until has rank and then choosing . It is well-known that has rank with probability
Note that is exponentially close to whenever . Thus has full rank after attempts with high probability. Furthermore, one can compute the rank of in time using the Gaussian elimination by bringing into the row echelon form. It is also well-known that conditioned on having full rank, the subspace is distributed uniformly on the set of all subspaces of of dimension . Thus we can choose .
The next step is computing matrices and such that is spanned by the first rows of and . Let us first set and . Choose a zero quadratic form for all . Let be the -th row of the matrix . One can make orthogonal to by making calls to the function SHRINK defined in Appendix B. (Recall that SHRINK∗ does not update the coefficients of .) Finally we shift by a random uniformly distributed vector . At this point is a random affine space represented in the standard form. It remains to choose random coefficients of the quadratic form in the basis . Since must be distributed uniformly on the set of all quadratic forms , we must choose , , and for as random uniform elements of the respective sets. Then the entire matrix is determined by and , see Eq. (46). The entire algorithm is summarized below.
function RandomStabilizerState() Compute from Eq. (80) Sample from repeat Pick random until , , Now is full binary space all-zeros function on for to do -th row of SHRINK end for Now has the standard form Pick random Pick random Pick random Pick random for Set return end function
Each call to SHRINK takes time , see Appendix B, whereas each computation of takes time . Thus the entire algorithm takes time . Since with high probability, see above, the average runtime is , whereas the worst-case runtime is . Timing analysis for a MATLAB implementation is reported in Table 1.
Appendix E: Pauli measurements
Suppose is a stabilizer state of qubits represented in the standard form and is a Pauli operator. Define an operator
It is well-known that maps stabilizer states to (unnormalized) stabilizer states. Note that is a projector if is self-adjoint and is a unitary Clifford operator if . Below we describe an algorithm that computes the normalization and the standard form of the state . The algorithm has runtime . We shall be mostly interested in the case when is a projector (although our algorithm applies to the general case). Note that a projector onto the codespace of any stabilizer code with a stabilizer group can be written as a product of at most projectors associated with some set of generators of . Thus a projected state can be computed in time using the above algorithm.
Let be the standard form of and
| (81) |
We shall consider two cases depending on whether or not . This inclusion can be checked in time by computing inner products with . Namely, iff .
Case 1: . Define a function
| (82) |
By definition of a quadratic form one has
| (83) |
The state can be written as
| (84) |
Perform a change of variable with . Using Eq. (83) one can rewrite the above state as
| (85) |
with
| (86) |
and
| (87) |
Let us first compute . We have
| (88) |
The decomposition Eq. (88) can be computed in time . Once the coefficients are known, one can compute from
| (89) |
This takes time .
Suppose first that . Then and thus
We get
| (90) |
where
| (91) |
Let us choose a vector such that for all . We shall look for
| (92) |
Choosing and using one gets
| (93) |
To compute and consider expansions Eq. (88) and
| (94) |
One can compute all the coefficients in time . The fact that is a bilinear form implies
| (95) |
Thus can be computed in time . Let with . We arrived at
The standard form of the state defined in Eq. (90) can be computed by calling the function SHRINK, see Appendix B, which takes time .
Next suppose that . Then and thus
We shall choose a quadratic form such that
| (96) |
Define
| (97) |
Then the state in Eq. (85) can be written as
| (98) |
with a quadratic form
| (99) |
To get the standard form of we need to choose satisfying Eq. (96) and compute the coefficients of in the basis of . First, let us compute the basis-dependent representation of . Suppose and let . Substituting Eqs. (88,94) into Eq. (87) one gets
where are defined by Eq. (95). For any one has the following identity:
Choose such that . Then a function satisfying Eq. (96) has a basis-dependent representation , that is,
| (100) |
To summarize, the coefficients of the form in the basis are , where
| (101) |
and
| (102) |
This determines the standard form of .
Case 2: . Then for any and thus the states and are supported on disjoint subsets of basis vectors. Define an affine space of dimension , where is spanned by and . We equip with a basis , where . Then any vector can be written in a basis-dependent way as
Let . A simple algebra shows that
| (103) |
where is a quadratic form defined by
| (104) |
Here it is understood that depends only on the first coordinates of . Thus the coefficients of in the chosen basis of are , , and
| (105) |
Here is a row vector.
It remains to compute the standard form of . Below we define a function EXTEND that takes as input an affine space and a vector . If , the function does nothing. Otherwise, the function outputs an affine space such that the first rows of and are the same and the -th row of equals . Since the function EXTEND is very similar to the function SHRINK defined in Appendix B, we just state the algorithm skipping the analysis.
function =Extend() if then return end if Pick any for do end for Now Swap and . Swap and . return end function
It has runtime . We do not have to update the coefficients of since Eq. (104) defines in the basis which coincides with the new basis of . We conclude that the projected state can be computed in time .
Below we summarize the entire algorithm as a function MeasurePauli that takes as input a stabilizer state and a Pauli operator . The function returns the norm of the projected state . If , the function computes the standard form of the projected state . As before, we assume that the function can modify the data describing the input state.
function =MeasurePauli() for to do , end for Compute using Eq. (89) if and then Compute using Eq. (95) SHRINK if EMPTY then return end if if SAME then return end if if SUCCESS then return end if end if if and then Compute using Eqs. (101,102) return end if if then EXTEND , where is defined in Eq. (105) return end if end function
| Number of qubits | ||||||
|---|---|---|---|---|---|---|
| MeasurePauli | ||||||
| RandomStabilizerState | ||||||
| InnerProduct | ||||||
| ExponentialSum |
Appendix F: Simulation of the hidden shift algorithm
Here we provide further details of the simulations reported in Fig. 1. Recall that we simulate a circuit
| (106) |
where and are oracle circuits for some bent functions such that
| (107) |
Here is the hidden shift that can be found from . In our simulations the hidden shift was chosen at random from the uniform distribution. The function was chosen from (a subclass of) the Maiorana McFarland family of bent functions. In general, a Maiorana McFarland bent function is defined as follows. Suppose is even. Let
be any Boolean function and any permutation respectively. For any such pair we may define a bent function according to
| (108) |
The Hadamard transform of is given by
| (109) |
In our simulations we only used bent functions of the form Eq. (108) with (the identity permutation). The Boolean function was chosen at random, as explained below. Letting be the -qubit diagonal unitary
we see that a quantum circuit which implements the -qubit unitary oracle can be decomposed as
where is the two-qubit controlled- gate. Here the tensor product separates the first qubits from the last . Likewise, from Eqs. (107,109) one infers that
Note that the total -count of the circuit is twice the -count of . To construct a circuit implementing we chose a sequence of gates from the set , where is the controlled-controlled-Z gate. We first fixed the number of gates (five and six for the simulations reported in the left/right plots of Fig. 1 respectively), and then produced a circuit alternating the gates (on a randomly chosen triple of qubits) with random sequences of Clifford gates from the set . Note that the gate can be replaced by the Toffoli gate using the identity
| (110) |
To decompose Toffoli gates into Clifford and -gates we used a gadget proposed by Jones [13], see Fig. 3. The gadget uses four -gates, two ancillary qubits initialized in the state , several Clifford gates, and the -measurement. The final Clifford gate is classically controlled by the measurement outcome. To simulate the gadget we use the trick described in the remark between Eqs. (29, 30). Namely, in our simulation the measurement of the ancillary qubit is replaced by postselection on a random output bit in exactly the same way as was done for the -gate gadget. The second ancilla in the gadget is never measured and is returned to the state at the output; this ancilla is reused by all Toffolis in the circuit.
The simulation algorithm we implemented differs in some small details from the algorithm analyzed in the main text of the paper. To produce each data point in Fig. 1 we first fixed the output qubit . We then estimated the ratio (cf. Eq. (27))
| (111) |
for a randomly chosen postselection bit-string . For us where is the number of qubits in the original circuit to be simulated while is the number of ancillae initialized in the state which are used for the Toffoli gadgets. Since each Toffoli gadget requires two ancilla, one of which is shared by all of them, we have where is the number of Toffoli gadgets used. In Eq. (111) the number of postselection bits is where is the number of -gates in the circuit (including the four -gates within each Toffoli gadget). The unitary is a -qubit Clifford unitary which is obtained by replacing all Toffoli gadgets and gate gadgets by the appropriate Clifford circuits obtained by postselecting on the measurement outcomes defined by the bit string . Finally, the state in Eq. (111) is a -qubit state which approximates copies of the magic state . In particular, was derived from a -dimensional subspace of in the manner described in the main text of the paper. In our simulations we used (left plot in Fig. 1) and (right plot in Fig. 1). The fidelities were and respectively.
To estimate we computed integers and stabilizer groups such that
| (112) |
and
| (113) |
and then, if and , we computed approximations to the quantities Eqs. (113,112) using the norm estimation procedure described in the main text. The number of random stabilizer states sampled by the norm estimation procedure was chosen to be (left plot in Fig. 1) or (right plot in Fig. 1). Our estimate of was then (cf. Eq. (111)). Note that if either or then , and can be computed without ever calling the norm estimation subroutine. This special case occured for all qubits in both our simulations (as well as for some of the other data points).
References
- [1] D. Wecker and K. M. Svore, preprint arXiv:1402.4467 (2014).
- [2] D. Gottesman, preprint quant-ph/9807006 (1998).
- [3] S. Aaronson and D. Gottesman, Phys. Rev. A 70, 052328 (2004).
- [4] I. Markov and Y. Shi, SIAM J. on Comp. 38, 963 (2008).
- [5] M. Van den Nest, Quant. Inf. Comp. 10, 0258 (2010).
- [6] H. Pashayan, J. Wallman, and S. Bartlett, preprint arXiv:1503.07525 (2015).
- [7] S. Bravyi and A. Kitaev, preprint quant-ph/9811052 (1998).
- [8] A. Fowler, M. Mariantoni, J. M. Martinis, and A. N. Cleland, Phys. Rev. A 86, 032324 (2012).
- [9] V. Kliuchnikov, D. Maslov, and M. Mosca, Quant. Inf. and Comp. 13, 607 (2013).
- [10] P. Selinger, Quant. Inf. and Comp. 15, 159 (2015).
- [11] N. J. Ross and P. Selinger, preprint arXiv:1403.2975 (2014).
- [12] A. Fowler, S. Devitt, and C. Jones, Scientific Reports 3, 1939 (2013).
- [13] C. Jones, Physical Review A 87, 022328 (2013).
- [14] Note1, The MATLAB implementation of the sampling algorithm is available upon request to the authors.
- [15] S. Bravyi, G. Smith, and J. Smolin, preprint arXiv:1506.01396 (2015).
- [16] M. Rötteler, in Proceedings of the 21st ACM-SIAM Symposium on Discrete Algorithms (2010), pp. 448–457.
- [17] C. Dankert, R. Cleve, J. Emerson, and E. Livine, Phys. Rev. A 80, 012304 (2009).
- [18] H. J. García, I. Markov, and A. Cross, Quant. Inf. and Comp. 14, 683 (2014).
- [19] X. Zhou, D. W. Leung, and I. L. Chuang, Phys. Rev. A 62, 052316 (2000).
- [20] M. R. Jerrum, L. G. Valiant, and V. V. Vazirani, Theoretical Computer Science 43, 169 (1986).
- [21] M. Amy, D. Maslov, M. Mosca, and M. Roetteler, Computer-Aided Design of Integrated Circuits and Systems, IEEE Transactions on 32, 818 (2013), eprint 1206.0758.
- [22] D. Gosset, V. Kliuchnikov, M. Mosca, and V. Russo, Quant. Inf. and Comp. 14, 1261 (2014).
- [23] A. Kitaev, private communication (2003).
- [24] K.-U. Schmidt, Information Theory, IEEE Transactions on 55, 5803 (2009).
- [25] M. Araújo (2011), URL http://www.math.ist.utl.pt/~ggranja/manuel.pdf.
- [26] J. Dehaene and B. De Moor, Phys. Rev. A 68, 042318 (2003).
- [27] H. García-Ramírez, Ph.D. thesis, The University of Michigan (2014).