Entanglement detection with classical deep neural networks
In this study, we introduce an autonomous method for addressing the detection
and classification of quantum entanglement, a core element of quantum mechanics
that has yet to be fully understood. We employ a multi-layer perceptron to
effectively identify entanglement in both two- and three-qubit systems. Our
technique yields impressive detection results, achieving nearly perfect
accuracy for two-qubit systems and over $90\%$ accuracy for three-qubit
systems. Additionally, our approach successfully categorizes three-qubit
entangled states into distinct groups with a success rate of up to $77\%$.
These findings indicate the potential for our method to be applied to larger
systems, paving the way for advancements in quantum information processing
applications.
Julio Ureña, Antonio Sojo, Juani Bermejo, Daniel Manzano
# Entanglement detection with classical deep neural networks

###### Abstract

In this study, we introduce an autonomous method for addressing the detection and classification of quantum entanglement, a core element of quantum mechanics that has yet to be fully understood. We employ a multi-layer perceptron to effectively identify entanglement in both two- and three-qubit systems. Our technique yields impressive detection results, achieving nearly perfect accuracy for two-qubit systems and over 90% accuracy for three-qubit systems. Additionally, our approach successfully categorizes three-qubit entangled states into distinct groups with a success rate of up to 77%. These findings indicate the potential for our method to be applied to larger systems, paving the way for advancements in quantum information processing applications.

## 1 Introduction

Entanglement is one of the most important features of quantum mechanics. First proposed by Einstein, Podolski, and Rosen as a pretended proof of the incompleteness of the theory [1], it was later considered by Schrodinger as _the characteristic trait of quantum mechanics, the one that enforces its entire departure from classical lines of thought_[2]. Beyond its philosophical and fundamental interest, entanglement is a crucial resource for the development of new quantum technologies, being key to techniques such as quantum teleportation [3, 4], measurement-based quantum computation [5, 6], or super-dense coding [7].

One problem associated with entanglement is the development of separability criteria and entanglement measures [8, 9]. This problem is based on determining if a certain quantum system is entangled or not. Several criteria has been proposed including the celebrated Bell's inequalities [10], the Peres-Horodecki positive partial transpose criterion (PPT) [11, 12], entanglement witnesses [13, 14], and entropic criteria [15, 16]. For systems of dimension up to 6, the PPT criteria gives sufficient and necessary conditions for a quantum state, pure or mixed, to be entangled. For systems with a higher dimension there are not known sufficient conditions.

Recently, the fields of machine learning and quantum mechanics have been recently merged in the new field of _quantum machine learning_ (QML). This connection has been made in two directions. First, quantum features can be used to enhance the learning process [17, 18]. Second, machine learning techniques can be used to learn quantum operations and to design experiments [19, 20]. One specific line of research in these directions are quantum neural networks (QNN), meaning learning models inspired by biological systems [21, 22, 23].
In this paper, we address the problem of separability determination by the use of a deep multilayer perceptron (MLP) [24, 25], in order to develop an autonomous method for entanglement detection. We first test it in a solvable model, a two-qubit system, showing that it can acquire practically a 100% efficiency after a small number of learning experiences and with simple topologies. We check these results in dependence with the entanglement of the system and with its purity. Furthermore, we also study the stability of the detection procedure when noise is added to the system. Finally, we apply the same method to a non-solvable model, a three qubits system, and we show that the network can reach high efficiency rates close to 100% for the highest entangled cases. For this problem we also study the performance of the network based on the different entanglement families showing that some families are easier to classify than others.

This problem has been recently addressed in Refs. [26, 27] for the two qubits case and in Ref. [28] for systems up to 10 qubits with bipartite entanglement. In these works they can detect entanglement with very different efficiencies up to 97% in the best case scenario. We improve this efficiency and we show also the capabilities of neural network to distinguish between different amounts of multipartite entanglement.

## 2 Multilayer perceptron and the learning procedure

