# Comparing Entangled States

The SWAP Test is used to compare quantum states. It is constructed out of a Fredkin gate (controlled-SWAP) sandwiched between two Hadamard gates. The control qubit and Hadamard gates are placed on an ancilla qubit, and the SWAP gates are placed on the qubits that you want to compare. You measure only the ancilla qubit.

Two identical states measure 0 with a probability of 1, and two maximally-different states measure 0 with a probability of 50%. All other results either show how close the states are by having a probability of measuring 0 that is closer to 1, or how different they are by having a probability of measuring 0 that is closer to one-half.

Read more:

- Comparing Quantum States
- Basis-Specific SWAP Test
- Simplified Quantum Machine Learning (QML) Classification

The SWAP Test can also be used to compare entangled states. For purposes of this article, I’m just using the most basic GHZ states. If you have read the supplementary articles listed above, you’ll see that the approach is remarkably similar. You simply make a few adjustments to handle the additional qubits.

This SWAP Test compares the two most basic GHZ states: 000 and 111. The Hadamard gates and measurement are still on the ancilla qubit, but now there are three Fredkin gates. If you look at the lowercase “b” and “c,” you’ll see that the first Fredkin gate compares the top two qubits, the second compares the middle two qubits, and the last compares the bottom two qubits.

As should be expected from a SWAP Test, two maximally-different entangled states measure 0 with a probability of about 50%.

This is the same circuit as before, except that one GHZ state has a 1/3 pi rotation around the y axis and the other has a 2/3 pi rotation around the y axis.

The probability of measuring 0 noticeably increased as the entangled states were no longer maximally-different, but also not identical either.

This circuit keeps the GHZ state with the 1/3 pi rotation around the y axis, but substitutes a 1/4 pi rotation for the 2/3 pi rotation.

Because the two states are much closer together, the resultant histogram shows them as almost-but-not-quite identical.

This circuit keeps the GHZ states with the 1/3 pi and 1/4 pi rotations around the y axis, but adds a 2/3 pi rotation around the z axis for the latter.

Because of the rotation around the z axis, the result shows that the states have noticeably moved apart.

But, are the previous four circuits really comparing entangled states? All three qubits in each GHZ state should ideally measure the same, so what if I only measure the first qubit of each GHZ state, the ones to which I applied the rotations?

Comparing this histogram to the immediately previous one, we can see that there is indeed a difference between comparing the entire GHZ states and comparing only one qubit from each GHZ state.

But, what if we perform three SWAP Tests, separately comparing all three qubits in each GHZ state?

Any evidence of entanglement disappears. The SWAP Tests individually produce roughly similar results, but not in the synchronized way that you should expect from entangled states. Although this looks like a GHZ state that was run on a NISQ (keyword: noisy) device, it was actually run on the IBM Q simulator with no added noise model. Therefore, we are seeing an absence of entanglement, not the presence of noise.

**Future Work**

The circuits in this article only compare the most basic GHZ states. Future articles may show more practical comparisons, perhaps applicable to Quantum Machine Learning (QML) and Quantum Chemistry.