StateVector
表示为
态矢量
构造函数
默认构造函数
python
StateVector()构造
拷贝构造函数
python
StateVector(other: StateVector)作为另一个 StateVector 的拷贝构造 StateVector。
| 参数 | 类型 | 说明 |
|---|---|---|
| other | StateVector | 要拷贝的现有 StateVector。 |
从字典构造
python
StateVector(data: dict[int, complex])从将基态索引映射到复振幅的字典构造态矢量。字典中不存在的索引被设置为零。
| 参数 | 类型 | 说明 |
|---|---|---|
| data | dict[int, complex] | 从基态索引到振幅的映射。 |
从复数数组构造
python
StateVector(data: list[complex])从复振幅的扁平列表(或 numpy 数组)构造态矢量。
| 参数 | 类型 | 说明 |
|---|---|---|
| data | list[complex] | 复振幅的一维数组。 |
从 Eigen 向量构造
python
StateVector(data: numpy.ndarray)从一维复数 numpy 数组(或 Eigen 向量)构造态矢量。
| 参数 | 类型 | 说明 |
|---|---|---|
| data | numpy.ndarray | 复振幅的一维数组。 |
从量子比特数构造
python
StateVector(qbit_total: int)构造 qbit_total 个量子比特的态矢量,初始化为全零态
| 参数 | 类型 | 说明 |
|---|---|---|
| qbit_total | int | 量子比特数。结果矢量的维度为 |
方法
ndarray
python
ndarray() -> numpy.ndarray返回内部态矢量数据作为一维 numpy.ndarray。
purity
python
purity() -> float返回态的纯度
evolve
python
evolve(circuit: QCircuit) -> StateVector在给定量子线路下演化态矢量。返回一个新的 StateVector 包含结果;原始对象不被修改。
| 参数 | 类型 | 说明 |
|---|---|---|
| circuit | QCircuit | 要应用的量子线路。 |
update_by_evolve
python
update_by_evolve(circuit: QCircuit) -> StateVector在给定量子线路下原地演化态矢量,更新内部数据。同时返回结果的 StateVector。
| 参数 | 类型 | 说明 |
|---|---|---|
| circuit | QCircuit | 要应用的量子线路。 |
is_valid
python
is_valid() -> bool检查内部数据是否构成有效的量子态矢量(归一化为单位长度)。
get_density_matrix
python
get_density_matrix() -> DensityMatrix计算对应于此态矢量的密度矩阵
at
python
at(idx: int) -> complex返回指定基态索引处的振幅。
| 参数 | 类型 | 说明 |
|---|---|---|
| idx | int | 基态的索引(从 0 开始)。 |
dim
python
dim() -> int返回态矢量的维度,即
运算符
相等
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()