随机线路生成
随机线路生成和量子基准测试工具的 API 参考。
random_qcircuit
生成具有指定量子比特、深度和门类型的随机量子线路。
签名
python
random_qcircuit(qubits: list[int], depth: int, gate_type: list[str]) -> QCircuit参数
| 参数 | 类型 | 说明 |
|---|---|---|
| qubits | list[int] | 线路中包含的量子比特索引列表 |
| depth | int | 线路的深度(门层数) |
| gate_type | list[str] | 用于生成的门类型字符串列表,例如 ["H", "CNOT"] |
返回
QCircuit — 随机生成的量子线路。
示例
python
from pyqpanda3.core import random_qcircuit
# 在量子比特 [0, 1, 2] 上生成一个深度为 5、使用 H 和 CNOT 门的随机线路
circ = random_qcircuit([0, 1, 2], 5, ["H", "CNOT"])
print(f"Circuit depth: {circ.depth()}")
print(f"Gate count: {circ.count_ops()}")QV — 量子体积基准测试
生成给定配置的量子体积(QV, Quantum Volume)基准测试线路。
签名
python
QV(num_qubit: int, depth: int, seed: int) -> QCircuit参数
| 参数 | 类型 | 说明 |
|---|---|---|
| num_qubit | int | QV 测试的量子比特数 |
| depth | int | 线路的深度(层数) |
| seed | int | 用于可重复性的随机种子 |
返回
QCircuit — 量子体积基准测试线路。
示例
python
from pyqpanda3.core import QV
# 计算 4 量子比特、深度 4 线路的量子体积
qv = QV(num_qubit=4, depth=4, seed=42)
print(f"Quantum Volume: {qv}")数学背景
量子体积是一个单一数值指标,用于衡量量子处理器的整体能力。它考虑了量子比特数、门保真度、连接性和软件性能。QV 协议运行宽度为
其中
direct_twirl
对量子程序执行直接旋转(随机编译),将其分解为随机泡利帧序列。
签名
python
direct_twirl(
input_circ: QProg,
twirled_gate: str = "CNOT",
seed: int = 0
) -> QProg参数
| 参数 | 类型 | 说明 |
|---|---|---|
| input_circ | QProg | 要旋转的输入量子程序 |
| twirled_gate | str | 用于旋转的门类型(默认 "CNOT")。支持:"CNOT"、"CZ" |
| seed | int | 随机种子(默认 0) |
返回
QProg — 旋转后的量子程序。
示例
python
from pyqpanda3.core import H, CNOT, direct_twirl, QProg
# 构建简单程序
prog = QProg()
prog << H(0) << CNOT(0, 1)
# 应用直接旋转
twirled = direct_twirl(prog, "CNOT", 42)
print(f"Original gates: {prog.count_ops()}")
print(f"Twirled gates: {twirled.count_ops()}")数学背景
旋转通过用随机泡利算符共轭将一般量子信道转换为泡利信道。对于信道
这简化了错误表征并支持错误缓解技术。