Quantum circuit optimization using quantum Karnaugh map

Every quantum algorithm is represented by set of quantum circuits. Any optimization scheme for a quantum algorithm and quantum computation is very important especially in the arena of quantum computation with limited number of qubit resources. Major obstacle to this goal is the large number of elemental quantum gates to build even small quantum circuits. Here, we propose and demonstrate a general technique that significantly reduces the number of elemental gates to build quantum circuits. This is impactful for the design of quantum circuits, and we show below this could reduce the number of gates by 60% and 46% for the four- and five-qubit Toffoli gates, two key quantum circuits, respectively, as compared with simplest known decomposition. Reduced circuit complexity often goes hand-in-hand with higher efficiency and bandwidth. The quantum circuit optimization technique proposed in this work would provide a significant step forward in the optimization of quantum circuits and quantum algorithms, and has the potential for wider application in quantum computation.

In quantum information science there has been significant effort directed towards various physical implementations of quantum bits and quantum circuits [1][2][3][4][5][6][7][8][9][10][11] . The efficient design of quantum circuits for processing quantum information is a fundamental problem in quantum algorithm design and quantum computation because qubits are very expensive resources [12][13][14][15][16][17][18][19][20][21][22] . This is especially important in the regime of quantum computation with limited number of qubits [13][14][15][16][17][18][19][20][21][22] . More recent work [23][24][25][26][27][28][29][30] includes more fundamental quantum information theoretic aspects on quantum computations in relation to the previously mentioned queries. One approach to address this quantum design problem is to adapt some successful approaches that were used in the classical design of circuits. During the development of microelectronics, the separation of device technology and the systems by means of an invariant interface to simplify the design was an essential and outstanding step to cope with the complexity of the system 31 . It is almost certain that this principle of hierarchical design or a related one will also be valid for quantum architecture. Nonetheless, an equivalent invariant interface for the efficient design of quantum circuits is still lacking to the best of our knowledge. In the case of the conventional logic design there is an efficient method called the Karnaugh map 32 . However, applying this method to simplify quantum circuits is nontrivial because the representation of the quantum state evolution in Hilbert space by classical Boolean algebra through Karnaugh map is not quite straightforward 33,34 . Here, we propose a quantum mechanical version of Karnaugh map called the quantum Karnaugh map (QKM) which operates on the Hilbert space state vectors to facilitate the efficient design of universal quantum circuits. Our preliminary study shows an almost 60% and 46% reduction of the number of circuit elements for the four-and five-qubit Toffoli gates, respectively. While the representative, though non-trivial example of the Toffoli gate is simple to demonstrate the implementation of the QKM, realistic algorithm can have much more complexity and number of gates.
In classical logic gate design, the logic functions expressed by the minterm expansion can be generally simplified by utilizing theorems of Boolean algebra such as the consensus theorem:XY + X ′ Z + YZ = XY + X ′ Z 32, 35 Here X, Y , Z are Boolean variables and X ′ , Y ′ , Z ′ are their complement forms. The minterm 35 of n variables is a product of n literals in which each variable appears only once in true or complemented form, but not both. A literal is a Boolean variable or its complement. If we denote the value and the minterm of the truth table of ith row as a i and m i , the minterm expansion of logic function f is given by. ( In order to develop analogous quantum Karunaugh map (QKM), we start by recalling a controlled unitary gate C 1 (U) defined in the {|00�, |01�, |10�, |11�} basis that satisfies the following switching function properties: Here, U ij , i, j = 0, 1 are the unitary matrix elements of C 1 (U) . We found that, instead of counting the cases for the {|00�, |01�, |10�, |11�} basis separately, we obtain the same results by employing an compact 2-qubit basis 0 2 , 1 2 which are defined by.
Here, for simplicity, we denote I and O for the identity and null 2 × 2 matrices in 2-dimensional Hilbert space, respectively. In this compact 2-qubit notation, the first and the second column of 0 2 corresponds to two qubit states |00� and |01� , respectively. Likewise, the first and the second column of 1 2 corresponds to the two qubit states |10� and |11� ; respectively. One can expand C 1 (U) in the compact qubit basis as follows.
where U = u 00 u 01 u 10 u 11 . The detailed mathematical description of compact qubits and analysis of quantum circuits using QKM is given in the method section and the supplementary information (SI).

Results
Decomposition of four-and five-qubit Toffoli Gates. One can decompose the given gate in terms of single qubit gates and CNOT gates. The CNOT gate is denoted as the C 1 (X) gate in this work by substituting U by X in Eq. (2), where X is a Pauli matrix, X = (2) (4) www.nature.com/scientificreports/ Here, H is the Hadamard gate, S the phase gate and T is the π/8 gate 29 . These are the elementary single qubit gates acting on the single-qubit state. It was shown that these unitary operations on one qubit and the CNOT gate is sufficient for general quantum programming 12,37-39 . The top quantum circuit is the extension of the Toffoli gate described by the figure 4.9 of Nilsen and Chuang 38 by adding one more input qubits. The number of elementary gates to construct 4-qubit Toffoli gate C 3 (X) in the top circuits is 106 which consists of 36 CNOT gates and 70 single qubit gates. The bottom of Fig. 2 shows that the reduced gate has 11 elements which are equivalent to 16 CNOT gates and 29 single qubit gates. This is an almost 60% reduction of the number of elementary gates to implement 4-qubit Toffoli gate. Details of the 4-qubit Toffoli gate C 3 (X) reduction is given in the Section 3 of SI. The partial circuits A, B, C and D will be explored later in this section and in the SI. The first step of the reduction is replacing a half of the C 2 (X) gates by C 1 (X) gates. Here C 2 (X) gate is the 3-qubit Toffoli gate shown in Fig. S2 of SI and is described by equation (S3).
In Fig. 3, we show, by direct calculation, that the bottom circuits of Fig. 2 is indeed a four-qubit Toffoli gates in which |T out � = X|T in � if and only if C 1 = C 2 = C 3 = 1 otherwise the target bit |T in � is not changed. In order to prove that we first calculate the quantum states at points (1), (2), …, (10) marked in the bottom of the circuits in Fig. 3. We describe the changes of the target qubit at each point as: Here X α = X when α = 1 and X α = I when α = 0 . S α is defined in the same way. Furthermore X C 1 C 2 = X for C 1 C 2 = 1 and X C 1 C 2 = I for C 1 C 2 = 0(SI). Let's consider the possible combination of input qubits. When C 1 C 2 = 0 and C 3 = 0 , then HTX C3 T † X C1C2 TX C3 T † X C1C2 H = HTT † TT † H = HH = I ; When On the other hand, when C 1 C 2 = 1 and C 3 = 0 , , thus proving that the reduced quantum circuits is indeed four-qubit Toffoli gate. In Fig. 3, we also show the three QKMs for this reduced representation from the analysis we provided above. The first QKM is that of the partial circuit enclosed by blue-dashed line. The entries of the QKM are in the form of I ⊗ I ⊗ I ⊗ (·) and are obtained from the quantum states at point (9). The second QKM corresponds to the partial circuit enclosed by green-dashed line and the entries of the QKM are in the form of I ⊗ I ⊗ (•) ⊗ I and obtained from the above analysis. The final QKM is that of the four-qubit Toffoli gate C 3 (X) and is obtained by the multiplication of the first two QKMs defined by equation (S9).
In Figs. 4 and 5, we show that the first two quantum circuits shown in Fig. 2 are equivalent to C 3 (X) , by the equivalency of their QKM representations In order to achieve this, we first show that partial circuits A (enclosed by red-dashed line) and B (enclosed by blue-dashed line) of Fig. 2 have the same QKM in Fig. 4. The entries of the QKM are in the form of I ⊗ I ⊗ I ⊗ (·) . In Fig. 5, we show the QKM of a partial circuits C (enclosed by  One needs to check the QKM when you reduce the circuit in every step. Figure S7 of SI shows the fivequbit Toffoli gate constructed with the minimum number of elemental gates using this technique. If we denote χ m {C m (X)} the number of elemental gates needed to construct C m (X) gate, we obtain, χ 2 C 2 (X) = 16 , χ 3 C 3 (X) = 45 and χ 4 C 4 (X) = 115 for our QKM based technique. Until now the simplest known decomposition 13,37 of the five-qubit Toffoli gate requires 50 two-qubit gates or 250 elemental gates. Our decomposition of five-qubit Toffoli gate is 46% smaller than that of the simplest known decomposition.
It would be interesting to consider the potential application of QKM to quantum algorithms. Figure 6 shows the elementary implementation of the Deutsch algorithm 32    www.nature.com/scientificreports/ studies on IBM's 20-qubit 'Poughkeepsie' architecture, one of the authors (P. M. A.) found that a single CNOT operation can be reliably performed in this NISQ environment 40 . The comparison of the QKM reduced circuits and the conventional circuits on the real NISQ machine such as IBM-Q will be the subject of future study.

Discussion
The present results offer an efficient methodology for the design of complex quantum circuits which are the building blocks of quantum computers and quantum information processors. The lessons from the development of classical microelectronics taught us that the separation of device technology and the systems by means of an invariant interface to simplify the design is an essential and outstanding step to cope with the complexity of the system. Our hypothesis is that this principle of hierarchical design will be, in some form, valid for quantum architecture. This can begin to be impactful especially with the advent of prototype quantum computers with around 50 available qubits from IBM, Google and Intel, to name a few, where qubits are the most expensive resources. Following this motivation, we demonstrated here a ~ 60% reduction in the number of elementary gates to implement four-qubit quantum gate using the QKM. The first step of the reduction of four-qubit Toffoli gate C 3 (X) can be achieved by replacing half of the three-qubit Toffoli gates C 2 (X) embedded in a 4-qubit quantum circuit by two-qubit CNOT gates C 1 (X) , as can be seen by the Fig. 4. Further simplification can be achieved by replacing the phase shift circuit C by a 2-qubit S gate embedded in a 4-qubit quantum circuit as can be seen Fig. 2. We also demonstrated the decomposition of five-qubit Toffoli gate with 46% reduction in the number of elementary gate when compared with known simplest decomposition. We hope that the introduction of the QKM proposed in this work would lead to further development of quantum information science and engineering by separating the quantum circuit design and the device technology. The use of the QKM may help accelerate the solid-state implementation of quantum computers because the proposed scheme utilizes most of the conventional design methodology. where U = u 00 u 01 u 10 u 11 .

Method
The controlled unitary gate satisfies the following switching function properties: It is well known that we may expand any operators by outer product of the complete basis, i.e., C 1 (U) = n C 1 (U)|n��n| with n |n��n| = I n where I n is the n × n identity matrix in an n-dimensional Hilbert space and |n��n| ≡ |n� ⊗ �n| with ⊗ denoting a tensor product. Equation (7) can be rewritten as We found that instead of counting the cases for the {|00�, |01�, |10�, |11�} basis, we obtain the same results by employing a compact 2-qubit basis 0 2 , 1 2 which are defined by.
Here, for simplicity, we denote I and O for the identity and null 2 × 2 matrices in 2-dimensional Hilbert space; respectively. In this compact 2-qubit notation, the first and the second column of 0 2 corresponds to two qubit states |00� and |01� ; respectively. Likewise the first and the second column of 1 2 corresponds to the two qubit states |10� and |11� ; respectively. The compact 2-qubit is a short-hand notation representing two qubits with common first qubit index such as 0 in |00� and |01� , denoted as 0 2 . The compact 2-qubits satisfies the following closure relation:   where the first and the second column corresponds to 3-qubit states |000� and |001� ; respectively. It is straightforward to show that the compact 3-qubits satisfy the following completeness relation.

Data availability
All data generated or analyzed during this study are included in this article (and its supplementary information files).