In this section, we provide a short explanation of the MLP model used and how it is applied to our specific problem. Our MLP is a neural network (NN) model originally based on the McCulloch-Pitts model of neurons [29] and backpropagation of the error [30]. For the two-qubits case the input of the network will be the elements of the density matrix of the state, while for the three-qubits one it will be the vector state. By doing so we ensure that the complexity of the problem is comparable in both cases. As density matrices are Hermitian this means that for an \(N\) qubits system the dimension of the matrix is

Figure 1: Scheme of the data processing. Explanation in the main text.
that corresponds to \(2^{2N}\) real values that the MLP takes as input. As MLP are topologically invariant the order of the input parameters plays no major role. For the vector case the input is composed by \(2^{N}\) complex values that correspond to \(2^{(N+1)}\) real parameters. For some specific cases we have artificially increased the input space by redundancy to improve the learning procedure.

To analyse our network we study three figures of merit. At the end of the learning we calculate the Average Success Rate (ASR), meaning the percentage of well-classified states for the set of interest. Furthermore, to also study the evolution of the learning procedure in binary classification problems we use the binary cross entropy (BCE) loss. If we have an output \(a^{\prime}\) and an expected output \(a\) the BCE is defined as

\[BCE(a,a^{\prime})=-\left(a\,\log(a^{\prime})+(1-a)\,\log(1-a^{\prime})\right). \tag{1}\]

Finally, in Section 4 we also studied the problem of classifying four entanglement families. In this case, the output layer consists of four neurons with activations \(a_{i}\), \(i\in\{1,\,2,\,3,\,4\}\), each of them corresponding to one of the families. For this specific case the readout of the MLP is not the activation of the neurons but the softmax function of these activations defined as

\[S(a_{i})=\frac{\exp(a_{i})}{\sum_{j=1}^{4}\exp(a_{j})}. \tag{2}\]

This can be considered as a probability distribution defined over the four entanglement families. The considered loss function for this problem will be the cross entropy between the predicted probability distribution \(\{S(a_{i})\}\) and the desired one that is just \(\delta_{ii^{\prime}}\), being \(i^{\prime}\) the correct classification and \(\delta\) the Kronecker-delta function. Therefore, we define the Categorical Cross Entropy (CCE) as

\[CCE(a_{i},i^{\prime})=-\sum_{j}\delta_{ji^{\prime}}\,\log\left(S(a_{j})\right) =-\log\left(S(a_{i^{\prime}})\right), \tag{3}\]

that depends only on the softmax function of the neuron which is associated to the correct classification.

The training procedure is organised in epochs of training. One epoch entails feeding the network with the whole training set, i.e. using every training sample once to compute an estimation of the loss function gradient. Datasets have a size \(S\) that is generally divided into \(S/2\) separable and \(S/2\) entangled states. The batch size, \(M\) is the number of samples that are processed before the MLP is updated once. Unless stated otherwise, we assume \(M=40\). The parameter \(f\) is the proportion of the whole dataset that is used for training and it is set to \(f=0.8\) except stated otherwise. As \(M\) takes an integer value between one and the number of samples in the training set, \(f\cdot S\), one epoch takes \((f\cdot S)/M\) updates of the trainable parameters. The datasets are generated randomly (see appendix A).

Once the density matrices for both separables and entangled states are generated and stored in files, the data should be prepared to be computed by the MLP. The data processing is sketched in Fig 1. It is divided into six steps. **Step one:** The separable and entangled density matrices (or state vectors in the three-qubits case) are read from the files and transformed into real vectors of size \(2^{2N}\), generating two arrays of size \(\left(2^{2N}+C\right)\times S/2\) where \(C\) is one for the case of a binary categorical classification, meaning that we add the value \(0/1\) to classify separable/entangled states. For the three-qubits classification problem \(C=4\) as we add to the input vector a new vector of dimension \(4\) with each element determined by \(\delta_{ji^{\prime}}\), being \(i^{\prime}\) the family of the state and \(j=1,\,\,2,\,3,\,4\) each vector element. **Step
**two:** Both arrays are stacked, giving rise to the whole dataset of \(S\) samples. **Step three:** The array is randomly shuffled to mix the separable and entangled density matrices. **Step four and five:** The dataset is split into the training set, of size \(f\cdot S/2\), and the test set of size \((1-f)\cdot S/2\). **Step six:** Both the training and test set are split up into the input set (density matrices/state vectors) and output set (binary label for binary classification cases and four dimension vectors for 3-qubits categorical classification). The rows of the input set are fed into the input layer of the MLP. The output is used, together with the expected output \(a\) to calculate the BCE by Eq. (1).

