跳到正文
原文
Google AI:DEV 作者专属(RSS)· Malcolm Low·· 3 小时前AI 评分27

布洛赫球可视化指南:基态 |0⟩、|1⟩ 与 Pauli X、Z 门

Bloch Sphere Visual Guide: Basis States |0⟩, |1⟩, and Pauli X & Z Gates

AI 导读

量子计算学习路径系列 Module 2 用布洛赫球解释单量子比特几何:Pauli X 门绕 x 轴旋转 π 弧度,把 |0⟩ 翻转到 |1⟩;Pauli Z 门绕 z 轴旋转 π 弧度,不改变计算基下的测量概率,但把赤道上的 |+⟩ 翻转为 |−⟩。文中还推导了极角 θ、φ,并给出 Hadamard 门绕 (x+z) 对角轴旋转 180° 的变换,附可运行的 Qiskit 可视化代码。

正文

Module 2 in the Quantum Computing: A Complete Learning Path series on malcolmlow.com. Following our Introduction to Qubits and Superposition (Module 1), this guide establishes the 3D geometric intuition for single-qubit quantum states and rotations before moving to Two-Qubit Entanglement (Module 3).

Every single-qubit quantum state lives on the surface of a unit sphere in three-dimensional Euclidean space: the Bloch sphere. While classical bits are confined to discrete binary values $0$ and $1$, a qubit can point in any direction defined by spherical coordinates $(\theta, \phi)$.

Yet many beginners struggle to bridge the algebraic definition of a state $|\psi\rangle = \alpha |0\rangle + \beta |1\rangle$ with its physical geometry. Why is $|1\rangle$ at the South Pole when classical intuition expects it to be 90° away from $|0\rangle$? How does an $X$ gate flip a state without changing relative phase? And how does a $Z$ gate alter quantum information if it never changes measurement probabilities in the computational basis?

In this guide, we break down single-qubit geometry from first principles: deriving the polar angles $\theta$ and $\phi$, tracking the basis states $|0\rangle$ and $|1\rangle$, visualizing the equatorial superposition states $|+\rangle$ and $|-\rangle$, analyzing how the Pauli $X$, Hadamard $H$, and Pauli $Z$ gates rotate vectors, and verifying the complete transformation with runnable Qiskit visualization code.


Quick Answer & Key Insight

How do Pauli X and Z gates rotate qubit states on the Bloch sphere?

Yes, Pauli X and Z gates flip states on the sphere. The Pauli $X$ gate rotates the qubit state vector by $\pi$ radians (180°) around the x-axis, flipping computational basis state $|0\rangle$ to $|1\rangle$. The Pauli $Z$ gate rotates the state vector by $\pi$ radians around the z-axis, leaving $|0\rangle$ and $|1\rangle$ unchanged in probability while flipping relative phase on equatorial superposition states (transforming $|+\rangle$ to $|-\rangle$). Blindly rotating qubits without tracking orthogonal axes causes fatal phase errors in quantum algorithms.


1. Why the Bloch Sphere Works: Geometry of a Pure State

A pure single-qubit state is a normalized vector in two-dimensional complex Hilbert space $\mathbb{C}^2$:

$$|\psi\rangle = \alpha |0\rangle + \beta |1\rangle, \quad |\alpha|^2 + |\beta|^2 = 1$$

Because physical measurements depend only on relative phase (global phase factor $e^{i\gamma}$ is unobservable), any pure state can be uniquely parameterized by two real angles $\theta \in [0, \pi]$ and $\phi \in [0, 2\pi)$:

$$|\psi\rangle = \cos\left(\frac{\theta}{2}\right) |0\rangle + e^{i\phi} \sin\left(\frac{\theta}{2}\right) |1\rangle$$

This corresponds directly to a unit vector $\vec{r} = (x, y, z)$ on the 3D Bloch sphere:

  • $x = \sin\theta \cos\phi$
  • $y = \sin\theta \sin\phi$
  • $z = \cos\theta$

Why the Half-Angle $\theta/2$?

Notice that $\theta$ ranges from $0$ to $\pi$ (180°), but $\theta/2$ ranges from $0$ to $\pi/2$ (90°). This mathematical half-angle is the key: orthogonal quantum states (90° in Hilbert space) are mapped to antipodal points (180° apart) on the Bloch sphere.


