State Vector

State vector representation module.

This module provides:

class graphqomb.statevec.StateVector[source]

Bases: BaseFullStateSimulator

State vector representation.

__init__(state=None, *, copy=None)[source]
property num_qubits: int

Get the number of qubits in the state vector.

Returns:

The number of qubits in the state vector.

Return type:

int

state()[source]

Get the state vector in external qubit order.

Returns:

The state vector as a numpy array in external qubit order.

Return type:

numpy.typing.NDArray[numpy.complex128]

copy()[source]

Create a copy of the state vector.

Returns:

A new StateVector instance with the same state.

Return type:

StateVector

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:

StateVector

Raises:

ValueError – If num_qubits is negative.

static tensor_product(a, b)[source]

Tensor product with other state vector, self ⊗ other.

Parameters:
Returns:

The resulting state vector after tensor product.

Return type:

StateVector

evolve(operator, qubits)[source]

Evolve the state by applying an operator to a subset of qubits.

Parameters:
measure(qubit, meas_basis, result)[source]

Measure a qubit in a given measurement basis.

Parameters:
  • qubit (int) – The qubit to measure.

  • meas_basis (MeasBasis) – The measurement basis to use.

  • result (int) – The measurement result.

add_node(num_qubits)[source]

Add plus state to the end of state vector.

Parameters:

num_qubits (int) – number of qubits to add

entangle(qubit1, qubit2)[source]

Entangle two qubits.

Parameters:
  • qubit1 (int) – first qubit index

  • qubit2 (int) – second qubit index

normalize()[source]

Normalize the state.

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

norm()[source]

Get norm of state vector.

Returns:

norm of state vector

Return type:

float

expectation(operator, qubits)[source]

Calculate expectation value of operator.

Parameters:
Returns:

expectation value

Return type:

float

Raises:

ValueError – if operator is not Hermitian