diff --git a/src/braket/circuits/circuit_helpers.py b/src/braket/circuits/circuit_helpers.py index 5f493208b..d62ca19a6 100644 --- a/src/braket/circuits/circuit_helpers.py +++ b/src/braket/circuits/circuit_helpers.py @@ -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`. """ + 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`" diff --git a/test/unit_tests/braket/circuits/test_circuit_helpers.py b/test/unit_tests/braket/circuits/test_circuit_helpers.py index d6a91515f..4805ce009 100644 --- a/test/unit_tests/braket/circuits/test_circuit_helpers.py +++ b/test/unit_tests/braket/circuits/test_circuit_helpers.py @@ -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)