A (quasi-)polynomial time heuristic algorithm for synthesizing T-depth optimal circuits

We investigate the problem of synthesizing T-depth optimal quantum circuits for exactly implementable unitaries over the Clifford+T gate set. We construct a subset, Vn\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$${{\mathbb{V}}}_{n}$$\end{document}, of T-depth 1 unitaries. T-depth-optimal decomposition of unitary U is eiϕ∏iViC\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$${e}^{i\phi }\left({\prod }_{i}{V}_{i}\right)C$$\end{document}, Vi∈Vn\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$${V}_{i}\in {{\mathbb{V}}}_{n}$$\end{document}, C is Clifford and ∣Vn∣≤n⋅25.6n\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$| {{\mathbb{V}}}_{n}| \,\le \,n\cdot {2}^{5.6n}$$\end{document}. We use nested meet-in-the-middle technique to synthesize provably depth-optimal and T-depth-optimal circuits. For the latter, we achieve space and time complexity O((4n2)⌈d/c⌉)\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$O({({4}^{{n}^{2}})}^{\lceil d/c\rceil })$$\end{document} and O((4n2)(c−1)⌈d/c⌉)\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$O({({4}^{{n}^{2}})}^{(c-1)\lceil d/c\rceil })$$\end{document} respectively (d is the minimum T-depth, c ≥ 2 a constant). The previous best algorithm had complexity O((3n⋅2kn2)⌈d2⌉⋅2kn2)\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$O({({3}^{n}\cdot {2}^{k{n}^{2}})}^{\lceil \frac{d}{2}\rceil }\cdot {2}^{k{n}^{2}})$$\end{document}(k > 2.5 a constant). We design a more efficient algorithm with space and time complexity poly(n, 25.6n, d) (or poly(nlogn,25.6n,d)\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$${{{\rm{poly}}}}({n}^{\log n},{2}^{5.6n},d)$$\end{document} with weaker assumptions). The claimed efficiency, optimality depends on conjectures.


Introduction
The notion of a quantum computer was introduced by Feynman [1] as a solution to the limitations of conventional or classical computers.In numerous fields algorithms designed for quantum computers outperform their classical counterparts.Some examples include integer factorization [2,3], searching an unstructured solution space [4].One of the most widely used methods for describing and implementing quantum algorithms is quantum circuits, which consists of a series of elementary operations dictated by the implementing technologies.
Circuit synthesis and optimization is a significant part of any computer compilation process whose primary goal is to translate from a human readable input (programming language) into instructions that can be executed directly on a hardware.In quantum circuit synthesis the aim is to decompose an arbitrary unitary operation into a sequence of gates from a universal set, which usually consists of Clifford group gates and at least one more non-Clifford gate [5].The non-Clifford gates are more expensive to implement fault-tolerantly than Clifford gates.A popular universal fault-tolerant gate set is the "Clifford+T", in which the cost of fault tolerant implementation of the T gate [6,7,8] exceeds the cost of the Clifford group gates by as much as a factor of hundred or more in most error correction schemes.Fault tolerant designs and quantum error correction are essential in order to deal with errors due to noise on quantum information, faulty quantum gates, faulty quantum state preparation and faulty measurements.In particular, for long computations, where the number of operations in the computation vastly exceeds the number of operations one could hope to execute before errors make negligible the likelihood of obtaining a useful answer, faulttolerant quantum error correction is the only known way to reliably implement the computation.
With recent advances in quantum information processing technologies [9,10,11,12] and faulttolerant thresholds [13,7,14], as scalable quantum computation is becoming more and more viable we need efficient automated design tools targeting fault-tolerant quantum computers.And minimization of the number of T gates in quantum circuits remain an important and widely studied goal.It has been argued [15,16,17,18,19] that it is also important to reduce the maximum number of T gates in any circuit path.While the former metric is referred to as the T-count, the latter is called the T-depth of the circuit.
An n-qubit quantum circuit consisting of Clifford+T gates implements a 2 n × 2 n unitary.In the context of reducing resources (such as T gates) necessary to implement a unitary U , two types of problems have been investigated -(a) synthesis and (b) re-synthesis.The input to an algorithm for a quantum circuit synthesis problem is a 2 n ×2 n unitary matrix and the goal is to output a circuit implementing it [20,21].When we impose additional constraints like minimizing certain resources such as T-count or T-depth [16], we often call this as (resource)-optimal synthesis problem.From here on, we focus on the T-depth as the resource being minimized.To be more precise, there can be more than one (equivalent) circuits implementing U .A T-depth-optimal synthesis algorithm is required to output a circuit with the minimum T-depth.We call this a T-depthoptimal circuit.With a slight abuse of terminology, we use the terms "synthesis algorithm" and "T-depth optimal synthesis algorithm" interchangeably, which should be clear from the context.It must be observed that with the addition of this tighter constraint on the output (i.e. that it be T-depth optimal), there is a probability that the complexity of the problems change.For example, it was known that a quantum circuit can be synthesized in poly (2 n ) time, where 2 n is the input size [20,22].The work in [23] was the first to propose a poly(2 n ) time algorithm for synthesizing T-count-optimal circuits.
With an input size O(2 n ), we cannot hope to get an optimal synthesis algorithm with complexity less than that.This makes these algorithms practically intractable after a certain value of n.Hence re-synthesis algorithms have been developed, where some more information is provided as input, usually a circuit implementing U [17,24] and the task is to reduce (not minimize) the T-depth in the input circuit.In the literature, nearly every re-synthesis algorithm (usually with complexity poly(n)) does not account for the complexity of generating the initial input circuit from U. This step itself has complexity O(2 n ).A full study comparing these two kinds of algorithms and quality of their results is beyond the scope of this work.
Despite their higher complexity compared to re-synthesis algorithms, the importance of studying optimal synthesis algorithms cannot be undermined.They can be used to assess the quality of a re-synthesis algorithm, for example, how close are their output to an optimal one.They can be used to generate the input circuit of a re-synthesis algorithm.A large circuit can be fragmented and the unitary of each part can be synthesized optimally, giving an overall reduction in resources.From a theoretical viewpoint, they shed light on the complexity of problems that are usually harder than their relaxed re-synthesis counterpart.As an illustration for the significance of developing resourceoptimal synthesis algorithms we observe the following.In our paper we have been able to generate T-depth-optimal circuits for standard unitaries like Toffoli, Fredkin, Peres and Quantum OR, which were not generated by the re-synthesis methods used in [16] 1 .Though this has a T-depth-optimal synthesis algorithm, they could not synthesize beyond 2 -qubit unitaries with T-depth 2. For larger unitaries like the mentioned 3-qubit ones, they used peep-hole optimization, a popular re-synthesis method.Except for the Toffoli, they obtained T-depth 4. The new approach in this paper had significantly lower complexity than the synthesis method in [16] and was able to synthesize T-depth 3 circuits.
The Solovay-Kitaev algorithm [25,20] guarantees that given a unitary U , we can generate a circuit with a universal gate set like Clifford+T, such that the unitary U ′ implemented by the circuit is at most a certain distance from U (the distance being induced by some appropriate norm).In fact it has been proved that we can get a Clifford+T circuit that exactly implements U , i.e.U ′ = U (up to some global phase) if and only if the entries of U are in the ring Z i, 1 √ 2 [21].We denote this group of unitaries by J n .For example, the Toffoli and Fredkin gates belong to J 3 .Thus quantum synthesis algorithms can be further sub-divided into two categories : (a) exact synthesis algorithms, that output a circuit implementing U ′ = U (e.g.[26,23]) and (b) approximate synthesis algorithms, that output a circuit implementing U ′ such that U ′ is close to U (e.g.[27]).
In this paper we focus on the group J n of unitaries that can be exactly synthesized and consider the following synthesis problem.MIN T-DEPTH : Given U ∈ J n synthesize a T-depth optimal circuit for it.In the decision version of this problem we are given U ∈ J n and m ∈ N, and the goal is to decide if the minimum T-depth of U is at most m.

