Qubit (qiskit_addon_sqd.qubit
)¶
Functions for handling quantum samples.
- solve_qubit(bitstring_matrix, hamiltonian, *, verbose=False, **scipy_kwargs)[source]¶
Find the energies and eigenstates of a Hamiltonian projected into a subspace.
The subspace is defined by a collection of computational basis states which are specified by the bitstrings (rows) in the
bitstring_matrix
.This function calls scipy.sparse.linalg.eigsh for the diagonalization.
- Parameters:
bitstring_matrix (ndarray) – A 2D array of
bool
representations of bit values such that each row represents a single bitstring. This set of bitstrings specifies the subspace into which thehamiltonian
will be projected and diagonalized.hamiltonian (SparsePauliOp) – A Hamiltonian specified as a Pauli operator.
verbose (bool) – Whether to print the stage of the subroutine.
**scipy_kwargs –
Keyword arguments to be passed to scipy.sparse.linalg.eigsh.
- Returns:
1D array with the eigenvalues
2D array with the eigenvectors. Each column represents an eigenvector.
- Raises:
ValueError – Bitstrings (rows) in
bitstring_matrix
must have length <64
.- Return type:
- project_operator_to_subspace(bitstring_matrix, hamiltonian, *, verbose=False)[source]¶
Project a Pauli operator onto a Hilbert subspace defined by the computational basis states (rows) in
bitstring_matrix
.The output sparse matrix,
A
, represents anNxN
matrix s.t.N
is the number of rows inbitstring_matrix
. The rows ofA
represent the input configurations, and the columns represent the connected component associated with the configuration in the corresponding row. The non-zero elements of the matrix represent the complex amplitudes associated with the connected components.Note
The bitstrings in the
bitstring_matrix
must be unique and sorted in ascending order according to their unsigned integer representation. Otherwise the projection will return wrong results. This function does not explicitly check for uniqueness and order because this can be rather time consuming. Seeqiskit_addon_sqd.qubit.sort_and_remove_duplicates()
for a simple way to ensure your bitstring matrix is well-formatted.Note
This function relies on
jax
to efficiently perform some calculations.jax
converts the bit arrays toint64_t
, which means the bit arrays inbitstring_matrix
may not have length greater than63
.- Parameters:
bitstring_matrix (ndarray) – A 2D array of
bool
representations of bit values such that each row represents a single bitstring. This set of bitstrings specifies the subspace into which thehamiltonian
will be projected and diagonalized.hamiltonian (SparsePauliOp) – A Pauli operator to project onto a Hilbert subspace defined by
bitstring_matrix
.verbose (bool) – Whether to print the stage of the subroutine.
- Returns:
A scipy.sparse.coo_matrix representing the operator projected in the subspace. The rows represent the input configurations, and the columns represent the connected component associated with the configuration in the corresponding row. The non-zero elements of the matrix represent the complex amplitudes associated with the pairs of connected components.
- Raises:
ValueError – Bitstrings (rows) in
bitstring_matrix
must have length <64
.- Return type:
spmatrix
- sort_and_remove_duplicates(bitstring_matrix)[source]¶
Sort a bitstring matrix and remove duplicate entries.
The lowest bitstring values will be placed in the lowest-indexed rows.
- matrix_elements_from_pauli(bitstring_matrix, pauli)[source]¶
Find the sparse matrix elements of a Pauli operator in the subspace defined by the bitstrings.
The sparse matrix,
A
, defined by the outputs represents anNxN
matrix s.t.N
is the number of rows inbitstring_matrix
. The rows ofA
represent the input configurations, and the columns represent the connected component associated with the configuration in the corresponding row. The output arrays define the sparse matrix,A
, as follows:A[rows[k], cols[k]] = amplutides[k]
.Note
The bitstrings in the
bitstring_matrix
must be unique and sorted in ascending order according to their unsigned integer representation. Otherwise the projection will return wrong results. This function does not explicitly check for uniqueness and order because this can be rather time consuming. Seeqiskit_addon_sqd.qubit.sort_and_remove_duplicates()
for a simple way to ensure your bitstring matrix is well-formatted.Note
This function relies on
jax
to efficiently perform some calculations.jax
converts the bit arrays toint64_t
, which means the bit arrays inbitstring_matrix
may not have length greater than63
.- Parameters:
bitstring_matrix (ndarray) – A 2D array of
bool
representations of bit values such that each row represents a single bitstring. The bitstrings in the matrix must be sorted according to their unsigned integer representations. Otherwise the projection will return wrong results.pauli (Pauli) – A Pauli operator for which to find connected elements
- Returns:
The complex amplitudes corresponding to the nonzero matrix elements
The row indices corresponding to non-zero matrix elements
The column indices corresponding to non-zero matrix elements
- Raises:
ValueError – Bitstrings (rows) in
bitstring_matrix
must have length <64
.- Return type: