Skip to content

StateVector

表示为 2n 维复列向量的纯量子态,其中 n 是量子比特数。每个元素对应一个计算基态的概率振幅。

态矢量 |ψ 必须满足归一化条件:

ψ|ψ=i|ψi|2=1

构造函数

默认构造函数

python
StateVector()

构造 |0 态的单量子比特系统的态矢量:[1+0j,0+0j]

拷贝构造函数

python
StateVector(other: StateVector)

作为另一个 StateVector 的拷贝构造 StateVector

参数类型说明
otherStateVector要拷贝的现有 StateVector

从字典构造

python
StateVector(data: dict[int, complex])

从将基态索引映射到复振幅的字典构造态矢量。字典中不存在的索引被设置为零。

参数类型说明
datadict[int, complex]从基态索引到振幅的映射。

从复数数组构造

python
StateVector(data: list[complex])

从复振幅的扁平列表(或 numpy 数组)构造态矢量。

参数类型说明
datalist[complex]复振幅的一维数组。

从 Eigen 向量构造

python
StateVector(data: numpy.ndarray)

从一维复数 numpy 数组(或 Eigen 向量)构造态矢量。

参数类型说明
datanumpy.ndarray复振幅的一维数组。

从量子比特数构造

python
StateVector(qbit_total: int)

构造 qbit_total 个量子比特的态矢量,初始化为全零态 |0n

参数类型说明
qbit_totalint量子比特数。结果矢量的维度为 2qbit_total

方法

ndarray

python
ndarray() -> numpy.ndarray

返回内部态矢量数据作为一维 numpy.ndarray

purity

python
purity() -> float

返回态的纯度 Tr(ρ2)。对于由态矢量表示的纯态,纯度始终为 1.0。

evolve

python
evolve(circuit: QCircuit) -> StateVector

在给定量子线路下演化态矢量。返回一个StateVector 包含结果;原始对象不被修改。

参数类型说明
circuitQCircuit要应用的量子线路。

update_by_evolve

python
update_by_evolve(circuit: QCircuit) -> StateVector

在给定量子线路下原地演化态矢量,更新内部数据。同时返回结果的 StateVector

参数类型说明
circuitQCircuit要应用的量子线路。

is_valid

python
is_valid() -> bool

检查内部数据是否构成有效的量子态矢量(归一化为单位长度)。

get_density_matrix

python
get_density_matrix() -> DensityMatrix

计算对应于此态矢量的密度矩阵 ρ=|ψψ|

at

python
at(idx: int) -> complex

返回指定基态索引处的振幅。

参数类型说明
idxint基态的索引(从 0 开始)。

dim

python
dim() -> int

返回态矢量的维度,即 n 个量子比特的 2n

运算符

相等

python
sv_a == sv_b -> bool

如果两个 StateVector 对象具有相同的内部数据则返回 True

示例

python
import numpy as np
from pyqpanda3.quantum_info import StateVector

# 从列表构造(Bell 态 |00> + |11>)
sv = StateVector([1/np.sqrt(2), 0, 0, 1/np.sqrt(2)])

print(sv.dim())       # 4
print(sv.is_valid())  # True
print(sv.purity())    # 1.0

# 访问振幅
amp = sv.at(3)  # (0.7071...+0j)

# 转换为密度矩阵
dm = sv.get_density_matrix()

# 获取 numpy 数组
arr = sv.ndarray()

另见

Released under the MIT License.