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 Optional, Union 

15 

16from pydantic import BaseModel, confloat, conint, conlist, constr 

17 

18 

19class SingleTarget(BaseModel): 

20 """ 

21 Single target index. 

22 

23 Attributes: 

24 target (int): The target index. This is an int >= 0. 

25 

26 Examples: 

27 >>> SingleTarget(target=0) 

28 """ 

29 

30 target: conint(ge=0) 

31 

32 

33class DoubleTarget(BaseModel): 

34 """ 

35 Target indices of length 2. 

36 

37 Attributes: 

38 targets (List[int]): A list with two items and all items are int >= 0. 

39 

40 Examples: 

41 >>> DoubleTarget(targets=[0, 1]) 

42 """ 

43 

44 targets: conlist(conint(ge=0), min_items=2, max_items=2) 

45 

46 

47class MultiTarget(BaseModel): 

48 """ 

49 Variable length target indices. 

50 

51 Attributes: 

52 targets (List[int]): A list with items that are all int >= 0. 

53 

54 Examples: 

55 >>> MultiTarget(targets=[0, 1]) 

56 """ 

57 

58 targets: conlist(conint(ge=0), min_items=1) 

59 

60 

61class OptionalMultiTarget(BaseModel): 

62 """ 

63 Optional variable length target indices 

64 

65 Attributes: 

66 targets (Optional[List[int]]): A list with items that are all int >= 0. 

67 

68 Examples: 

69 >>> OptionalMultiTarget(targets=[0, 1]) 

70 """ 

71 

72 targets: Optional[conlist(conint(ge=0), min_items=1)] 

73 

74 

75class MultiControl(BaseModel): 

76 """ 

77 Variable length control indices. 

78 

79 Attributes: 

80 controls (List[int]): A list with at least two items and all items are int >= 0. 

81 

82 Examples: 

83 >>> MultiControl(controls=[0, 1]) 

84 """ 

85 

86 controls: conlist(conint(ge=0), min_items=1) 

87 

88 

89class DoubleControl(BaseModel): 

90 """ 

91 Control indices of length 2. 

92 

93 Attributes: 

94 controls (List[int]): A list with two items and all items are int >= 0. 

95 

96 Examples: 

97 >>> DoubleControl(targets=[0, 1]) 

98 """ 

99 

100 controls: conlist(conint(ge=0), min_items=2, max_items=2) 

101 

102 

103class SingleControl(BaseModel): 

104 """ 

105 Single control index. 

106 

107 Attributes: 

108 control (int): The control index. This is an int >= 0. 

109 

110 Examples: 

111 >>> SingleControl(control=0) 

112 """ 

113 

114 control: conint(ge=0) 

115 

116 

117class Angle(BaseModel): 

118 """ 

119 Single angle in radians (floating point). 

120 

121 Attributes: 

122 angle (float): The angle in radians. 

123 inf, -inf, and NaN are not allowable inputs. 

124 

125 Examples: 

126 >>> Angle(angle=0.15) 

127 """ 

128 

129 angle: confloat(gt=float("-inf"), lt=float("inf")) 

130 

131 

132class TwoDimensionalMatrix(BaseModel): 

133 """ 

134 Two dimensional non-empty matrix. 

135 

136 Attributes: 

137 matrix (List[List[List[float]]]): Two dimensional matrix with complex entries. 

138 Each complex number is represented using a List[float] of size 2, with 

139 element[0] being the real part and element[1] imaginary. 

140 inf, -inf, and NaN are not allowable inputs for the element. 

141 

142 Examples: 

143 >>> TwoDimensionalMatrix(matrix=[[[0, 0], [1, 0]], [[1, 0], [0, 0]]]) 

144 """ 

145 

146 matrix: conlist( 

147 conlist( 

148 conlist(confloat(gt=float("-inf"), lt=float("inf")), min_items=2, max_items=2), 

149 min_items=1, 

150 ), 

151 min_items=1, 

152 ) 

153 

154 

155class Observable(BaseModel): 

156 """ 

157 An observable. If given list is more than one element, this is the tensor product 

158 of each operator in the list. 

159 

160 Attributes: 

161 observable (List[Union[str, List[List[List[float]]]]): A list with at least 

162 one item and items are strings matching the observable regex 

163 or a two dimensional hermitian matrix with complex entries. 

164 Each complex number is represented using a List[float] of size 2, with 

165 element[0] being the real part and element[1] imaginary. 

166 inf, -inf, and NaN are not allowable inputs for the element. 

167 

168 Examples: 

169 >>> Observable(observable=["x"]) 

170 >>> Observable(observable=[[[0, 0], [1, 0]], [[1, 0], [0, 0]]]) 

171 """ 

172 

173 observable: conlist( 

174 Union[ 

175 constr(regex="(x|y|z|h|i)"), 

176 conlist( 

177 conlist( 

178 conlist(confloat(gt=float("-inf"), lt=float("inf")), min_items=2, max_items=2), 

179 min_items=2, 

180 ), 

181 min_items=2, 

182 ), 

183 ], 

184 min_items=1, 

185 ) 

186 

187 

188class MultiState(BaseModel): 

189 """ 

190 A list of states in bitstring form. 

191 

192 Attributes: 

193 states (List[string]): Variable length list with all strings matching the 

194 state regex 

195 

196 Examples: 

197 >>> lMultiState(states=["10", "10"]) 

198 """ 

199 

200 states: conlist(constr(regex="^[01]+$", min_length=1), min_items=1)