Skip to content

枚举 — GateType, OpType, PIC_TYPE

pyqpanda3 核心枚举类型的 API 参考。

GateType

所有量子门类型的枚举。用于 QGate.gate_type()、噪声模型配置和转译。

说明
GATE_NOP无操作(恒等占位符)
GATE_UNDEFINED未定义门类型
I恒等门
X泡利-X(NOT)门
Y泡利-Y 门
Z泡利-Z 门
X1SX 门(X
Y1Y1 门(Y
Z1Z1 门(Z
HHadamard 门
TT 门(π/8 门)
SS 门(相位门)
P参数化相位门
RX绕 X 轴旋转
RY绕 Y 轴旋转
RZ绕 Z 轴旋转
RPHIR-Phi 门
U1U1 门(单参数)
U2U2 门(双参数)
U3U3 门(三参数)
U4U4 门(四参数)
CU受控 U 门
CNOT受控非门
CZ受控 Z 门
CP受控相位门
CRX受控 RX 门
CRY受控 RY 门
CRZ受控 RZ 门
RYYYY 旋转门
RXXXX 旋转门
RZZZZ 旋转门
RZXZX 旋转门
ISWAPiSWAP 门
SQISWAP平方根 iSWAP 门
SWAPSWAP 门
IDLEIDLE(无操作)门
ECHOEcho 门
ORACLEOracle(用户自定义幺正)门
TOFFOLIToffoli(CCNOT)门
BARRIER屏障操作
MSMolmer-Sorensen 门

示例

python
from pyqpanda3.core import H, GateType

gate = H(0)
print(gate.gate_type())  # GateType.H

OpType

量子程序中操作类型的枚举。

说明
Gate量子门操作
Measure测量操作

示例

python
from pyqpanda3.core import H, OpType

gate = H(0)
op = gate  # Operation with m_operation_type == OpType.Gate

PIC_TYPE

线路可视化输出格式的枚举。

注意: GateMeasurepyqpanda3.core.__init__ 中导出的别名:

  • Gate = OpType.Gate
  • Measure = OpType.Measure

检查操作类型时可以使用这些简写别名。

说明
TEXTASCII 文本可视化
LATEXLaTeX 源码线路图

示例

python
from pyqpanda3.core import draw_qprog, QProg, H, CNOT, PIC_TYPE

prog = QProg()
prog << H(0) << CNOT(0, 1)

# 文本可视化
text_output = draw_qprog(prog, PIC_TYPE.TEXT)
print(text_output)

# LaTeX 可视化
latex_output = draw_qprog(prog, PIC_TYPE.LATEX)

另见


set_print_options

配置量子线路和程序文本输出的全局打印选项。影响线路图在打印或转换为字符串时的渲染方式。

签名

python
set_print_options(precision: int = 8, param_show: int = True, linewidth: int = 100) -> None

参数

参数类型默认值说明
precisionint8输出中参数值的浮点精度
param_showintTrue是否在线路输出中显示门参数(TrueFalse
linewidthint100每行最大字符数

示例

python
from pyqpanda3.core import set_print_options, QCircuit, H, RX

# 设置紧凑输出,4位精度
set_print_options(precision=4, linewidth=60)

circ = QCircuit()
circ << H(0) << RX(1, 0.123456789)
print(circ)

Released under the MIT License.