The controlled SWAP test for determining quantum entanglement

Quantum entanglement is essential to the development of quantum computation, communications, and technology. The controlled SWAP test, widely used for state comparison, can be adapted to an efficient and useful test for entanglement of a pure state. Here we show that the test can evidence the presence of entanglement (and further, genuine n-qubit entanglement), can distinguish entanglement classes, and that the concurrence of a two-qubit state is related to the test's output probabilities. We also propose a multipartite measure of entanglement that acts similarly for n-qubit states. The number of copies required to detect entanglement decreases for larger systems, to four on average for many (n>8) qubits for maximally entangled states. For non-maximally entangled states, the average number of copies of the test state required to detect entanglement increases with decreasing entanglement. Furthermore, the results are robust to second order when typical small errors are introduced to the state under investigation.


Introduction
Quantum entanglement is an essential resource for obtaining a quantum advantage in communications [16; 38], metrology [11; 43], imaging [1; 33], and computation [8; 14; 35]. Quantum teleportation [9] uses pre-shared entanglement to transfer an unknown quantum state from one location to another using only classical channels. It provides a fundamental primitive for quantum information processing. Teleportation has been realised optically [47; 18] and with ion traps, [42] as approaches towards distributed quantum computation [5].
In general, the amount of entanglement in a state determines its usefulness. For example, information can only be teleported perfectly by maximally entangled states [44], which are necessarily pure. The current widely-used method for experimentally determining entanglement, quantum state tomography, does not scale well with an increasing number n of qubits [6]. This makes practical alternative tests of interest. In this paper, we investigate a method for detecting entanglement and quantifying the amount of entanglement in a multipartite pure state: the controlled SWAP test.
The controlled SWAP test for entanglement discussed here is an adapted version of the widely used controlled SWAP test for state comparison, which determines whether a pair of states are inequivalent, and requires only a single application of the test to achieve this. This elegance can be applied to the detection and quantification of entanglement in a state, and so is promising as a more efficient alternative to quantum state tomography. The controlled SWAP test for entanglement was first introduced in [7], and then used by Gutowski et al. [24] to prove a series of computational complexity results, by using repeated applications of the controlled SWAP test for entanglement as a product state test. Although detecting entanglement can be done efficiently, the inverse problem -determining whether a given state is a separable, i.e., a product state -is NP-hard [23]. Our purpose in this paper is practical: to determine the conditions under which the controlled SWAP test for entanglement is likely to be experimentally useful.
The paper is laid out as follows. First, pure state entanglement and its measures are introduced in Section 2. The controlled SWAP test for state comparison is then explained in Section 2.2, leading on to its adaptation to the controlled SWAP test for entanglement in Section 3. Then in Section 4.1, we present the outcomes of the test for a range of pure states, and the corresponding results in terms of the multipartite measure of entanglement in Section 4.2. The efficiency of the test for these various states is considered in Section 4.3, and finally several typical error scenarios are investigated in Section 5.
A composite system |ψ 2 is in an entangled state if it cannot be written as a product state for its component systems, i.e. |ψ 2 = |ψ 1 |φ 1 for any pure states |ψ 1 , |φ 1 . The concurrence [45] is a measure of two-qubit entanglement, with 0 ≤ C 2 ≤ 1, so a separable or 'product' state has C 2 = 0 and a maximally entangled state has C 2 = 1. There are many other measures of entanglement which quantify the amount of entanglement in a state, though for bipartite pure states they can all be shown to be equivalent to the entropy of the subsystems [36]. For two qubit states, concurrence is simpler to calculate, so more convenient for our work. More generally, an entanglement measure has to satisfy certain properties, such as not increasing on average under local operations and classical communication (LOCC) [34]. In essence, it must be true that [41] where ε is an entanglement measure, j refers to the outcomes of a local measurement, and p j the probability of these outcomes. For two qubit entangled states, the possibilities are straightforward. There are four orthogonal maximally entangled two-qubit states [34; 39], known as the Bell states: Under reversible LOCC, Bell states can be transformed into one another, but cannot be transformed into a state with less than maximal entanglement. Bell states are therefore considered equivalent to one another and form a unique class of maximally entangled two-qubit states. For systems with more than two qubits, there are multiple distinct classes of entanglement, based on whether the states can be transformed into each other under reversible LOCC. Within each class, there is a subset of maximally entangled states. For example, for three qubits, there are two types of pure entangled states, GHZ [13] and W states, which are inequivalent under reversible LOCC. For more qubits, GHZ and W states naturally generalise, alongside further distinct types of entangled states. In the computational basis for n qubits where n ≥ 3, the maximally entangled GHZ and W states are [15] where we have introduced the notation |0 n for n qubits all in state |0 . Under reversible LOCC, GHZ and W states remain maximally entangled within their respective classes. However, GHZ states are considered more entangled than W states, based on various pure state entanglement measures; while W states are more robust, as loss or measurement of some qubits can still leave an entangled state of the remainder [15]. In this paper, we focus on these two types of entangled states, which are of particular interest due to their applications in quantum computing [13; 28; 30].
Reversible (unitary) transformations of quantum states can be represented as quantum gates, the model used in this paper. An important and relevant single-qubit example is the Hadamard gate H: [34] Multi-qubit gates of relevance include the two-qubit CNOT gate which flips the target qubit only if the control qubit is |1 . It can be represented by the matrix where the first qubit is the control and the second the target. The three-qubit Toffoli gate has two controls and one target: the target qubit is flipped only if both the controls are |1 . It has the matrix where the first two qubits are the controls.

