Skip to content

Commit

Permalink
add dtype parameter to PauliSumOp.to_list
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsung committed Oct 13, 2022
1 parent af82b4d commit 04ad868
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion qiskit/opflow/primitive_ops/pauli_sum_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ def from_list(
cls,
pauli_list: List[Tuple[str, complex]],
coeff: Union[complex, ParameterExpression] = 1.0,
dtype: type = complex,
) -> "PauliSumOp":
"""Construct from a pauli_list with the form [(pauli_str, coeffs)]
Expand All @@ -443,7 +444,7 @@ def from_list(
Returns:
The PauliSumOp constructed from the pauli_list.
"""
return cls(SparsePauliOp.from_list(pauli_list), coeff=coeff)
return cls(SparsePauliOp.from_list(pauli_list, dtype=dtype), coeff=coeff)

def is_zero(self) -> bool:
"""
Expand Down
5 changes: 5 additions & 0 deletions test/python/opflow/test_pauli_sum_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ def test_from_list(self):
)
self.assertEqual(target, expected)

a = Parameter("a")
target = PauliSumOp.from_list([("X", 0.5 * a), ("Y", -0.5j * a)], dtype=object)
expected = PauliSumOp(SparsePauliOp.from_list([("X", 0.5 * a), ("Y", -0.5j * a)], dtype=object)
self.assertEqual(target, expected)

def test_matrix_iter(self):
"""Test PauliSumOp dense matrix_iter method."""
labels = ["III", "IXI", "IYY", "YIZ", "XYZ", "III"]
Expand Down

0 comments on commit 04ad868

Please sign in to comment.