跳轉到

9.2 量子糾錯碼入門#

概念說明#

古典糾錯靠冗餘:把 0 複製成 000,多數表決。量子版本面對三重障礙:不可克隆(無法複製未知態)、連續誤差(錯誤可以是任意角度的旋轉,不只翻轉)、測量破壞態(量一下就塌縮)。量子糾錯碼用兩個巧思同時克服:

  1. 不複製,而是「展開」:把一個邏輯量子位元的資訊分散編碼進多個物理位元的糾纏中,例如
\[ |\psi_L\rangle = \alpha|000\rangle + \beta|111\rangle \]

這不是 \(\alpha\psi\otimes\alpha\psi\otimes\alpha\psi\) (那才是克隆),而是把 \(\alpha,\beta\) 藏在糾纏結構裡——單看任何一個位元都得不到 \(|\psi\rangle\) 的資訊。

  1. 量 syndrome 而不是量資料:測量「哪裡錯了」(parity 資訊)而非「資料是什麼」。例如測 \(Z_1Z_2\) (前兩位元的奇偶),結果只告訴你「1、2 位元是否相異」,不會塌縮掉 \(\alpha, \beta\) 。

線性碼的經典三例:

  • 3 位元位元翻轉碼:糾正任意單一 \(X\) 錯誤。 \(Z_1Z_2, Z_2Z_3\) 的 syndrome:(00) 無錯、(10) 第 1 位、(11) 第 2 位、(01) 第 3 位。
  • 3 位元相位翻轉碼:對偶版本,糾正 \(Z\) 錯誤,編碼 \(|\pm\rangle\) 的重複。
  • Shor 9 位元碼:位元翻轉碼與相位翻轉碼的級聯,糾正任意單位元錯誤。關鍵事實:由於任意誤差 \(E = e_0 I + e_1 X + e_2 Y + e_3 Z\) 是線性組合,糾正了 \(X, Y, Z\) 三種基本錯誤就糾正了一切——連續誤差被量子測量的塌縮「數位化」成離散 syndrome。

穩定子形式:碼空間由一群對易算子(穩定子) \(g_i\) 的共同 +1 本徵空間定義。測 \(g_i\) 的本徵值得到 syndrome,效率遠高於一般投影測量。

Python 範例:3 位元位元翻轉碼#

import numpy as np

ket = {0: np.array([1,0], dtype=complex), 1: np.array([0,1], dtype=complex)}
X = np.array([[0,1],[1,0]], dtype=complex)
Z = np.array([[1,0],[0,-1]], dtype=complex)
I2 = np.eye(2, dtype=complex)

def kron3(a, b, c): return np.kron(np.kron(a, b), c)

def encode(psi):
    """|ψ> = α|0>+β|1> -> α|000>+β|111>(用 CNOT×2 從第 0 位複製到 1,2 位)"""
    a, b = psi
    return a*kron3(ket[0], ket[0], ket[0]) + b*kron3(ket[1], ket[1], ket[1])

def syndrome(logical_rho_or_state, error):
    """模擬 syndrome 測量:先套錯誤,再量 Z1Z2、Z2Z3"""
    state = error @ logical_rho_or_state
    z12 = state @ kron3(Z, Z, I2)   # 簡化:對純態直接取內積
    z23 = state @ kron3(I2, Z, Z)
    s1 = (z12 @ state).real > 0.5   # +1(同意)=0, -1(相異)=1
    s2 = (z23 @ state).real > 0.5
    return (int(s1), int(s2)), state

def correct(state, s1, s2):
    if (s1, s2) == (1, 0): return kron3(X, I2, I2) @ state
    if (s1, s2) == (1, 1): return kron3(I2, X, I2) @ state
    if (s1, s2) == (0, 1): return kron3(I2, I2, X) @ state
    return state

psi = np.array([0.6, 0.8], dtype=complex)
enc = encode(psi)
print("編碼後:", np.round(enc, 3))

for loc in [0, 1, 2]:
    E = kron3(*(X if i == loc else I2 for i in range(3)))
    damaged = E @ enc
    (s1, s2), _ = syndrome(damaged, E)
    fixed = correct(damaged, s1, s2)
    print(f"錯誤在第 {loc} 位 -> syndrome ({s1},{s2}) -> 糾正後 = 原態? "
          f"{np.allclose(fixed, enc)}")

# 單位元錯誤無論多「連續」(如小幅旋轉),syndrome 測量後塌縮為 X 型錯誤
theta = 0.3
R = np.array([[np.cos(theta), -np.sin(theta)],[np.sin(theta), np.cos(theta)]], dtype=complex)
E_soft = kron3(R, I2, I2)
damaged = E_soft @ enc
# 直接量 syndrome:塌縮成「無錯」或「X 錯」兩種離散結果之一
print("\n連續旋轉誤差也會被數位化為離散 syndrome —— 這是量子糾錯的奇蹟")

複雜度分析#

  • 3 位元碼:編碼 2 個 CNOT、syndrome 2 次測量、糾正至多 1 個 X。能糾正 \(t=1\) 個錯誤(碼距 3,滿足 \(d = 2t+1\) )。
  • 一般 \([[n, k, d]]\) 碼: \(n\) 個物理位元編碼 \(k\) 個邏輯位元、糾正 \(t = \lfloor(d-1)/2\rfloor\) 個錯誤。Shor 碼 \([[9,1,3]]\) ;Steane 碼 \([[7,1,3]]\) ;表面碼(surface code)用 \(d^2\) 個物理位元、糾正 \(\lfloor d/2\rfloor\) 個。
  • 若單位元錯誤率 \(p\) ,未編碼成功率 \((1-p)\) ;3 位元碼後失敗率 \(\approx 3p^2\) (需兩個以上錯誤才會壞)—— \(p\) 小時是平方改善。

練習#

  1. 證明 3 位元碼的編碼態 \(\alpha|000\rangle+\beta|111\rangle\) 中,任一單位元的約化密度矩陣都不含 \(\alpha\beta^*\) 項——資訊確實不在單一位元裡。
  2. (程式)為 3 位元碼加上「兩個位元同時錯」的情境,觀察糾正失敗,並驗證失敗率 \(\approx 3p^2\) 的標度律。
  3. (觀念)為什麼量 \(Z_1Z_2\) 不會破壞 \(\alpha, \beta\) ?用「 \(|000\rangle\) 與 \(|111\rangle\) 都是 \(Z_1Z_2=+1\) 的本徵態」說明。