Skip to content

Commit

Permalink
fix #8992 (#8998) (#9000)
Browse files Browse the repository at this point in the history
(cherry picked from commit be1e697)

Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com>
  • Loading branch information
mergify[bot] and ikkoham committed Oct 26, 2022
1 parent 471e8b5 commit e678199
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __init__(self, data, coeffs=None, *, ignore_pauli_phase=False, copy=True):

pauli_list = PauliList(data.copy() if copy and hasattr(data, "copy") else data)

dtype = coeffs.dtype if isinstance(coeffs, np.ndarray) else complex
dtype = object if isinstance(coeffs, np.ndarray) and coeffs.dtype == object else complex

if coeffs is None:
coeffs = np.ones(pauli_list.size, dtype=dtype)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Fix :meth:`.SparsePauliOp.dot` between operators with real coefficients.
To fix this, the dtype that :class:`SparsePauliOp` can take is restricted to
``np.complex128`` and ``object``.
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,13 @@ def commutes(left: Pauli, right: Pauli) -> bool:
)
)

def test_dot_real(self):
"""Test dot for real coefficiets."""
x = SparsePauliOp("X", np.array([1]))
y = SparsePauliOp("Y", np.array([1]))
iz = SparsePauliOp("Z", 1j)
self.assertEqual(x.dot(y), iz)


if __name__ == "__main__":
unittest.main()

0 comments on commit e678199

Please sign in to comment.