A quantum state.
cirq.QuantumState(
data: np.ndarray,
qid_shape: (tuple[int, ...] | None) = None,
*,
dtype: (DTypeLike | None) = None,
validate: bool = True,
atol: float = 1e-07
) -> None
Can be a state vector, a state tensor, or a density matrix.
Raises | |
---|---|
ValueError
|
The qid shape was not specified and could not be inferred. |
ValueError
|
Invalid quantum state. |
Attributes | |
---|---|
data
|
The data underlying the quantum state. |
dtype
|
The data type of the quantum state. |
qid_shape
|
The qid shape of the quantum state. |
Methods
density_matrix
density_matrix() -> np.ndarray
Return the density matrix of this state.
A density matrix stores the entries of a density matrix as a matrix (a two-dimensional array).
state_tensor
state_tensor() -> (np.ndarray | None)
Return the state tensor of this state.
A state tensor stores the amplitudes of a pure state as an array with shape equal to the qid shape of the state. If the state is a density matrix, this method returns None.
state_vector
state_vector() -> (np.ndarray | None)
Return the state vector of this state.
A state vector stores the amplitudes of a pure state as a one-dimensional array. If the state is a density matrix, this method returns None.
state_vector_or_density_matrix
state_vector_or_density_matrix() -> np.ndarray
Return the state vector or density matrix of this state.
If the state is a denity matrix, return the density matrix. Otherwise, return the state vector.
validate
validate(
*, dtype: (DTypeLike | None) = None, atol=1e-07
) -> None
Check if this quantum state is valid.
Args | |
---|---|
dtype
|
The expected data type of the quantum state. |
atol
|
Absolute numerical tolerance to use for validation. |
Raises | |
---|---|
ValueError
|
Invalid quantum state. |