An Extended Approach for Generating Unitary An Extended Approach for Generating Unitary Matrices for Quantum Circuits Matrices for Quantum Circuits

: In this paper, we do research on generating unitary matrices for quantum circuits automatically. We consider that quantum circuits are divided into six types, and the unitary operator expressions for each type are offered. Based on this, we propose an algorithm for computing the circuit unitary matrices in detail. Then, for quantum logic circuits composed of quantum logic gates, a faster method to compute unitary matrices of quantum circuits with truth table is introduced as a supplement. Finally, we apply the proposed algorithm to different reversible benchmark circuits based on NCT library (including NOT gate, Controlled-NOT gate, Toffoli gate) and generalized Toffoli (GT) library and provide our experimental results.


Introduction
Quantum computation has become a very active and promising field of research and machine learning has been transformed a lot through the introduction of quantum computing [Liu, Gao, Wang et al. (2019)].Quantum computation has gained a lot of advances in experimental physics and engineering which have made possible to build the quantum computer prototypes.A quantum computer is built from a quantum circuit containing wires and elementary quantum gates to carry around and manipulate the quantum information.In this respect, quantum gates and quantum circuits play an essential role in quantum computation.Usually, we utilize a unitary matrix to describe the quantum gate.The unitary matrix is a mathematical model and precisely reflect the mathematical properties of the quantum gates.This applies to quantum circuits as well because quantum circuits are cascaded by elementary quantum logic gates according to a certain logical relationship.On the basis of it, we propose an algorithm for calculating unitary matrices corresponding to quantum circuits automatically.Reversible circuits are capable to realize the reversible function using the reversible gates.All the quantum operations are necessarily reversible in nature and mapping the reversible circuit to its equivalent quantum circuit efficiently is the area of keen interest [Handique and Sonkar (2018)].In this paper, quantum circuits are divided into six types and we consider the reversible circuits of NCT and GT library as benchmark circuits with the .tfcfile [Maslov, Dueck and Scott (2009)] as the storage for circuits.The remainder of this paper is structured as follows.The next section briefly reviews the basics of reversible and quantum circuits.Later in this section, it gives the information about the machine-readable formatted .tfcfile and the six types of quantum circuits.Section 3 introduces the proposed algorithm and mentions the truth table method as a supplement to this algorithm.Afterwards, we apply the proposed algorithm to different reversible benchmark circuits and provide our experimental results in Section 4. Finally, conclusions are drawn in Section 5.

Preliminaries
This section describes the background necessary for this paper.Readers interested in more detail should consult the literature [Nielsen and Chuang (2000)].

Reversible gates and circuits
The function is reversible if it has the same number of inputs and outputs and maps each unique input of the function to a unique output and vice versa.A reversible function can be realized by a circuit comprised of a cascade of reversible gates with no fan-out and feedback [Nielsen and Chuang (2000)].Some of the fundamental reversible gates have been introduced including NOT gate, Controlled-NOT gate (CNOT, also known as Feynman gate), Toffoli gate [Toffoli (1980)] and the family of these gates is called NCT library.A multiple-control Toffoli (MCT) gate has a target line and several control lines.The target line is inverted if all the controls have value 1 (e.g., in Fig. 1(c), the target line t is inverted, if and only if all control lines c1 to c2 are equal to 1.), otherwise the value on the target line is passed through unchanged.The values on the control lines and unconnected lines always pass through the gate unchanged.An MCT gate with no control lines acts like the NOT gate and with one and two control line(s), the MCT gate is called CNOT and Toffoli gate respectively as shown in Fig. 1.The family of MCT gate is called generalized Toffoli (GT) library [Maslov, Dueck and Scott (2009)].MCT gates are universal in that all reversible functions can be realized using this gate type alone [Toffoli (1980)].The Fredkin et al. [Fredkin and Toffoli (1982)] and the Peres gate [Thapliyal and Ranganathan (2010); Peres (1985)] can, for example, be realized using MCT gates [Sasanian, Wille and Miller (2012)].

Quantum gates and circuits
Quantum gates are the basic unit of quantum circuits and a cascade of quantum gates constitutes the quantum circuit.There are a potentially infinite number of distinct quantum gates.However, in practice, researchers consider circuits composed of a small number of gate types [Sasanian, Wille and Miller (2012)].The NCV library Li et al. [Li, Chen, Song et al. (2017)] is the fundamental library introduced by Barenco et al. [Barenco, Bennett, Cleve et al. (1995)] in quantum circuits.The NCV library can realize any reversible Boolean function.Therefore, the NCV library is the universal quantum logic gate library that contains the following set of quantum gates: 1) NOT gate: It inverts a single qubit described by the unitary matrix .
2) CNOT gate: The target qubit is inverted if the control qubit is 1.
3) Controlled-V gate: As shown in Fig. 2(a), it performs a V operation on the target qubit if the control qubit is 1.The operation is described by the unitary matrix V = . 4) Controlled-V † gate: As shown in Fig. 2(b), it performs a V † operation on the target qubit if the control qubit is 1 and unitary matrix describes as . Although the NCV gate library is universal, other libraries are of interest as they can lead to better circuits, e.g., fewer gates.In Sasanian et al. [Sasanian, Wille and Miller (2012)], a modification to the NCV gate library is introduced based on the concept of multi-valued logic [Muthukrishnan and Stroud (2000)].However, in this work we do not consider the multivalued logic gates i.e., the 1 NCV-v gate library mentioned in Sasanian et al. [Sasanian, Wille and Miller (2012)].

