Hey @Kamal_Mohamed and welcome to the forum @Wenlong_Yang!
Great discussion going on here. I’ll address @Wenlong_Yang’s original post first. If we apply an R_x gate to the Z basis states, this is what we get:
\begin{align*}
R_x(\theta) \vert 0 \rangle &= \cos(\tfrac{\theta}{2}) \vert 0 \rangle - i \sin(\tfrac{\theta}{2}) \vert 1 \rangle \\
R_x(\theta) \vert 1 \rangle &= - i \sin(\tfrac{\theta}{2}) \vert 0 \rangle + \cos(\tfrac{\theta}{2})\vert 1 \rangle
\end{align*}
The \vert y + \rangle and \vert y-\rangle states are:
\begin{align*}
\vert y + \rangle &= \frac{1}{\sqrt{2}}\left( \vert 0 \rangle + i\vert 1 \rangle \right)\\
\vert y - \rangle &= \frac{1}{\sqrt{2}}\left( \vert 0 \rangle - i\vert 1 \rangle \right)
\end{align*}
At first glance, it looks like we cannot get these states from applying an R_x gate. However, we can with a little trickery! Firstly,
\begin{align*}
R_x(\theta = -\tfrac{\pi}{2}) \vert 0 \rangle &= \cos(-\tfrac{\pi}{4}) \vert 0 \rangle - i \sin(-\tfrac{\pi}{4}) \vert 1 \rangle \\
&= \frac{1}{\sqrt{2}}\left( \vert 0 \rangle + i\vert 1 \rangle \right) \\
&= \vert y + \rangle.
\end{align*}
One down! One to go…
\begin{align*}
R_x(\theta = -\tfrac{\pi}{2}) \vert 1 \rangle &= - i \sin(-\tfrac{\pi}{4}) \vert 0 \rangle + \cos(-\tfrac{\pi}{4}) \vert 1 \rangle \\
&= \frac{1}{\sqrt{2}}\left( i \vert 0 \rangle + \vert 1 \rangle \right)
\end{align*}
Now, global phases — e^{i\varphi} — in quantum mechanics don’t affect any physics. So, I can safely multiply any state by a global phase. Let’s multiply the above by e^{ - i \tfrac{\pi}{2}} = -i:
\begin{align*}
&= \frac{1}{\sqrt{2}}\left( -i \times i \vert 0 \rangle - i \vert 1 \rangle \right) \\
& = \frac{1}{\sqrt{2}}\left( \vert 0 \rangle - i \vert 1 \rangle \right) \\
& = \vert y - \rangle
\end{align*}
And we’re done… sorta! But, this clears up your confusion @Kamal_Mohamed — your intuition on Bloch sphere rotations is correct!
However, this doesn’t really answer the codebook question, as we had to “cheat” — it’s not really cheating — with that global phase trick. One way to get the \vert y + \rangle and \vert y-\rangle states right away is to apply a Hadamard — qml.Hadamard
— gate and a Phase gate — qml.S
. Check out the docs for the phase gate operator, do the multiplication, and verify that you get the the \vert y + \rangle and \vert y-\rangle states!