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)$.
Quantum Computing Stack Exchange is a question and answer site for engineers, scientists, programmers, and computing professionals interested in quantum computing. It only takes a minute to sign up.
Sign up to join this communityI'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)$.
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}$$
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$.