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 pydantic import BaseModel
18from braket.ir.jaqcd.shared_models import MultiState, Observable, OptionalMultiTarget
21class Expectation(OptionalMultiTarget, Observable):
22 """
23 Expectation of specified targets and observable as requested result.
24 If no targets are specified, the observable must only operate on 1 qubit and it
25 will be applied to all qubits in parallel. Otherwise, the number of specified targets
26 must be equivalent to the number of qubits the observable can be applied to.
28 Attributes:
29 type (str): The result type. default = "expectation". (type) is optional.
30 This should be unique among all result types.
31 targets (Optional[List[int]]): The target qubits. This is a list of int >= 0.
32 observable (List[Union[str, List[List[List[float]]]]): A list with at least
33 one item and items are strings matching the observable regex
34 or a two dimensional hermitian matrix with complex entries.
35 Each complex number is represented using a List[float] of size 2, with
36 element[0] being the real part and element[1] imaginary.
37 inf, -inf, and NaN are not allowable inputs for the element.
39 Examples:
40 >>> Expectation(targets=[1], observable=["x"])
41 """
43 class Type(str, Enum):
44 expectation = "expectation"
46 type = Type.expectation
49class Sample(OptionalMultiTarget, Observable):
50 """
51 Sample for specified targets and observable as requested result.
52 If no targets are specified, the observable must only operate on 1 qubit and it
53 will be applied to all qubits in parallel. Otherwise, the number of specified targets
54 must be equivalent to the number of qubits the observable can be applied to.
56 Attributes:
57 type (str): The result type. default = "sample". (type) is optional.
58 This should be unique among all result types.
59 targets (Optional[List[int]]): The target qubits. This is a list of int >= 0.
60 observable (List[Union[str, List[List[List[float]]]]): A list with at least
61 one item and items are strings matching the observable regex
62 or a two dimensional hermitian matrix with complex entries.
63 Each complex number is represented using a List[float] of size 2, with
64 element[0] being the real part and element[1] imaginary.
65 inf, -inf, and NaN are not allowable inputs for the element.
67 Examples:
68 >>> Sample(targets=[1], observable=["x"])
69 """
71 class Type(str, Enum):
72 sample = "sample"
74 type = Type.sample
77class Variance(OptionalMultiTarget, Observable):
78 """
79 Variance of specified targets and observables as requested result.
80 If no targets are specified, the observable must only operate on 1 qubit and it
81 will be applied to all qubits in parallel. Otherwise, the number of specified targets
82 must be equivalent to the number of qubits the observable can be applied to.
84 Attributes:
85 type (str): The result type. default = "variance". (type) is optional.
86 This should be unique among all result types.
87 targets (List[int]): The target qubits. This is a list of int >= 0.
88 observable (List[Union[str, List[List[List[float]]]]): A list with at least
89 one item and items are strings matching the observable regex
90 or a two dimensional hermitian matrix with complex entries.
91 Each complex number is represented using a List[float] of size 2, with
92 element[0] being the real part and element[1] imaginary.
93 inf, -inf, and NaN are not allowable inputs for the element.
95 Examples:
96 >>> Variance(targets=[1], observable=["x"])
97 """
99 class Type(str, Enum):
100 variance = "variance"
102 type = Type.variance
105class StateVector(BaseModel):
106 """
107 The full state vector as requested result.
109 Attributes:
110 type (str): The result type. default = "statevector". (type) is optional.
111 This should be unique among all result types.
113 Examples:
114 >>> StateVector()
115 """
117 class Type(str, Enum):
118 statevector = "statevector"
120 type = Type.statevector
123class Amplitude(MultiState):
124 """
125 Amplitudes of specified states as requested result.
127 Attributes:
128 type (str): The result type. default = "amplitude". (type) is optional.
129 This should be unique among all result types.
130 states (List[string]): Variable length list with with all strings
131 matching the state regex
133 Examples:
134 >>> Amplitude(states=["01", "10"])
135 """
137 class Type(str, Enum):
138 amplitude = "amplitude"
140 type = Type.amplitude
143class Probability(OptionalMultiTarget):
144 """
145 Probability of all states if no targets are specified or the marginal probability
146 of a restricted set of states if only a subset of all qubits are specified as targets
148 Attributes:
149 type (str): The result type. default = "probability". (type) is optional.
150 This should be unique among all result types.
151 targets (Optional[List[int]]): The target qubits. This is a list of int >= 0.
153 Examples:
154 >>> Probability(targets=[1, 2])
155 """
157 class Type(str, Enum):
158 probability = "probability"
160 type = Type.probability