Experimentally determining entanglement
The most commonly used method for determining entanglement is quantum state tomography. Quantum state tomography builds a system's density matrix entry by entry in order to derive its entanglement. A large ensemble of identical states is prepared to carry out the required number of measurements [4; 29; 2]. The density matrix grows exponentially with the system size and so this method becomes unfavourable for large systems. For an n-qubit state, the number of measurements required is typically [6; 2] in the order of 3 n . If only the entanglement of the system is of interest, there are alternative methods that are arguably more efficient. Entanglement witnesses are functionals of a state's density matrix that can be directly measured and determine whether a state is entangled. To obtain the witness of an n-qubit state, as few as 2n − 1 measurements are required. However, the witness must be optimised for the state, and so this is not a general method [25; 40; 20].
Many attempts have been made to improve upon the above methods in terms of efficiency and generality. The experiment in Walborn et al. [39] determines how entangled two-qubit states are by measuring only the final polarisation. This method is able to detect and distinguish Bell states; the probability of measuring the |Ψ − Bell state is then related to the concurrence to quantify the entanglement. Thousands of measurements are needed to achieve sufficient statistics. Theory extending this method to any number of qubits is provided by Harrow and Montanaro [27]. Further proposals include Ekert et al. [17] which is also based on the controlled SWAP test for state comparison, and Amaro et al. [3] which is an improved witness-based method.

The controlled SWAP test for equivalence
The controlled SWAP test for equivalence is a widely applied method for determining whether two given pure n-qubit states |ψ and |φ are equivalent, detailed in [12] and its optical implementation in [7]. The circuit for this procedure can be seen in Figure  1a. Three states are required, with the initial composite state |Ψ = |ψ A |φ B |0 C . A Hadamard gate is applied to the control qubit C, followed by a controlled-SWAP gate on the two test states A and B, controlled on the single qubit [7; 19; 21]. The SWAP gate is applied according to the state at the control qubit C: if |C = |0 C there is no change, whereas |1 C will result in the states of A and B being swapped Figure 1: The quantum circuit for an equivalency SWAP test on the two states |ψ and |φ . H is a Hadamard gate from equation (7). (a) The SWAP gate swaps all qubits in the test states on the condition that the control qubit is in state |1 . (b) shows the SWAP gate broken down into individual gates for the one-qubit test state case. The central gate, shown in red, is a Toffoli gate from equation (9) and the two gates either side in blue are CNOT gates from equation (8), where the crossed circles are controlled on the dots. The final CNOT gate -not necessary for the test outcome -returns the system to its initial state in the case of equivalent states. [19]. In the case of a single qubit state comparison, the SWAP gate is composed of two CNOT gates [34] and a Toffoli gate [34], as shown in Figure 1b [7; 31]. Finally, another Hadamard gate is applied to the control qubit. The resulting composite state is then It is clear that if |φ = |ψ , the control qubit will be in |0 C with absolute certainty.
Measuring the control qubit in |1 C therefore proves that the two states A and B are inequivalent. If the two states are identical, confidence of this outcome is increased by repeating the test and obtaining multiple measurements of |0 C with no measurements of |1 C [19; 7; 21].

The controlled SWAP test for entanglement
The controlled SWAP (c-SWAP) test for state comparison can be modified to instead test for entanglement. This is outlined for the two-qubit state case in van Dam et al. [7], along with a potential optical setup. Harrow and Montanaro [26] discuss multiple applications of the c-SWAP test as a product-state test, proving its correctness for all numbers of qubits and its optimal soundness. Following this, Gutoski et al. [24] prove the product-state c-SWAP test is a complete problem for the complexity class BQP. This section details the theory of the c-SWAP test for entanglement. The quantum circuit used for state comparison, Figure 1, is adapted to Figure 2. Two copies of the state to be tested for entanglement are required, labelled |A A and |B B , and several control qubits -one control qubit for each qubit in the test state. Figure 2a shows the quantum circuit for the simplest case, a two qubit entangled state. Initially, the control state is in |00 C . The two Hadamard gates and the SWAP gate act on each qubit in the control state. The SWAP gate is applied to the corresponding qubits in the test states such that the ith qubits in the test and copy states are swapped with one another if the ith qubit in the control is |1 C . The initial composite state is Passing this system through the entire test in Figure 2 gives the final result Ideally, the copy state is an exact copy of the test state. In this case, the above equation reduces to and so the probability of the control being in |01 C or |01 C is zero. This expression can in fact be written in terms of the concurrence C 2 (as given by equation (2)): with the ±s being + in the case that A 00 A 11 > A 01 A 10 and − if A 00 A 11 < A 01 A 10 .
If the system is in a product state then C 2 = 0; applying this to the above equation and so the control state is |00 C with certainty. Any measurement of |11 for the control qubits therefore proves a non-zero concurrence, and evidences the presence of entanglement [7] in state |A . Note that if the test state is a product state, and only then, the final state is the same as the initial state. In this case, the test is non-destructive and so the output state can be used as an input state in the next test iteration.
To expand the setup to any number of qubits n, the test simply requires n control qubits, as shown in Figure 2b. The summation notation above as derived by [7] demonstrates that certain outcomes of the control state evidence entanglement in the test state. However, fully investigating the capability of the c-SWAP test requires the derivation of the expanded resulting state, which we discuss in the next section.

The controlled SWAP test on ideal states
We have analytically derived the final probability distributions in the control state for the most general pure two-qubit and three-qubit test states. The final expressions are quite lengthy, and are given in Appendix A and Appendix B respectively. Specialising to more symmetric classes of states, for which these expressions simplify, we then extrapolated the probability expressions to those for n-qubit states, verified these by computation up to six qubits for non-symmetric test states, and to eight qubits for symmetric test states. In this section, we present the results for GHZ and W states, discuss their relationship to the amount of entanglement in the test state, and investigate the measurement efficiency of the test.

Bell, GHZ, and W states
If the test state is a product state, then only |0 will be measured for any qubit in the control state. In the ideal case, where the copy state is an exact copy of the test state (unequal copy states are investigated in section 5.2), a measurement of any number of |1 s in the control evidences the presence of entanglement. These states, with one or more |1 s, that provide evidence of entanglement we call entanglement signatures.
If the test state is a Bell state and the copy state is an exact copy, for example |A = |B = |Ψ + from equation (4), the resulting probability distribution in the control state is: As seen in Section 3, any measurement of |11 C evidences some amount of entanglement for any two-qubit state. Therefore this is the entanglement signature for all two-qubit systems. Probability P 0 (W) P 0 (GHZ) P two (W) P even (GHZ) Figure 3: The probability results for maximally entangled GHZ and W states for increasing number of qubits n. P 0 refers to P (|0 n C ), P even to P (|even no. of 1s n C ), and P two to P (|exactly two 1s n C ).
When |A = |B = |GHZ n as in equation (5), the probability results in the control state are where n is the number of qubits in the test state. All other states have zero probability. The states |even no. of 1s C are the entanglement signatures for any GHZ-like state. When |A = |B = |W n as in equation (6), the probability expressions in terms of n are with |exactly two 1s C as the entanglement signatures for W-like states. For n = 2, the equations for both GHZ and W reduce to those for Bell states, and so for much of the paper we only consider Bell states as the GHZ/W n = 2 case. As seen in Figure 3, the probability of measuring |0 n C and the entanglement signatures each converge to 1 2 as n increases, for both maximally entangled cases. The entanglement signature probabilities are always greater for GHZ states than for W states, and as n increases so does the signature probability. This suggests that the entanglement signature probabilities are related to the amount of entanglement in the test states.   (16) against number of qubits for the GHZ state from equation (5) and W state from equation (6).

