Simulator Backend¶
The base class for simulator backends.
This module provides:
QubitIndexManager: Manages the mapping of external qubit indices to internal indicesBaseSimulatorBackend: Abstract base class for simulator backends.BaseFullStateSimulator: Abstract base class for full state simulators.
- class graphqomb.simulator_backend.QubitIndexManager[source]¶
Bases:
objectManages the mapping of external qubit indices to internal indices.
- property num_qubits: int¶
Get the number of qubits managed by this manager.
- Returns:
The number of qubits.
- Return type:
- add_qubits(num_qubits)[source]¶
Add a specified number of qubits to the index manager.
- Parameters:
num_qubits (
int) – The number of qubits to add.
- remove_qubit(qubit)[source]¶
Remove specified qubit from the index manager.
- Parameters:
qubit (
int) – The qubit to remove.
- match(order)[source]¶
Check if the current indices match the given order.
- Parameters:
order (
collections.abc.Sequence[int]) – A sequence of indices to compare against the current indices.- Returns:
True if the current indices match the given order, False otherwise.
- Return type:
- reorder(permutation)[source]¶
Reorder the indices based on a given permutation.
if permutation is [2, 0, 1], then # [q0, q1, q2] -> [q1, q2, q0]
- Parameters:
permutation (
collections.abc.Sequence[int]) – A sequence of indices that defines the new order of the indices.- Raises:
ValueError – If the length of the permutation does not match the number of indices.
- inverse_permutation()[source]¶
Get the permutation that would recover the original order of indices.
- external_to_internal(external_qubits: int) int[source]¶
- external_to_internal(external_qubits: Sequence[int]) tuple[int, ...]
Convert external qubit indices to internal indices.
- class graphqomb.simulator_backend.BaseSimulatorBackend[source]¶
Bases:
ABCBase class for simulator backends.
- abstract property num_qubits: int¶
Get the number of qubits in the state.
- Returns:
The number of qubits in the state.
- Return type:
- abstractmethod 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.
- class graphqomb.simulator_backend.BaseFullStateSimulator[source]¶
Bases:
BaseSimulatorBackendBase class for full state simulators.
- abstractmethod state()[source]¶
Get the current state vector.
- Returns:
The current state vector.
- Return type:
- abstractmethod norm()[source]¶
Get the current state vector norm.
- Returns:
The current state vector norm.
- Return type:
- abstractmethod add_node(num_qubits)[source]¶
Add a node to the state.
- Parameters:
num_qubits (
int) – The number of qubits in the new node.
- abstractmethod expectation(operator, qubits)[source]¶
Calculate the expectation value of an operator.
- Parameters:
operator (
numpy.typing.NDArray[numpy.complex128]) – The operator to calculate the expectation value for.qubits (
int|collections.abc.Sequence[int]) – The qubits to apply the operator to.
- Returns:
The expectation value of the operator.
- Return type: