{'fraction_non_alphanumeric': 0.034227240649259, 'fraction_numerical': 0.020171724300164666, 'mean_word_length': 4.405276541640178, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Measuring the Tangle of Three-Qubit States

We present a quantum circuit that transforms an unknown three-qubit state into its canonical form, up to relative phases, given many copies of the original state. The circuit is made of three single-qubit parametrized quantum gates, and the optimal values for the parameters are learned in a variational fashion. Once this transformation is achieved, direct measurement of outcome probabilities in the computational basis provides an estimate of the tangle, which quantifies genuine tripartite entanglement. We perform simulations on a set of random states under different noise conditions to asses the validity of the method.


Introduction
The description of entanglement in a three-qubit system uncovers the subtle and vast problem of classifying and quantifying multipartite entanglement in a reliable way. Although the concept of entanglement is of central importance in the fields of Quantum Information and Computation [1], or in Condensed Matter Physics [2], there is no known general theory of entanglement yet. As the number of qubits increases, an exponentially large number of entanglement invariants under local unitaries can be constructed, and different entanglement classes can be distinguished [3][4][5]. Furthermore, the possibility of measuring these entanglement quantifiers on actual states seems out of reach for more than a few qubits [6].
The mainstream approach to deal with multipartite entanglement consists of considering different bipartitions of the system of n qubits and analyze the entanglement that characterizes them. The mathematical tool usually employed is the Singular Value Decomposition, which describes a pure state as a linear combination of product states from the two partitions of the complete system [7]. In turn, the eigenvalues of this decomposition can be used to compute entanglement entropies [8,9], which are employed to quantify entanglement. For condensed matter systems, the analysis of subsystems of increasing size displays the phenomenon of scaling of the entanglement entropy, often obeying the so-called area law [10].
In contradistinction to bipartite states, there is no simple equivalent to the Singular Value Decomposition for tripartite systems [11,12]. In that case, a canonical representation allows to set several coefficients of the original state to zero and fix some of its relative phases through local unitaries. In particular, the canonical form of three-qubit states was found by Acín et al. in Reference [13].
When dealing with pure bipartite states, a variational quantum algorithm [14,15] can be trained on several copies of the original state in order to discover the local unitaries that reveal its Schmidt form. Then, direct measurements in the computational basis provide the eigenvalues of the Singular Value Decomposition, which in turn are used to compute entanglement entropies. Here, we shall explore a similar strategy to obtain the canonical form and measure the tangle of three-qubit states. We propose a quantum circuit made of three local unitaries, each acting on one of the qubits. The action of these unitaries cast the state into its canonical form, up to relative phases, and can be determined in a variational way. Once this transformation is achieved, the frequencies of measurement outputs in the computational basis are used to compute the tangle of the three-qubit system, which quantifies genuine tripartite entanglement.
The standard procedure for measuring the tangle of a given quantum state involves performing quantum tomography [16]. Such method requires knowledge of 4 3 observables, obtained through 3 3 different measurement settings. In contrast, the algorithm herein proposed only needs one measurement setting, namely measuring in the computational basis, but several copies of the state are demanded for the optimization. Overall, both methods involve a similar number of copies. However, our proposal also returns the canonical form of the state.
The rest of the paper is organized as follows. The tangle of three-qubit states is briefly reviewed in Section 2. Then, the algorithm for measuring the tangle on a quantum computer is presented in Section 3. The results of simulations under different noise conditions are shown in Section 4. Finally, conclusions are drawn in Section 5.

Tangle in Three-Qubit States
Let us focus now in more detail in tripartite entanglement [17]. Consider a three-qubit system where each qubit constitutes a partition, namely, A, B and C, where {|ijk } are the computational-basis states, and the complex coefficients in the tensor t ijk obey a normalization relation. A genuine entanglement measure of a three-qubit system |ψ ABC is the tangle [18], denoted by τ. It can be obtained from Cayley's hyperdeterminant, which is a generalization of a square-matrix determinant [19]. To be precise, In this case, the hyperdeterminant Hdet(t ijk ) is a polynomial of order four in the amplitudes {t ijk } [20], Hdet(t ijk ) = t 2 000 t 2 111 + t 2 001 t 2 110 + t 2 010 t 2 101 + t 2 100 t 2 011 + 4 (t 000 t 110 t 101 t 011 + t 111 t 001 t 010 t 100 ) − 2 (t 000 t 111 t 011 t 100 + t 000 t 111 t 101 t 010 + t 000 t 111 t 110 t 001 + t 011 t 100 t 101 t 010 + t 011 t 100 t 110 t 001 + t 101 t 010 t 110 t 001 ) .
The distribution of the tangle τ for three-qubit random states is depicted in Figure 1. We consider random states with t ijk = a ijk + i b ijk such that a ijk and b ijk are random real numbers between −0.5 and 0.5, further subject to global normalization. These states tend to populate values of the tangle around ∼ 0.3. In contrast, the equivalent of the tangle for two-qubit states, namely the concurrence C = 2 |t 00 t 11 − t 01 t 10 |, peaks at larger values [21].
In the case of bipartite entanglement, knowledge of the Schmidt coefficients suffices to compute entanglement measures, whereas a full description of a three-qubit state is needed for computing the tangle. However, that being the case, a canonical representation of the three-qubit state may be achieved via local unitaries (LU), allowing for an easier characterization of the entanglement structure. Note that entanglement is not affected by LU [22]. This property of entanglement invariance under local unitary operations is a cornerstone of entanglement theory. In this sense, the canonical representation allows to set several amplitudes of the original state to zero and fix some of its relative phases. A canonical form of a tripartite state such that it respects all its entanglement invariants must be constructed with the use of three local unitaries U A ⊗ U B ⊗ U C , each acting on a partition. For a three-qubit state, the complete rationale for this construction goes as follows. The total number of degrees of freedom of a three-qubit state is 2 × 2 3 real numbers for the coefficients t ijk , minus a global phase and norm constraints, which makes a total amount of 14. Now, we remove the freedom carried by the three single-qubit unitaries, which is 3 × 3. Thus, the number of degrees of freedom is 5. In consequence, there are 5 entanglement invariants under local unitaries [13]. Note that a similar argument applied to n qubits shows that the number of entanglement invariants grows as 2 × 2 n − 3n − 2.
It is then always possible to bring a three-qubit state to a canonical form, where three amplitudes are set to zero and only one relative phase remains [13]. This canonical form reads where {λ i } are real positive values and φ is a relative phase 0 ≤ φ ≤ π, attached by convention to |100 . Once the canonical form of the tripartite state is obtained, it is possible to compute the 5 entanglement invariants [23] as where µ i = λ 2 i and ∆ = |λ 1 λ 4 e iφ − λ 2 λ 3 | 2 . Therefore, from Equations (2) and (5), it follows that Consequently, given a state in its canonical form, the tangle can be directly computed as the product of the outcome probabilities of the states |000 and |111 in the computational basis, multiplied by four.

Quantum Algorithm for Measuring the Tangle
Let us assume that we receive an unknown three-qubit state |ψ ABC . Our goal is to perform local unitary operations on this state in order to transform it to its canonical form in Equation (4). Such operations are defined as where |ϕ is the canonical form of |ψ ABC (we drop the subscript ABC in the canonical form for convenience), and each unitary takes the form with θ = (θ 0 , θ 1 , θ 2 ). It is then necessary to find the values ( θ A , θ B , θ C ) opt that achieve this transformation. We will follow a hybrid variational strategy and define where C is the cost function, defined as Notice that the optimal solution, i.e., the configuration ( θ A , θ B , θ C ) opt that renders this cost function equal to zero, transforms |ψ ABC into an up-to-phases canonical form |φ , given by |φ = λ 0 |000 + λ 1 e iφ 1 |100 + λ 2 e iφ 2 |101 + +λ 3 e iφ 3 |110 + λ 4 e iφ 4 |111 .
Such transformation is less restrictive than the canonical transformation in Equation (7). Therefore, there exist many possible optimal parameters. The quantum circuit implementing this operation is depicted in Figure 2. Once the optimal parameters are obtained, it is straightforward to measure the tangle τ in an actual quantum computer. This quantity will be equal to where P ijk is the probability of measuring |ijk . The statistical additive error of P ijk is given by the sampling process of a multinomial distribution, that is, P ijk (1 − P ijk )/M, where M is the number of measurements.
We propose a manner to mitigate random errors occurring when computing the tangle, via post-selection. After the optimization is completed, and a low value of the cost function is obtained, it is licit to assume that |ψ ABC has been properly transformed into |φ . Thus, if the outcome of a measurement is either |001 , |010 or |011 after the transformation into the up-to-phases canonical form, it is due to an error in the circuit. In this case, this outcome can be discarded.

Simulations
The algorithm for measuring the tangle can be benchmarked on simulations. We considered a set of 1000 random states, accounting for finite sampling and noise. The state |GHZ = (|000 + |111 ) / √ 2 has been treated as a particular case, as it is the one that maximizes the tangle and, in addition, it is already in its canonical form. To be precise, we sampled 10 4 times and introduced random Pauli errors in the quantum circuits in every run, for increasing noise levels. Each measure of the tangle has been repeated ten times, with and without post-selection. We employed the standard Python Library Scipy [24] for the optimization procedure. In particular, we employed the Powell method as it was found to provide accurate results [25]. The mean number of optimization steps is of the order of a few hundred.
Not all optimization instances were found to be satisfactory. Some trials did not reach a proper minimum during the first attempt. In order to avoid outliers, only those instances whose cost function was under a certain threshold were accepted. For those that did not match this criterium, the algorithm was rerun. A maximum number of five attempts were allowed.

Error Model
We now present the error model that we have used in the simulations. In this model, single-qubit gates can appear randomly with certain probabilities, to be discussed later. These gates modify the state within the quantum circuit and may appear only after applying the unitary gates from Equation (7). As the algorithm for measuring the tangle does not require the use of entangling gates, we assume that the qubits have no cross-talk, and thus two-qubit errors are omitted.
We consider two different types of error. First, random bit-flips, phase-flips and bit-phase-flips are modeled with Pauli-X, Z, and Y gates respectively. All of them may appear sequentially for each one of the qubits. The second kind of error is measurement errors, which are modeled with a Pauli-X gate appearing just before readout. A scheme for the occurrence of these gates is shown in Figure 3.
Every gate has an independent probability of appearing in the circuit, i.e., all error events are uncorrelated. Therefore, the probability of one error ε occurring is where p e is the probability that one error occurs, and the product runs over all possible errors. This can be easily extended to calculate the probability of occurrence of a higher number of errors. The probabilities of single-qubit and measurement errors are taken as 0.1 t% and 1 t% respectively, where t = {0, 1, 2, 3, 4, 5} is a tuning parameter. These numbers were selected in agreement with the orders of magnitude present in the experiment in Reference [26]. Considering t = 5, there is one error in ∼ 17% of the samples, and there are ∼ 1.5% of events with two errors. Three or more errors are unlikely to happen, with appearance rates under 0.1%.
As Pauli-X, Y, Z gates do not commute, choosing to apply first one or another is not equivalent. However, the probability of this kind of events is very low. For instance, the probability of two measurement errors is p ∼ 10 −4 , of one measurement and one single-qubit error is p ∼ 10 −5 , and for two single-qubit errors is only p ∼ 10 −6 . Therefore, we choose one particular ordering. Notice as well that the tangle is not affected by some of these errors, such as Pauli-Z errors alone.

Results
Two different types of simulations have been carried out. First, we study the |GHZ state, which maximizes the tangle, τ = 1. This state is already in its canonical form. Therefore, there is no need for applying single-qubit gates, and no optimization procedure is needed in this case. The averaged results for the tangle obtained without optimization are represented by solid lines in Figure 4, while the shadowed regions span all results. On the other hand, the full procedure can be applied to the |GHZ state as if it were an unknown input state. The results obtained in the latter manner are shown as dots in Figure 4. This allows us to check that the distortion induced by the optimization procedure does not play a significant role. Both methods were simulated with and without post-selection. Secondly, we consider 1000 random states and simulate the proposed algorithm for measuring the tangle. The final results are depicted in Figure 5. As it should be expected, results are better for post-selected cases. Those random states whose optimization returned a value of the cost function C above a certain threshold have been discarded. This process cleans the points far from the solid line in Figure 5. From now, we set said threshold to t 2%, i.e., for t = 5 we allow a minimization error up to 10%.  From the results obtained, it is possible to conclude that circuits with no errors can estimate the tangle properly. In contrast, circuits where errors occur present a tendency to return values of the tangle which are lower than the exact ones. Besides, dispersion increases with the errors. We present, in Figure 6, results of the relative errors in the computation of the tangle, given by where τ is the estimate obtained through the variational method, and τ is the exact result. It can be observed that the average behavior of this algorithm in the presence of noise is to underestimate the tangle, as already mentioned. The procedure alone returns an estimate of the tangle ∼ −30% lower than the exact value, while post-processing reduces the error to ∼ −17%.

Conclusions
We have presented a variational quantum algorithm that casts an unknown three-qubit state into its canonical form, up to relative phases, given many copies of it. Subsequently, the tangle can be readily measured. The idea behind this procedure is to set three out of eight amplitudes, namely those corresponding to |001 , |010 and |011 , to zero. Furthermore, a post-selection scheme allows for a mitigation of the errors.
We have performed simulations on a set of random states to benchmark the proposed algorithm under different noise conditions. We have found that the quantum circuit delivers the correct value of the tangle, with a degradation of the results as the noise levels increase. To be precise, assuming errors comparable to those in state-of-the-art quantum processors, the average relative error is of the order of ∼ −17%. It is noteworthy that the tangle is, in most cases, underestimated.
This algorithm does not provide an improvement in the required number of copies of the quantum state, compared to quantum tomography. Nevertheless, the method herein proposed also returns the canonical form of the states and, therefore, might be used as a module in other algorithms. For instance, it can be applied as a pre-processing for a quantum classifier. That is, once the canonical form is cast, the quantum classifier may use this feature to distinguish between different quantum states for a particular task.

Conflicts of Interest:
The authors declare no conflict of interest.