Simulator Backend

The base class for simulator backends.

This module provides:

class graphqomb.simulator_backend.QubitIndexManager[source]

Bases: object

Manages the mapping of external qubit indices to internal indices.

__init__(num_qubits)[source]

Initialize the QubitIndexManager with a list of initial indices.

property num_qubits: int

Get the number of qubits managed by this manager.

Returns:

The number of qubits.

Return type:

int

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:

bool

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.

Returns:

A sequence of indices that maps the current order back to the original order.

Return type:

list[int]

external_to_internal(external_qubits: int) int[source]
external_to_internal(external_qubits: Sequence[int]) tuple[int, ...]

Convert external qubit indices to internal indices.

Parameters:

external_qubits (int | collections.abc.Sequence[int]) – A sequence of external qubit indices.

Returns:

A list of internal qubit indices corresponding to the external ones.

Return type:

int | tuple[int, …]

internal_to_external(internal_qubits: int) int[source]
internal_to_external(internal_qubits: Sequence[int]) tuple[int, ...]

Convert internal qubit indices to external indices.

Parameters:

internal_qubits (int | collections.abc.Sequence[int]) – A sequence of internal qubit indices.

Returns:

A list of external qubit indices corresponding to the internal ones.

Return type:

int | tuple[int, …]

class graphqomb.simulator_backend.BaseSimulatorBackend[source]

Bases: ABC

Base 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:

int

abstractmethod evolve(operator, qubits)[source]

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

Parameters:
abstractmethod 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.

class graphqomb.simulator_backend.BaseFullStateSimulator[source]

Bases: BaseSimulatorBackend

Base class for full state simulators.

abstractmethod state()[source]

Get the current state vector.

Returns:

The current state vector.

Return type:

numpy.typing.NDArray[numpy.complex128]

abstractmethod norm()[source]

Get the current state vector norm.

Returns:

The current state vector norm.

Return type:

float

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 entangle(qubit1, qubit2)[source]

Entangle two qubits in the state.

Parameters:
  • qubit1 (int) – The first qubit to entangle.

  • qubit2 (int) – The second qubit to entangle.

abstractmethod reorder(permutation)[source]

Reorder the qubits in the state.

Parameters:

permutation (list[int]) – The permutation to apply.

abstractmethod expectation(operator, qubits)[source]

Calculate the expectation value of an operator.

Parameters:
Returns:

The expectation value of the operator.

Return type:

float