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

Add error message for shot vectors for QiskitDevice #576

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions pennylane_qiskit/qiskit_device_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions tests/test_qiskit_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use @pytest.mark.parametrize.

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])
Loading