# How to implement a Square root of Swap gate that swaps 2n-qubits on the IBM Q (composer)?

I am looking for an implementation using the quantum gates provided by the IBM composer of the following quantum function:

• input $2n$ qubits
• output $2n$ qubits wherein $50\%$ of the cases the state of the $2$ sets of $n$ qubits are swapped and in the other $50\%$ of the cases the state of the $2n$ qubits remain unchanged. With swapped I mean that qubit $q[i]$ will get the state of qubit $q[n+i]$ and qubit $q[n+i]$ will get the state of $q[i]$. Note also that all the qubits must be swapped or not.

E.g. $n=3$: If input $|000111\rangle$ then output in 50% of the cases is $|000111\rangle$ and in the other 50% of the cases is $|111000\rangle$

We have already a solution when $n=1$ in the following StackOverflow question:

but how can we do that when $n>1$?

• I wonder if we can use a classical coin-flipper, and add an "if" statement in the QASM editor? – user1271772 Jun 8 '18 at 15:19

## 1 Answer

A general trick for smoothing a big discrete operation into a continuous operation is to apply the phase estimation algorithm, then apply a phase gradient to the phase register, then uncompute the phase estimation. For example, see this blog post on computing the fractional fourier transform.

Because the swap operation has exactly two eigenvalues (+1 and -1), the phase estimation is extremely simple. It only requires a single phase estimation qubit. The resulting circuit looks like this:

Note that the top qubit should start and end in the 0 state. You can continuously vary how much swappery there is by varying the angle of the Z rotation in the middle.

• thanks for the circuit. If you don't care about the output state of the top qubit: would the first part of the circuit (up to and not including the 2nd H gate) not already implement the square root of swap gate that swaps 2x3 qubits ? – JanVdA Jun 9 '18 at 7:31
• @JanVdA No, that's just the first phase estimation. You'll just have a qubit telling you which eigenspace of the swap operation the other qubits are in. You need to use it and get rid of it for the circuit to work. – Craig Gidney Jun 9 '18 at 13:32