Coverage for src/braket/ir/jaqcd/results.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 enum import Enum
16from braket.ir.jaqcd.shared_models import MultiState, Observable, OptionalMultiTarget
17from pydantic import BaseModel
20class Expectation(OptionalMultiTarget, Observable):
21 """
22 Expectation of specified targets and observable as requested result.
23 If no targets are specified, the observable must only operate on 1 qubit and it
24 will be applied to all qubits in parallel. Otherwise, the number of specified targets
25 must be equivalent to the number of qubits the observable can be applied to.
27 Attributes:
28 type (str): The result type. default = "expectation". (type) is optional.
29 This should be unique among all result types.
30 targets (Optional[List[int]]): The target qubits. This is a list of int >= 0.
31 observable (List[Union[str, List[List[List[float]]]]): A list with at least
32 one item and items are strings matching the observable regex
33 or a two dimensional hermitian matrix with complex entries.
34 Each complex number is represented using a List[float] of size 2, with
35 element[0] being the real part and element[1] imaginary.
36 inf, -inf, and NaN are not allowable inputs for the element.
38 Examples:
39 >>> Expectation(targets=[1], observable=["x"])
40 """
42 class Type(str, Enum):
43 expectation = "expectation"
45 type = Type.expectation
48class Sample(OptionalMultiTarget, Observable):
49 """
50 Sample for specified targets and observable as requested result.
51 If no targets are specified, the observable must only operate on 1 qubit and it
52 will be applied to all qubits in parallel. Otherwise, the number of specified targets
53 must be equivalent to the number of qubits the observable can be applied to.
55 Attributes:
56 type (str): The result type. default = "sample". (type) is optional.
57 This should be unique among all result types.
58 targets (Optional[List[int]]): The target qubits. This is a list of int >= 0.
59 observable (List[Union[str, List[List[List[float]]]]): A list with at least
60 one item and items are strings matching the observable regex
61 or a two dimensional hermitian matrix with complex entries.
62 Each complex number is represented using a List[float] of size 2, with
63 element[0] being the real part and element[1] imaginary.
64 inf, -inf, and NaN are not allowable inputs for the element.
66 Examples:
67 >>> Sample(targets=[1], observable=["x"])
68 """
70 class Type(str, Enum):
71 sample = "sample"
73 type = Type.sample
76class Variance(OptionalMultiTarget, Observable):
77 """
78 Variance of specified targets and observables as requested result.
79 If no targets are specified, the observable must only operate on 1 qubit and it
80 will be applied to all qubits in parallel. Otherwise, the number of specified targets
81 must be equivalent to the number of qubits the observable can be applied to.
83 Attributes:
84 type (str): The result type. default = "variance". (type) is optional.
85 This should be unique among all result types.
86 targets (List[int]): The target qubits. This is a list of int >= 0.
87 observable (List[Union[str, List[List[List[float]]]]): A list with at least
88 one item and items are strings matching the observable regex
89 or a two dimensional hermitian matrix with complex entries.
90 Each complex number is represented using a List[float] of size 2, with
91 element[0] being the real part and element[1] imaginary.
92 inf, -inf, and NaN are not allowable inputs for the element.
94 Examples:
95 >>> Variance(targets=[1], observable=["x"])
96 """
98 class Type(str, Enum):
99 variance = "variance"
101 type = Type.variance
104class StateVector(BaseModel):
105 """
106 The full state vector as requested result.
108 Attributes:
109 type (str): The result type. default = "statevector". (type) is optional.
110 This should be unique among all result types.
112 Examples:
113 >>> StateVector()
114 """
116 class Type(str, Enum):
117 statevector = "statevector"
119 type = Type.statevector
122class Amplitude(MultiState):
123 """
124 Amplitudes of specified states as requested result.
126 Attributes:
127 type (str): The result type. default = "amplitude". (type) is optional.
128 This should be unique among all result types.
129 states (List[string]): Variable length list with with all strings
130 matching the state regex
132 Examples:
133 >>> Amplitude(states=["01", "10"])
134 """
136 class Type(str, Enum):
137 amplitude = "amplitude"
139 type = Type.amplitude
142class Probability(OptionalMultiTarget):
143 """
144 Probability of all states if no targets are specified or the marginal probability
145 of a restricted set of states if only a subset of all qubits are specified as targets
147 Attributes:
148 type (str): The result type. default = "probability". (type) is optional.
149 This should be unique among all result types.
150 targets (Optional[List[int]]): The target qubits. This is a list of int >= 0.
152 Examples:
153 >>> Probability(targets=[1, 2])
154 """
156 class Type(str, Enum):
157 probability = "probability"
159 type = Type.probability