9

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?

Sanchayan Dutta
  • 17,497
  • 7
  • 48
  • 110
JanVdA
  • 1,148
  • 8
  • 17
  • 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[1],q[0]; h q[0]; h q[1]; cx q[1],q[0]; h q[0]; h q[1]; cx q[1],q[0]; – Lying Dancer Jun 04 '18 at 14:36
  • 1
    @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 04 '18 at 22:59
  • Anyone would do for me. No preference for a particular one. – JanVdA Jun 05 '18 at 06:18

3 Answers3

12

Here is a SQRT(SWAP) construction which only requires CNOTs in one direction, Hadamards, S gates ($Z^{\frac{1}{2}}$), S dagger gates ($Z^{-\frac{1}{2}}$), T gates ($Z^{\frac{1}{4}}$) and T dagger gates ($Z^{-\frac{1}{4}}$):

enter image description here

You should be able to encode it directly into the composer.

Craig Gidney
  • 36,389
  • 1
  • 29
  • 95
  • How does one obtain this from first principles? – user1271772 No more free time Jun 05 '18 at 02:04
  • @user1271772 Which are the "first principles"? – Norbert Schuch Jun 05 '18 at 03:17
  • I don't know how to implement $Z^{1/2}$ and $Z^{-1/2}$ using the IBM composer. – JanVdA Jun 05 '18 at 07:31
  • 1
    @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 05 '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 05 '18 at 11:40
  • I simulated the above on IBM composer and I didn't get the expected outcome. So first I applied X-gate to the qubit 0 - so I get |01>, when I then apply the above SQRT(SWAP) construction it always returned 10 as output while I would expect 10 in 50% and 01 in the other 50% of the cases. – JanVdA Jun 05 '18 at 18:58
  • @JanVdA could you link a picture of your circuit? – Craig Gidney Jun 05 '18 at 21:12
  • Here a picture of my circuit https://imgur.com/Rd8gm4K – JanVdA Jun 06 '18 at 06:32
  • @JanVdA Bah, I got some angles doubled by accident and somehow didn't notice. I updated the answer with the correct circuit. – Craig Gidney Jun 06 '18 at 11:14
  • excellent: I just tested it and it gave in about 50% of the cases 01 and in the other 50% cases 10 when 10 is provided as input. – JanVdA Jun 06 '18 at 12:25
  • @JanVdA That doesn't mean it's a square root of swap. – Norbert Schuch Jun 06 '18 at 14:55
  • @NorbertSchuch I agree that my test is not a prove that the above circuit implements a square root of swap. If it is not the case please raise so. – JanVdA Jun 06 '18 at 15:09
  • @JanVdA Why don't you test it yourself? Eeach gate is a 4x4 matrix. Multiply them and check what you get. – Norbert Schuch Jun 06 '18 at 15:15
  • Craig, see comment @NorbertSchuch : is there a prove that above circuit indeed implements the SQRT(SWAP) gate. I guess you have used the algassert.com site for this but I have no experience with that. I also notice that the link [a SQRT(SWAP) construction] in the answer refers to a diagram that contains other gates besides the gates that are shown in the diagram pasted in the answer. – JanVdA Jun 06 '18 at 15:37
  • @JanVdA Dude: Write down the matrices for each gate and multiply them. If you don't know how to do that, you should start by learning that first. Otherwise, there is no way you will succeed developing quantum algorithms. – Norbert Schuch Jun 06 '18 at 16:25
  • 1
    Multiplying matrices is obviously a good skill to have, but I think it is valid to want to get some experience in first. I'd suggest to @JanVdA that you prepare Bell states and test your sqrt(swap) gates on them. If they work, they should have no effect (though this is again not a full proof). – James Wootton Jun 06 '18 at 20:27
5

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.

Norbert Schuch
  • 6,521
  • 16
  • 27
  • 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 06 '18 at 06: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 06 '18 at 14:54
  • FYI: I have used the above sqrt-SWAP description to test the solution suggested for https://quantumcomputing.stackexchange.com/questions/2209/how-to-create-a-quantum-algorithm-that-produces-2-n-bit-sequences-with-equal-num on the IBM composer. – JanVdA Jun 06 '18 at 15:14
  • @JanVdA Which one? The accepted one? That one only talks about a controlled-SWAP. (For that: https://journals.aps.org/pra/abstract/10.1103/PhysRevA.53.2855) – Norbert Schuch Jun 06 '18 at 15:25
  • Sorry I am referring to the accepted solution for question: https://mathoverflow.net/questions/301733/how-to-create-a-quantum-algorithm-that-produces-2-n-bit-sequences-with-equal-num – JanVdA Jun 06 '18 at 15:29
0

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.