{
"cells": [
{
"cell_type": "markdown",
"id": "fe853c49",
"metadata": {},
"source": [
"# 4.2 单量子比特运算"
]
},
{
"cell_type": "markdown",
"id": "011ecf95",
"metadata": {},
"source": [
"未完成的证明:练习 4.11"
]
},
{
"cell_type": "code",
"execution_count": 54,
"id": "9cdd2263",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import scipy\n",
"from qiskit import QuantumCircuit, Aer, assemble\n",
"from qiskit.visualization import plot_bloch_multivector"
]
},
{
"cell_type": "markdown",
"id": "1c61d061",
"metadata": {},
"source": [
"## 练习 4.1"
]
},
{
"cell_type": "markdown",
"id": "15fa9b30",
"metadata": {},
"source": [
":::{admonition} 练习 4.1\n",
"\n",
"练习 2.11 计算了 Pauli 矩阵的特征向量 (如果还没有做这个练习,请现在就做),在 Bloch 球面上求出不同 Pauli 矩阵的归一化特征向量对应的点。\n",
"\n",
":::"
]
},
{
"cell_type": "markdown",
"id": "afcd33b5",
"metadata": {},
"source": [
"首先,这三个 Pauli 矩阵 $X, Y, Z$ 的特征值均为 $\\lambda_1 = -1, \\lambda_2 = 1$。它们的特征向量分别是\n",
"\n",
"$$\n",
"\\begin{alignat*}{4}\n",
"|x_1\\rangle &= - \\frac{1}{\\sqrt{2}} |0\\rangle + \\frac{1}{\\sqrt{2}} |1\\rangle,& \\quad |x_2\\rangle &= \\frac{1}{\\sqrt{2}} |0\\rangle + \\frac{1}{\\sqrt{2}} |1\\rangle \\\\\n",
"|y_1\\rangle &= - \\frac{1}{\\sqrt{2}} |0\\rangle + \\frac{i}{\\sqrt{2}} |1\\rangle,& \\quad |y_2\\rangle &= \\frac{1}{\\sqrt{2}} |0\\rangle + \\frac{i}{\\sqrt{2}} |1\\rangle \\\\\n",
"|z_1\\rangle &= |1\\rangle,& \\quad |z_2\\rangle &= |0\\rangle\n",
"\\end{alignat*}\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "f7ce77b4",
"metadata": {},
"source": [
"下面使用程序绘制 Bloch 球面。我们先用 NumPy 给出本征向量,随后代入到 Qiskit 中绘制。可以看到,$X, Y, Z$ 的本征值分别对应 Bloch 球面上 $x, y, z$ 三个方向。"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "6f736ab3",
"metadata": {},
"outputs": [],
"source": [
"X = np.array([[0, 1], [1, 0]])\n",
"Y = np.array([[0, -1j], [1j, 0]])\n",
"Z = np.array([[1, 0], [0, -1]])"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "dfb83b9c",
"metadata": {},
"outputs": [],
"source": [
"def ex_4_1(matrix, title=None):\n",
" \"\"\" Input Pauli matrix X or Y or Z; Draw eigenvectors of matrix on Bloch sphere. \"\"\"\n",
" eig = np.linalg.eigh(matrix)[1].T\n",
" circ = QuantumCircuit(2)\n",
" for n, e in enumerate(eig):\n",
" circ.initialize(e, n)\n",
" return plot_bloch_multivector(circ, title)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "1509cc0a",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\r\n",
"\r\n",
"\r\n",
"\r\n"
],
"text/plain": [
"