StateVector
A pure quantum state represented as a complex column vector of dimension
The state vector
Constructors
Default constructor
StateVector()Constructs a state vector for a single-qubit system in the
Copy constructor
StateVector(other: StateVector)Construct a StateVector as a copy of another StateVector.
| Parameter | Type | Description |
|---|---|---|
| other | StateVector | An existing StateVector to copy. |
From a dictionary
StateVector(data: dict[int, complex])Construct a state vector from a dictionary mapping basis-state indices to complex amplitudes. Indices not present in the dictionary are set to zero.
| Parameter | Type | Description |
|---|---|---|
| data | dict[int, complex] | Mapping from basis-state index to amplitude. |
From a complex array
StateVector(data: list[complex])Construct a state vector from a flat list (or numpy array) of complex amplitudes.
| Parameter | Type | Description |
|---|---|---|
| data | list[complex] | A 1-D array of complex amplitudes. |
From an Eigen vector
StateVector(data: numpy.ndarray)Construct a state vector from a 1-D complex numpy array (or Eigen vector).
| Parameter | Type | Description |
|---|---|---|
| data | numpy.ndarray | A 1-D array of complex amplitudes. |
From qubit count
StateVector(qbit_total: int)Construct a state vector for qbit_total qubits initialized to the all-zeros state
| Parameter | Type | Description |
|---|---|---|
| qbit_total | int | The number of qubits. The resulting vector has dimension |
Methods
ndarray
ndarray() -> numpy.ndarrayReturn the internal state-vector data as a 1-D numpy.ndarray.
purity
purity() -> floatReturn the purity
evolve
evolve(circuit: QCircuit) -> StateVectorEvolve the state vector under the given quantum circuit. Returns a new StateVector with the result; the original object is not modified.
| Parameter | Type | Description |
|---|---|---|
| circuit | QCircuit | The quantum circuit to apply. |
update_by_evolve
update_by_evolve(circuit: QCircuit) -> StateVectorEvolve the state vector under the given quantum circuit in place, updating the internal data. Also returns the resulting StateVector.
| Parameter | Type | Description |
|---|---|---|
| circuit | QCircuit | The quantum circuit to apply. |
is_valid
is_valid() -> boolCheck whether the internal data constitutes a valid quantum state vector (normalized to unit length).
get_density_matrix
get_density_matrix() -> DensityMatrixCompute the density matrix
at
at(idx: int) -> complexReturn the amplitude at the specified basis-state index.
| Parameter | Type | Description |
|---|---|---|
| idx | int | The index of the basis state (0-based). |
dim
dim() -> intReturn the dimension of the state vector, i.e.,
Operators
Equality
sv_a == sv_b -> boolReturn True if the two StateVector objects have identical internal data.
Examples
import numpy as np
from pyqpanda3.quantum_info import StateVector
# Construct from a list (Bell state |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
# Access an amplitude
amp = sv.at(3) # (0.7071...+0j)
# Convert to density matrix
dm = sv.get_density_matrix()
# Get numpy array
arr = sv.ndarray()