Is it possible to perform a controlled swap test with multiple targets with qiskit? I have tried using cswap(ancilla,qb1,qb2), where qb1 is an n-qubit register and qb2 is as well
It is possible, but when calling
cswap, all of the arguments need to be of the same size. In your example, assuming
ancilla is 1 qubit, you would need
qb2 to also be 1 qubit. If
qb2 are QuantumRegisters of size > 1, then you would need multiple
cswap calls. For example, if
qb2 are of size 2:
circuit.cswap(ancilla, qb1, qb2) circuit.cswap(ancilla, qb1, qb2)
This way the
ancilla qubit is still the control for both calls, and all of the arguments in both calls are of the same size.
If you aren't keeping the states that you performed the swap test on, you don't need to use CSWAPs to perform the swap test. You can instead just pair up the qubits from each system, perform Bell basis measurements on them, and count whether you see the 11 result and odd or even number of times.
Gives the same result statistics as this:
But the latter is much less demanding on the quantum hardware, because the three qubit gates can be done in the classical postprocessing.