2. Basis States and the Equatorial Plane

Bloch Sphere Basis States and Superpositions
Figure 1: Computational basis states at the poles vs. equal superposition states on the equatorial plane.

The Computational Basis (Z-Axis Poles)

  • North Pole ($z = +1$): $\theta = 0 \implies |\psi\rangle = |0\rangle$
  • South Pole ($z = -1$): $\theta = \pi \implies |\psi\rangle = |1\rangle$

Because $|0\rangle$ and $|1\rangle$ lie at opposite poles, any state along the z-axis has a well-defined probability of collapsing into classical bits when measured.

The Equatorial Plane (X and Y Axes)

When $\theta = \pi/2$, $\cos(\pi/4) = \sin(\pi/4) = 1/\sqrt{2}$. The qubit has an equal 50/50 probability of yielding $0$ or $1$:

  • Positive X-Axis ($+x$): $\phi = 0 \implies |+\rangle = \frac{|0\rangle + |1\rangle}{\sqrt{2}}$
  • Negative X-Axis ($-x$): $\phi = \pi \implies |-\rangle = \frac{|0\rangle - |1\rangle}{\sqrt{2}}$
  • Positive Y-Axis ($+y$): $\phi = \pi/2 \implies |+i\rangle = \frac{|0\rangle + i|1\rangle}{\sqrt{2}}$
  • Negative Y-Axis ($-y$): $\phi = 3\pi/2 \implies |-i\rangle = \frac{|0\rangle - i|1\rangle}{\sqrt{2}}$

3. The Pauli X Gate: 180° Rotation Around the X-Axis

The Pauli $X$ gate represents quantum bit-flip logic:

$$X = \begin{pmatrix} 0 & 1 \ 1 & 0 \end{pmatrix}$$

Geometrically, $X$ rotates the state vector by $\pi$ radians around the x-axis:

  • $X |0\rangle = |1\rangle$ (North Pole rotates through the equator to South Pole)
  • $X |1\rangle = |0\rangle$ (South Pole rotates back to North Pole)
  • $X |+\rangle = |+\rangle$ (State along the x-axis is an eigenstate and remains unchanged!)

4. The Hadamard Gate: Bridging Poles and Equator

The Hadamard gate $H$ creates quantum superposition:

$$H = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \ 1 & -1 \end{pmatrix}$$

Geometrically, $H$ is a 180° rotation around the diagonal $(x + z)$ axis. It swaps the computational basis with the Hadamard basis:

  • $H |0\rangle = |+\rangle$ (Moves North Pole to positive x-axis)
  • $H |1\rangle = |-\rangle$ (Moves South Pole to negative x-axis)
  • $H |+\rangle = |0\rangle$ and $H |-\rangle = |1\rangle$ (Reversible self-inverse: $H^2 = I$)

5. The Pauli Z Gate: 180° Phase Rotation Around the Z-Axis

The Pauli $Z$ gate represents phase-flip logic:

$$Z = \begin{pmatrix} 1 & 0 \ 0 & -1 \end{pmatrix}$$

Geometrically, $Z$ rotates the state vector by $\pi$ radians around the z-axis:

  • $Z |0\rangle = |0\rangle$ (North Pole lies on the rotation axis; unchanged)
  • $Z |1\rangle = -|1\rangle$ (Global phase; probability unchanged)
  • $Z |+\rangle = |-\rangle$ (Rotates the vector across the equatorial plane from $+x$ to $-x$!)
  • $Z |-\rangle = |+\rangle$

Why this matters: A $Z$ gate does not change measurement outcomes in the computational basis ($|0\rangle$ vs $|1\rangle$), but it fundamentally flips quantum phase. In algorithms like Grover's search and Deutsch-Jozsa, this phase flip enables constructive and destructive interference.


6. X, H, and Z Transformations Side by Side

Bloch Sphere Gate Transformations
Figure 2: Visual progression of quantum states under Pauli X, Hadamard H, and Pauli Z gate operations.

Gate Matrix Operator Geometric Axis Input State Output State Physical Effect
Pauli X $\begin{pmatrix} 0 & 1 \ 1 & 0 \end{pmatrix}$ Rotation by $\pi$ around $x$ $ 0\rangle$ $
Hadamard $\frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \ 1 & -1 \end{pmatrix}$ Rotation by $\pi$ around $x+z$ $ 0\rangle$ $
Pauli Z $\begin{pmatrix} 1 & 0 \ 0 & -1 \end{pmatrix}$ Rotation by $\pi$ around $z$ $ +\rangle$ $

