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$?

  • $\begingroup$ I wonder if we can use a classical coin-flipper, and add an "if" statement in the QASM editor? $\endgroup$ Jun 8, 2018 at 15:19

1 Answer 1


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:

Big sqrt swap

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.

  • $\begingroup$ 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 ? $\endgroup$
    – JanVdA
    Jun 9, 2018 at 7:31
  • $\begingroup$ @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. $\endgroup$ Jun 9, 2018 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.