Coverage for src/braket/ir/jaqcd/shared_models.py : 100%

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.
14from typing import Optional, Union
16from pydantic import BaseModel, confloat, conint, conlist, constr
19class SingleTarget(BaseModel):
20 """
21 Single target index.
23 Attributes:
24 target (int): The target index. This is an int >= 0.
26 Examples:
27 >>> SingleTarget(target=0)
28 """
30 target: conint(ge=0)
33class DoubleTarget(BaseModel):
34 """
35 Target indices of length 2.
37 Attributes:
38 targets (List[int]): A list with two items and all items are int >= 0.
40 Examples:
41 >>> DoubleTarget(targets=[0, 1])
42 """
44 targets: conlist(conint(ge=0), min_items=2, max_items=2)
47class MultiTarget(BaseModel):
48 """
49 Variable length target indices.
51 Attributes:
52 targets (List[int]): A list with items that are all int >= 0.
54 Examples:
55 >>> MultiTarget(targets=[0, 1])
56 """
58 targets: conlist(conint(ge=0), min_items=1)
61class OptionalMultiTarget(BaseModel):
62 """
63 Optional variable length target indices
65 Attributes:
66 targets (Optional[List[int]]): A list with items that are all int >= 0.
68 Examples:
69 >>> OptionalMultiTarget(targets=[0, 1])
70 """
72 targets: Optional[conlist(conint(ge=0), min_items=1)]
75class MultiControl(BaseModel):
76 """
77 Variable length control indices.
79 Attributes:
80 controls (List[int]): A list with at least two items and all items are int >= 0.
82 Examples:
83 >>> MultiControl(controls=[0, 1])
84 """
86 controls: conlist(conint(ge=0), min_items=1)
89class DoubleControl(BaseModel):
90 """
91 Control indices of length 2.
93 Attributes:
94 controls (List[int]): A list with two items and all items are int >= 0.
96 Examples:
97 >>> DoubleControl(targets=[0, 1])
98 """
100 controls: conlist(conint(ge=0), min_items=2, max_items=2)
103class SingleControl(BaseModel):
104 """
105 Single control index.
107 Attributes:
108 control (int): The control index. This is an int >= 0.
110 Examples:
111 >>> SingleControl(control=0)
112 """
114 control: conint(ge=0)
117class Angle(BaseModel):
118 """
119 Single angle in radians (floating point).
121 Attributes:
122 angle (float): The angle in radians.
123 inf, -inf, and NaN are not allowable inputs.
125 Examples:
126 >>> Angle(angle=0.15)
127 """
129 angle: confloat(gt=float("-inf"), lt=float("inf"))
132class TwoDimensionalMatrix(BaseModel):
133 """
134 Two dimensional non-empty matrix.
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.
142 Examples:
143 >>> TwoDimensionalMatrix(matrix=[[[0, 0], [1, 0]], [[1, 0], [0, 0]]])
144 """
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 )
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.
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.
168 Examples:
169 >>> Observable(observable=["x"])
170 >>> Observable(observable=[[[0, 0], [1, 0]], [[1, 0], [0, 0]]])
171 """
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 )
188class MultiState(BaseModel):
189 """
190 A list of states in bitstring form.
192 Attributes:
193 states (List[string]): Variable length list with all strings matching the
194 state regex
196 Examples:
197 >>> lMultiState(states=["10", "10"])
198 """
200 states: conlist(constr(regex="^[01]+$", min_length=1), min_items=1)