Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug when multiplying SparsePauliOp by np.int64 (bp #5417) #5419

Merged
merged 1 commit into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions qiskit/quantum_info/operators/base_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def __init__(self, input_dims, output_dims):
self._num_qubits = None # number of qubit subsystems if N-qubit operator
self._set_dims(input_dims, output_dims)

# Set higher priority than Numpy array and matrix classes
__array_priority__ = 20

def __call__(self, qargs):
"""Return a clone with qargs set"""
if isinstance(qargs, int):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Fixes bug in :class:`~qiskit.quantum_info.SparsePauliOp` where multiplying
by a certain non Python builtin Numpy scalar types returned incorrect values.
Fixes `#5408 <https://github.com/Qiskit/qiskit-terra/issues/5408>`__
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def test_sub_qargs(self, num_qubits):
value = (spp_op1 - spp_op2(qargs)).to_operator()
self.assertEqual(value, target)

@combine(num_qubits=[1, 2, 3], value=[0, 1, 1j, -3+4.4j])
@combine(num_qubits=[1, 2, 3], value=[0, 1, 1j, -3+4.4j, np.int64(2)])
def test_mul(self, num_qubits, value):
"""Test * method for {num_qubits} qubits and value {value}."""
spp_op = random_unitary(2 ** num_qubits, seed=self.RNG)
Expand Down