Member-only story
Basis-Specific SWAP Test (Comparing Quantum States)
The standard SWAP Test is basis-agnostic. It measures the “overlap” of quantum states, which is to say you measure 0 with a probability of 1 when the states are identical and 0 with a probability of .5 when the states are maximally different (on completely opposite sides of the Bloch sphere such as |0> and |1>, |+> and |->, |i> and |-i>, and all other opposite points). Measurements between 0 and .5 show how close or far apart the vectors are, but not along which basis. Two states differing in the z basis by the same angle as two states that differ in the y basis will produce the same result. Furthermore, two states differing in the z basis will produce the same result even if you measure the x basis or the y basis.
The workaround for this, if you want to know the overlap in each basis, is to use three ancilla qubits per basis, instead of just the one ancilla qubit used in the standard SWAP Test. Each of the two states to be compared is the control qubit for a CNOT to one of the ancilla qubits. The standard SWAP Test is then performed on the ancilla qubits. You can then rotate the data qubits as if to measure in the x basis or the y basis, but repeating the same procedure with CNOTs and SWAP Tests on other sets of three ancilla qubits. To measure all three bases, therefore, 11 qubits are required: 2 for the data qubits and 9 for the ancilla qubits (3 for…