# How to implement the “Square root of Swap gate” on the IBM Q (composer)?

I would like to simulate a quantum algorithm where one of the steps is "Square root of Swap gate" between 2 qubits.

How can I implement this step using the IBM composer?

• Maybe it can be useful to use simple swap gate as a "brick" to construct square root of swap gate. You can simulate on IBM Q in this way: cx q,q; h q; h q; cx q,q; h q; h q; cx q,q; – Lying Dancer Jun 4 '18 at 14:36
• @JanVdA The square root is not unique. In fact, there should be 2^4=16 possible roots. Which one do you mean? – Norbert Schuch Jun 4 '18 at 22:59
• Anyone would do for me. No preference for a particular one. – JanVdA Jun 5 '18 at 6:18

Here is a SQRT(SWAP) construction which only requires CNOTs in one direction, Hadamards, S gates ($Z^{\frac{1}{2}}$), inverse S gates ($Z^{-\frac{1}{2}}$), T gates ($Z^{\frac{1}{4}}$) and inverse T gates ($Z^{-\frac{1}{4}}$): You should be able to encode it directly into the composer.

• How does one obtain this from first principles? – user1271772 Jun 5 '18 at 2:04
• @user1271772 Which are the "first principles"? – Norbert Schuch Jun 5 '18 at 3:17
• I don't know how to implement $Z^{1/2}$ and $Z^{-1/2}$ using the IBM composer. – JanVdA Jun 5 '18 at 7:31
• @user1271772 I started with the CNOT-NOTC-CNOT SWAP circuit, replaced the middle CNOT with a C-sqrt(not) to make the whole thing a sqrt(SWAP), decomposed the C-srt(not) into S+CNOT gates, moved some gates around until I managed to cancel one of the CNOTs, then used Hadamards to flip the direction of any CNOT pointing the wrong way. – Craig Gidney Jun 5 '18 at 11:39
• @JanVdA $Z^{1/2}$ is $S$, and $Z^{-1/2}$ is $S^\dagger$ (look at the blue gates in the composer). – Craig Gidney Jun 5 '18 at 11:40

What you want to do is a rotation on the subspace spanned by $|01\rangle$ and $|10\rangle$ which rotates it by $\sqrt{X}$. To this end, you can first do a CNOT, which maps this subspace to $\{|01\rangle,|11\rangle\}$. Now you need to do the $\sqrt{X}$ rotation on the first qubit, conditioned on the second qubit being one. Implementing controlled-$U$ gates using CNOTs is a standard construction, which can be found in a range of places, see e.g. https://arxiv.org/abs/quant-ph/9503016. Depending how you do this step, you might have to fix the "global" phase of the 1st qubit (given the 2nd is $|1\rangle$). Finally, you need to undo the CNOT.

• It is not clear to me 1) how you do a $\sqrt{X}$ in composer. 2) how to undo a CNOT in composer 3) you mention controlled-U gates but it is not clear where they should be used in the algorithm. I think that a step wise description of the algorithm would be helpful for implementing this on the IBM composer. – JanVdA Jun 6 '18 at 6:38
• @JanVdA I'm afraid you'll have to do some work yourself to familiarize yourself with quantum circuits and their manipulations. Otherwise, what are you going to do once you know the circuit for the sqrt-SWAP? – Norbert Schuch Jun 6 '18 at 14:54
• FYI: I have used the above sqrt-SWAP description to test the solution suggested for quantumcomputing.stackexchange.com/questions/2209/… on the IBM composer. – JanVdA Jun 6 '18 at 15:14
• @JanVdA Which one? The accepted one? That one only talks about a controlled-SWAP. (For that: journals.aps.org/pra/abstract/10.1103/PhysRevA.53.2855) – Norbert Schuch Jun 6 '18 at 15:25
• Sorry I am referring to the accepted solution for question: mathoverflow.net/questions/301733/… – JanVdA Jun 6 '18 at 15:29

Every 2-qubit gate has a "Paulinomial decomposition" which means it can be written as a polynomial of Pauli matrices.

For the gate you want:

$\sqrt{ \mbox{SWAP} } = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \frac{1}{{2}} (1+i) & \frac{1}{{2}} (1-i) & 0 \\ 0 & \frac{1}{{2}} (1-i) & \frac{1}{{2}} (1+i) & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} = \frac{1-i}{4}\left(X_1X_2+Y_1Y_2+Z_1Z_2\right) +\frac{3+i}{2}I,$

where $X_i$ is an $X$ gate applied to the $i^\textrm{th}$ qubit.

• OK, thanks for the answer - I need to study a bit to figure out how I can translate this to the IBM Composer. – JanVdA Jun 4 '18 at 17:28
• @JanVdA What's wrong? Can't you drag and drop the X,Y, and Z gates into the circuit? You may wish to ask a separate question about how to multiply a gate by a constant. – user1271772 Jun 4 '18 at 17:44
• I can drag and drop X, Y, Z gates but I don't know how to do the multiplications (e.g. $X_1X_2$), the additions (e.g. $X_1X_2+Y_1Y_2$), the multiplication by a constant, I even don't know what you mean by $I$. I guess I must sound like a complete idiot. – JanVdA Jun 4 '18 at 18:55
• $X_1X_2$ means you're applying $X$ to qubit 1 and $X$ to qubit 2. However, as I mention in the previous comment, I think you should ask a separate question about how to multiply by a constant. – user1271772 Jun 4 '18 at 19:04
• See also Eq. 8 of this paper: arxiv.org/pdf/1805.10478.pdf, and the circuit diagrams in the supplementary material. Eq. 8 of the paper is exactly like what I gave you, except with only $Z$ gates. It's still a "Paulinomial" but with only $Z$ gates, and it is implemented in the IBM composer in that paper. – user1271772 Jun 4 '18 at 19:07