State Vector¶
State vector representation module.
This module provides:
StateVector: State vector representation class.
- class graphqomb.statevec.StateVector[source]¶
Bases:
BaseFullStateSimulatorState vector representation.
- property num_qubits: int¶
Get the number of qubits in the state vector.
- Returns:
The number of qubits in the state vector.
- Return type:
- state()[source]¶
Get the state vector in external qubit order.
- Returns:
The state vector as a numpy array in external qubit order.
- Return type:
- copy()[source]¶
Create a copy of the state vector.
- Returns:
A new
StateVectorinstance with the same state.- Return type:
- static from_num_qubits(num_qubits)[source]¶
Create a state vector in the plus state with given number of qubits.
- Parameters:
num_qubits (
int) – Number of qubits in the state vector.- Returns:
The resulting state vector in the plus state.
- Return type:
- Raises:
ValueError – If num_qubits is negative.
- static tensor_product(a, b)[source]¶
Tensor product with other state vector, self ⊗ other.
- Parameters:
a (
StateVector) – first state vectorb (
StateVector) – second state vector
- Returns:
The resulting state vector after tensor product.
- Return type:
- evolve(operator, qubits)[source]¶
Evolve the state by applying an operator to a subset of qubits.
- Parameters:
operator (
numpy.typing.NDArray[numpy.complex128]) – The operator to apply.qubits (
int|collections.abc.Sequence[int]) – The qubits to apply the operator to.
- add_node(num_qubits)[source]¶
Add plus state to the end of state vector.
- Parameters:
num_qubits (
int) – number of qubits to add
- reorder(permutation)[source]¶
Permute qubits.
if permutation is [2, 0, 1], then # [q0, q1, q2] -> [q1, q2, q0]
- Parameters:
permutation (
collections.abc.Sequence[int]) – permutation list
- expectation(operator, qubits)[source]¶
Calculate expectation value of operator.
- Parameters:
operator (
numpy.typing.NDArray[numpy.complex128]) – Hermitian operator matrixqubits (
int|collections.abc.Sequence[int]) – target qubits
- Returns:
expectation value
- Return type:
- Raises:
ValueError – if operator is not Hermitian