Our results
In this paper we consider the complexity of our exact synthesis algorithms as a function of m and N = 2 n .We treat arithmetic operations on the entries of U at unit cost, and we do not account for the bit-complexity associated with specifying or manipulating them.
We first show (in Section 4.1) that the nested meet-in-the-middle (MITM) technique developed in [23] can be applied to the problem of synthesizing provably depth-optimal circuits.This gives us a depth-optimal-synthesis algorithm with time complexity min-depth of input unitary and c ≥ 2 is the extent of nesting.This gives us a space-time trade-off for MITM-related techniques applied to this problem.
Next we apply this technique to synthesize T-depth optimal circuits in Section 4.2.We work with channel representation of unitaries (described in Section 2.1).In Section 3 we define a "special" subset, V n , of T-depth-1 unitaries, which can generate a T-depth-optimal decomposition of any exactly implementable unitary (up to some Clifford).We prove |V n | ∈ O(n • 2 5.6n ).Then we give an algorithm that returns provably T-depth-optimal circuits and has time and space complexity , respectively, where d is the min-T-depth of input unitary.
This is much less than the complexity of the algorithm in [16].It had a complexity O(( 29,30], for some constant k > 2.5.In [16] the authors iteratively used C n , as indicated by the stated complexity.It took more than 4 days to generate C 3 [16].In fact, in [16] the largest circuit optimally synthesized had 2 qubits and had T-depth 2. We use much smaller sets, which has cardinality O(4 n2 ) and can be derived from V n .We can generate V 3 in a few seconds (Table 1).This gives a (rough) indication about the computational advantage one can have if algorithms are designed with such smaller sets, and thus the motivation to come up with alternate representations.
To improve the efficiency further, we develop another algorithm whose complexity depends on some conjectures that have been motivated by the polynomial complexity algorithm in [23] for synthesizing T-count optimal circuits.At this point our conjectures do not seem to be derived from the ones in [23].If our assumptions are true, then this algorithm returns T-depth-optimal circuits with space and time complexity poly(n, 2 5.6n , d).Under a weaker assumption this complexity is poly(n log n , d, 2 5.6n ).
Apart from T-depth-optimal circuit synthesis algorithms for exactly implementable unitaries, the generating set V n , has found other applications like optimal synthesis algorithms for approximately implementable unitaries [31].

Related work
The technique of meet-in-the-middle (MITM) and its variant (nested MITM) was used for exact synthesis of provably T-count optimal circuits in [26,23] as well as provably depth optimal circuits in [16].This MITM technique has also been used with deterministic walks in [32] to construct a parallel framework for the synthesis of T-count optimal circuits.The time as well as space complexity of the algorithms in [26,32] is O ((2 n ) m ) where m is the T-count 2 of the 2 n × 2 n input unitary.The time and space complexity of the algorithm in [16] where k is a constant and d is the min-T-depth.The first T-count-optimal synthesis algorithm which reduces the complexity to poly(2 n , m), assuming some conjectures, was given in [23].

Organization
We provide some necessary preliminary results and notations in Section 2. Results about T-depth have been derived in Section 3. The algorithms have been given in Section 4 and 5. Finally we conclude in Section 6.

Preliminaries
We write [K] = {1, 2, . . ., K}.We assume that a set has distinct elements.We denote the n × n identity matrix by I n or I if the dimension is clear from the context.The size of an n-qubit unitary is denoted by N = 2 n .We call the number of non-zero entries in a matrix as its Hamming weight.
We have given some preliminary definitions and facts about the Cliffords, Paulis and the group J n generated by Clifford and T gates in Appendix A. We denote the group of n-qubit Pauli operators and Clifford operators by P n and C n respectively.Parenthesized subscripts are used to indicate qubits on which an operator acts.For example, X (1) = X ⊗ I ⊗(n−1) implies that Pauli X matrix acts on the first qubit and the remaining qubits are unchanged.
The T-count of a circuit is the number of T-gates in it.The T-count of a unitary U (denoted by T (U )) is the minimum number of T-gates required to implement it.We often simply say, "T-count" instead of "T-count of a unitary".It should be clear from the context.

Channel representations
An n-qubit unitary U can be completely determined by considering its action on a Pauli P s ∈ P n : U P s U † .Since P n is a basis for the space of all Hermitian N × N matrices we can write where This defines a N 2 × N 2 matrix U with rows and columns indexed by Paulis P r , P s ∈ P n .We refer to U as the channel representation of U [26].By Hermitian conjugation each entry of the matrix U is real.The channel representation respects matrix multiplication, i.e.U V = U V .Setting V = U † and using the fact that we see that the channel representation U is unitary.If U ∈ J n , implying its entries are in the ring Z i, 1 √ 2 , then from Equation 1 the entries of U are in the same ring.Since U is real, its entries are from the subring The channel representation identifies unitaries which differ by a global phase.We write the following for the groups in which global phases are modded out.
n is a unitary matrix with one nonzero entry in each row and each column, equal to ±1.This is because Cliffords map Paulis to Paulis up to a possible phase of −1.The converse also holds : if W ∈ J n has this property then W ∈ C n .Since the definition of T-count is insensitive to global phase, it is well-defined in the channel representation and so T ( U ) is defined to be equal to T (U ).If a unitary U requires ancilla to be implemented (Theorem A.1), then we can consider the unitary that acts on the joint state space of input and ancilla qubits.From here on, with a slight abuse of notation when we write U ∈ J n we assume it is the unitary that acts on this joint state space.More details can be found in Appendix A.3.However, it is not essential for the rest of the paper.

Definition 2.1. For any non-zero
We define sde(0) = 0.For a d 1 × d 2 matrix M with entries over this ring we define sde(M ) = max sde(M ab )

T-depth
The purpose of this section is to derive a generating set consisting of T-depth 1 unitaries, such that we can write a T-depth-optimal decomposition of any exactly implementable unitary (up to global phase) as product of elements of this set and a trailing Clifford.This set must be efficiently generated and have a finite cardinality.We first give some essential definitions.
Definition 3.1.The depth of a circuit is the length of any critical path through the circuit.
Representing a circuit as a directed acyclic graph with nodes corresponding to the circuit's gates and edges corresponding to gate inputs/outputs, a critical path is a path of maximum length flowing from an input of the circuit to an output.
In other words, suppose the unitary U implemented by a circuit is written as a product U = U m U m−1 . . .U 1 such that each U i can be implemented by a circuit in which all the gates can act in parallel or simultaneously.We say U i has depth 1 and m is the depth of the circuit.We often refer to each U i as a stage or (parallel) block.The T-depth of a circuit is the number of stages (or unitaries U i ) where the T/T † gate is the only non-Clifford gate and all the T/T † gates can act in parallel.The min-T-depth or T-depth of a unitary U is the minimum T-depth of a Clifford+T circuit that implements it (up to a global phase).We often simply say "T-depth" instead of "T-depth of a unitary".It should be clear from the context.
Any unitary U , having a circuit with T-depth t can be written as follows.
In the above equation For simplicity we ignore the global phase.We can also write the above equation as follows.
We call each V j as a (parallel) block.It is a product of T or T † gates on distinct qubits, conjugated by a Clifford.Thus the following set can be regarded as a generating set (up to a Clifford) for the decomposition of an exactly implementable unitary.More precisely, any exactly implementable unitary U (ignoring global phase) can be written as a product of elements from this set and a Clifford.The number of elements from V n is equal to the T-depth of this decomposition or circuit.Any decomposition of U with the minimum number of parallel blocks is called a T-depth-optimal decomposition.A circuit implementing U with the minimum T-depth is called a T-depth-optimal circuit.We can equivalently write each V j as follows.
The R(P ) unitaries and somewhat similar unitaries called Pauli gadgets have been studied extensively in previous works like [26,33] We believe that the conclusions derived in this paper will enhance the study of these gadgets or special unitaries, such that we can have more applications (for example [31]).Also (R(P ) Thus we can write Equation 5 as follows.
The second subscript of P ij gives the index of the block.The ordering of the intermediate T/T † gates does not matter.It merely changes the sequence of R(P ij ), but we get the same product V j .Given a set S of qubits there are 3 |S| possible ways of placing a T/T † /I gate in each qubit.We call each such placement as a configuration of T gates and denote it by T S .From Equation 7we get a simple way of constructing V ′ n .
1.For each C ∈ C n do the following.
(a) For each configuration T [n] do the following.
i. V ← I.
ii.For each i ∈ [n] do the following. If From [26] we know that there are at most 4 ).Every n-length string of R(P ) does not have T-depth 1.We are over-counting a lot here.Our aim is to construct a more compact (smaller) set of T-depth 1 unitaries such that it is possible to write any T-depth 1 unitary as product of unitaries from this set and a Clifford.This is sufficient because it will enable us to write any T-depth-d decomposition (and hence T-depthoptimal decomposition) of a unitary as product of elements from this set and a Clifford (up to global phase).In this way, we can use information from a set of less number of unitaries in order to make more intelligent guesses about a T-depth-optimal decomposition (specially Section 5).We would want to prune many Cliffords to be considered at step 1.
Here we make the following observation.There are 2 O(n 2 ) Clifford operators that can map Z (i) to a particular Pauli P ∈ P n .All of them lead to the same unitary R(P ).Similarly there are many Cliffords such that when i Z (i) (where the Zs are on different qubits) is conjugated it leads to the same sequence of Paulis (ordering does not matter) i.e. it will give the same unitary i R(P i ).So for our purpose, what is more important are the mappings or rather images of mappings, and not the Clifford operators.If CP C † = P , we call it a trivial conjugation, for any P ∈ P n , C ∈ C n .P , in this case, is trivially conjugated by C.
We now construct a smaller generating set, V n .We consider each R(P ) as the starting unit of a string and then determine the remaining n − 1 units.A formal constructive definition of V n is as follows.
Definition 3.2.We define V n , a subset of n-qubit unitaries with T-depth 1, that is constructed as follows.
2. For each P ∈ ±P n \ {I}, for each q ∈ [n] and for each R ∈ {R, R † } do the following.
(a) For each Clifford C such that P = CZ (q) C † .(If P = Z (q) , we will skip this iteration for Z (q) .We will discuss later which Cliffords to consider.)i.For each configuration T [n]\{q} do the following.
A. V ← R(P ).B. For each i ∈ [n] \ {q} do the following. If Cliffords to be considered (or not considered) at step 2(a) : We have explained before that for our purpose, combinations of images obtained by conjugating Z (i) (ordering does not matter) is the most important, in order to have distinct unitaries.So we can make some choice of Cliffords to be considered (or rather, not to be considered) at step 2(a).For this, we can make some observations.
) for any C ∈ C n then it is equal to the unitary j T (j) , even if the set of indices i and j are not same.Thus we have included each R(Z (j) ) at step 1. Products of these also give T-depth 1 unitaries.In step 2(a) if P = Z (q) then we skip the iteration.In this loop we always consider those sequences of conjugations where there is at least one non-trivial mapping.So we always start with a non-trivial conjugation.

If
, where each U i has T-depth 1.So it is sufficient to consider each C i and not C.
, where a ≤ j ≤ b.Then we can decompose U = U 1 U 2 where U 1 excludes T (j) and U 2 = T (j) and each is of T-depth 1.This implies we should be concerned with the images of non-trivial conjugations.(More reason to separate the trivial conjugations at step 1.) To determine the Cliffords to be considered we follow the mappings given in [28].Consider i ∈ [n].First, we fix 2(4 n − 1)4 n Cliffords in C n that conjugate Z (i) or X (i) non-trivially.We call these coset leaders of Z (i) .The elements of C n that conjugate Z (i) and X (i) trivially, form a group isomorphic to C n−1 with the number of cosets at most 2(4 n − 1)4 n .For example, let C ∈ C n is a coset leader (of Z (i) ) such that CZ (i) C † = P where P = Z (i) , then any other Clifford that does the same conjugation (which is not a coset leader of In step 2(a) (when q = i) we consider all these coset leaders only.Suppose C is a coset leader that conjugates Z (i) to P = Z (i) .In the loop 2(a) we considered all possible sequences of R(P ) or images obtained by conjugation of Z (j) (j = i) by C. Let C ′ is non-coset leader of Z (i) and does the trivial conjugation of Z (i) .Now among all the Z (j) (j = i) where CC ′ conjugates non-trivially, it has to be the coset leader of one of them.This follows from the counting argument.So again we take all possible combinations of images obtained by conjugations by CC ′ , when the loop starts with that particular position of T/T † .
Taking product : Now suppose and there is no qubit such that a T/T † -gate is placed in both the unitaries.Let C 1 conjugates Z (j) trivially if j is a qubit in which there is a T/T † gate in U 2 .Similarly C 2 Z (i) C † 2 = Z (i) , where there is a T/T † gate on qubit i in U C † 2 = P j and C 1 P j C † 1 = P j then we do not need the commutation condition.It is straightforward to check that these conditions satisfy the 3 observations made earlier3 .Thus we can generate T-depth 1 unitaries (without trailing Clifford) by taking product of unitaries from V n .
Thus, from the above discussion we can have the following result.
Theorem 3.1.Any U ∈ J n with T-depth 1 can be written as follows : Proof.We ignore the global phase and the trailing Clifford.Let U = C i∈[n] T (i) C † (Equation 3).Let S ⊆ [n] is the set of qubits such that C conjugates Z (i) trivially, where i ∈ S. Then we can Each of these R(Z (i) ) are included in V n (step 1).So now let us consider the second term, U ′ , in the product.If C = ⊗ j C j then we can write U ′ = j C j k∈S j T (k) C † j = j U ′ j , where S j ⊆ S is the set of qubits on which C j acts.If there are no T/T † gates at any qubit of S j then C j C † j = I.Else, there exists at least one k ∈ S j such that C j conjugates Z (k) non-trivially.In step 2 of the definition of V n , we have included each such U j in our set.This proves the theorem.
In [26] it has been shown that {R(P ) : P ∈ P n } generates the T-count-optimal decomposition of any exactly implementable unitary, up to a Clifford.The channel representation inherits these decompositions and in this representation the global phase goes away.Thus we can write the following.
Proof.From Definition 3.2, for each starting R(P )/R † (P ) there can be n positions for first T/T † gate respectively.In the remaining qubits we can have T, T † or I. Thus there are at most 3 n−1 ways to place the T/T † gates in remaining (n − 1) qubits.Given a starting Clifford and a configuration, the rest of the R(P ) unitaries are uniquely determined.We have discussed that we need to consider at most 2 • 4 n • 4 n Cliffords (coset leaders, as discussed before) that can map each Z (i) to any P [28, 29,30].More precisely, there are at most 2 • 4 n • 4 n choices for the starting Clifford for each of the n positions of the starting T/T † gate, that can lead to distinct strings of R(P ) during the construction of V n .So we get the stated bounds.
In Table 1 we have compared the cardinalities and generation time of V n and C n .The latter has been used in [16] to design a T-depth-optimal-synthesis algorithm.We use the set V n for our heuristic algorithm in Section 5.In the next section we use a bigger set with cardinality O(4 n 2 ), much less than |C n | ∈ O(2 kn 2 ), where k > 2.5.This set can be derived from V n , or we can simply use V ′ n .We will see in the following sections how the cardinalities of these sets make a difference in the running time and space of the various algorithms.The following fact can be easily proved from Fact 3.2 in [23].Some more information about the properties of R(P ) and R † (P ) have been provided in Appendix A.4.This will help in computing V n faster, but it will not make much difference in the asymptotic complexity of any of our algorithms.So these are not essential for the rest of the paper.

A faster synthesis algorithm for T-depth
In this section we describe an exact synthesis algorithm that finds a circuit that is provably T-depthoptimal.We modify the algorithm by Amy et al. [16] and employ a nested meet-in-the-middle technique, as has been done by Mosca and Mukhopadhyay [23], to optimize T-count.This gives more space efficient algorithm to get optimal depth circuit.Furthermore, we work with channel representations to get T-depth-optimal circuits.This reduces both the time and space complexity compared to the algorithm in [16].

An exact algorithm for depth-optimal circuits
We first describe a general algorithm where we are given a set of gates (and their inverses), G, with which we want to design a depth optimal circuit implementing a unitary U .The set G is called the instruction set.Let V n,G be the set of n-qubit unitaries of depth 1 that can be implemented by a circuit designed with the gates in G.We state the following lemma which can be regarded as a generalization of Lemma 1 in [16].The proof has been given in Appendix B. This observation allows us to search for circuits of depth d by only generating circuits of depth at most d c (c ≥ 2).Lemma 4.1.Let S i ⊂ U (2 n ) be the set of all unitaries implementable in depth i over the gate set G. Given a unitary U , there exists a circuit over G of depth We now describe our procedure (Nested MITM), whose pseudocode has been given in Appendix C (Algorithm 1).The input consists of the unitary U , instruction set G, depth d and c ≥ 2 that indicates the extent of nesting or recursion we want in our meet-in-the-middle approach.If U is of depth at most d then the output consists of a decomposition of U into smaller depth unitaries, else the algorithm indicates that U has depth more than d.At the beginning of the algorithm we generate the set V n,G .
The algorithm consists of d c iterations and in the i th such iteration we generate circuits of depth i (S i ) by extending the circuits of depth i − 1 (S i−1 ) by one more level.Then we use these two sets to search for circuits of depth at most ci .The search is performed iteratively where in the k th (1 ≤ k ≤ c − 1) round we generate unitaries of depth at most ki by taking k unitaries We search for a unitary W ′ in S i or S i−1 such that W † U = W ′ .By Lemma 4.1 if we find such a unitary it would imply that depth of U is k ′ + i or k ′ + i − 1 respectively.In the other direction if the depth of U is either k ′ + i or k ′ + i − 1 then there should exist such a unitary W ′ in S i or S i−1 respectively.Thus if the depth of U is at most d then the algorithm terminates in one such iteration and returns a decomposition of U .This proves the correctness of this algorithm.

Time and space complexity
We impose a strict lexicographic ordering on unitaries such that a set S i can be sorted with respect to this ordering in O (|S i | log |S i |) time and we can search for an element in this set in O (log |S i |) time.An example of such an ordering is ordering two unitaries according to the first element in which they differ.Now consider the k th round of the i th iteration (steps 3-17 of Algorithm 1 in Appendix C).We build unitaries W of depth at most ki using elements from S i or S i−1 .Number of such unitaries is at most

Reducing both space and time complexity to find T-depth optimal circuits
We now consider the special case where G is the Clifford+T gate set and the goal is to design a Tdepth optimal circuit for a given unitary U .We work with the channel representation of unitaries.We generate the set V ′′ n , which consists of products of unitaries from V n and has T-depth 1.We have explained in Section 3 how to perform such products.We can even use V ′ n described in the previous section.In Section 3 we gave conditions for generating these products.Thus we replace V n,G with V ′′ n .It is easy to see that for any T-depth 1 unitary U there exists V ∈ V ′′ n such that U = V C for some Clifford C ∈ C n .This motivates us to use the following definition from [26].sde(W ) .If a < 0, or if a = 0 and b < 0, multiply every element of the column by −1.Otherwise, if a > 0, or a = 0 and b > 0, do nothing and move on to the next column.(3) After performing this step on all columns, permute the columns so that they are ordered lexicographically from left to right.

Since unitaries stored in V ′′
n are distinct, we can say that this set stores the coset labels of T-depth 1 unitaries.The following can be shown.
The nested meet-in-the-middle search for T-depth-optimal circuit is performed as described before, except for the following changes.We replace the set V n,G with the set V ′′ n (step 4 of Algorithm 1), for reasons described before.This helps us to generate coset labels of unitaries with increasing T-depth.We work with channel representations W , W 1 , W 2 , . ... So at the k th round of the i th iteration, we calculate W = k j=1 W j where W j ∈ S i or S i−1 .Then we check if Space and time complexity From Fact 3.1 we know that | V n | ≤ n • 2 5.6n and V ′′ n is formed by taking product of unitaries from V n .The most naive upper bound that we can have is , which is the bound on V ′ n discussed in Section 3. 4 Thus analysing in the same way as before we can say that the algorithm has space complexity O (4 . This is much less than the space and time complexity of the T-depth-optimal algorithm in [16].They use the MITM technique and the space and time complexity is The cardinality of the n-qubit Clifford group, C n , is O(2 kn 2 ) (k > 2.5) [28,29].So the space and 3 n⌈ d 2 ⌉ , where k > 2.5.Clearly, even if the extent of nesting is 2 i.e. c = 2, in which case our procedure becomes a MITM algorithm, we get a significant improvement in both time and space complexity.

A more efficient algorithm to synthesize T-depth optimal circuits
In this section we describe an algorithm that on input a 2 n × 2 n unitary U finds a T-depth optimal circuit for it and has space and time complexity poly(n, 2 5.6n , d) with some conjecture (or poly(n log n , d, 2 5.6n ) with a weaker conjecture), where d is the min-T-depth of U .We draw inspiration from some observations made in [23], while developing a polynomial time algorithm for synthesizing T-count-optimal circuits.We came up with another novel way of pruning the search space.The numerical results of this section (Table 2 and Table 3) are available online at https://github.com/vsoftco/t-depth.
The input of our algorithm is the channel representation of a 2 n × 2 n unitary U .From Theorem 3.1 (Section 3) we know there exists a T-depth-optimal decomposition of U as follows : dn and d is the T-depth of U .We iteratively try to guess the blocks V i by looking at the change in some "properties" of the matrix V i −1 U ′ where U ′ = i+1 j=d ′′ V j −1 U .If we have the correct sequence then we should reach C 0 , a matrix consisting of exactly one +1 or −1 in each row and column.As in [23] we consider two properties of the resultant matrices -their sde and Hamming weight.The intuition is as follows.Consider a unitary W and we multiply it by where ham(.) is the Hamming weight.Now we multiply Y by then with high probability we do not expect to see this kind of change.This helps us to distinguish the V i 's in at least one T-depth-optimal decomposition.
The pseudocode for algorithm MIN T-DEPTH has been given in Appendix C (Algorithm 3).We iteratively call the sub-procedure A( U , d ′ ) with the value d ′ ∈ Z increasing in each iteration.We accumulate all decompositions returned by A. Then in MIN T-DEPTH we check if in each such decomposition we can combine consecutive unitaries to form a T-depth 1 unitary (Section 3).We output a decomposition with the minimum T-depth.Here let us explain the starting value for d ′ .If we know that any circuit requires at least x T gates to implement U , we know that the T-depth of any circuit implementing U will be at least ⌈ x n ⌉.Thus if we know T (U ) i.e. the T-count of U we can start the iterations with d ′ = ⌈ T (U ) n ⌉.If we do not know that, we can consider sde( U ). Due to Fact 3.2 we know T (U ) ≥ sde( U ), so we can also start the iterations with d ′ = ⌈ sde( U ) n ⌉.We can also determine stopping criteria from these information.For example, if we get a decomposition with T-depth ⌈ T (U ) n ⌉, then we can stop immediately.Alternatively, we can generate the set V ′′ n , described in Section 4 and stop as soon as we get a decomposition in A.
It will be useful if we depict the procedure A using a tree (Figure 1), where each node stores a unitary.The root (depth 0) stores U .The edges are labeled by unitaries from V n −1 , which is defined as This is a set of n-qubit unitaries with T-depth 1 (refer Section 3).A child node unitary is obtained by multiplying the parent unitary with the unitary of the edge.We refer to these two types of unitaries as "node-unitary" and "edge-unitary" respectively.The product of the edge unitaries on a path from the root to a non-root node is referred to as the "path unitary" with respect to the non-root node.By "path T-count" of a non-root node we refer to the sum of the number of R(P ) terms in the edge-unitaries.Each R(P ) has one T-gate.At each depth of the tree we group the nodes into some "hypernodes" such that the path T-count of each node within a hypernode is same.At this point it will be useful to observe , where V n,j −1 is the set of unitaries with j number of R(P ) −1 .
In Figure 1 we have grouped the edges such that the edge-unitaries within one such "hyperedge" are from V n,j −1 for some j.
At each depth, within each such hypernode we sub-divide the nodes according to the sde of its unitary and change in Hamming weight of this unitary compared to the parent node-unitary.By change in Hamming weight we mean if it has increased or decreased or remains unchanged, with respect to the Hamming weight of the parent node.Within each hypernode we select the set of nodes with minimum cardinality such that sde of its unitaries can be reduced to 0 within depth d ′ of the tree.We build the nodes in the next level from the "selected" node-unitaries only.We stop building the tree as soon as we reach a node-unitary with sde 0, indicating we reached a Clifford.If we have not reached any Clifford within depth d ′ we quit and conclude that minimum T-depth of U is more than d ′ .A pseudocode of the procedure A has been given in Appendix C (Algorithm 2).The number of hypernodes in depth i can be at most ni − i + 1, since the path T-count of any unitary can be at most ni and at least i.Also, since the sde can change by at most 1 after multiplying by any R(P ) −1 (Fact 3.2), then after multiplying by any unitary in V −1 n,j sde of any unitary can change by at most j.So (at step 25 of Algorithm 2) we select the minimum sized set among those sets of unitaries which has the potential to reach the Clifford within the remaining steps. in the path from the root to each node in this hyper-node.Within each hyper-node we select some nodes according to some criteria and the nodes in the next level are built from these selected (black) nodes.
To analyse the space and time complexity of our algorithm we make the following conjecture.
Conjecture 1.(a) While dividing the nodes according to their sde and change in Hamming weight within any hypernode, the minimum cardinality of any set (such that its sde can be potentially reduced to 0) is bounded by poly(2 n ).(b) Also, we get at least one T-depth-optimal decomposition.
So our conjecture has two parts.(a) bounds the size of the tree and thus determines the complexity of the algorithm.(b) implies that we can preserve at least one T-depth-optimal decomposition by pruning in this way.So it determines the efficiency.We can make a weaker conjecture with a more relaxed bound.
Conjecture 2 (Weaker version).(b) While dividing the nodes according to their sde and change in Hamming weight within any hypernode, the minimum cardinality of any set (such that its sde can be potentially reduced to 0) is bounded by poly(n log n , 2 n ).(b) Also, we get at least one T-depthoptimal decomposition.
Comparison with Conjecture 1 in [23] In [23] the authors proposed some conjectures to reduce the complexity of synthesizing T-count-optimal circuits.Our algorithm has been motivated by that work but based on current knowledge it does not appear that Conjectures Table 2: Performance of our algorithm on some benchmark circuit unitaries.The T-depth returned by our algorithm (3rd column) is optimal for all unitaries.In most cases it is less than the Tdepth of the circuits shown in [16].We have also tabulated the T-count (4th column) of the T-depth-optimal circuits, running time (5th column) as well as the maximum number of nodes or intermediate unitaries (6th column) that accumulate at any level while running our algorithm.The running time excludes the pre-processing time to generate V 3 .
be derived from the conjecture used in [23], with the present knowledge.The main intuition of these conjectures stem from the following observation.Suppose we multiply a unitary U ′ by R(P 1 ).We will notice some change in the properties (like sde, Hamming weight) in the product unitary W ′ = U ′ R(P 1 ) compared to the initial U ′ .Now when we multiply W ′ by R(P 1 ) −1 we will see these effects reversed.But if we multiply W ′ by R(P i ) −1 (where i = 1) then with high probability we will observe some other effects.In [23] the authors used these intuitions to design a T-count-optimal algorithm, where they iteratively tried to guess a sequence of R(P )s in a T-countoptimal decomposition of U , by observing these change in properties.In our present algorithm (see Figure 1) we consider many paths with different T-counts at each level.Now the T-depth-optimal decompositions will follow some of these paths.When we select the minimum cardinality set in each hypernode (where all unitaries have same path T-count), we expect that the "distinguishing property" that we explained before does not get destroyed even if we multiply an (intermediate) unitary by up to n R(P )  we can generate the T-depth-optimal decomposition of any exactly synthesizable unitary (up to a Clifford).We prove |V n | ∈ O(n • 2 5.6n ).We adopt the nested meet-in-the-middle (MITM) technique used by Mosca and Mukhopadhyay [23] to synthesize T-count optimal circuits.First we show a space-time trade-off for the application of MITM techniques to the depth-optimal synthesis problem.To synthesize T-depth optimal circuits we further use the channel representation of unitaries and V n in the nested MITM framework.We achieve a space and time complexity exp 4 n 2 , d .The T-depth-optimal synthesis algorithm in [16] had a space and time complexity exp (3 n |C n |, d), where C n is the set of n-qubit Clifford operators (up to global phase).Since |C n | ∈ O 2 kn 2 (k > 2.5), we achieve a significant speed-up.
To increase the efficiency further we develop another algorithm that returns a T-depth-optimal decomposition with complexity poly(n, 2 5.6n , d) if some conjectures are true.Assuming a weaker conjecture this complexity is poly(n log n , 2 5.6n , d).Using this algorithm, we could synthesize Tdepth-optimal circuits of larger unitaries than in [16] in reasonable time.
Since the product states span the entire state space, we must have U ′ = V ⊗ U .So from Lemma A.1 we can calculate U ′ from U and V .
U ′ = V ⊗ U Note in many cases the ancilla remains unchanged at the end of operations i.e.V = I.From here on, with a slight abuse of notation when we write U ∈ J n we assume it is the unitary that acts on the joint state space of input and ancilla qubits.
so the k th iteration of the for loop within the i th iteration of the while loop, takes time O |V n,G | (c−1)i log |V n,G | .Thus the time taken by the algorithm is O |V n,G | (c−1)⌈ d c ⌉ log |V n,G | .In the algorithm we store unitaries of depth at most d c .So the space complexity of the algorithm is O |V n,G | ⌈ d c ⌉ .Since |V n,G | ∈ O (|G| n ), so we have an algorithm with space complexity O |G| n⌈ d c ⌉ and time complexity O n|G| n(c−1)⌈ d c ⌉ log |G| .

Definition 4 . 1 (
Coset label).Let W ∈ J n .Its coset label W (co) is the matrix obtained by the following procedure.(1) Rewrite W so that each nonzero entry has a common denominator, equal to √ 2 sde(W ) .(2) For each column of W , look at the first non-zero entry (from top to bottom) which we write as v = a+b √ 2 √ 2 such a unitary exists it would imply U = e iφ W W ′ C for some Clifford C ∈ C n .From Lemma 4.1 we can say that U can be implemented by a circuit with T-depth equal to the sum of the T-depth of the circuit for W and W ′ .

Figure 1 :
Figure 1: The tree built in A (Algorithm 2).Each node stores a unitary, the root at level 0 storing U .The edges are labeled by unitaries in V n −1 .A child node unitary is obtained by multiplying the edge unitary with the parent node unitary.The edges are grouped into hyper-edges, where each hyper-edge is labeled by a unitary in V n,j −1 .The nodes are grouped into hyper-nodes, where each hyper-node has a number indicating the number of R(P ) −1

Lemma A. 2 . 1 j=tR 1 + e i π 4 I n + 1 2 1 − e i π 4 P 1 j=tR
If U = e iφ 1 j=t R(P j ) C 0 where R ∈ {R, R † }, P j ∈ P n \ {I} and C 0 ∈ C n , thenI m ⊗ U = e iφ   (I m ⊗ P j )   (I m ⊗ C 0 ) Also R(I m ⊗ P ) = I m ⊗ R(P ) Proof.We know R(P ) = 1 2 = αI n + βP (Let).Then R(I m ⊗ P ) = α(I m ⊗ I n ) + β(I m ⊗ P ) = (I m ⊗ αI n ) + (I m ⊗ βP ) = I m ⊗ (αI n + βP ) = I m ⊗ R(P )Similarly we can show that R † (I m ⊗ P ) = I m ⊗ R † (P ).NowI m ⊗ U = e iφ m ⊗ P j )   (I m ⊗ C 0 )Thus from Lemma A.2 we get one decomposition of U ′ = I m ⊗ U and hence U ′ .U ′ = I m ⊗ U =   (I m ⊗ P j )   ( I m ⊗ C 0 )(15) it does not already exist.† } and P ∈ ±P n .Without loss of generality we can assume that every string or sequence is of length n, by filling in The time complexity of this procedure isO (|C n |) or O 2 kn 2 , where k is a constant.A bound on |V ′n | can be obtained by counting all possible distinct n-length strings of R(P ), where R ∈ {R, R

Table 1 :
Comparison of generation time of V n and C n .

Table 3 :
Performance of MIN-T-DEPTH on random circuits.For each entry in the table, we generate 10 random circuits.