Visualizing a Hadamard gate
If we want to understand the visualization of pure states in Quantum Computing, the most used tool is the Bloch sphere.
Let´s draw the rotations using python and the QuTip library.
The first step is to get a Bloch sphere:
from qutip import *
b = qutip.Bloch()
b.make_sphere()
b.show()
We can identify any point in the sphere following this formula:
Being Theta and Phi the following angles:
Over the Bloch sphere, when you apply a Hadamard gate is similar to a rotation of 90º over the Y-axe, followed by a rotation of 180º over the X-axe (it rotates over itself).
Let’s use a function than rotate the state |0> (also with the 180º over X than doesn’t change anything)
Let’s apply a Hadamard gate to the |0> state.
states = rotate(pi/2,0)
animate_bloch(states, duration=0.1, save_all=False,file_name='output/bloch_anim0.gif')
And also over |1>
As you can see if you apply a Hadamard gate to the state |0> you get a state |+> and if you do it over |1> you get |->
If we want to see it in a non-fundamental state, we need to apply the rotation equation for X-axis.
You can multiply for those matrices to rotate a vector:
If we do it, for example to a vector with these angles:
origin_theta = pi\8
origin_phi = 0
And apply a Hadamard gate with the two rotations:
So you need two rotations to apply an H gate.
References
Tanay Roy: How to animate a Bloch Sphere
Wikipedia: Esfera de Bloch
Wikipedia: Bloch sphere