噪声 -- NoiseModel, QuantumError, NoiseOpType
pyqpanda3 中噪声建模的 API 参考。噪声框架通过在量子操作上应用错误信道来模拟真实的量子硬件。
NoiseModel
管理模拟期间应用的量子错误和读出错误的集合。
签名
python
class NoiseModel:
def __init__() -> None方法
NoiseModel.is_enabled
python
is_enabled() -> bool检查噪声模型是否包含任何错误。
NoiseModel.add_read_out_error
python
add_read_out_error(probs: list[list[float]], qubit: int) -> None| 参数 | 类型 | 说明 |
|---|---|---|
| probs | list[list[float]] | 读出错误结果的概率 |
| qubit | int | 应用读出错误的量子比特索引 |
NoiseModel.add_all_qubit_read_out_error
python
add_all_qubit_read_out_error(probs: list[list[float]]) -> None| 参数 | 类型 | 说明 |
|---|---|---|
| probs | list[list[float]] | 读出错误结果的概率 |
NoiseModel.add_quantum_error(指定量子比特)
python
add_quantum_error(error: QuantumError, gate_type: GateType, qubits: list[list[int]]) -> None
add_quantum_error(error: QuantumError, gate_types: list[GateType], qubits: list[list[int]]) -> None| 参数 | 类型 | 说明 |
|---|---|---|
| error | QuantumError | 要添加的量子错误 |
| gate_type(s) | GateType 或 list[GateType] | 应用错误的门类型 |
| qubits | list[list[int]] | 应用错误的量子比特索引集合 |
NoiseModel.add_all_qubit_quantum_error
python
add_all_qubit_quantum_error(error: QuantumError, gate_type: GateType) -> None
add_all_qubit_quantum_error(error: QuantumError, gate_types: list[GateType]) -> None| 参数 | 类型 | 说明 |
|---|---|---|
| error | QuantumError | 要添加的量子错误 |
| gate_type(s) | GateType 或 list[GateType] | 应用错误的门类型 |
示例
python
from pyqpanda3.core import (
NoiseModel, QuantumError, GateType,
pauli_x_error, depolarizing_error,
CPUQVM, QProg, H, CNOT, measure
)
# 创建噪声模型
model = NoiseModel()
# 向所有 H 门添加单量子比特去极化噪声
model.add_all_qubit_quantum_error(depolarizing_error(0.01), GateType.H)
# 向所有 CNOT 门添加双量子比特泡利-X 噪声
model.add_all_qubit_quantum_error(pauli_x_error(0.02), GateType.CNOT)
# 含噪声运行
qvm = CPUQVM()
prog = QProg()
prog << H(0) << CNOT(0, 1) << measure(0, 0) << measure(1, 1)
qvm.run(prog, 1000, model)
print(qvm.result().get_counts())QuantumError
表示量子错误信道,可以通过 Kraus 矩阵或泡利错误概率指定。
签名
python
class QuantumError:
def __init__() -> None
def __init__(kraus_matrices: list[numpy.ndarray]) -> None
def __init__(pauli_probs: dict[str, float]) -> None| 参数 | 类型 | 说明 |
|---|---|---|
| kraus_matrices | list[numpy.ndarray] | Kraus 矩阵列表 |
| pauli_probs | dict[str, float] | 泡利错误标签和概率(例如 {"X": 0.01}) |
方法
QuantumError.tensor
python
tensor(quantum_error: QuantumError) -> QuantumError| 参数 | 类型 | 说明 |
|---|---|---|
| quantum_error | QuantumError | 要进行张量积操作的量子错误 |
与另一个量子错误进行张量积操作。
QuantumError.expand
python
expand(quantum_error: QuantumError) -> QuantumError| 参数 | 类型 | 说明 |
|---|---|---|
| quantum_error | QuantumError | 要扩展的量子错误 |
将错误扩展到更大的量子比特系统。
QuantumError.compose
python
compose(quantum_error: QuantumError) -> QuantumError| 参数 | 类型 | 说明 |
|---|---|---|
| quantum_error | QuantumError | 要组合的量子错误 |
将错误与另一个量子错误组合。
QuantumError.qubit_num
python
qubit_num() -> int错误影响的量子比特数。
QuantumError.error_type
python
error_type() -> NoiseOpType错误表示的类型(Kraus 矩阵或噪声线路)。
QuantumError.error_circuit
python
error_circuit(qubits: list[int]) -> QCircuit| 参数 | 类型 | 说明 |
|---|---|---|
| qubits | list[int] | 应用错误线路的量子比特索引 |
错误的线路表示。
QuantumError.error_karus
python
error_karus(qubits: list[int]) -> Karus| 参数 | 类型 | 说明 |
|---|---|---|
| qubits | list[int] | 获取 Kraus 矩阵的量子比特索引 |
错误的 Kraus 矩阵表示。
NoiseOpType
噪声操作表示类型的枚举。
| 值 | 说明 |
|---|---|
KARUS_MATRIICES | 通过 Kraus 矩阵表示的错误 |
NOISE | 通过噪声线路表示的错误 |
错误工厂函数
pauli_x_error
python
pauli_x_error(prob: float) -> QuantumError| 参数 | 类型 | 说明 |
|---|---|---|
| prob | float | 泡利-X 错误的概率 |
创建单量子比特泡利-X(比特翻转)错误信道。以概率
pauli_y_error
python
pauli_y_error(prob: float) -> QuantumError创建泡利-Y(比特相位翻转)错误信道。
pauli_z_error
python
pauli_z_error(prob: float) -> QuantumError创建泡利-Z(相位翻转)错误信道。
depolarizing_error
python
depolarizing_error(prob: float) -> QuantumError创建去极化错误信道。以概率
amplitude_damping_error
python
amplitude_damping_error(prob: float) -> QuantumError创建振幅阻尼(T1 弛豫)错误信道,模拟能量耗散。
其中
phase_damping_error
python
phase_damping_error(prob: float) -> QuantumError创建相位阻尼(T2 去相位)错误信道,模拟相位相干性的损失。
decoherence_error
python
decoherence_error(T1: float, T2: float, time_param: float) -> QuantumError| 参数 | 类型 | 说明 |
|---|---|---|
| T1 | float | T1(振幅阻尼)弛豫时间 |
| T2 | float | T2(相位阻尼)去相位时间 |
| time_param | float | 门操作时间 |
创建组合退相干错误,同时模拟 T1(振幅阻尼)和 T2(相位阻尼)过程。