7. Python Verification in Qiskit

You can generate this exact multi-panel 3D Bloch visualization using Qiskit and Matplotlib:

from pathlib import Path
import matplotlib.pyplot as plt
import numpy as np
from qiskit.circuit.library import HGate, XGate, ZGate
from qiskit.quantum_info import Statevector
from qiskit.visualization.bloch import Bloch

def bloch_vector(state):
    """Calculates (x, y, z) Bloch coordinates from a 2-element Statevector."""
    alpha, beta = state.data
    overlap = np.conj(alpha) * beta
    return [
        float(2 * np.real(overlap)),
        float(2 * np.imag(overlap)),
        float(abs(alpha) ** 2 - abs(beta) ** 2),
    ]

# Define base states
zero = Statevector.from_label("0")
one = zero.evolve(XGate())
plus = zero.evolve(HGate())
minus = plus.evolve(ZGate())

assert one.equiv(Statevector.from_label("1"))
assert plus.equiv(Statevector.from_label("+"))
assert minus.equiv(Statevector.from_label("-"))

rows = [
    ("X gate", zero, one, r"Input: $|0\rangle$", r"Output: $|1\rangle$"),
    ("H gate", zero, plus, r"Input: $|0\rangle$", r"Output: $|+\rangle$"),
    ("Z gate", plus, minus, r"Input: $|+\rangle$", r"Output: $|-\rangle$"),
]

fig = plt.figure(figsize=(9.6, 12.6), facecolor="white")

for row_index, (gate, before, after, before_title, after_title) in enumerate(rows):
    for column_index, (state, title, color) in enumerate((
        (before, before_title, "#1565C0"),
        (after, after_title, "#D32F2F"),
    )):
        axis = fig.add_subplot(
            3, 2, row_index * 2 + column_index + 1, projection="3d"
        )
        sphere = Bloch(fig=fig, axes=axis, font_size=13)
        sphere.xlabel = [r"$|+\rangle$", r"$|-\rangle$"]
        sphere.vector_color = [color]
        sphere.add_vectors(bloch_vector(state))
        sphere.render(title=title)

    fig.text(
        0.03, 0.805 - row_index * 0.31, gate,
        rotation=90, va="center", ha="center", fontweight="bold",
    )

fig.suptitle(
    "Bloch-Sphere Gate Progression: X, then H, then Z",
    fontsize=18, fontweight="bold", y=0.98
)
plt.tight_layout()
plt.savefig("bloch_progression.png", dpi=300)
print("Saved bloch_progression.png successfully!")

8. Summary & Key Takeaways

  1. Orthogonality vs. Antipodality: In Hilbert space, orthogonal states $|0\rangle$ and $|1\rangle$ have zero inner product ($\langle 0|1\rangle = 0$). On the Bloch sphere, they point in opposite directions (separated by 180°).
  2. Single-Qubit Unitaries are Rotations: Every single-qubit quantum gate is isomorphic to an $SO(3)$ rotation of the Bloch sphere around some axis.
  3. The Foundation of Entanglement: The Bloch sphere only describes pure single-qubit states. As soon as two qubits become entangled, individual Bloch vectors shrink inside the sphere, representing mixed states.

Frequently Asked Questions

Why is |1⟩ at the South Pole instead of 90° away from |0⟩?

Because of the mathematical half-angle factor $\theta/2$ in the Bloch parametrization $|\psi\rangle = \cos(\theta/2)|0\rangle + e^{i\phi}\sin(\theta/2)|1\rangle$. While $|0\rangle$ and $|1\rangle$ are orthogonal in complex vector space (90°), their geometric representation maps $\theta = \pi$ (180°), placing them at antipodal poles.

Does the Pauli Z gate change measurement probabilities?

Not in the computational basis. For computational states $|0\rangle$ and $|1\rangle$, the $Z$ gate leaves measurement probabilities at 100%. However, for superposition states like $|+\rangle$, $Z$ flips the relative phase to $|-\rangle$, which can be detected with 100% certainty by measuring in the Hadamard basis.


Originally published at malcolmlow.com.

来源:Google AI:DEV 作者专属(RSS) · dev.to