Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# Copyright 2019-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"). You 

4# may not use this file except in compliance with the License. A copy of 

5# the License is located at 

6# 

7# http://aws.amazon.com/apache2.0/ 

8# 

9# or in the "license" file accompanying this file. This file is 

10# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 

11# ANY KIND, either express or implied. See the License for the specific 

12# language governing permissions and limitations under the License. 

13 

14from braket.circuits import Circuit, ResultType 

15 

16 

17def validate_circuit_and_shots(circuit: Circuit, shots: int) -> None: 

18 """ 

19 Validates if circuit and shots are correct before running on a device 

20 

21 Args: 

22 circuit (Circuit): circuit to validate 

23 shots (int): shots to validate 

24 

25 Raises: 

26 ValueError: If no result types specified for circuit and shots=0. 

27 See `braket.circuit.result_types. Or, if `StateVector` or `Amplitude` 

28 are specified as result types when shots > 0. 

29 """ 

30 if not shots and not circuit.result_types: 

31 raise ValueError( 

32 "No result types specified for circuit and shots=0. See `braket.circuit.result_types`" 

33 ) 

34 elif shots and circuit.result_types: 

35 for rt in circuit.result_types: 

36 if isinstance(rt, ResultType.StateVector) or isinstance(rt, ResultType.Amplitude): 

37 raise ValueError("StateVector or Amplitude cannot be specified when shots>0")