diff --git a/pennylane_qiskit/qiskit_device_legacy.py b/pennylane_qiskit/qiskit_device_legacy.py index d44a17d7..2ca2ccfc 100644 --- a/pennylane_qiskit/qiskit_device_legacy.py +++ b/pennylane_qiskit/qiskit_device_legacy.py @@ -133,6 +133,11 @@ def __init__(self, wires, provider, backend, shots=1024, **kwargs): self.shots = 1024 + if shots and not isinstance(shots, int): + raise ValueError( + f"Shots needs to be an integer value. Shot vectors are not supported for {self.name}." + ) + self._capabilities["returns_state"] = self._is_state_backend # Perform validation against backend diff --git a/tests/test_qiskit_device.py b/tests/test_qiskit_device.py index 8674301d..5fb512f7 100644 --- a/tests/test_qiskit_device.py +++ b/tests/test_qiskit_device.py @@ -324,3 +324,16 @@ def barrier_func(): res = barrier_func() assert barrier_func.tape.operations[0] == qml.Barrier([0, 1]) assert np.allclose(res, dev.batch_execute([barrier_func.tape]), atol=0) + + +def test_aer_device_shots_value_error(): + """Tests that aer device raises an error when given a shot vector""" + with pytest.raises( + ValueError, match="Shots needs to be an integer value. Shot vectors are not supported" + ): + AerDevice(backend="aer_simulator", wires=1, shots=(1, 1, 1)) + + with pytest.raises( + ValueError, match="Shots needs to be an integer value. Shot vectors are not supported" + ): + AerDevice(backend="aer_simulator", wires=1, shots=[1, 1, 1])