The activation function for the hidden layers is set to the Rectified Linear Unit (ReLU) [31, 32], the output layer has a sigmoidal activation function [30]. To backpropagate the error and optimise the network we use both the Adam Optimization Algorithm [33] and the Root Mean Squared Propagation (RMSProp) [34] as indicated in the caption of each figure. The simulations have been performed by the use of Python 3.8.10 and the libraries NumPy 1.21.4, Pandas 1.3.4, Tensorflow 2.7.0, Keras 2.7.0, Scipy 1.7.2 and Matplotlib 3.4.3. The initial values of weights and biases of the network have been stablished by the uniform Glorot method of the Keras library [35].

## 3 Entanglement detection for two qubits systems

The first problem we have studied is the detection of entanglement in an analytically solvable case, a two-qubit system. For this case necessary and sufficient separability conditions are given by the PPT separability criteria [11, 12, 8]. First of all we study the capability of the network in order to classify totally separable states from maximally entangled ones. In appendix A, there is a description of the method used to generate the datasets. For this problem the network achieves a 100% efficiency even with a simple topology, with only two hidden layers, and in a small number of epochs.

In Figure 2, we can see the evolution of the binary cross entropy (BCE) loss as a function of the number of elapsed epochs of training. After a very small number of epochs, the network is able to classify the separable and maximally entangled states with practically 100% efficiency. Even if this is a solvable model this result is remarkable. The PPT criteria

Figure 2: Differentiation of maximally entangled states from separable states for pure states. The curve represents the BCE loss as a function of the elapsed epochs of the learning process. The curve is averaged over 100 simulations and belong to MLP with a topology \(\langle 16:8:1\rangle\). RMSprop optimizer was used and the dataset size is \(S=2\cdot 10^{4}\).
is a complex procedure that involves both partially transposing and eigenvalue calculation. The fact that a neural network can learn an equivalent procedure in less than five epochs highlights the potential of MLPs in the problem of entanglement detection.

Furthermore, the network can also be trained to detect entanglement for non-maximally entangled states. As a measure of the amount of entanglement we have used the negativity. For a general state \(\rho\) its negativity is defined as

\[\mathcal{N}(\rho)=\frac{\left|\left|\rho^{T_{1}}\right|\right|-1}{2}, \tag{4}\]

where \(\rho^{T_{1}}\) represents the partial transpose of the density matrix with respect to the first qubit and \(||A||\equiv\mathrm{Tr}\sqrt{A^{\dagger}A}\) is the trace norm. The maximum value of negativity for a two-qubits case is 0.5, meaning that the system is fully entangled.

In this analysis we classify random quantum states in sets with different amounts of entanglement. These sets allows us to study the performance of the networks depending on the negativity of the entangled states of the training set in comparison with the test set. The results are displayed in Fig 3. In this plot we can see the average success rate for the test set, after the network has been fully trained, when the system is trained with (TW) sets of different negativity values, and it is tested on (TO) the different sets. We have ordered the sets in 0.1 width intervals, meaning that there are 5 intervals. The analysis has been performed by training and testing the MLP for both pure and mixed states. For this problem the optimal topology of the network strongly depends on the negativity of the training sample. Samples with lower negativities require deeper and bigger networks to be properly classified. For all cases we have profoundly studied different topologies and selected the simplest one that achieves the maximum efficiency.
The first conclusion that can be drawn from Fig. 3 is that networks trained with pure/mixed states are optimal for detecting entanglement only for pure/mixed states. The entanglement signatures in the density matrix strongly depend on the purity of the states, and the learning procedure is affected by this. However, a network trained with mixed states performs slightly better when tested on pure states than the other way around. Another conclusion is that only networks trained with states of low negativity are capable of detecting the entanglement of these same states. Furthermore, these networks perform well with states with higher negativity. However, this does not happen in the other direction, as networks trained with highly entangled states lose efficiency when applied to less entangled sets. These results indicate that networks should be trained for worst-case scenarios so they can perform well in any case.

