10
$\begingroup$

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?

$\endgroup$
5
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ 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$). $\endgroup$ – DaftWullie May 25 '18 at 11:09
  • 1
    $\begingroup$ 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. $\endgroup$ – James Wootton May 25 '18 at 11:37
  • $\begingroup$ 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! $\endgroup$ – DaftWullie May 25 '18 at 11:44
  • $\begingroup$ Absolutely. I've added the optimization in now (though I think the IBM compiler would probably do it anyway) $\endgroup$ – James Wootton May 25 '18 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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