Quantifying the amount of entanglement
If |A = |B , the two-qubit probability expressions in terms of the concurrence C 2 from equation (2) are Therefore, if the control state's probability distribution is obtained (from repeats of the c-SWAP test), these results can be used to calculate the concurrence. Exploration of the results of the c-SWAP test for a range of example states leads us to propose a more general expression for the amount of multipartite entanglement C n : which is consistent with two-qubit concurrence from equation (2). C n therefore has a range of 0 ≤ C n ≤ 2( 1 2 − 1 2 n ) 1 2 , with the upper limit tending to √ 2 as n → ∞. Figure. 4 shows the behaviour of this expression C n for the GHZ n and W n states. As expected, the W state has a value of C n consistently lower than that of a GHZ state. As n approaches infinity the C n of both W states and GHZ states tends to √ 2, but at a lower rate (as a function of n) in the W case.
As previously discussed, a valid measure of entanglement must satisfy the equation (3) for any state, i.e.: for any |ψ . It is trivial to prove that this condition is satisfied for all W-like states (the probability expressions of which are shown in Appendix C.3), and of course all GHZlike states (because measuring a single qubit destroys all GHZ-like entanglement). From the results in Appendix B we have shown computationally that this condition is satisfied for any 3-qubit pure state, and we thus conjecture that it is true for any n-qubit pure state.

