“Learning the quantum algorithm for state overlap” by Lukasz Cincio, Yiğit Subaşı, Andrew T. Sornborger, and Patrick J. Coles proposes a simplified circuit for comparing single-qubit quantum states as compared to the canonical SWAP Test. Whereas the SWAP Test requires two Hadamard gates, one Fredkin gate, and one measurement, this paper proposes using only one CNOT gate, one Hadamard gate, and two measurements. That’s a circuit depth of 14 (IBM Q Experience) versus a circuit depth of only 2.
However, in comparing the SWAP Test to this proposed alternative, I discovered that the proposed second measurement is unnecessary. By using only one CNOT gate, one Hadamard gate, and one measurement, the results can be interpreted just like the SWAP Test. For single-qubit comparisons, this eliminates the need for the complex classical post-processing that the authors suggest is necessary.
I borrowed some ideas from one of my previous articles, “Basis-Specific SWAP Test (Comparing Quantum States),” and ran some side-by-side comparisons.
With the canonical SWAP Test, the ancilla qubit measures |0> with a probability of 1 when the states are identical and |0> with a probability of 0.5 when the states are maximally different.
The top three qubits show the canonical SWAP Test comparing |0> and |1>, and the bottom two qubits show the proposed alternative comparing the same maximally-different states.
Both algorithms measure |0> with a probability of roughly 0.5, as should be expected with the canonical SWAP Test.
Simulator vs Real Hardware
It is worth noting that the canonical SWAP Test should be expected to fare worse on a real quantum processor; the circuits in this article were run on the IBM Q Experience simulator. The proposed alternative drastically reduces circuit depth, and that is definitely worthy of consideration.
The canonical SWAP Test measures |0> with a probability closer to 1 for states that are closer together and |0> with a probability closer to 0.5 for states that are farther apart.
Instead of |0> and |1>, both algorithms now compare |0> and |+>.
It is worth noting that the canonical SWAP Test accurately determines that the states are now closer together, but that the proposed alternative incorrectly shows a uniform distribution. Ironically, however, the SWAP Test also has some issues with comparing the |+> state to other states.
The canonical SWAP Test is basis-agnostic and compares states regardless of in which bases the states differ. Therefore, the proposed alternative must also compare states that differ around the z axis.
Both algorithms now compare T and TDG rotations away from the |+> state.
Once again, both algorithms measure |0> with comparable probabilities. Therefore, we can assume that with additional testing, perhaps not involving Hadamard gates, that the proposed alternative will produce results comparable to the SWAP Test.
The canonical SWAP Test works with multi-state comparisons as well as entangled states. The paper does not propose a simplified way of doing either, so I attempted to expand upon my single-measurement variation. After all, the paper warns about the complexity of classical post-processing using multiple measurements:
“the classical post-processing is somewhat complicated, and its complexity scales linearly with the problem size”
Adding one qubit per algorithm, the new comparison is T to TDG and S, all rotated away from the |+> state.
While the SWAP Test produces an actual result, my guess as to how to expand the alternative produces a uniform distribution. Maybe the alternative works when measuring all qubits and using complex classical post-processing, but that makes the SWAP Test much simpler to use if you’re going to use already complex algorithms such as classification.
The proposed alternative seems useful for single-qubit comparisons and should be far more accurate than the canonical SWAP Test on NISQ hardware due to the greatly-reduced circuit depth. Both algorithms have issues with the |+> state, so the failed test should take that into consideration.
However, the canonical SWAP Test has been vetted, and you can find quite a few papers about it on arXiv. Furthermore, it’s results are easy to decipher without any complex post-processing and regardless of overall circuit complexity.
For now, I am inclined to use both algorithms side-by-side, and incorporate the compact alternative in my final algorithm whenever the results are comparable to that of the vetted SWAP Test.
Because it is possible to simplify the SWAP Test when comparing single-qubit states, I would like to work some more on a multi-qubit variation. Reducing circuit depth is critically important, especially while we remain in the NISQ era, but I would like to retain the SWAP Test’s simple post-processing requirements.