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 typing import Sequence 

15 

16from braket.circuits.gate import Gate 

17 

18 

19class AngledGate(Gate): 

20 """ 

21 Class `AngledGate` represents a quantum gate that operates on N qubits and an angle. 

22 """ 

23 

24 def __init__(self, angle: float, qubit_count: int, ascii_symbols: Sequence[str]): 

25 """ 

26 Args: 

27 angle (float): The angle of the gate in radians. 

28 qubit_count (int): The number of qubits that this gate interacts with. 

29 ascii_symbols (Sequence[str]): ASCII string symbols for the gate. These are used when 

30 printing a diagram of a circuit. The length must be the same as `qubit_count`, and 

31 index ordering is expected to correlate with the target ordering on the instruction. 

32 For instance, if a CNOT instruction has the control qubit on the first index and 

33 target qubit on the second index, the ASCII symbols should have `["C", "X"]` to 

34 correlate a symbol with that index. 

35 

36 Raises: 

37 ValueError: If the `qubit_count` is less than 1, `ascii_symbols` are `None`, or 

38 `ascii_symbols` length != `qubit_count`, or `angle` is`None` 

39 """ 

40 super().__init__(qubit_count=qubit_count, ascii_symbols=ascii_symbols) 

41 if angle is None: 

42 raise ValueError(f"angle must not be None") 

43 self._angle = angle 

44 

45 @property 

46 def angle(self) -> float: 

47 """ 

48 Returns the angle for the gate 

49 

50 Returns: 

51 angle (float): The angle of the gate in radians 

52 """ 

53 return self._angle 

54 

55 def __repr__(self): 

56 return f"{self.name}('angle': {self.angle}, 'qubit_count': {self.qubit_count})"