Based on these results we can infer that a network trained with both pure and mixed states with low entanglement may be the more general entanglement detector for arbitrary states (mixed and pure with arbitrary negativity). To test this hypothesis we have trained a network with a dataset composed by a shuffling of pure and mixed states with negativity \(\mathcal{N}\in(0,\,0.1)\). After the training procedure we tested the network in training sets with both pure and mixed states with different negativities. As it is shown in Fig. or all the training sets we obtain an average success rate rate higher than \(97\%\).

Figure 3: Average success rate (efficiency) of MLPs that resulted from the training with pure (up) and mixed (down) states, when tested over datasets containing pure (left) and mixed (right) entangled states with different negativities. TW stands for ‘trained with’, while TO stands for ‘tested on’. The success rate for TW and TO datasets that belong to different negativity subinterval are averaged over the whole datasets, whereas TW and TO being the same dataset are averaged over the original test set (\(20\%\) of the data). The results are averaged over 10 simulations. The topologies used are for pure states: \(\mathcal{N}\in(0.0,\,0.1)\rightarrow(256:128:16:1)\), \((0.1,\,0.2)\rightarrow(128:16:1)\), \((0.2,\,0.3)\rightarrow(64:16:1)\), \((0.3,\,0.4)\rightarrow(32:4:1)\), \((0.4,\,0.5)\rightarrow(16:4:1)\). And for mixed states: \(\mathcal{N}\in(0.0,\,0.1)\rightarrow(256:128:16:1)\), \((0.1,\,0.2)\rightarrow(128:16:1)\), \((0.2,\,0.3)\rightarrow(64:8:1)\), \((0.3,\,0.4)\rightarrow(16:4:1)\), \((0.4,\,0.5)\rightarrow(16:1)\). The datasets sizes are \(S=2\cdot 10^{4}\).
To further analyse the performance of the network in the boundaries between separable and entangled states, we have studied two specific two-qubits families. First, we have trained the network with systems of arbitrary negativity and we checked the probability of determining that a certain state is entangled for states

\[\ket{\psi_{\epsilon}}=\frac{\ket{\psi_{\text{sep}}}+\epsilon\ket{\psi_{\text{Bell }}}}{\sqrt{1+\abs{\epsilon}^{2}+2\text{Re}\left\{\epsilon\bra{\psi_{\text{sep }}}\psi_{\text{Bell}}\right\}}}, \tag{5}\]

where in general \(\epsilon\in\mathbb{C}\) but we have studied only the case of \(\epsilon\in[0,1]\), \(\ket{\psi_{\text{sep}}}\) are bipartite separable states, and \(\ket{\psi_{\text{Bell}}}\) are maximally entangled states. These states are separable only in the limit \(\epsilon=0\) and entangled otherwise.

The purpose of studying these types of states is to evaluate the network's robustness to noise. As the volume of separable states is much smaller than that of entangled states, especially for pure systems [36], it is expected that if a separable system is subject to noise, it will become entangled. Therefore, it would be desirable if the network can correctly classify states that are close to being separable as separable. However, for some contexts this could also be considered a failure in entanglement detection. The parameter \(\epsilon\) at which the network detects entanglement would vary depending on the specific states being analysed, making this case interesting to study and classify.

The results are presented in Figure 5 for both pure and mixed states (see Appendix for details about the generation of states). Interestingly, for mixed states and a small network with only two hidden layers, the classification performance is not robust under the presence of small noise, as it classifies up to 15% of states as entangled for small \(\epsilon\) values. However, if we increase the network depth to four hidden layers, the learning becomes more robust, and it classifies almost all states as separable if \(\epsilon<0.1\). For higher values of \(\epsilon\), both networks behave similarly. For pure states the behaviour of both networks is similar but

