From 50c5ee0ffa95ae10e49d61a04fa4bce659874f17 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Fri, 12 Jul 2024 16:07:26 -0400 Subject: [PATCH 1/4] test --- tests/test_qiskit_device.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_qiskit_device.py b/tests/test_qiskit_device.py index 020a7f15..af4652d1 100644 --- a/tests/test_qiskit_device.py +++ b/tests/test_qiskit_device.py @@ -326,3 +326,15 @@ 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]) From 41c90747a75a9a37570b4f76fc7e11a95518f237 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Fri, 12 Jul 2024 16:08:02 -0400 Subject: [PATCH 2/4] fujnctionality --- pennylane_qiskit/qiskit_device.py | 5 +++++ tests/test_qiskit_device.py | 1 + 2 files changed, 6 insertions(+) diff --git a/pennylane_qiskit/qiskit_device.py b/pennylane_qiskit/qiskit_device.py index b03a9692..8f3805b7 100644 --- a/pennylane_qiskit/qiskit_device.py +++ b/pennylane_qiskit/qiskit_device.py @@ -178,6 +178,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 af4652d1..92327226 100644 --- a/tests/test_qiskit_device.py +++ b/tests/test_qiskit_device.py @@ -327,6 +327,7 @@ def 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( From 3b2bfa8451d3522abdb77bf1b1eb4cdd1fd98e9a Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Tue, 30 Jul 2024 10:12:58 -0400 Subject: [PATCH 3/4] merge confs --- pennylane_qiskit/qiskit_device.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pennylane_qiskit/qiskit_device.py b/pennylane_qiskit/qiskit_device.py index 04b3ca97..bfaa0e43 100644 --- a/pennylane_qiskit/qiskit_device.py +++ b/pennylane_qiskit/qiskit_device.py @@ -338,6 +338,7 @@ def __init__( self._service = getattr(backend, "_service", None) self._session = session + kwargs["shots"] = shots 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}." From aa7aa421e2042918819c9b6d27ee32c6643e69a0 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Tue, 30 Jul 2024 10:16:59 -0400 Subject: [PATCH 4/4] merge confs --- pennylane_qiskit/qiskit_device.py | 4 ---- pennylane_qiskit/qiskit_device_legacy.py | 5 +++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pennylane_qiskit/qiskit_device.py b/pennylane_qiskit/qiskit_device.py index bfaa0e43..ae8ae4b2 100644 --- a/pennylane_qiskit/qiskit_device.py +++ b/pennylane_qiskit/qiskit_device.py @@ -339,10 +339,6 @@ def __init__( self._session = session kwargs["shots"] = shots - 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}." - ) # Perform validation against backend available_qubits = ( 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