Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

Bloch Sphere

Download NotebookDownload CodeView source on GiteeRun in ModelArts

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