Skip to content

Commit a23a4e3

Browse files
committed
Fixed improper testing of shotsdefinition.
1 parent 5b271c1 commit a23a4e3

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

pennylane_scaleway/aer_device.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ class AerDevice(Device):
9898

9999
def __init__(self, wires=None, shots=None, seed=None, **kwargs):
100100

101+
if shots and not isinstance(shots, int):
102+
raise ValueError(
103+
"Only integer number of shots is supported on this device (vectors are not supported either). The set 'shots' value will be ignored."
104+
)
105+
101106
super().__init__(wires=wires, shots=shots)
102107

103108
if isinstance(seed, int):

tests/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
pytest
1+
pytest
2+
pytest-progress

tests/test_aer_device.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import pytest
1616
import os
1717
import numpy as np
18+
19+
from pennylane.exceptions import PennyLaneDeprecationWarning
1820
import pennylane as qml
1921

2022
# Credentials
@@ -187,14 +189,30 @@ def circuit_var():
187189
def test_shot_vector_error(device_kwargs):
188190
"""Tests that a shot vector raises a ValueError."""
189191

190-
with qml.device("scaleway.aer", wires=1, shots=[10, 20], **device_kwargs) as dev:
192+
with pytest.warns(
193+
PennyLaneDeprecationWarning, match="Setting shots on device is deprecated"
194+
):
195+
with qml.device("scaleway.aer", wires=1, shots=10, **device_kwargs) as dev:
191196

192-
@qml.qnode(dev)
193-
def circuit():
194-
qml.Hadamard(wires=0)
195-
return qml.expval(qml.PauliZ(0))
197+
@qml.qnode(dev)
198+
def circuit():
199+
qml.Hadamard(wires=0)
200+
return qml.expval(qml.PauliZ(0))
201+
202+
circuit()
203+
204+
with pytest.raises(
205+
ValueError, match="Only integer number of shots is supported on this device"
206+
):
207+
with qml.device(
208+
"scaleway.aer", wires=1, shots=[10, 20], **device_kwargs
209+
) as dev:
210+
211+
@qml.qnode(dev)
212+
def circuit():
213+
qml.Hadamard(wires=0)
214+
return qml.expval(qml.PauliZ(0))
196215

197-
with pytest.raises(ValueError, match="Invalid shots value"):
198216
circuit()
199217

200218

0 commit comments

Comments
 (0)