qiskit_addon_sqd.qubit.matrix_elements_from_pauli¶
- matrix_elements_from_pauli(bitstring_matrix, pauli)[source]¶
Find the matrix elements of a Pauli operator in the subspace defined by the bitstrings.
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.
- Returns:
A 1D array corresponding to the nonzero matrix elements A 1D array corresponding to the row indices of the elements A 1D array corresponding to the column indices of the elements
- Raises:
ValueError – Bitstrings (rows) in
bitstring_matrix
must have length <64
.- Return type: