1

I was trying to implement the 2-qubit Grover algorithm without the auxiliary bit. Before finding the gate symbol for the controlled $\mathrm{Z}$, I worked with the controlled $\mathrm{Rz}$. The gate glossary states: " $\mathrm{Z}$ is equivalent to $\mathrm{Rz}$ for the angle $\pi$". So I thought the controlled $\mathrm{Rz}$ with angle $\pi$ should be equal with the controlled $\mathrm{Z}$ gate. However, I get very different results in the browser state-vector representation.

So my question is, should they be equivalent?

Here are my circuits: 2-Qubit Grover with cRz 2-Qubit Grover with cZ

Martin Vesely
  • 13,891
  • 4
  • 28
  • 65

1 Answers1

1

I realized that $\mathrm{Rz}(\lambda)$ is implemented in following way on IBM Q:

gate crz(lambda) a,b
{
  u1(lambda/2) b;
  cx a,b;
  u1(-lambda/2) b;
  cx a,b;
}

Setting $\lambda =\pi$, a matrix describing construction above is following: $$ \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & -i & 0 \\ 0 & 0 & 0 & i \\ \end{pmatrix} $$

This is not problem when the gate is not controlled as $i$ is a global phase, however, it matters for controlled gates.

I also checked that these values are really returned for computation basis states in state vector visualization on IBM Q.

Conclusion is that controlled $\mathrm{Rz}(\pi)$ is not equivalent to controlled $\mathrm{Z}$ on IBM Q.

Note that application of single qubit $\mathrm{Rz}(\pi)$ returns same results as single qubit $\mathrm{Z}$.


Solution:

To make controlled $\mathrm{Rz}(\pi)$ behave as expected, you have to put controlled global phase gate before $\mathrm{Rz}(\pi)$. You can do that by application single-qubit gate $\mathrm{U1}(\pi/2)$ on controlling qubit of $\mathrm{Rz}(\pi)$, i.e. $q_0$ in your case.

Martin Vesely
  • 13,891
  • 4
  • 28
  • 65
  • 1
    You say this is a bug, but I wouldn't call it so. The definition follows very naturally from the single-qubit definitions. The bug is the expectation that they should be the same. They shouldn't because of the difference between global and relative phase. – DaftWullie Feb 28 '20 at 12:10
  • @DaftWullie: I would expect that controlled version of single qubit gate $\mathrm{U}$ is described by matrix $\begin{pmatrix} I & O \ O & U\end{pmatrix}$ as e.g. in case of controlled $\mathrm{X}$, $\mathrm{Z}$ or $\mathrm{H}$. – Martin Vesely Feb 28 '20 at 12:45
  • It is, i's just the $U$ that you're talking about is equivalent to $Z$ up to a global phase, but it is not $Z$. – DaftWullie Feb 28 '20 at 12:53
  • @DaftWullie: Yes and that is the point. If $Rz(\pi)$ is equivalent to $Z$ then controlled version of $Rz(\pi)$ should be equivalent to controlled $Z$, right? But this is not the case on IBM Q because of the phase. As a result, output is different for controlled $Z$ and controlled $Rz(\pi)$ as mentioned in the question. And this does not seems right. – Martin Vesely Feb 28 '20 at 12:56
  • No, that is the complete opposite of the point. I can define single-qubit gates $U$ and $V=e^{i\phi}U$ for arbitrary $\phi$. These are equivalent. Controlled-$U$ and Controlled-$V$ are absolutely different things that are not equivalent. – DaftWullie Feb 28 '20 at 12:59
  • Maybe, there was some misunderstanding. What I tried to say is the same as you that $C-U$ and $C-V$ are different gates. Would you agree that if $Rz$ is single qubit z-rotation then its controlled equivalent should be $\begin{pmatrix}I & O \ O & Rz\end{pmatrix}$? – Martin Vesely Feb 28 '20 at 13:04
  • Yes, I agree with that. I absolutely agree "that C−U and C−V are different gates" what I was objecting to is "controlled version of Rz(π) should be equivalent to controlled Z", which is the opposite statement. – DaftWullie Feb 28 '20 at 13:08
  • OK, the non-equivalence of the gates is the issue. If you agree that controlled $Rz(\lambda)$ should be described by $\begin{pmatrix}I & O \ O & Rz(\lambda)\end{pmatrix}$, why it seems to you that implementation on IBM Q is right? Apparently, IBM Q behaves according to a different matrix. – Martin Vesely Feb 28 '20 at 13:13
  • I'm not an expert on IBM Q and don't know what definitions they use. But if you take $R_z(\theta)=e^{-iZ\theta/2}$ (which is certainly one choice of $\pm$ sign and factor of two convention), you get $R_Z(\pi)=\left[\begin{array}{cc} -i & 0 \ 0 & i \end{array}\right]$. – DaftWullie Feb 28 '20 at 13:16
  • Yes, but this is a single qubit gate. If you put this to controlled version, it is something different. Please look at the results in the question. They are completely different because of phase difference in controlled $Rz$. Hence I answered that controlled $Z$ and controlled $Rz(\pi)$ are not equivalent on IBM Q despite the fact that IBM Q help states that they are. That was the reason I called it a bug. – Martin Vesely Feb 28 '20 at 13:21
  • Where does IBM Q help state that they are? At least in the original question, it only stated that the single-qubit gates are equivalent. The OP inferred that the controlled versions should be equivalent. – DaftWullie Feb 28 '20 at 13:23
  • Help for controlled $Rz$: The controlled-Rz gate, like the controlled-NOT, acts on a control and target qubit. It performs a Rz rotation on the target whenever the control is in state $|1\rangle$. So for $\lambda = \pi$ it should perform $Z$ on target qubit. – Martin Vesely Feb 28 '20 at 13:27
  • 1
    No, because $R_z$ is not $Z$. $R_z=-iZ$. – DaftWullie Feb 28 '20 at 13:29
  • Because there's not supposed to be. If I perform controlled-Z on ${|00\rangle,|01\rangle,|10\rangle,|11\rangle}$, I should get ${|00\rangle,|01\rangle,|10\rangle,-|11\rangle}$. If I perform controlled-(-iZ), I should get ${|00\rangle,|01\rangle,-i|10\rangle,i|11\rangle}$. – DaftWullie Feb 28 '20 at 13:35
  • Ah, I see. Maybe that is a problem. So, my answer is right in the sense that $C-Z$ and $C-Rz$ are not equivalent but by controlled global phase it is possible to convert each other. But I was wrong in statement that it is a bug. Thanks for your insight and help. – Martin Vesely Feb 28 '20 at 13:35
  • 1
    This, I can agree with. – DaftWullie Feb 28 '20 at 13:37
  • @DaftWullie: I just realized where the misunderstanding come from. There is a different convention used on IBM Q in comparison with the on in physics. See here discussion on $Rz$ gate: https://quantumcomputing.stackexchange.com/questions/9287/can-you-use-rz-to-flip-from-rangle-to-rangle/9292#9292 – Martin Vesely Feb 28 '20 at 15:58
  • Ah! If that is indeed the case for IBM Q (unusual convention!), then there is an inconsistency in how these things are defined. – DaftWullie Mar 02 '20 at 08:01