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

fix: Add error message for running a circuit without instructions #161

Merged
merged 3 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 5 additions & 3 deletions src/braket/circuits/circuit_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ def validate_circuit_and_shots(circuit: Circuit, shots: int) -> None:
shots (int): shots to validate

Raises:
ValueError: If no result types specified for circuit and `shots=0`.
See `braket.circuit.result_types`. Or, if `StateVector` or `Amplitude`
are specified as result types when `shots > 0`.
ValueError: If circuit has no instructions. Also, if no result types
specified for circuit and `shots=0`. See `braket.circuit.result_types`.
Or, if `StateVector` or `Amplitude` are specified as result types when `shots > 0`.
Comment on lines +26 to +28
Copy link
Member

Choose a reason for hiding this comment

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

Is the check for Sample with shots=0 done somewhere else? I forgot. If it is, does it make sense to move it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's already a check for that in the default simulator and API. I don't think we need to add a duplicate check here.

"""
if not circuit.instructions:
raise ValueError("Circuit must have instructions to run on a device")
if not shots and not circuit.result_types:
raise ValueError(
"No result types specified for circuit and shots=0. See `braket.circuit.result_types`"
Expand Down
10 changes: 10 additions & 0 deletions test/unit_tests/braket/circuits/test_circuit_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
from braket.circuits.circuit_helpers import validate_circuit_and_shots


@pytest.mark.xfail(raises=ValueError)
def test_validate_circuit_and_shots_no_instructions():
validate_circuit_and_shots(Circuit(), 100)


@pytest.mark.xfail(raises=ValueError)
def test_validate_circuit_and_shots_0_no_instructions():
validate_circuit_and_shots(Circuit(), 0)


@pytest.mark.xfail(raises=ValueError)
def test_validate_circuit_and_shots_0_no_results():
validate_circuit_and_shots(Circuit().h(0), 0)
Expand Down