Coverage for src/braket/task_result/gate_model_task_result_v1.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 Dict, List, Optional, Union
16from pydantic import BaseModel, Field, confloat, conint, conlist, constr
18from braket.ir.jaqcd.program_v1 import Results
19from braket.schema_common import BraketSchemaBase, BraketSchemaHeader
20from braket.task_result.additional_metadata import AdditionalMetadata
21from braket.task_result.task_metadata_v1 import TaskMetadata
24class ResultTypeValue(BaseModel):
25 """
26 Requested result type and value of gate model task result.
28 Attributes:
29 type (Union[Expectation, Sample, StateVector, Variance, Probability, Amplitude]): The
30 requested result type
31 value (Union[List, float, Dict]): The value of the requested result
32 """
34 type: Union[Results]
35 value: Union[List, float, Dict]
38class GateModelTaskResult(BraketSchemaBase):
39 """
40 The gate model task result schema
42 Attributes:
43 braketSchemaHeader (BraketSchemaHeader): Schema header. Users do not need
44 to set this value. Only default is allowed.
45 measurements (List[List[int]]: List of lists, where each list represents a shot
46 and each index of the list represents a qubit. Default is `None`.
47 measurementProbabilities (Dict[str, float]): A dictionary of probabilistic results.
48 Key is the measurements in a big endian binary string.
49 Value is the probability the measurement occurred.
50 Default is `None`.
51 measuredQubits (List[int]): The indices of the measured qubits.
52 Indicates which qubits are in `measurements`. Default is `None`.
53 resultTypes (List[ResultTypeValue]): Requested result types and their values.
54 Default is `None`.
55 taskMetadata (TaskMetadata): The task metadata
56 additionalMetadata (AdditionalMetadata): Additional metadata of the task
57 """
59 _GATE_MODEL_TASK_RESULT_HEADER = BraketSchemaHeader(
60 name="braket.task_result.gate_model_task_result", version="1"
61 )
63 braketSchemaHeader: BraketSchemaHeader = Field(
64 default=_GATE_MODEL_TASK_RESULT_HEADER, const=_GATE_MODEL_TASK_RESULT_HEADER
65 )
66 measurements: Optional[conlist(conlist(conint(ge=0, le=1), min_items=1), min_items=1)]
67 measurementProbabilities: Optional[
68 Dict[constr(regex="^[01]+$", min_length=1), confloat(ge=0, le=1)]
69 ]
70 resultTypes: Optional[List[ResultTypeValue]]
71 measuredQubits: Optional[conlist(conint(ge=0), min_items=1)]
72 taskMetadata: TaskMetadata
73 additionalMetadata: AdditionalMetadata