Skip to content

Commit

Permalink
Use XZ logic to specify Pauli terms in qubit module (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb-johnson authored Sep 25, 2024
1 parent 799346f commit 7791689
Showing 1 changed file with 3 additions and 42 deletions.
45 changes: 3 additions & 42 deletions qiskit_addon_sqd/qubit.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ def matrix_elements_from_pauli(
d, n_qubits = bitstring_matrix.shape
row_array = np.arange(d)

diag, sign, imag = _pauli_to_bool(pauli.to_label()[::-1])
diag = np.logical_not(pauli.x)
sign = pauli.z
imag = np.logical_and(pauli.x, pauli.z)

int_array_rows = _int_conversion_from_bts_matrix_vmap(bitstring_matrix)

Expand All @@ -224,47 +226,6 @@ def matrix_elements_from_pauli(
return matrix_elements, row_array, col_array


def _pauli_to_bool(pauli_str: str) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
"""
Transform sequences of Pauli strings into arrays.
A Pauli operator will be transformed into 3 arrays which represent
the diagonal terms of the Pauli operator.
Args:
pauli_str: A Pauli string such that index ``0`` corresponds to qubit ``0``.
Returns:
A 3-tuple:
- A mask signifying the diagonal Pauli terms (I, Z).
- A mask signifying whether there is a change in sign between the two rows
of the Pauli matrix (Y, Z).
- A mask signifying whether the Pauli matrix elements are purely imaginary.
"""
diag = []
sign = []
imag = []
for p in pauli_str:
if p == "I":
diag.append(True)
sign.append(False)
imag.append(False)
if p == "X":
diag.append(False)
sign.append(False)
imag.append(False)
if p == "Y":
diag.append(False)
sign.append(True)
imag.append(True)
if p == "Z":
diag.append(True)
sign.append(True)
imag.append(False)

return np.array(diag), np.array(sign), np.array(imag)


def _connected_elements_and_amplitudes_bool(
bitstring_matrix: np.ndarray, diag: np.ndarray, sign: np.ndarray, imag: np.ndarray
) -> tuple[NDArray[np.bool_], Array]:
Expand Down

0 comments on commit 7791689

Please sign in to comment.