Abstract
Estimating the overlap between two states is an important task with several applications in quantum information. However, the typical swap test circuit can only measure a sole pair of quantum states at a time. In this study, a recursive quantum circuit is designed to measure overlaps of n quantum states \(\left | {\phi _{1} } \right \rangle ,\left | {\phi _{2} } \right \rangle ,\ldots\left | {\phi _{n} }\right \rangle \) concurrently with \(O(k2^{k})\) controlled-swap(CSWAP) gates and \(O(k)\) ancillary qubits, where \(k=\left \lceil {\log n} \right \rceil \). All pairwise overlaps among input quantum states \(|\langle \phi _{i}|\phi _{j}\rangle |^{2}\) can be obtained in this circuit. Compared with existing scheme for measuring the overlap of multiple quantum states, the circuit provides higher precision and less consumption of ancillary qubits. In addition, some simulation experiments are performed on IBM quantum cloud platform to verify the superiority of this algorithm.
Similar content being viewed by others
Explore related subjects
Discover the latest articles, news and stories from top researchers in related subjects.1 Introduction
The concept of quantum computing was proposed by Richard Feynman in the early 1980s [1] and David Deutsch later gave a quantum algorithm solution to a toy issue [2]. In recent years, quantum algorithms and their applications in fields like encryption [3], database search [4], quantum simulation [5], optimization problems [6], dataset compression [7], quantum A-optimal projection (AOP) algorithm [8], variational quantum algorithm (VQA) [9], ridge regression (RR) [10], quantum algorithm for association rules mining [11], quantum algorithm for the Toeplitz systems [12], quantum algorithm for visual tracking [13], block-encoding-based quantum algorithm [14], and linear systems of equations [15] (refer to [16] for more information) have proved spectacular. For certain problems, these quantum algorithms outperform classical algorithms in terms of speed. Typically, quantum algorithms are described using quantum circuits, which are made up of a sequence of quantum gates that can handle qubits. When dealing with quantum circuits, it’s important to measure the similarity or overlap between two states \(\left | \phi \right \rangle \) and \(\left | \psi \right \rangle \), which can be denoted by \(\left | {\left \langle {\phi ,\psi} \right \rangle } \right |^{2}\) [17].
Swap Test is a well-known quantum circuit for measuring overlap, which uses a controlled-swap(CSWAP) gate and an ancillary qubit to estimate the inner product \(\left | {\left \langle {\phi ,\psi } \right \rangle } \right |^{2}\) of two states \(\left |\phi \right \rangle ,\left | \psi \right \rangle \) [18, 19]. It has attracted interests as a fundamental primitive and its efficient implementation on near-term quantum computers is a hot research issue at the moment. In [20], L. Cincio et al. presented a machine learning approach for discovering short-depth algorithm to compute state overlap, whose performance is better than the linear scaling of Swap Test. In [21], M. Fanizza et al. studied the estimation of overlap between two unknown pure quantum states in a finite-dimensional system, given M and N copies of each type. They demonstrated that allowing for general collective measurements on all copies can yield a more precise estimate. In [22], U. Chabaud et al. proposed a strategy for a programmable projective measurement device, which may be interpreted as an optimal Swap Test when only one copy of one state and \(M-1\) of the other is available. There are many applications that require states overlap computation thus making Swap Test appear as a subroutine in these applications. For instance, it is used to measure entanglement and indistinguishabiliy for quantum states [19, 23], to check for the falsification of the quantum signature state pair [24], to solve matrix multiplication [25], to build quantum neural networks [26], and also common in quantum supervised learning to measure the distances of quantum states [27–29]. What’s more, proofs-of-concept in implementations of quantum computers [30, 31] called for this Swap Test as well.
Consider the case when there are n quantum states \(\left | {\phi _{1} }\right \rangle ,\left | {\phi _{2} }\right \rangle ,\ldots,\left |{\phi _{n} } \right \rangle \) and Swap Test can only assess the overlap of two states at a time. In order to obtain the overlap \(\left | {\left \langle {\phi _{i} } \right |\left . {\phi _{j} } \right \rangle } \right |^{2}\) between arbitrary two states \(\left |{\phi _{i} } \right \rangle ,\left | {\phi _{j} }\right \rangle (i,j=1,2,\ldots,n;i \ne j)\), there is a trivial solution which requires \(\frac{{n(n - 1)}}{2}\) Swap Tests and \(\frac{{n(n - 1)}}{2}\) ancillary qubits. In [32], X. Gitiaux et al. extended two-state Swap Test to n quantum states \(\left |{\phi _{1} } \right \rangle ,\left | {\phi _{2} } \right \rangle ,\ldots,\left | {\phi _{n} } \right \rangle \). They built a unitary \({\mathrm{U}}_{4}\) circuit with three ancillaries, three CSWAP gates, and one Swap Test to compute overlap for four states. Based on the \({\mathrm{U}}_{4}\) circuit, they developed a recursive algorithm to generalize a circuit which can estimate overlaps between n quantum states. But the overlap of only one pair of quantum states among the n quantum states can be obtained by executing the circuit one time.
In this paper, following the idea of [32], we design a new circuit \({\mathrm{U}}_{4}\) with two ancillaries, two CSWAP gates, and two Swap Test. We also present two rules to swap four groups of quantum states. Based on the swap rules and our \({\mathrm{U}}_{4}\), a circuit to calculate the overlap between different pairs of n arbitrary input states is presented. The overlaps of four pairs of quantum states among n quantum states can be obtained simultaneously by executing our circuit one time.
The paper is organized as follows: some correlative preliminaries are introduced in Sect. 2; a multi-state Swap Test algorithm is proposed in Sect. 3; In Sect. 4, the simulation for a concrete example of 8-state Swap Test algorithm on IBM Quantum Experience platform is described. And the correctness and performance of the algorithm are analyzed in Sect. 5. A brief discussion and a summary are given in Sect. 6.
2 Preliminaries
2.1 Two-state Swap Test and its quantum circuit
Swap Test is used to estimate the overlap between two unknown quantum states, and it has a variety of applications. Given two unknown quantum states \(|\phi \rangle \) and \(|\psi \rangle \), the overlap between them is defined as \(|\langle \phi |\psi \rangle |^{2}\), i.e. the inner product between their state vectors. The Swap Test quantum circuit for estimating the overlap between \(|\phi \rangle \) and \(|\psi \rangle \) is shown in Fig. 1, where the first qubit is an auxiliary qubit used for measurement and the other two states are used for inputs.
According to the quantum circuit, the output denoted by \(|\rho \rangle \) can be calculated as:
According to Equ.(1), the probability of measuring \(|0\rangle \) is \(Prob(0) = \frac{{1 + | {\langle \phi | \psi \rangle } |^{2} }}{2}\).
Obviously, the overlap \(\langle \phi |\psi \rangle \) is related to the probability of measuring \(|0\rangle \). So it can be derived:
In [19], Juan Carlos Garcia-Escartin et al. showed that the Hong-Ou-Mandel effect from quantum optics is equivalent to Swap Test. Then, they gave a destructive Swap Test module that can provide better performance than the traditional Swap Test. The basic implementation of their Swap Test costs three quantum registers and a CSWAP gate to estimate the overlap between two unknown quantum states. The CSWAP circuit is inspired by classical XOR swapping, so the two-state Swap Test circuit in Fig. 1 can be inverted into a new form, which is shown in Fig. 2.
X gate equivalent to \(HZH\) operation, and if the Z gate is replaced by a controlled-\(Z(CZ)\) gate such that \(CZ|x\rangle |y\rangle =(-1)^{x y}|x\rangle |y\rangle \), the resulting circuit acts as a CNOT gate. A controlled-controlled-Z gate can be similarly defined. So the equivalent quantum circuit of Swap Test is shown in Fig. 3.
Obviously, the ancillary qubit is not affected by the tested qubits after \(CCZ\) gate. The last H and \(CNOT\) gates are elitimated and measurements are performed directly after the \(CCZ\) gate with no effect on the ancillary qubit and the result of Swap Test. Moreover, with the help of a trick called “phase kickback” in [33], the circuit can be rewritten in Fig. 4.
The output of ancillary qubit can be predicted according to the output of tested qubits in the classical method, which is sometimes called the principle of deferred measurement. Clearly, the ancillary qubit can be ignored and a improved Swap Test circuit is shown in Fig. 5.
2.2 Gitiaux’s Swap Test for multiple quantum states
In [32], Xavier Gitiaux et al. gave a new quantum algorithm that is used to estimate the overlap between multiple quantum states based on the standard two-state Swap Test. First, they defined a unitary \({\mathrm{U}}_{4}\) for a 4-state circuit as a building block to develop a recursive algorithm to produce a n-state circuit.
As shown in Fig. 6, there are a total of four input states which can form 6 pairs of combinations. It requires at least 6 orthogonal states to label them. Therefore, the minimum number of ancillary qubits is three, and the minimum number of CSWAP gates is also three, each acting as control once.
Terms contained in the superposition state are listed in Table 1, where \(s_{1}\), \(s_{2}\), \(s_{3}\) denote the basis states of the three ancillary qubits from bottom to top in the ancillary section in Fig. 6. The four state registers are labeled by \(q_{i}(i=1,2,3,4)\). The input state is \(|\phi _{1}\phi _{2}\phi _{3}\phi _{4}\rangle \), and the order of the output states depends on the measured values of the auxiliary qubits. As shown in Table 1, the output state will be \(|\phi _{4}\phi _{3}\phi _{2}\phi _{1}\rangle \) if the ancillary qubits are \(|011\rangle \). The essence of this algorithm is that each possible overlap between two states can be generated by only measuring the first two qubits, which can be verified by Table 1.
And the \({\mathrm{U}}_{8}\) for 8 inputs can be constructed from \({\mathrm{U}}_{4}\) which is shown in Fig. 7.
The circuit is built into two sections of three ancillaries and three groups of three CSWAP gates, which amounts to six ancillaries and nine CSWAP gates. It is obvious that the quantum circuit is divided into two groups of four registers: \(q_{1}q_{2}q_{3}q_{4}\) and \(q_{5}q_{6}q_{7}q_{8}\) respectively. In the first step, the corresponding registers in the two sets are controlled by a set of three ancillaries in parallel which brings all six pairs in \(|\phi _{1}\rangle ,|\phi _{2}\rangle ,|\phi _{3}\rangle ,|\phi _{4} \rangle \) to \(q_{1}q_{2}\) and all six pairs in \(|\phi _{5}\rangle ,|\phi _{6}\rangle ,|\phi _{7}\rangle ,|\phi _{8} \rangle \) to \(q_{5}q_{6}\) respectively. Then another set of three ancillaries is introduced to control the pairing among \(q_{1}q_{2}q_{5}q_{6}\) which makes the pairing between all 8 registers possible.
Next the case \(n=2^{k}\) is considered. As shown in Fig. 8, the \({\mathrm{U}}_{n}\) is built by repeating the same operation in \({\mathrm{U}}_{8}\). Denoting the number of ancillaries in \({\mathrm{U}}_{n}\) as \(d_{n}=3k-3\) and the number of CSWAP gate as \(c_{n}=3(2^{k-1}-1)\), where \(k=log_{2}n\).
To clarify, the procedure is to use \({\mathrm{U}}_{4}\) within different groups first, and then on the resultant registers of each group. \({\mathrm{U}}_{4}\) acts each time to allow pairing of two registers(these parts could be the simplest group or a group already combined by \({\mathrm{U}}_{4}\) in the previous step.).
3 Quantum multi-state Swap Test algorithm
Two swap rules are designed at first: Suppose that there are \(2^{k}( k \in \{ 2,3,\ldots\})\) quantum states \(| {\phi _{1} }\rangle ,| {\phi _{2} }\rangle ,\ldots,|{\phi _{2^{k}} } \rangle \). They can be divided into four groups \(G_{1}\), \(G_{2}\), \(G_{3}\), \(G_{4}\). \(Rule1\) is to exchange the 2nd and 3rd group of states in turn and get \(G_{1}\), \(G_{3}\), \(G_{2}\), \(G_{4}\); \(Rule 2\) is to exchange the 2nd and 4th group of states in turn and get \(G_{1}\), \(G_{4}\), \(G_{3}\), \(G_{2}\).
A multi-state Swap Test algorithm based on the two swap rules is presented as follows. In this algorithm, a circuit can be constructed to take all n input states at once and to get the overlap of arbitrary two input states in \(| {\phi _{1} }\rangle ,| {\phi _{2} } \rangle ,\ldots,|{\phi _{n} } \rangle \).
(1) Constructing a circuit \({\mathrm{U}}_{4}\) to estimate the overlaps of arbitrary pairs of 4 quantum states \(| {\phi _{1} } \rangle ,|{\phi _{2} }\rangle ,| {\phi _{3} }\rangle ,| {\phi _{4} }\rangle \). In \({\mathrm{U}}_{4}\), there are two ancillary qubits \(s_{1}\), \(s_{2}\) and four registers \(q_{1}\), \(q_{2}\), \(q_{3}\), \(q_{4}\). The initial states are \(s_{1}s_{2}=|+\rangle |+\rangle \) and \(q_{1}q_{2}q_{3}q_{4}=| {\phi _{1} }\rangle | {\phi _{2} } \rangle | { \phi _{3} }\rangle | {\phi _{4} }\rangle \). \(q_{1}q_{2}q_{3}q_{4}\) are divided into four groups \(G_{1}=q_{1};G_{2}=q_{2};G_{3}=q_{3};G_{4}=q_{4}\). There are also two CSWAP gates, where \(s_{2}(s_{1})\) is the control qubit to swap two groups \(G_{2}\), \(G_{3}(G_{2},G_{4})\) according to \(Rule 1(Rule 2)\). Two Swap Test for two quantum states are placed at the end of \({\mathrm{U}}_{4}\) to measure the overlap of two quantum states stored separately in registers \((q_{1},q_{2})\) and \((q_{3},q_{4})\). The circuit \({\mathrm{U}}_{4}\) is shown in Fig. 9, where ST denotes the two-state Swap Test circuit shown in Fig. 1.
The relation between the states of ancillary qubits \(s_{1}\), \(s_{2}\) and the states of quantum registers \(q_{1}\), \(q_{2}\), \(q_{3}\), \(q_{4}\) is shown in Table 2. For example, if \(s_{1}s_{2}=\left | {0} {0} \right \rangle \), the states stored in registers \((q_{1}q_{2})\) are \(\left | {\phi _{1} \phi _{2} }\right \rangle \), the states stored in registers \((q_{3}q_{4})\) are \(\left | {\phi _{3} \phi _{4} } \right \rangle \). The overlaps of \(\left | {\phi _{1} \phi _{2} } \right \rangle \) and \(\left | {\phi _{3} \phi _{4} } \right \rangle \) can be obtained through two Swap Test separately placed on \((q_{1}q_{2})\) and \((q_{3}q_{4})\). If \(s_{1}s_{2}=\left | {0} {1} \right \rangle \), the states stored in registers \((q_{1}q_{2})\) are \(\left | {\phi _{1} \phi _{3} }\right \rangle \), the states stored in registers \((q_{3}q_{4})\) are \(\left | {\phi _{2} \phi _{4} } \right \rangle \). The overlap of \(\left | {\phi _{1} \phi _{3} } \right \rangle \) and \(\left | {\phi _{2} \phi _{4} } \right \rangle \) can be obtained through two Swap Test separately placed on \((q_{1}q_{2})\) and \((q_{3}q_{4})\). If \(s_{1}s_{2}=\left | {1} {0} \right \rangle \), the states stored in registers \((q_{1}q_{2})\) are \(\left | {\phi _{1} \phi _{4} }\right \rangle \), the states stored in registers \((q_{3}q_{4})\) are \(\left | {\phi _{3} \phi _{2}} \right \rangle \). The overlap of \(\left | {\phi _{1} \phi _{4}} \right \rangle \) and \(\left | {\phi _{3} \phi _{2}} \right \rangle \) can be obtained through two Swap Test separately placed on \((q_{1}q_{2})\) and \((q_{3}q_{4})\).
(2) Constructing a circuit \({\mathrm{U}}_{8}\) to estimate the overlap of arbitrary pairs of 8 quantum states \(| {\phi _{1} } \rangle ,| {\phi _{2} }\rangle ,| {\phi _{3} } \rangle ,| {\phi _{4} } \rangle ,| {\phi _{5} } \rangle \), \(| {\phi _{6} } \rangle ,| {\phi _{7} }\rangle ,| {\phi _{8} } \rangle \). In \({\mathrm{U}}_{8}\), there are four ancillary qubits \(s_{1}\), \(s_{2}\), \(s_{3}\), \(s_{4}\) and eight registers \(q_{1}\), \(q_{2}\), \(q_{3}\), \(q_{4}\), \(q_{5}\), \(q_{6}\), \(q_{7}\), \(q_{8}\). The initial states are \(s_{1}s_{2}s_{3}s_{4}=|+\rangle |+\rangle | + \rangle |+\rangle \) and \(q_{1}q_{2}q_{3}q_{4}q_{5}q_{6}q_{7}q_{8}=| {\phi _{1} } \rangle ,| { \phi _{2} }\rangle ,| {\phi _{3} } \rangle ,| {\phi _{4} } \rangle ,| { \phi _{5} } \rangle ,| {\phi _{6} } \rangle ,| {\phi _{7} }\rangle \), \(| {\phi _{8} }\rangle \). \(q_{1}q_{2}q_{3}q_{4}q_{5}q_{6}q_{7}q_{8}\) are divided into four groups \(G_{1}=q_{1}q_{2};G_{2}=q_{3}q_{4};G_{3}=q_{5}q_{6};G_{4}=q_{7}q_{8}\). There are also eight CSWAP gates. \(s_{2}(s_{1})\) is a control qubit on two CSWAP gates to swap \(G_{2}\), \(G_{3}(G_{2},G_{4})\) according to \(Rule 1(Rule 2)\). And \(s_{3}\), \(s_{4}\), \(q_{1}\), \(q_{2}\), \(q_{3}\), \(q_{4}\) can be seen as inputs of \({\mathrm{U}}_{4}\) and \(s_{3}\), \(s_{4}\), \(q_{5}\), \(q_{6}\), \(q_{7}\), \(q_{8}\) can also be seen as inputs of \({\mathrm{U}}_{4}\). Four Swap Test for two quantum states are placed at the end of \({\mathrm{U}}_{8}\) to measure the overlap of two quantum states stored separately in registers \((q_{1},q_{2})\), \((q_{3},q_{4})\), \((q_{5},q_{6})\) and \((q_{7},q_{8})\). The circuit \({\mathrm{U}}_{8}\) is shown in Fig. 10, where ST denotes two-state Swap Test circuit shown in Fig. 1.
The relation between the states of ancillary qubits \(s_{1}\), \(s_{2}\), \(s_{3}\), \(s_{4}\) and the states of quantum registers \(q_{1}\), \(q_{2}\), \(q_{3}\), \(q_{4}\), \(q_{5}\), \(q_{6}\), \(q_{7}\), \(q_{8}\) is shown in Table 3. For example, if \(s_{1}s_{2}s_{3}s_{4}=\left | {1} {0} {0}{1}\right \rangle \), the states stored in registers \((q_{1}q_{2})\) are \(\left | {\phi _{1} \phi _{7} }\right \rangle \), the states stored in registers \((q_{3}q_{4})\) are \(\left | {\phi _{2} \phi _{8} } \right \rangle \), the states stored in registers \((q_{5}q_{6})\) are \(\left | {\phi _{5} \phi _{3} }\right \rangle \), the states stored in registers \((q_{7}q_{8})\) are \(\left | {\phi _{6} \phi _{4} } \right \rangle \). The overlap of \(\left | {\phi _{1} \phi _{7} } \right \rangle \), \(\left | {\phi _{2} \phi _{8}} \right \rangle \), \(\left | {\phi _{5} \phi _{3} } \right \rangle \) and \(\left | {\phi _{6} \phi _{4}} \right \rangle \) can be obtained through four Swap Test separately placed on \((q_{1},q_{2})\), \((q_{3},q_{4})\), \((q_{5},q_{6})\) and \((q_{7},q_{8})\). The frequency counts of state pairs calculated according to the auxiliary qubit \(s_{1}\), \(s_{2}\), \(s_{3}\), \(s_{4}\) encoding results is shown in Table 4.
(3) Constructing a circuit \({\mathrm{U}}_{2^{k}}\) to estimate arbitrary pairs of n states \(\left | {\phi _{1} } \right \rangle ,\left | {\phi _{2} } \right \rangle ,\ldots, \left | {\phi _{n} } \right \rangle \). If \(2^{k - 1} < n < 2^{k} \), \(2^{k} - n\) copies of any input states should be added to get \(2^{k}\) quantum states. In \({\mathrm{U}}_{2^{k}}\), there are \(2(k-1)\) ancillary qubits \(s_{1},s_{2},\ldots,s_{2(k-1)}\) and \(2^{k}\) registers \(q_{1},q_{2},\ldots,q_{2^{k}}\). The initial states are \(s_{i}=\left | + \right \rangle \) and \(q_{i}=\left | {\phi _{i} } \right \rangle (i=1,2,\ldots,2^{k})\). \(q_{1},q_{2},\ldots,q_{2^{k}}\) are divided into four groups \(G_{1}=q_{1},q_{2},\ldots,q_{2^{k-2}}\), \(G_{2}=q_{2^{k-2}+1},q_{2^{k-2}+2},\ldots,q_{2(2^{k-2})}\), \(G_{3}=q_{2(2^{k-2})+1},q_{2(2^{k-2})+2},\ldots,q_{3(2^{k-2})}\), \(G_{4}=q_{3(2^{k-2})+1},q_{3(2^{k-2})+2},\ldots,q_{2^{k}}\). There are also \((k - 1)2^{k - 1}\) CSWAP gates in \({\mathrm{U}}_{{2^{k}}}\). \(s_{2}(s_{1})\) is a control qubit on \(\frac{{2^{k} }}{4}\) CSWAP gates to swap the states in \(G_{2}\), \(G_{3}(G_{2},G_{4})\) according to \(Rule 1(Rule 2)\). Then the \(2^{k-1}\) inputs of \(G_{1}G_{2}(G_{3}G_{4})\) can be used to construct a circuit \({\mathrm{U}}_{2^{k-1}}\). After recursively constructing round by round, \(s_{(2(k - 1) - \frac{{2^{k} }}{4} + i)}, q_{4i - 3} ,q_{4i - 2}, q_{4i - 1}, q_{4i }(i=1,2,\ldots,\frac{{2^{k} }}{4})\) can be used as inputs of \({\mathrm{U}}_{4}\). \(2^{k - 1}\) Swap Test for two quantum states are placed at the end of \({\mathrm{U}}_{2^{k}}\) to measure the overlap of two quantum states stored separately in registers \((q_{1},q_{2})\), \((q_{3},q_{4})\),…, \((q_{2^{k}-1},q_{2^{k}})\). The circuit \({\mathrm{U}}_{2^{k}}\) is shown in Fig. 11, where ST denotes two-state Swap Test circuit shown in Fig. 1.
4 Simulation of multi-state Swap Test algorithm
In this section, we prepare 8 random input states \(|\phi _{1}\rangle |\phi _{2}\rangle |\phi _{3}\rangle |\phi _{4} \rangle |\phi _{5}\rangle |\phi _{6}\rangle |\phi _{7}\rangle |\phi _{8} \rangle \) and try to estimate the overlap between each two quantum states using the multi-state Swap Test algorithm. After the experiment, the correctness of the scheme is verified by comparing the estimated value with the exact value.
The simulated quantum circuit for a 8-state example on IBM quantum cloud platform is given in Fig. 12. The inputs of the simulated quantum circuit consists of 3 parts: \(q_{0}q_{1}q_{2}q_{3}\) are the registers that correspond to auxiliary control qubits \(s_{1}s_{2}s_{3}s_{4}\) in Fig. 10. The initial auxiliary control qubits \(q_{0}q_{1}q_{2}q_{3}\) in our example are \(\left | +\right \rangle \left | +\right \rangle \left | + \right \rangle \left | + \right \rangle \); \(q_{4}q_{5}q_{6}q_{7}q_{8}q_{9}q_{10}q_{11}\) are the registers that correspond to the initial input states \(q_{1}q_{2}q_{3}q_{4}q_{5}q_{6}q_{7}q_{8}\) in Fig. 10, which are \(|\phi _{1}\rangle |\phi _{2}\rangle |\phi _{3}\rangle |\phi _{4} \rangle |\phi _{5}\rangle |\phi _{6}\rangle |\phi _{7}\rangle |\phi _{8} \rangle \). The initial input states \(q_{4}q_{5}q_{6}q_{7}q_{8}q_{9}q_{10}q_{11}\) in our example are \(|\phi _{1}\rangle =[0.0864,0.9963]\), \(|\phi _{2}\rangle =[0.8391,0.5440]\), \(|\phi _{3}\rangle =[0.2202,0.9755]\), \(|\phi _{4}\rangle =[0.5486,0.8361]\), \(|\phi _{5}\rangle =[0.2607,0.9654]\), \(|\phi _{6}\rangle =[0.4164,0.9091]\), \(|\phi _{7}\rangle =[0.9981,0.0609]\), \(|\phi _{8}\rangle =[0.4658, 0.8849]\); and \(q_{12}q_{13}q_{14}q_{15}\) are the registers that correspond to the result qubits of two-state Swap Test.
This simulated quantum circuit are executed 32,768 shots and QASM simulator included in the Qiskit package is selected as the backend. The specific counts of different measurement results in registers \(q_{0}q_{1}q_{2}q_{3}q_{12}q_{13}q_{14}q_{15}\) are recorded in Table 5. For example, the count of \(q_{0}q_{1}q_{2}q_{3}q_{12}q_{13}q_{14}q_{15}=|00010010\rangle \) is 10 in Table 5, the auxiliary control qubits are \(q_{0}q_{1}q_{2}q_{3}=0001\). According to the relation between the auxiliary control qubits and the initial input states shown in Table 3, the counts of \(q_{12}\)’s measurement result can be used to estimate the overlap of \(\left | {\phi _{1} \phi _{3} } \right \rangle \), the counts of \(q_{13}\)’s measurement result can be used to estimate the overlap of \(\left | {\phi _{2} \phi _{4} } \right \rangle \), the counts of \(q_{14}\)’s measurement result can be used to estimate the overlap of \(\left | {\phi _{5} \phi _{7} } \right \rangle \) and the counts of \(q_{15}\)’s measurement result can be used to estimate the overlap of \(\left | {\phi _{6} \phi _{8} } \right \rangle \).
For arbitrary two states \(|\phi _{i}\rangle ,|\phi _{j}\rangle (i,j = 1,2,\ldots,8;i \ne j)\), the estimated value of overlap denoted by \(\widehat{o}(|\phi _{i}\rangle ,|\phi _{j}\rangle )\) which can be calculated according to the relation shown in Table 3 and the counts of measurement results shown in Table 5. For example, when \(q_{0}q_{1}q_{2}q_{3}=\left | {0010} \right \rangle \) and \(q_{0}q_{1}q_{2}q_{3}=\left | {0011} \right \rangle \), the measurement results of \(q_{15}\) is related to estimated overlap \(|\left \langle{\phi _{6} } \right |\left . {\phi _{7} } \right \rangle |^{2}\). After counting times \(t_{1}\) of \(q_{15}= \left | 1 \right \rangle \) and the times \(t_{0}\) of \(q_{15}= \left | 0 \right \rangle \), \(\widehat{o}(| {\phi _{6} } \rangle ,| {\phi _{7} }\rangle ) = { \frac{{2t_{0} }}{{t_{0} + t_{1} }} - 1}\). In this example we get \(t_{0}=1276\) and \(t_{1}=813\), so the result is \(\widehat{o}(| {\phi _{6} } \rangle ,| {\phi _{7} }\rangle ) =0.2216\). The exact overlap denoted by \(o(|\phi _{i}\rangle ,|\phi _{j}\rangle )\) which can be calculated by the definition of overlap \(\left | {\left \langle {{\phi _{i} }}\mathrel{\left | { \vphantom {{\phi _{i} } {\phi _{j} }} } \right . \kern -\nulldelimiterspace}{{\phi _{j} }} \right \rangle } \right |^{2}\). And the exact overlap of \(| {\phi _{6} } \rangle ,| {\phi _{7} }\rangle \) is \(o(| {\phi _{6} } \rangle ,| {\phi _{7} }\rangle )=0.2218\). The exact overlap \(o(|\phi _{i}\rangle ,|\phi _{j}\rangle )\) and the estimated overlap \(\widehat{o}(|\phi _{i}\rangle ,|\phi _{j}\rangle )(i,j = 1,2,\ldots,8;i \ne j)\) are shown in Table 6.
The results of this simulation are visualized by a scatter diagram which is shown in Fig. 13. Here the exact overlap \(o(|\phi _{i}\rangle ,|\phi _{j}\rangle )\) is X-axis and the estimated overlap \(\widehat{o}(|\phi _{i}\rangle ,|\phi _{j}\rangle )\) is Y-axis. It can be seen from Fig. 13 that most points fall near the line \(y = x\), indicating that the estimated overlap results are close to the exact overlap results, and our scheme is correct.
The scatter diagram of exact overlap \(o(\left | {\phi _{i} } \right \rangle ,\left | {\phi _{j} } \right \rangle )\) and estimated overlap \(\widehat{o}(\left |{\phi _{i} } \right \rangle ,\left | {\phi _{j} } \right \rangle )\), where \(i,j = 1,2,\ldots,8;i \ne j;|\phi _{1}\rangle =[0.0864,0.9963],|\phi _{2} \rangle =[0.8391,0.5440],|\phi _{3}\rangle =[0.2202,0.9755],|\phi _{4} \rangle =[0.5486,0.8361],|\phi _{5}\rangle =[0.2607,0.9654],|\phi _{6} \rangle =[0.4164,0.9091],|\phi _{7}\rangle =[0.9981,0.0609],|\phi _{8} \rangle =[0.4658, 0.8849]\)
And we also prepare another 9 groups of quantum states \(D_{1}\), \(D_{2}\), \(D_{3}\), \(D_{4}\), \(D_{5}\), \(D_{6}\), \(D_{7}\), \(D_{8}\), \(D_{9}\) by Python random package in the same way, which is using for verifying the correctness of the scheme. The initial quantum states for each group are shown in the Appendix. And the scatter diagrams of these 9 groups of quantum states are shown in Fig. 14, where the estimated overlap is X-axis and the exact overlap is Y-axis. It can be seen from Fig. 14 that, for each experiment, most points fall near the line \(y=x\), which indicate that the estimated value is effective and the scheme is correct.
The scatter diagrams of exact overlap and estimated overlap for \(D_{1},D_{2},D_{3},D_{4},D_{5},D_{6},D_{7},D_{8},D_{9}\) in the Appendix
5 Analysis
In this section, we analyze the correctness and performance of the multi-state Swap Test algorithm in theory.
5.1 Correctness analysis
There is a transformation \({\mathrm{U}}_{2^{k}}\), which can take arbitrary unknown states \(\left | {\phi _{1} } \right \rangle ,\left | {\phi _{2} } \right \rangle ,\ldots, \left | {\phi _{n} } \right \rangle (2^{k - 1} < n \le 2^{k} )\) as input states and \(2(k-1)\) \(\left | + \right \rangle \) as ancillaries. In \({\mathrm{U}}_{2^{k}}\), each pair of states \(\left | {\phi _{i} } \right \rangle ,\left | {\phi _{j} } \right \rangle (i,j = 1,2,\ldots,n; i \ne j)\) can be labeled by ancillaries \(\left | {a_{ij} } \right \rangle \) by Lemma 5.1.
Lemma 5.1
For \(2^{k} (k > 1)\), there exists a unitary \({\mathrm{U}}_{2^{k}}\) that maps
where \(|\phi _{i}\rangle ,|\phi _{j}\rangle \) are arbitrary two input quantum states, and they are in adjacent quantum registers, i.e. in the quantum registers \((q_{2i-1},q_{2i}),i\in \{1,2,\ldots,2^{k-1}\}\). \(|G_{ij}'\rangle ,|G_{ij}\rangle ,|y_{ij}\rangle \) are garbage states which are irrelevant to our target states, i.e. \(|\phi _{i}\rangle ,|\phi _{j}\rangle \). \(|1_{ij}\rangle ,\ldots,|m_{ij}\rangle \) represent the states in the first \(d_{k}\) quantum registers. That means all pairs \(|\phi _{i}\rangle |\phi _{j}\rangle ,i\neq j\) can be obtained by measuring the specific \((q_{2i-1},q_{2i}),i\in \{1,2,\ldots,2^{k-1}\}\) in the quantum circuit.
Constructive proof of Lemma 5.1.
According to scientific induction, we assume that Lemma 5.1 is correct at first. Let the \(2^{k}\) quantum registers \(q_{1},q_{2},\ldots,q_{2^{k}}\) divided into 4 groups \(Q_{1}^{1}=(q_{1},\ldots,q_{2^{k-2}})\), \(Q_{1}^{2}=(q_{2^{k-2}+1},\ldots,q_{2^{k-1}})\), \(Q_{1}^{3}=(q_{2^{k-1}+1},\ldots,q_{3\times 2^{k-2}})\), \(Q_{1}^{4}=(q_{3 \times 2^{k-2}+1},\ldots,q_{2^{k}})\). Furthermore, we get 4 quantum states \(|\Phi _{1}^{1}\rangle =|\phi _{1}...\phi _{2^{k-2}}\rangle \), \(|\Phi _{1}^{2}\rangle =|\phi _{2^{k-2}+1},\ldots,\phi _{2^{k-1}} \rangle \), \(|\Phi _{1}^{3}\rangle =|\phi _{2^{k-1}+1},\ldots,\phi _{3\times 2^{k-2}} \rangle \), \(|\Phi _{1}^{4}\rangle =|\phi _{3\times 2^{k-2}+1},\ldots,\phi _{2^{k}} \rangle \). Applying \({\mathrm{U}}_{2^{k-1}}\) to \((Q_{1}^{1},Q_{1}^{2})\) and \((Q_{1}^{3},Q_{1}^{4})\) respectively, we can get all pairs of input states \(|\Phi _{1}^{1}\Phi _{1}^{2}\rangle \), i.e. \(|\phi _{1}\rangle ,\ldots,|\phi _{2^{k-1}}\rangle \), and the same is true for the other \({\mathrm{U}}_{2^{k-1}}\). If we apply a unitary \({\mathrm{U}}_{4}\) on \((Q_{1}^{1},Q_{1}^{2},Q_{1}^{3},Q_{1}^{4})\) before the \({\mathrm{U}}_{2^{k-1}}\), we will get all pairs of input states \(|\phi _{1}\rangle ,\ldots,|\phi _{2^{k}}\rangle \). For example, we want to get a pair \(|\phi _{a}\phi _{b}\rangle ,a\in [1,2^{k-2}],b\in [2^{k-1}+1,{3 \times 2^{k-2}}]\). \(|\Phi _{1}^{1}\Phi _{1}^{3}\rangle \) will be stored in \((Q_{1}^{1},Q_{1}^{2})\) if the ancillary qubits of \({\mathrm{U}}_{4}\) is \(|01\rangle \), and the pair \(|\phi _{a}\phi _{b}\rangle \) might be measured after \({\mathrm{U}}_{2^{k-1}}\).
Similarly, the correctness of \({\mathrm{U}}_{2^{k-1}}\) can be provide by using \({\mathrm{U}}_{2^{k-2}}\) and \({\mathrm{U}}_{4}\), and so on. Finally, it’s easy to prove the correctness of \({\mathrm{U}}_{4}\) according to Table 2. So Lemma 5.1 is proved. For the case that if \(n \ne 2^{k} \), \(2^{k}-n\) copies of any input states can be added as the rest inputs in order to construct \(U_{2^{k}}\).
So far, all pairs of \(2^{k}\) input quantum states have been obtained and each pair can be exactly gotten according to the measurement results of auxiliary qubits. Therefore, the two-state Swap Test needs to be applied in all specific registers \((q_{1},q_{2}),\ldots,(q_{2^{k}-1},q_{2^{k}})\) to get the overlap between two input quantum states. The measurement results of \(2(k-1)\) auxiliaries determine the quantum state in each quantum register uniquely. Because it has been proved that all pairs of input quantum states have the opportunity to be measured in specific registers, all overlap estimates can be obtained after enough measurements. □
5.2 Performance analysis
In this section, our scheme, the scheme for an arbitrary number of quantum states given by Gitiaux(referred to as SAN scheme), and the scheme of parallel original Swap Test circuit(referred to as PST scheme) are compared in reliability, efficiency and flexibility.
5.2.1 Reliability
In the NISQ(Noisy Intermediate-Scale Quantum) era, for quantum circuits, the error rate of the circuit increases as the width increases [34]. The widths of our scheme, SAN scheme and PST scheme are examine to prove the reliability.
In terms of width, the number of auxiliaries \(w_{k}\) of our scheme follows the recursive relation:
which means each time the number of input quantum states is doubled, two additional auxiliaries are required. It can be rewritten as \(w_{k}=2(k-1)\), and for SAN scheme the number of ancillaries is \(3(k-1)\). The relationship between the number of auxiliaries and the number of input quantum states (assuming that all input quantum states are single quantum states) is shown in Fig. 15. As shown in Fig. 15, the red line and the green line represent our scheme and SAN scheme respectively. Obviously it can be seen that the number of auxiliaries required by our scheme is less than that of the SAN scheme. Considering the additional auxiliaries brought by the subsequent two-state Swap Test, the number of auxiliaries can be reduced by using the improved Swap Test circuit mentioned in Fig. 5 through classical calculation. At this time, the total number of qubits required by our scheme is less than that required by the SAN scheme. As for the PST scheme, there is no doubt that it can be used to calculate each pair of states in parallel. To estimate the overlap of each pair of \(2^{k}\) states, \(C_{2^{k}}^{2}\) two-state Swap Test circuits are needed. There is no need for ancillary qubits to encode the results.
Therefore, our scheme is superior to SAN scheme in width, which implies that it has a lower error rate and higher reliability, and the original Swap Test is better than both two schemes.
5.2.2 Efficiency
The efficiency of the circuit is the number of measurement outputs for each run with a fixed amount of computational resources consumption. Intuitively, although our scheme contains more computing gates, it also outputs more results per run. To measure how efficiently the three scheme uses computational resources, the number of results per run divided by the number of gates in the circuit is defined as the efficiency of a scheme.
Consider the circuit for \(2^{k}\) input states. For our scheme, the circuit contains \((k-1)\cdot 2^{k-1}\) CSWAP gates and obtains \(2^{k-1}\) measuring results per run. The efficiency of our scheme is \(\frac{1}{k-1}\). For the SAN scheme, the circuit contains \(3 (2^{k-1}-1)\) CSWAP gates and obtains one measuring result per run. The efficiency of SAN scheme is \(\frac{1}{3 (2^{k-1}-1)}\). The relationship between the efficiency and the number of input quantum states (assuming that all input quantum states are single quantum states) is shown in Fig. 16. As shown in Fig. 16, the red line and the green line represent our scheme and SAN scheme respectively. It is clear from the Fig. 16 that our scheme is quite more efficient than the SAN one, which means that our scheme can get more measurement results with the same circuit size. For the PST scheme, each Swap Test circuit contains 3 CSWAP gates and obtains 1 measurement result per run. The efficiency of PST scheme is \({\frac{1}{3}}\). And the PST scheme has the best efficiency.
Based on all of the conclusions above, it can be realized that if the two-state Swap Test is used to calculate the overlap of each pair of states parallel, no auxiliaries is needed. And a circuit has small width and better efficiency. On the surface it seems that way. But consider that to get results corresponding to all the pairings in that kind of scenario, \(C_{n}^{2}\) pairing cases have to be manually calculated and be entered into the circuit separately where n is the number of input state. As n grows, such a manual action would be quite tedious and inefficient. So while making a sacrifice in the computational resources required for each output, the overall work is much more automated and much more efficient in our scheme. This is the point of our pursuit of concurrent circuit.
5.2.3 Flexibility
In our scheme, the width of quantum circuit is restricted to \(2^{k}\). For the case that the input quantum states could not be expressed as \(2^{k}\), there are some lines are redundancy. And the common solution is using the copy of some input states as the inputs of the redundancy lines, which seems to be a sign of inflexibility. However, the problem of this scheme is that the coding of the auxiliary qubits will show a complex and disorderly pattern for different qubits, so it is necessary to calculate the table of the corresponding pairs of auxiliary qubits and the circuit structure diagram for different numbers of qubit in advance. And then it is necessary to find the corresponding table to view the auxiliary qubits and construct the circuit when applying.
In contrast, if taking the scheme with a width of \(2^{k}\), it can cope with the needs with \(2^{k-1}+1\) to \(2^{k}\) input states by keeping the input as 0 for the extra qubits. This wastes a small number of bits, but we obtain a generalized line structure that does not require changing the line structure and the auxiliary qubit-pairing result correspondence table for different qubits, as long as the upper limit is not exceeded. No more tedious table lookup/construction of lines is required for application.
Due to above considerations, we abandon the arbitrary even number scheme and adopt our current scheme. Although it lacks flexibility, it is more general and convenient in the application process.
6 Conclusion
In this paper, a new quantum multi-party Swap Test algorithm is proposed. Given arbitrary number of input quantum states \(|\phi _{1}\rangle ,\ldots|\phi _{n}\rangle \), the algorithm provides a way to estimate the overlap \(|\langle \phi _{i}|\phi _{j}\rangle |^{2}\) for all pairs of input quantum states where \(i \ne j, i,j\in \{1,2,\ldots,n\}\).
A circuit \({\mathrm{U}}_{2^{k}}\) is constructed according to \(n(2^{k - 1} < n \le 2^{k} )\) input quantum states \(|\phi _{1}\rangle ,\ldots,|\phi _{n}\rangle \), which is used to obtain a specific superposition state, so that we can get all pairs of input quantum states at a specific position \((q_{2i-1},q_{2i}),i\in \{1,2,\ldots,2^{k-1}\}\). In order to decode the measurement results, we use \(O(k)\) auxiliary qubits, their measurement results reveal what the quantum state in the register is. Finally, the results are obtained by performing two-state Swap Test on these positions to estimate the value of overlap between each pair. \(O(k2^{k})\) CSWAP gates are used in the quantum circuit. Some experiments are carried out on IBM cloud platform, and an exact analysis is given to verify the correctness of our algorithm. At the same time, the reliability, efficiency and flexibility of our algorithm are analyzed. Compared with the scheme in [32], our scheme uses fewer auxiliary qubits, has higher reliability and performs better in terms of width. Compared with the original Swap Test, our scheme can provide a relative efficient circuit module with high cohesion.
There are many improvements to this algorithm in the future. For example, when the number of input quantum states cannot be expressed as \(2^{k}\), we can try to replace the bottom \({\mathrm{U}}_{2^{k-1}}\) structure of the circuit with another simpler structure. As shown in Table 3, the distribution of state pairs in the current design is not uniform, which will affect the accuracy of the overlap estimation of some state pairs. We will investigate strategies such as adjusting the choice of initial quantum states, or applying advanced post-processing algorithms to achieve a more uniform frequency distribution. Moreover, this scheme only focuses on the situation that we want to get the overlap between each pair of states in a group of quantum states. Referring to this way that using CSWAP gate to encode measurement results, we can get more schemes for other situations such as multi-group of input quantum states.
Availability of data and materials
Not applicable.
Abbreviations
- CSWAP:
-
Controlled-swap
- AOP:
-
A-optimal projection
- RR:
-
Ridge regression
- VQA:
-
Variational quantum algorithm
- CZ:
-
controlled-Z
- NISQ:
-
Noisy intermediate-scale quantum
References
Shor PW. Int J Theor Math Phys. 1982;21:467–88.
Deutsch D. Proc R Soc Lond Ser A, Math Phys Sci. 1982;400:97–117.
Shor PW. SIAM Rev. 1999;26:1484–509.
Grover LK. Proceedings of the 28th ACM symposium on theory of computing(STOC96); 1996. p. 212–9.
Lloyd S. Science. 1996;273:1073–8.
Farhi E, Goldstone J, Gutmann S, Sipser M. arXiv:quant-ph/0001106 (2000).
Yu CH, Gao F, Lin S. Quantum Inf Process. 2019;18(8):1–20.
Pan SJ, Wan LC, Liu HL. Phys Rev A. 2020;102(5):052402.
Liu HL, Wu YS, Wan LC, Pan SJ, Gao F, Qin SJ, Wen QY. Phys Rev A. 2020;104(2):022418.
Yu CH, Gao F, Wen QY. IEEE Trans Knowl Data Eng. 2021;33(3):858–66.
Yu CH, Gao F, Wang QL et al.. Phys Rev A. 2016;94(4):042311.
Wan LC, Yu CH, Pan SJ et al.. Phys Rev A. 2018;97(6):062322.
Yu CH, Gao F, Liu C et al.. Phys Rev A. 2019;99(2):022301.
Wan LC, Yu CH, Pan SJ et al.. Phys Rev A. 2021;104(6):062414.
Harrow AW, Hassidim A, Lloyd S. Phys Rev Lett. 2009;103:150502.
Jordan S. https://quantumalgorithmzoo.org/. Accessed: 2020-11-07.
Aimeur E, Zekrifa DMS, Gambs S. Proceedings of the 19th international conference on advances in artificial intelligence: Canadian society for computational studies of intelligence. Berlin: Springer-Verlag; 2006. p. 431–42.
Gottesman D, Chuang L. arXiv:quant-ph/0105032 (2001).
Garcia-Escartin JC, Chamorro-Posada P. Phys Rev A. 2013;87:052330.
Cincio L, Subaşı Y, Sornborger AT, Coles PJ. New J Phys. 2018;20:113022.
Fanizza M, Rosati M, Skotiniotis M, Calsamiglia J, Giovannetti V. Phys Rev Lett. 2020;124:060503.
Chabaud U, Diamanti E, Markham D, Kashefi E, Joux A. Phys Rev A. 2018;98:062318.
Linke NM, Johri S, Figgatt C, Landsman KA, Monroe C. APS March meeting 2018 Bull Am Phys Soc. 2017;63:1.
Schuld M, Sinayskiy I, Petruccione F, et al. arXiv:1409.3097 (2014).
Shao C. arXiv:1803.01601 (2018).
Zhao J, Zhang YH, Shao CP, Wu YC, Guo GC, Guo GP. Phys Rev A. 2019;100:012334.
Lloyd S, Mohseni M, Rebentrost P. arXiv:1307.0411 (2013).
Wiebe N, Kapoor A, Svore K. Quantum Inf Comput. 2014;15:318–58.
Havlíček V et al.. Nature. 2019;567:209–12.
Kang MS, Choi HW, Pramanik T, Han SW, Moon S. Quantum Inf Process. 2018;17:254.
Kang M-S, Heo J, Moon S, Han S-W. Sci Rep. 2020;9(1):5123.
Gitiaux X, Morris I, Emelianenko M, Tian M. Quantum Inf Process. 2022;21(10):344.
Preskill J. Quantum. 2018;2:79.
Acknowledgements
The authors would like to thank the editor and the referees for carefully reading the paper, and for their useful comments which helped improve the paper.
Funding
Ts work was supported in part by the National Key Research and Development Program in China(2022YFC3302103-01),the Strategic Research Program of Science and Technology Commission of the Ministry of Education of China(JYB2022-01), and the Fundamental Research Funds for the Central Universities.
Author information
Authors and Affiliations
Contributions
WL contributed to the initiation of the research and was a major contributor in writing the manuscript. YZL and HWY implemented circuit simulations. ZRW and WJ contributed to the comment and revision of the manuscript. All authors read and approved the final manuscript.
Corresponding author
Ethics declarations
Ethics approval and consent to participate
Not applicable.
Consent for publication
Not applicable.
Competing interests
The authors declare no competing interests.
Additional information
Publisher’s Note
Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Appendix
Appendix
See Table 7.
Rights and permissions
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article’s Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article’s Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/.
About this article
Cite this article
Liu, W., Li, YZ., Yin, HW. et al. Quantum multi-state Swap Test: an algorithm for estimating overlaps of arbitrary number quantum states. EPJ Quantum Technol. 11, 46 (2024). https://doi.org/10.1140/epjqt/s40507-024-00259-5
Received:
Accepted:
Published:
DOI: https://doi.org/10.1140/epjqt/s40507-024-00259-5