Visualizing a qubit in Python
In this recipe, we will use generic Python with NumPy to create a vector and visual representation of a bit and show how it can be in only two states, 0 and 1. We will also introduce our first, smallish foray into the Qiskit® world by showing how a qubit can not only be in the unique 0 and 1 states but also in a superposition of these states. The way to do this is to take the vector form of the qubit and project it on the so-called Bloch sphere, for which there is a Qiskit® method. Let's get to work!
In the preceding recipe, we defined our qubits with the help of two complex parameters—a and b. This meant that our qubits could take values other than the 0 and 1 of a classical bit. But it is hard to visualize a qubit halfway between 0 and 1, even if you know a and b.
However, with a little mathematical trickery, it turns out that you can also describe a qubit using two angles—theta () and phi ()—and visualize the...