diff --git a/pennylane_qiskit/qiskit_device_legacy.py b/pennylane_qiskit/qiskit_device_legacy.py index dc7c304f..382df063 100644 --- a/pennylane_qiskit/qiskit_device_legacy.py +++ b/pennylane_qiskit/qiskit_device_legacy.py @@ -134,6 +134,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 b832cbcc..51d3ae9e 100644 --- a/tests/test_qiskit_device.py +++ b/tests/test_qiskit_device.py @@ -322,3 +322,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])