DEV Community

Kauê Miziara
Kauê Miziara

Posted on

1

Bloch Sphere: Qubit Visualization

Index

Quantum States

In quantum computing, the possible states of a system can be mathematically represented as a linear combination of the vectors 0\ket 0 and 1\ket 1 .

Considering a system with only one quantum bit (qubit), we have:

ψ=α0+β1 \ket \psi = \alpha \ket 0 + \beta \ket 1

Where α,βC\alpha, \beta \in \mathbb{C} .


Bloch Sphere

Without physical meaning, it is a mathematical model used to geometrically represent the state of a qubit, as shown below for the state 0\ket 0 :

Bloch Sphere representing the state 0

Useful for verifying states in superposition, it can be used to visualize the application of logical operators through the rotation of the state vector.

To be represented on the Sphere, a quantum state can be rewritten in terms of a pair of angles:

ψ=cosθ20+eiϕsinθ21 \ket \psi = \cos\frac \theta 2 \ket 0 + e^{i\phi}\sin\frac \theta 2 \ket 1

Visualizing a Quantum State

Using Qiskit, a development kit written by IBM to create and manipulate quantum states and circuits in Python, it is possible to generate a random state (using the relation above) and visualize the generated vector on the Bloch Sphere.

1. Required Dependencies

  • NumPy: For angle calculations.
  • Qiskit: For state generation and Bloch sphere rendering.
  • Interactive Environment (e.g., Jupyter Notebook): For image display.
  • Matplotlib: Required by Qiskit for plotting.
$ pip install numpy matplotlib qiskit ipykernel
Enter fullscreen mode Exit fullscreen mode
import numpy as np
from qiskit.quantum_info import Statevector
from qiskit.visualization import plot_bloch_multivector
Enter fullscreen mode Exit fullscreen mode

2. Generating a Random State

First, we can use NumPy methods to create the angles θ\theta and ϕ\phi :

theta = np.random.uniform(0, np.pi)
phi   = np.random.uniform(0, 2*np.pi)
Enter fullscreen mode Exit fullscreen mode

The angle limitations will be explained later.

With the angles, we create a Statevector from a list, where the first element represents the 0\ket 0 portion of the vector, and the second represents the 1\ket 1 portion:

state = Statevector([
    np.cos(theta/2),
    np.exp(phi * 1.j) * np.sin(theta/2)
])
Enter fullscreen mode Exit fullscreen mode

Note: since in computing i is a commonly used letter, the complex root is represented by j.

3. Displaying the state and Bloch Sphere

By executing this code in Jupyter cells, we can display the results of the operations

  • writing the state created by Statevector in text or LaTeX format
  • illustrating the Sphere as an image
display(state.draw('LaTeX'))
plot_bloch_multivector(state)
Enter fullscreen mode Exit fullscreen mode

An example output would be:

0.77275074280+(0.4500494484+0.4475620442i)1 0.7727507428 \ket 0 + (−0.4500494484 + 0.4475620442 i)\ket 1

Bloch Sphere representing the random state


Deriving the Equation

Let's deduce the equation, showing in a simplified manner why it is valid.

Polar Coordinates

Let zz be a complex number, such that z=x+iyz = x + iy (where ii is the imaginary unit).

This number can be represented in the Argand-Gauss plane as a vector with modulus ρ\rho :

Complex z on the Argand-Gauss plane

We can represent the vector in its polar form, rewriting its sides in terms of the angle between them:

x=ρcosθy=ρsinθz=ρcosθ+iρsinθz=ρ(cosθ+isinθ) x = \rho\cos\theta \\ y = \rho\sin\theta \\ \therefore z = \rho\cos\theta + i\rho\sin\theta \\ z = \rho(\cos\theta + i\sin\theta)

Applying Euler's Formula, we have:

z=ρeiθz = \rho e^{i\theta}

Thus, we can rewrite the state vector ψ\psi as:

ψ=ρ0eiθ00+ρ1eiθ11 \ket\psi = \rho_0e^{i\theta_0}\ket 0 + \rho_1e^{i\theta_1}\ket 1

Simplifying the Vector

In summary, the “global phase” is a mathematical representation of the phase of a quantum system, consisting of a factor that multiplies a state without altering its physical properties.

That is, we can multiply the state vector by its global phase while maintaining the described relations:

ψ=eiθ00ψ=ρ00+ρ1ei(θ1θ0)1 \ket{\psi'} = e^{-i\theta_0}\ket 0 \\ \ket{\psi'} = \rho_0\ket 0 + \rho_1e^{i(\theta_1-\theta_0)}\ket 1

Let θ=θ1θ0\theta = \theta_1 - \theta_0 :

ψ=ρ00+ρ1eiθ1 \ket{\psi'} = \rho_0\ket 0 + \rho_1e^{i\theta}\ket 1

We can also rewrite one of the coefficients in the form x+iyx + iy , since the original coefficients ( α\alpha and β\beta ) are complex:

β=ρ1eiθ=x+iy \beta = \rho_1e^{i\theta} = x + iy

As this notation is equivalent to the original, the vector remains normalized, that is:

ρ02+x+iy2=1ρ02+x2+y2=1 |\rho_0|^2 + |x + iy|^2 = 1 \\ \rho_0^2 + x^2 + y^2 = 1

This last equation represents a sphere in a three-dimensional space, meaning that the state vector can be represented on a sphere.

Polar Coordinates on a Sphere

Analogous to a two-dimensional vector, a three-dimensional vector ( x,y,zx, y, z ) on a sphere can have its components written in polar form as:

x=ρsinθcosϕy=ρsinθsinϕz=ρcosθ x = \rho\sin\theta\cos\phi \\ y = \rho\sin\theta\sin\phi \\ z = \rho\cos\theta

Where:

  • θ\theta is the angle formed between the vector and the zz axis;
  • ϕ\phi is the angle formed between the vector and the xx axis;
  • ρ0=z\rho_0 = z ;
  • Normalization ensures that ρ=1\rho = 1 .

Rewriting the vector in polar coordinates, we have:

ψ=z0+(x+iy)1ψ=cosθ0+sinθ(cosϕ+isinϕ)1ψ=cosθ0+eiϕsinθ1 \ket{\psi'} = z\ket 0 + (x+iy)\ket 1 \\ \ket{\psi'} = \cos\theta\ket 0 + \sin\theta(\cos\phi+i\sin\phi)\ket 1 \\ \ket{\psi'} = \cos\theta\ket 0 + e^{i\phi}\sin\theta\ket 1

Half Angles

However, this is not the complete Sphere. To be able to represent any state vector, we restrict the angles such that:

  • 0θπ0 \leq \theta \leq \pi
  • 0ϕ2π0 \leq \phi \leq 2\pi

Thus, we arrive at the general form of a quantum state vector as a function of its angles:

ψ=cosθ20+eiϕsinθ21 \ket \psi = \cos\frac \theta 2 \ket 0 + e^{i\phi}\sin\frac \theta 2 \ket 1

Conclusion

Using this relation, we ensure that the generated state can always be visualized on a Bloch Sphere, which implies that it will always be a valid state.

Top comments (0)

👋 Kindness is contagious

DEV is better (more customized, reading settings like dark mode etc) when you're signed in!

Okay