Unitary
从量子线路提取的幺正算符。结果矩阵
签名
python
Unitary(
qcircuit: QCircuit,
system_type: StateSystemType = StateSystemType.Q2Q1Q0,
)参数
| 参数 | 类型 | 说明 |
|---|---|---|
| qcircuit | QCircuit | 要计算幺正矩阵的量子线路。 |
| system_type | StateSystemType | 量子比特排序约定。Q2Q1Q0 表示对于二进制状态 10,量子比特 1 为 1,量子比特 0 为 0。默认为 Q2Q1Q0。 |
方法
ndarray
python
ndarray() -> numpy.ndarray返回幺正矩阵作为二维 numpy.ndarray。
运算符
相等
python
u_a == u_b -> bool如果两个 Unitary 对象具有相同的内部数据则返回 True。
示例
python
from pyqpanda3.core import QCircuit, H, CNOT
from pyqpanda3.quantum_info import Unitary
# 构建 Bell 线路
qc = QCircuit()
qc << H(0)
qc << CNOT(0, 1)
# 提取幺正矩阵
u = Unitary(qc)
print(u.ndarray())
# [[ 0.707+0.j, 0.707+0.j, 0+0.j, 0+0.j],
# [ 0+0.j, 0+0.j, 0.707+0.j, -0.707+0.j],
# [ 0+0.j, 0+0.j, 0.707+0.j, 0.707+0.j],
# [ 0.707+0.j, -0.707+0.j, 0+0.j, 0+0.j]]