I am designing quantum algorithms where the quantum circuit uses CSWAP gates a lot. The result is very noisy on the quantum hardwares. So I designed really simple circuits to test whether it is indeed the CSWAP that are causing the problems.
This is a simple circuit to calculate the square sum of diagonal terms of the density matrix.
qubits = 2
qc = QuantumCircuit(4*qubits+2,1)
qc.h([0,0+qubits])
qc.cx([0,0+qubits],[1,1+qubits])
for i in range(2*qubits):
qc.cx(i,-i-2)
qc.h(-1)
for i in range(qubits):
qc.cswap(-1,i,i+qubits)
qc.h(-1)
qc.measure(-1,0)
And it looks like this:
The difference of the probability of measuring 0 and 1 should be 0.5 ({1: 0.23828125, 0: 0.76171875}), since we are calculating the square of the diagonal terms of the density matrix of simple bell state. which is exactly what the simulator gives. However, on the real hardware, there is no difference in the probability.
So I further simplified the circuit to:
qubits = 1
qc = QuantumCircuit(4*qubits+1,1)
qc.h([0,0+qubits])
for i in range(2*qubits):
qc.cx(i,-i-2)
qc.h(-1)
for i in range(qubits):
qc.cswap(-1,i,i+qubits)
qc.h(-1)
qc.measure(-1,0)
The simulator gives the correct result again. But the hardware shows even possibility of 0 and 1, again.
Does this mean that the real hardware cannot handle control swap gate at all? I know it has to do with the underlying topology of the hardware. But is 1 simple control swap too many? Or did I made mistakes? Please share some ideas.