3. 双量子比特门纠缠保真度基准测试
任务拆解:从门层噪声到纠缠保真度
双量子比特门(如 CX、CZ、iSWAP)的纠缠保真度不能直接由单比特 RB 推出,因为双比特门会引入关联噪声(如 ZZ 串扰、控制通道泄漏)和串扰(相邻比特同时驱动时的频率牵引)。本例采用两条互补路径:
- XEB(交叉熵基准):用随机双比特门序列构造线路,比较实测比特串分布与理想分布,通过交叉熵估计每周期保真度,对关联噪声敏感,适合评估"整门"性能。
- 贝尔态层析:制备 Bell 态后做 9 组基测量,重建密度矩阵,计算纠缠保真度
F = Tr(ρ_ideal · ρ_exp),直接给出纠缠质量,适合诊断特定噪声通道。
下面用 Qiskit + Aer 构建一个可复现的基准脚本,覆盖三种噪声模型(去极化、热弛豫、ZZ 串扰),并对比"孤立门"与"含串扰门"的 XEB 保真度差异。
基准线路与噪声模型配置
核心思路:固定随机种子生成同一组双比特门序列,分别注入不同噪声模型,用同一套分析函数提取保真度,保证可比性。关键参数:
| 参数 | 取值 | 说明 |
|---|---|---|
| 量子比特数 | 2 | 被测门作用在 q0、q1 |
| XEB 深度 d | 4, 8, 12, 16, 20 | 每层含 1 个双比特门 + 单比特随机门 |
| 每深度采样数 | 2000 shots | 统计比特串分布 |
| 去极化参数 p | 0.01 / 0.02 / 0.05 | 双比特门后注入 |
| 热弛豫 | T1=50μs, T2=70μs, 门时长 200ns | 用 thermal_relaxation_error |
| ZZ 串扰 | ζ = 0.02 / 0.05 rad | RZZ(ζ) 附加在 CX 后 |
关键实现要点:XEB 的交叉熵估计需要"理想分布"与"实测分布"的逐比特串概率对齐;贝尔态层析需要 9 组测量基(XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ),每组 1024 shots。
可运行基准脚本
import numpy as np
from qiskit import QuantumCircuit, transpile
from qiskit_aer import AerSimulator
from qiskit_aer.noise import (NoiseModel, depolarizing_error,
thermal_relaxation_error, coherent_unitary_error)
from qiskit.quantum_info import state_fidelity, DensityMatrix
from scipy.linalg import expm
SEED = 20240517
rng = np.random.default_rng(SEED)
def build_xeb_layer(depth, seed):
"""构造 depth 层随机双比特门 + 单比特随机门线路"""
r = np.random.default_rng(seed)
qc = QuantumCircuit(2, 2)
for _ in range(depth):
# 随机单比特门(用 U3 参数化)
for q in range(2):
qc.u(*r.uniform(0, 2*np.pi, 3), q)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])
return qc
def ideal_probs(depth, seed):
"""无噪声理想分布"""
qc = build_xeb_layer(depth, seed)
qc.remove_final_measurements()
sim = AerSimulator()
qc.save_statevector()
sv = sim.run(transpile(qc, sim)).result().get_statevector()
return np.abs(sv.data)**2
def xeb_fidelity(p_exp, p_ideal):
"""交叉熵保真度估计:F = (sum p_exp*p_ideal) / (sum p_ideal^2) 归一化"""
# 简化版:用 fidelity 近似(教学示例)
return float(np.sum(p_exp * p_ideal) / np.sum(p_ideal**2))
def make_noise(model, p_dep=0.0, t1=50e-6, t2=70e-6, gate_time=200e-9, zz=0.0):
nm = NoiseModel()
if p_dep > 0:
nm.add_all_qubit_quantum_error(depolarizing_error(p_dep, 2), ['cx'])
if t1 and t2:
err = thermal_relaxation_error(t1, t2, gate_time)
nm.add_all_qubit_quantum_error(err.tensor(err), ['cx'])
if zz > 0:
# RZZ(zz) 作为相干误差附加在 CX 后
rzz = expm(-1j * zz/2 * np.kron(np.diag([1,-1]), np.diag([1,-1])))
from qiskit.quantum_info import Operator
nm.add_all_qubit_quantum_error(coherent_unitary_error(Operator(rzz)), ['cx'])
return nm
def run_xeb(depth, noise_model, shots=2000):
qc = build_xeb_layer(depth, SEED)
sim = AerSimulator(noise_model=noise_model)
counts = sim.run(transpile(qc, sim), shots=shots).result().get_counts()
p_exp = np.zeros(4)
for i, bs in enumerate(['00','01','10','11']):
p_exp[i] = counts.get(bs, 0) / shots
p_id = ideal_probs(depth, SEED)
return xeb_fidelity(p_exp, p_id)
# 三种噪声模型对比
dep_model = make_noise('dep', p_dep=0.02)
th_model = make_noise('th', t1=50e-6, t2=70e-6)
zz_model = make_noise('zz', zz=0.05)
for d in [4, 8, 12, 16, 20]:
f_dep = run_xeb(d, dep_model)
f_th = run_xeb(d, th_model)
f_zz = run_xeb(d, zz_model)
print(f"depth={d:2d} depol={f_dep:.4f} thermal={f_th:.4f} ZZ={f_zz:.4f}")
贝尔态层析交叉验证
XEB 给出的是"每周期平均保真度",而贝尔态层析直接测量纠缠态质量。两者应相互印证:若 XEB 估计的每周期保真度为 F_cycle,则深度 d 的 Bell 态保真度约 F_cycle^d(近似)。用 9 组基测量重建密度矩阵:
from qiskit.quantum_info import state_fidelity
from qiskit import QuantumCircuit
def bell_tomography(noise_model, shots=1024):
bases = ['XX','XY','XZ','YX','YY','YZ','ZX','ZY','ZZ']
results = {}
for b in bases:
qc = QuantumCircuit(2, 2)
qc.h(0); qc.cx(0, 1)
# 旋转到对应测量基
for q, axis in zip([0,1], b):
if axis == 'X': qc.h(q)
elif axis == 'Y': qc.sdg(q); qc.h(q)
qc.measure([0,1],[0,1])
sim = AerSimulator(noise_model=noise_model)
counts = sim.run(transpile(qc, sim), shots=shots).result().get_counts()
results[b] = counts
# 重建密度矩阵(简化:用期望值组合)
# 实际实现需 9 组 Pauli 期望值线性组合
return results
# 理想 Bell 态
bell_ideal = DensityMatrix.from_label('00').evolve(
QuantumCircuit(2).compose(QuantumCircuit(2).h(0).cx(0,1)))
print("理想 Bell 态保真度基准:", state_fidelity(bell_ideal, bell_ideal))
教学示例说明:上述脚本在 Aer 模拟器上运行,输出为预期趋势——去极化噪声下 XEB 保真度随深度指数衰减;ZZ 串扰在浅层影响小、深层累积明显;热弛豫在门时长 200ns 下影响相对温和。实际数值取决于模拟器版本与随机种子,需以本地运行结果为准。
串扰影响的判读逻辑
串扰的核心特征是"非马尔可夫性":相邻比特同时驱动时,ZZ 耦合导致相位累积,表现为 XEB 曲线偏离纯指数衰减(出现振荡或斜率变化)。判读方法:
- 对每个深度拟合
F(d) = A · p^d + B,若残差显著大于去极化模型,提示存在相干串扰。 - 对比"仅 q0-q1 驱动"与"q0-q1 + q2 同时驱动"两种配置的 XEB 保真度,差值即为串扰贡献。
- 用贝尔态层析的密度矩阵非对角元衰减速率交叉验证:串扰会加速 off-diagonal 项退相干。
结果判读与通过条件
基准测试的"通过"不是单一数值,而是一致性判据:
- XEB 与层析一致:
|F_bell - F_cycle^d| < 0.05(教学示例阈值),说明两条路径对同一噪声源的估计自洽。 - 噪声模型可区分:去极化与热弛豫的衰减曲线应接近指数;ZZ 串扰应出现可检测的残差偏离(拟合 R² 下降)。
- 串扰可量化:孤立驱动与邻比特同时驱动的 XEB 保真度差值,即为串扰贡献的估计值。
常见陷阱:①XEB 的交叉熵估计对 shots 数敏感,2000 shots 在深度 20 时统计误差可能掩盖串扰信号,建议每深度至少 5000 shots;②贝尔态层析的 9 组基若未做测量误差校正,会系统性低估保真度;③ZZ 串扰的 RZZ 角度需与硬件标定值对齐,教学示例中的 0.05 rad 仅为示意。
快速执行清单
| 步骤 | 操作 | 检查点 |
|---|---|---|
| 1 | 固定随机种子,生成深度 4–20 的 XEB 线路 | 同一 seed 下线路可复现 |
| 2 | 分别注入 depol / thermal / ZZ 噪声模型 | 噪声参数记录在案 |
| 3 | 运行 XEB,拟合 F_cycle(d) | 残差分析识别非指数行为 |
| 4 | 运行贝尔态层析,重建 ρ_exp | 9 组基测量完成 |
| 5 | 交叉验证 F_bell 与 F_cycle^d | 差值 < 0.05 视为自洽 |
| 6 | 对比孤立/邻比特驱动,量化串扰 | 差值即串扰贡献估计 |