Efficiency
The resource we will be considering as a indicator of efficiency is the number of copies of the test state required for the test. If the operator of the test is only interested in detecting some entanglement in the test state (without obtaining knowledge of the amount, or whether it is genuine n-qubit entanglement), only one entanglement signature needs to be detected. It is straightforward to calculate the average number of measurements on the control state, and therefore the average number of copies, required to reveal the first entanglement signature. The expected number of copies is simply E any (no. of copies) = 2 P (|even no. of 1s C ) .
Therefore, the less entangled the state, the lower the entanglement signature probability, and the higher the number of measurements required. This can be illustrated in terms of proposed measure of entanglement C n from equation (16): E any (no. of copies) = 8 C 2 n shown in Figure 5. This expression depends on n only through C n , which for a maximally entangled state increases with increasing n from a value of one for n = 2 towards an upper bound of √ 2. Thus, for maximally entangled states, entanglement can be detected on average with eight copies or fewer. With increasing level of entanglement, the expected number of copies decreases at a rate inversely proportional to the square of C n ; as such, there is a large range of C n for which the expected number of copies is reasonably low.
Also plotted in Figure 5 are the values of E(Y ) = 3 n , the minimum number of copies required for quantum state tomography. This figure therefore illustrates the range of C n of a given n-qubit state for which the c-SWAP test requires less copies (on average) than quantum state tomography: (the upper bound of which is C n 's absolute maximum). For example, 0.31 < C 4 ≤ 1.32 for 4-qubit states and 0.18 < C 5 ≤ 1.37 for 5-qubit states. When evidencing entanglement, there is a large regime in which the c-SWAP test outperforms quantum state tomography in terms of required number of copies. This is especially true for large systems, where for almost any amount of entanglement the c-SWAP test would be more suited than quantum state tomography.
However, if knowledge that the test state is genuinely n-qubit entangled is required then the required number of copies increases. Instead of detecting any one entanglement signature, one more than the total number of entanglement signatures for the (n − 1)-qubit case must be observed. Therefore the expected number of copies  Figure 6b. The GHZ state and W state cases are shown in Figure 6a. The scaling with both n and C n is not favourable. However, the values of E(no. of copies) for quantum state tomography have again been plotted and there is a regime where the number of copies required for the c-SWAP test are less than 3 n , for states with high entanglement and less than five qubits. Therefore, carrying out this more detailed c-SWAP test is still favourable for highly entangled small systems.

Robustness against errors
To examine the robustness of the c-SWAP test we consider a range of possible errors. Clearly, it is possible that the pure state supplied is not exactly as expected. One typical example of this is that errors in the test and copy state could occur as errors in their existing non-zero amplitudes, which will be referred to as unbalanced.
Another typical error could be an additional non-zero amplitude introduced into the state, referred to as corrupted. Furthermore, a quantum state can also interact (entangle) with its environment and through this suffers a level of decoherence. For example, dephasing, energy dissipation, and scattering all cause decoherence, which from an ensemble perspective introduces mixture (and non-zero entropy). From a . Also shown are the crossover points (marked with crosses) for minimum scaling for quantum state tomography, E(no. of copies) = 3 n , such that values of C n right of the tomography plots give numbers of copies less than 3 n . state perspective, errors in the state amplitudes arise [34]. In this example it may be that only the copy state contains error and so the test state and copy state are not equivalent, which we refer to as unequal, as would be expected from sampling a mixed ensemble. Here we also investigate an example unequal case, where the copy state is unbalanced but the test state is not.

Unbalanced
Our first example of error is to vary the amplitudes of otherwise maximally entangled states. Consider an unbalanced n-qubit GHZ state: The c-SWAP test results therefore are which are shown in Figure 7a (as well as the unbalanced Bell state which is the n = 2 case). The error introduced by a small non-zero value of δ is ∆ = (2 − 4 2 n )δ 2 . The n dependence goes to zero exponentially, so the leading order is independent of n. Therefore the error is approximately 2δ 2 for small delta and so in this case the test is robust, by which we mean that the leading order is δ 2 , as opposed to δ.
An unbalanced GHZ 3 state can replicate the probability results given by a W 3 state. This happens in the above parametisation when δ = ± sin −1 2 3 − π  (17). The dashed line denotes P (|even no. of 1s C ). (b) shows the results for unbalanced W test states from equation (18). The dashed line denotes P (|exactly two 1s C ).
This requires amplitude percentage errors of 15% and 18%, a large margin of error. If necessary this uncertainty can be overcome by measuring one qubit and then applying the two-qubit c-SWAP test to the remaining state, to detect any remaining entanglement. The result would always be zero for an unbalanced GHZ 3 but not for a W 3 state. This 'mimic' case is only possible with three-qubit states.
Consider an unbalanced W state with error introduced to one amplitude and the compensating error spread across the remaining amplitudes: This gives sin 2 δ (4(n − 1) + (n − 2) sin 2 δ) P (|exactly two 1s C ) = 1 2 − 1 2n + 1 2n 2 (n − 1) sin 2 δ (4(n − 1) + (n − 2) sin 2 δ) shown in Figure 7b. For small δ, the error ∆ = 2 n 2 δ 2 . The n-dependence tends to zero with increasing n. Unlike the GHZ case, there is no term independent of n and so for large n there is very little variation in probability for any δ.  (a) shows the probability results against δ for inequivalent copy states where one is a GHZ state and the other is equation (19). The dashed line denotes P (|even no. of 1s C ) and the dotted line denotes P (|odd no. of 1s C ) (which is the same for all n). (b) shows the results for one W state and copy state equation (20). The dashed line denotes P (|exactly two 1s C ) and the dotted line denotes P (|exactly one 1 ).

Unequal
While the c-SWAP test requires two copies of the test state, it may be that the two generated states are not equivalent (|A = |B ) if these are drawn from a mixed ensemble.
Consider the error case |A = |GHZ n (or |A = |Φ + in the n = 2 case) and giving: shown in Figure 8a. Any measurement of an odd number of |1 s in the control therefore demonstrates that the test state and copy state are not equivalent. This is similar to the c-SWAP test for equivalence from Section 2.2, where any measurement of |1 in the control qubit demonstrates the two test states are inequivalent. The equivalency c-SWAP test applied to the same test states from equation (19) that we have just considered for the entanglement c-SWAP gives the resulting probability of measuring |1 C (and therefore certainty of inequivalence) as: P (|1 C ) = 1 2 cos δ sin δ which with small δ approximates to ∆ 1 = 1 2 δ. This is in fact less robust than the entanglement test, the errors for which are all second order: for small δ, the errors satisfy ∆ 0 = 1 2 n δ 2 , ∆ odd = 1 2 δ 2 , and ∆ even = ( 1 2 − 1 2 n )δ 2 . Interestingly, the unequal states signature probability, P (|odd no. of 1s C ), has no n-dependence. Where it is present, the n-dependence again is confined to the coefficients and the error tend to zero exponentially with n. As its error has no term independent of n, P (|0 n C ) tends to 1 2 for large systems and so cannot be used as as indicator of large error. P (|odd no. of 1s C ) and P (|even no. of 1s C ) however always vary with δ.

Corrupted
Another source of error is to 'corrupt' an entangled state by introducing an additional non-zero amplitude. The following cases assume the test state and copy state are exact copies. The case |A = |B = cos δ |GHZ n + sin δ |0...1 (21) gives: shown in Figure 9a. For small δ, the error is ∆ = 2 2 n δ 2 and so again the errors tend to zero exponentially with n. Unlike the other GHZ examples, the individual signature probabilities are not equal to one another. The probabilities for states ending with |1 s and those ending with |0 s have different values, with the former independent of n. This is due to the final |1 in the additional state and alternative 'extra' states give different individual probabilities. shown in Figure 9b. For small δ the errors are ∆ = (1 − 1 n )δ 2 . The leading order is therefore independent of n, with the n dependence tending to zero inversely with n.

Summary and conclusions
Entanglement is essential for quantum information processes such as quantum teleportation. The controlled SWAP test is a proposed method to detect and quantify entanglement for any n-qubit pure state. We have investigated when it is practical to use and potentially more efficient than quantum state tomography. In terms of the required number of copies of the test state, the c-SWAP test for entanglement is more efficient for detecting entanglement for almost all states except two-qubit states. The average number of copies required to detect the presence of entanglement can be as low as four for larger high fidelity maximally entangled states. For perfect Bell states, it typically requires eight copies, and for states that are not maximally entangled it can rise to a thousand or more, with more copies required the less entangled the state is. The number of qubits n in the state has considerably less effect on this value, which in fact decreases with increasing n, and so the number of copies scales extremely well with system size. However, the short gate sequence required for the c-SWAP test for entanglement is more complicated than the single qubit rotations typically [2] required for quantum state tomography. Especially for linear optics [32], additional ancillary resources are needed if a probabilistic set up is used, to teleport in the gates, for example [22; 10]. In other settings, for example Rydberg atomic qubits [37], the long range interactions may facilitate the multi-qubit Toffoli gates [46], making the c-SWAP test more viable.
The test is also able to distinguish classes of entanglement in almost all cases (there is one case of three qubits for which the test is fooled, but this requires 18% amplitude error in the generated state). The results from a two-qubit test state are directly related to the concurrence of the state. Further, a multipartite measure of entanglement has been constructed that is given by any state's c-SWAP test results. Hence, the c-SWAP test can be used to estimate amount of entanglement in the test state. Detecting genuine n-qubit entanglement is more involved, and scales far less favourably with both n and the amount of entanglement, but is feasible for small numbers of qubits. Even though the test is capable of quantifying the amount of entanglement in the state, it is only suited to achieving this with small highly entangled systems.
The suitability of the entanglement SWAP test for experimental implementation is highlighted by the fact that various typical small deviations from ideal states all give second order errors for any number of qubits. This favourable error dependence allows the entanglement to be estimated accurately in a practical set up.
Future work, beyond the results reported here, could investigate in more detail the application of the controlled SWAP test to mixed states and other types of entangled states (qudits, coherent states). This would expand on our consideration of corrupted, unbalanced, and unequal test and copy states, and provide further information to support the practical application of the c-SWAP test for entanglement.

Appendices
Appendix A. Two-qubit probability results For completely general test states from equation (1) where |A = |B : If |A = |B : where C 2 is the concurrence.

Appendix B. Three-qubit probability results
For completely general test states where |A = |B :