Machine-readable format: .tfc file
The .tfc file Maslov et al. [Maslov, Dueck and Scott (2009)] is the machine-readable format for reversible circuits.It contains detailed information about reversible circuits such as input lines, output lines, gate netlist, garbage lines and constant inputs.In short, the .tfcfile provides a unified, formatted file storage method for reversible circuits that allows us to quickly read and identify reversible circuits.The detailed concept of the .tfcfile can be found at Maslov et al. [Maslov, Dueck and Scott (2009); Handique and Sonkar (2018)].

Classification of quantum circuits
In this section, we divide quantum circuits into six basic types in Fig. 3 [Samoladas (2008)].
Here, U is an n-qubit unitary operator.When U is below the quantum circuit, according to whether there is a control point above the gate, the circuit can be divided into two types, as shown in Figs.3(a) and 3(b).When U is above the quantum circuit, there are two types circuits similarly, as shown in Figs.3(d) and 3(e).If the target qubit is flipped when the control qubit is zero, we draw a hollow circle.We can get two more types of circuits as shown in Figs.3(c) and 3(f).In addition, U can be any of the six circuits mentioned above, which implements a nested way to describe general quantum circuits.
2) In Fig. 3 the expression for (b) is slightly more complex than (a): 3) The expression for (c) in Fig. 3 is: 4) The expression for (d) in Fig. 3 can be obtained by exchanging two operands of ⊗ operation of (a): 5) Similarly, the expression for (e) in Fig. 3 is: 6) The expression for (f) in Fig. 3 is: When n=1, the matrices of B U and D U are separately presented as below [Samoladas (2008)]: , where × unitary matrix.

Proposed method
The proposed method is able to generate the unitary matrix of the quantum circuit.We use a non-recursive approach with great simplification of this algorithm.Besides we use NumPy library and SymPy library in Python.NumPy is the fundamental package for scientific computing and SymPy is a Python library for symbolic mathematics.This method considers quantum circuits composed of NCT gates, MCT gates, GT gates, NCV gates, one-qubit gates and the gate whose target qubit is a one-qubit gate.Now we describe the key content of the proposed method as shown in Tab. 1.The proposed algorithm can calculate unitary matrices for complex quantum circuits such as Fig. 4 [Garcia-Martin and Sierra ( 2017  In addition, the truth table method can be used to calculate unitary matrices of reversible logic circuits.The quantum circuit being computed should be able to be described by a truth table.Although the truth table method is faster than proposed method, it is only suitable for quantum reversible logic circuit. In the truth table, the input value of a quantum circuit ranges from 0 to 2 1 − n .The input vector corresponding to the input value i is xi.In the xi, the i-th number (starting from zero) is 1 and the rest are 0. Suppose the matrix of the quantum circuit is A, under the action of quantum circuits, the output vector is yi.Clearly, yi is the i-th column of A, as expressed in the following equations.So we can calculate unitary matrices for quantum circuits by input and output logic values.

Conclusions
In this paper, quantum circuits are divided into six basic types and we discuss an approach for generating unitary matrices of quantum circuits.The algorithm by the aforementioned method is not fully optimized, and further optimization is possible.Our future work, we will concentrate on the improvement of the algorithm, how to incorporate the constraints into the truth table method and the simulation experiments based on IBM Q [Liu, Gao, Yu et al. (2018)].

Figure 3 :
Figure 3: Six constructions based on U and corresponding circuits 1) In Fig. 3 the expression for (a) is: )].

Figure 4 :
Figure 4: A Toffoli gate implemented as the product of 1-qubit gates and CNOTs

Figure 5 :
Figure 5: Equivalent SWAP gate and corresponding matrix

Table 1 :
The key of the proposed algorithm [Garcia-Martin and Sierra (2017)lent to a SWAP gate[Garcia-Martin and Sierra (2017)].It is enough to look at what happens to each state 00, 01, 10, and 11.Let us consider 01.The first gate CNOT does nothing since the control is 0. The second gate reversed CNOT flips the first qubit, so we have 11.Finally, the last CNOT flips the second qubit and we get 10.The other cases can be worked out similarly.Tab. 2 shows the truth table of this quantum circuit.The tensor product of the output states corresponds to each column of the matrix and according to the expression (7) above, the unitary matrix can be obtained i.e., (y0, y1, y2, y3) as shown in Fig.5(b).

Table 2 :
The truth table of the equivalent SWAP gate

Table 3 :
Time of generating unitary matrices for reversible benchmark circuits