12

I want to be able to applied controlled versions of the $R_y$ gate (rotation around the Y axis) for real devices on the IBM Q Experience. Can this be done? If so, how?

Sanchayan Dutta
  • 17,497
  • 7
  • 48
  • 110
James Wootton
  • 11,272
  • 1
  • 31
  • 72

2 Answers2

8

You can make controlled $R_y$ gates from cnots and $R_y$ rotations, so they can be be done on any pair of qubits that allows a cnot.

Two examples of controlled-Ys are shown in the image below. They are on the same circuit, one after the other.

Two versions of a controlled-Y

The first has qubit 1 as control and qubit 0 as target, which is easy because the cnots can be directly implemented in the right direction.

In the second example, qubit 0 is control and qubit 1 is target. This is achieved by using four H gates for each cnot to effectively turn it around.

This second example can also be optimized further. There are two adjacent H gates on the top line that can be canceled. And since H anticommutes with Y, $H\,u3(\theta,0,0)\,H$ can always be replaced with $u3(-\theta,0,0)$. (Thanks to @DaftWullie for pointing these out).

enter image description here

The single qubit gates used are $u3(\theta,0,0)$, which are $R_y(\theta)$ rotations. The angles used are pi/2 and -pi/2 in this case. These cancel when the control is $|0\rangle$. This gives the expected effect of the controlled-Y acting trivially in this case.

When the control is $|1\rangle$, the cnots perform an X either side of the $u3(-\pi/2,0,0)$, which has the effect

$X \, u3(\theta,0,0) \, X = u3(-\theta,0,0)$

This means that the $u3(-\pi/2,0,0)$ flips to $u3(\pi/2,0,0)$. The end effect on the control is then

$ u3(\pi/2,0,0) \, u3(\pi/2,0,0) \, = u\, 3(\pi,0,0) \, = \, Y$

which is a $Y$

A more general controlled $R_y$ rotation means that you want to do a fraction of a $Y$. So just reduce both angles by the corresponding fraction.

James Wootton
  • 11,272
  • 1
  • 31
  • 72
  • 1
    Why don't you cancel the two neighbouring Hadamard gates on qubit 0 in the second gate? I presume you can also combine Hadamard-U3($\theta$)-Hadamard as U3($-\theta$). – DaftWullie May 25 '18 at 11:09
  • 1
    That's very true. I did it in a modular way, and didn't look for optimizations. I think the non-optimal version is more pedagogical, though. – James Wootton May 25 '18 at 11:37
  • Of course, but if you want to implement it on a real quantum computer with noise, you need to make sure you're doing as little as possible, and making the most use of all these tricks! – DaftWullie May 25 '18 at 11:44
  • Absolutely. I've added the optimization in now (though I think the IBM compiler would probably do it anyway) – James Wootton May 25 '18 at 11:53
  • In this case, is there any advantage using the gate $u3(\theta, 0,0)$ instead of $R_{y}$ in qiskit? – German Alamilla Jun 17 '19 at 19:37
1

You can also (very easily) implement a multiple-controlled Y rotation gate using Qiskit. Notice that the number of single and two-qubit gates increases significantly for every extra control qubit. Therefore, the fidelity will decrease.