2
$\begingroup$

I've seen in google cirq that a $X^q$ gate is converted in openqasm to $RX(\pi q)$, why is that?

Same for $S^q$ into $RZ(\pi q/2)$.

$\endgroup$
  • 1
    $\begingroup$ Could you define the gates more specifiaclly? Or at least give a reference for where you have seen those conversions? I think that should be helpful to answer your question. $\endgroup$ – Josu Etxezarreta Martinez Feb 27 at 13:53
2
$\begingroup$

Note that $$RX(\phi) = \begin{pmatrix} \cos(\phi/2) & -i\sin(\phi/2) \\-isin(\phi/2) & \cos(\phi/2)\end{pmatrix}$$

Then $$RX(\pi q) = \begin{pmatrix} \cos(\pi q/2) & -i\sin(\pi q/2) \\-isin(\pi q/2) & \cos(\pi q/2)\end{pmatrix}.$$

Now, using that $\cos(\pi k + \pi/2) = 0 = \sin(\pi k)$ and $\cos(\pi k) = 1 = \sin(\pi k + \pi/2)$ for $k\in \mathbb{Z}$ and that a global phase does not physically affect the quantum state, we see that for odd $q$ we get $X$ and for even $q$ we get the identity matrix.

We can prove the other equation similarly using $$RZ(\phi) = \begin{pmatrix} e^{-\phi/2} & 0 \\ 0 & e^{\phi/2} \end{pmatrix}$$

$\endgroup$
2
$\begingroup$

This is the matrix for $Z^t$:

$$Z^t = \begin{bmatrix} 1&0\\0&(-1)^t \end{bmatrix} = \begin{bmatrix} 1&0\\0&e^{i \pi t} \end{bmatrix}$$

This is the matrix for $R_Z(\pi t)$:

$$R_Z(\pi t) = e^{-iZt/2} = \begin{bmatrix} e^{-i \pi t / 2}&0\\0&e^{+i \pi t / 2} \end{bmatrix} = e^{-i \pi t/2} Z^t $$

Which means that

$$Z^t \equiv R_Z(\pi t) \pmod{\text{global phase}}$$

Qiskit doesn't have a concept like $Z^t$, but it does have $R_Z$, so Cirq relies on this equality-up-to-global-phase and converts from one to the other when producing QASM. The exact same situation repeats with powers of $X$ and $Y$.

$\endgroup$
  • $\begingroup$ Thanks ! this is useful, but how can I prove that $$Z^t = \begin{bmatrix} 1&0\\0&(-1)^t \end{bmatrix} = \begin{bmatrix} 1&0\\0&e^{i \pi t} \end{bmatrix}$$ for an arbitrary $$ t \in R $$ $\endgroup$ – Reda Drissi Feb 27 at 20:55
  • $\begingroup$ @RedaDrissi $(-1)^t = (e^{\ln -1})^t = (e^{i \pi})^t = e^{i \pi t}$, at least along one of the branches of $(-1)^t$ (it's technically a multivalued function). $\endgroup$ – Craig Gidney Feb 27 at 21:44
  • $\begingroup$ I got that, what I want to know is how to calculate arbitrary powers of unitary gates, so that I may compute powers of matrices of other unitary gates such as Hadamard or SWAP/ISWAP etc $\endgroup$ – Reda Drissi Feb 28 at 8:46
  • 1
    $\begingroup$ @RedaDrissi Rule of thumb: to compute f(M) you eigendecompose M into M = sum_k a_k |v_k><v_k| then return sum_k f(a_k) |v_k><v_k|. $\endgroup$ – Craig Gidney Feb 28 at 14:42

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.