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