Bloch Sphere

Download NotebookDownload CodeView Source On Gitee

Single-qubit State

Unlike classical bits, qubits can be in both the computational basis vector |0 state and the |1 state, usually expressed as

|ψ=a|0+b|1

Here a and b are complex numbers. Due to the normalization condition of the quantum state ψ|ψ=1, therefore

|a|2+|b|2=1

For a two-dimensional Hilbert space, we can make the following mapping of the computational basis vector

|0=(10),|1=(01)

Thus, any single-qubit state can be expressed as

|ψ=(ab)

In the general case, we do not care about the global phase, so we can assume a=cos(θ/2),b=eiϕsin(θ/2):

|ψ=cos(θ/2)|0+eiϕsin(θ/2)|1

Here we might as well represent that arbitrary quantum state in the unit ball, as follows, taking θ and ϕ as the elevation and azimuth angles, respectively.

bloch-sphere

Next we will show how to demonstrate a single-qubit state in MindSpore Quantum and the evolution of the single-qubit state in the form of an animation.

Building Quantum Circuit

From the above bloch sphere, we can control the elevation angle θ by the revolving gate RX and the azimuth angle ϕ by RZ. Therefore, we can build the following quantum circuit.

[11]:
circ = Circuit()               # Build circuit for preparing an arbitrary single-qubit quantum state
circ += RX('theta').on(0)      # Control elevation via RX gate
circ += RZ('phi').on(0)        # Control azimuth via RZ gate
circ.svg()
[11]:
../_images/beginner_bloch_sphere_5_0.svg

Here we might as well take θ=π/4,ϕ=π/4 and calculate the corresponding quantum state.

[12]:
import numpy as np

state1 = circ.get_qs(pr={'theta': np.pi/4, 'phi': np.pi/4})
print(state1)
[0.85355339-0.35355339j 0.14644661-0.35355339j]

Displaying the Quantum State

In MindSpore Quantum, BlochScene is the module used to display the Bloch sphere. We can add as many single-qubit states as we want to the BlochScene and also animate the evolution of the single-qubit quantum states.

[13]:
scene = BlochScene()                       # Create Bloch drawing scene
fig, ax = scene.create_scene()             # Initialize the scene
state_obj1 = scene.add_state(ax, state1)   # Add a quantum state to the scene

In addition, we can also show the Bloch sphere in dark mode, as follows.

[14]:
scene = BlochScene('dark')                       # Create Bloch drawing scene
fig, ax = scene.create_scene()                   # Initialize the scene
state_obj1 = scene.add_state(ax, state1)         # Add a quantum state to the scene

Displaying the Evolution of the Quantum State

We can also create animations in the Bloch scene when the quantum state is a time-dependent quantum state. Here we may assume that the elevation θ and azimuthal ϕ are time-dependent and we can obtain the quantum states for all time.

[20]:
t = np.linspace(0, 10, 500)
all_theta = 4 * np.sin(2 * t)
all_phi = 5 * np.cos(3 * t)
states = []
for theta, phi in zip(all_theta, all_phi):
    states.append(circ.get_qs(pr={'theta': theta, 'phi': phi}))
states = np.array(states)

In the following, we create a dark Bloch scene and initialize the scene with the first one of the evolved quantum states.

[22]:
scene = BlochScene('dark')                          # Create Bloch drawing scene
fig, ax = scene.create_scene()                      # Initialize the scene
state_obj = scene.add_state(ax, states[0])          # Add a quantum state to the scene

To be able to display dynamically the evolution of quantum states, we create an animated object from the Bloch scene.

[23]:
anim = scene.animation(fig, ax, state_obj, states)

bloch-sphere-anim

From this, we can see that the quantum state of a single qubit has moved in the Bloch sphere.

[1]:
from mindquantum.utils.show_info import InfoTable

InfoTable('mindquantum', 'scipy', 'numpy')
[1]:
Software Version
mindquantum0.9.11
scipy1.10.1
numpy1.24.4
System Info
Python3.8.17
OSLinux x86_64
Memory16.62 GB
CPU Max Thread16
DateTue Jan 2 14:38:36 2024