Figure 4: Average success rate (efficiency) of the MLPs that resulted from training with a mixture of minimally entangled (\(\mathcal{N}\in(0,0,1)\)) pure and mixed states when applied to both pure and mixed training sets with different negativities. The activation function in the hidden layers is ReLU, and the used optimizer is RMSprop. Every efficiency is averaged over ten simulations. The results are averaged over 10 simulations. The MLP architecture is \(\langle 256:128:16\rangle\). The datasets sizes for this case is \(S=4\cdot 10^{4}\).
there are qualitatively differences, being the deeper network more efficient. This result suggests that, although the success probability of deep and non-deep networks is similar, deep networks are able to capture more entanglement features during the learning process. Hence, depending on the purpose of the network it would be more interesting to design it with a specific topology.

A similar result is obtained by studying Werner states in the form [37]

\[\rho_{W}=\frac{p}{3}\mathbb{I}+(1-\frac{4p}{3})|\psi_{\text{Bell}}\rangle \langle\psi_{\text{Bell}}| \tag{6}\]

where \(p\in[0,1]\), \(\mathbb{I}\) represents the maximally mixed state, and \(|\psi_{\text{Bell}}\rangle\) is a maximally entangled state (see Appendix). These kind of states are entangled if, and only if, \(p<\frac{1}{2}\). In this case, as it is shown if Figure 6, both networks overestimate the presence of entanglement, detecting more than half of the states as entangled up to \(p\sim 0.55\). A more interesting feature arises for values of \(p\) higher than \(0.8\). In this case, the network with two hidden layers starts detecting again the states as entangled. On the other hand, the network with four hidden layers makes a correct classification also in this case. This indicates that the deeper networks are more able to identify pure entanglement properties of the systems while the smaller ones can be tricked by other properties of the dataset as the Schmidt rank of the density matrices. Interestingly, in Refs [26, 27] a similar result is obtained for a very different neural network model and training procedure.

## 4 Entanglement detection and classification for three qubits systems

It is well-known that three-qubit systems exhibit much more complex behavior with respect to their separability properties. It has been proven that there are six possible entanglement classes, meaning six types of states that can be connected by stochastic local operations and classical communication (SLOCC). These are the separable, bipartite entangled (BE), Greenberger-Horne-Zeilinger (GHZ), and W classes [38, 39]. The bipartite class can be further divided into three classes, depending on the way in which the bipartition is performed. In our case, where all three qubits are identical, we consider bipartite entanglement as only one family. To keep the complexity of the problem comparable to the two-qubit case, we have only worked with pure states in this section. The MLP input consists of the 16 real parameters corresponding to the elements of the state vector.

First, we checked the learning rate of the MLP for each of the three families. Figure

Figure 5: Probability of determining that a certain state is entangled as a function of the parameter \(\epsilon\) for states of the form (5) for pure (left) and mixed (right) states.
7 (left) shows the BCE loss as a function of the learning procedure for each family. The vertical colored lines represent the moment when the best configuration is achieved, and the MLP starts to suffer from overfitting. We can see that each family has a different learning speed, as well as a different maximum achievable efficiency. The W states are the easiest to classify, reaching a BCE loss below 0.1 after just 10 epochs. They are also the family that achieves the highest detection efficiency. The worst learning scenario occurs for the GHZ states, where the BCE loss cannot go below 0.2. This result is very interesting and indicates a relation between the amount of tripartite entanglement and the rate of entanglement detection. It is known that the W family contains the only states with entanglement that can be considered both tripartite and bipartite, while GHZ states can be considered only tripartite entangled [39]. From this result, we can conclude that tripartite entanglement is the hardest to detect with our MLP, bipartite entanglement is easier, and W states are the easiest as they contain both tripartite and bipartite entanglement.

