diff --git a/src/braket/circuits/circuit_helpers.py b/src/braket/circuits/circuit_helpers.py index 2a9a276d8..f0e3f3144 100644 --- a/src/braket/circuits/circuit_helpers.py +++ b/src/braket/circuits/circuit_helpers.py @@ -12,7 +12,6 @@ # language governing permissions and limitations under the License. from braket.circuits import Circuit, ResultType -from braket.circuits.gates import GPhase def validate_circuit_and_shots(circuit: Circuit, shots: int) -> None: @@ -29,10 +28,10 @@ def validate_circuit_and_shots(circuit: Circuit, shots: int) -> None: if circuit has observables that cannot be simultaneously measured and `shots>0`; 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 all(isinstance(inst.operator, GPhase) and not inst.control for inst in circuit.instructions): - raise ValueError("Circuit must have at least one non-GPhase gate to run on a device") + if not circuit.instructions or all( + not (inst.target or inst.control) for inst in circuit.instructions + ): + raise ValueError("Circuit must have at least one non-zero-qubit gate 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.circuits.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 ed9c6b8b3..8960325cb 100644 --- a/test/unit_tests/braket/circuits/test_circuit_helpers.py +++ b/test/unit_tests/braket/circuits/test_circuit_helpers.py @@ -18,13 +18,15 @@ def test_validate_circuit_and_shots_no_instructions(): - with pytest.raises(ValueError, match="Circuit must have instructions to run on a device"): + with pytest.raises( + ValueError, match="Circuit must have at least one non-zero-qubit gate to run on a device" + ): validate_circuit_and_shots(Circuit(), 100) def test_validate_circuit_and_shots_only_gphase(): with pytest.raises( - ValueError, match="Circuit must have at least one non-GPhase gate to run on a device" + ValueError, match="Circuit must have at least one non-zero-qubit gate to run on a device" ): validate_circuit_and_shots(Circuit().gphase(0.15), 100) @@ -34,7 +36,9 @@ def test_validate_circuit_and_shots_ctrl_gphase(): def test_validate_circuit_and_shots_0_no_instructions(): - with pytest.raises(ValueError, match="Circuit must have instructions to run on a device"): + with pytest.raises( + ValueError, match="Circuit must have at least one non-zero-qubit gate to run on a device" + ): validate_circuit_and_shots(Circuit(), 0)