After training the selected classes, we evaluated the performance of the MLP on all three classes. The results are shown in Figure 7 (right). The MLP trained with W states and applied to GHZ states had the worst performance, followed by the situation where

Figure 6: Probability of determining that a certain state is entangled as a function of the parameter \(p\) for states of the form (6).

Figure 7: Left: BCE loss as a function of the epochs of learning for the three entanglement families. The architecture of the network is \(\langle 16:512:128:32:1\rangle\). The fraction of states in the dataset taken for training is \(f=0.75\) and the BCE is evaluated only in the test set. Each curve is averaged over 10 simulations. The vertical lines indicate the epochs in which the best configuration is reached. The datasets sizes are \(S=2\cdot 10^{5}\) and.
the training was performed with BE states and the network was again applied to the GHZ family. This supports our claim that bipartite entanglement is easier to learn than tripartite entanglement, and when networks are trained with states containing bipartite entanglement, they perform poorly when faced with tripartite entanglement. On the other hand, the best performance was obtained when the network was applied to the W states regardless of the training set. This may be due to the presence of both tripartite and bipartite entanglement in this family. Additionally, we observed that when the MLP was trained with W states, it performed poorly when applied to any other family.

Finally, we tested the MLP's ability to classify the states into four possible families: bipartite entangled, W, GHZ, and separable. To do this, we used a network with four output neurons as explained in Section 2. For this problem, the initial conditions of the network were very important, as shown in Figure 8 (left). We plotted the CCE as a function of the number of epochs for 10 different runs over the same dataset. Each run differed in the initialization of the network weights and the ordering of the dataset elements. As can be seen, different initial conditions led to different behavior with respect to the speed of learning, the final efficiency, and overfitting.

For these 10 runs the best final success rate achieved is 79.7% and the average one is 73.2%. In Figure 8 (right) we can observe the number of runs that have lead to each different success rate. The word case, 57.5% seems an unlikely event while most of runs lead to a final efficiency above 70%. We may also remark that in this case the probability of correctly classifying a state by a purely random procedure is 25% instead than 50% as is in the binary classification.

## 5 Conclusions

In this study, we have showcased the potential of deep learning algorithms to effectively address entanglement detection and classification challenges. Our findings are striking, as the network attains up to 100% efficiency in two-qubit scenarios and over 90% efficiency in three-qubit situations. Additionally, we identified a strong relationship between entanglement and purity, with networks trained on pure states underperforming when presented with mixed states and vice versa.

Moreover, deep networks display resilience to minor noise and can identify entanglement characteristics that allow them to excel when working with well-established quantum

Figure 8: Left: CCE of the categorical classification for 10 runs with different initial conditions over the same dataset. The vertical line marks the average number of epoch corresponding to the optimal training determined by an Early Stop algorithm. In these cases, the batch size is \(\mathsf{M}=1000\) and \(\mathsf{f}=0.75\). Right: Histogram showing the number of performances for different certain success rates. The topology of the network is \(\langle 16:512:128:32:4\rangle\). The dataset size is \(S=4\cdot 10^{5}\).
families like Werner states. In three-qubit instances, the network can pinpoint the entanglement family of a state with over 77% precision. Our research introduces a novel approach to detecting and classifying entanglement that bypasses the need for specific criteria or witnesses tailored to particular dimensions.

This study paves the way for further exploration in several areas. Firstly, investigating the impact of state properties such as purity on neural network performance could lead to improved detection algorithms and a deeper understanding of the interplay between various quantum properties. The techniques proposed here can also be adapted for other quantum information tasks, such as state comparison. Lastly, it would be valuable to investigate the creation of a quantum neural network capable of executing the same tasks, which could open up a myriad of applications and serve as a benchmark problem for both classical and quantum neural networks.

## 6 Acknowledgements

We want to acknowledge funding from the FEDER/Junta de Andalucia program A.FQM.752.UGR20 and project PID2021-128970OA-I00 funded by MCIN/AEI/ 10.13039/501100011033 and, by "ERDF A way of making Europe", by the "European Union".
