braket.tasks.gate_model_quantum_task_result module

class braket.tasks.gate_model_quantum_task_result.GateModelQuantumTaskResult(task_metadata: Dict[str, Any], result_types: List[Dict[str, str]], values: List[Any], measurements: Optional[numpy.ndarray] = None, measured_qubits: Optional[List[int]] = None, measurement_counts: Optional[Counter] = None, measurement_probabilities: Optional[Dict[str, float]] = None, measurements_copied_from_device: Optional[bool] = None, measurement_counts_copied_from_device: Optional[bool] = None, measurement_probabilities_copied_from_device: Optional[bool] = None)[source]

Bases: object

Result of a gate model quantum task execution. This class is intended to be initialized by a QuantumTask class.

Parameters
  • task_metadata (Dict[str, Any]) – Dictionary of task metadata. task_metadata must have keys ‘Id’, ‘Shots’, ‘Ir’, and ‘IrType’.

  • result_types (List[Dict[str, Any]]) – List of dictionaries where each dictionary has two keys: ‘Type’ (the result type in IR JSON form) and ‘Value’ (the result value for this result type). This can be an empty list if no result types are specified in the IR. This is calculated from measurements and the IR of the circuit program when shots>0.

  • values (List[Any]) – The values for result types requested in the circuit. This can be an empty list if no result types are specified in the IR. This is calculated from measurements and the IR of the circuit program when shots>0.

  • measurements (numpy.ndarray, optional) – 2d array - row is shot, column is qubit. Default is None. Only available when shots > 0. The qubits in measurements are the ones in GateModelQuantumTaskResult.measured_qubits.

  • measured_qubits (List[int], optional) – The indices of the measured qubits. Default is None. Only available when shots > 0. Indicates which qubits are in measurements.

  • measurement_counts (Counter, optional) – A Counter of measurements. Key is the measurements in a big endian binary string. Value is the number of times that measurement occurred. Default is None. Only available when shots > 0.

  • measurement_probabilities (Dict[str, float], optional) – A dictionary of probabilistic results. Key is the measurements in a big endian binary string. Value is the probability the measurement occurred. Default is None. Only available when shots > 0.

  • measurements_copied_from_device (bool, optional) – flag whether measurements were copied from device. If false, measurements are calculated from device data. Default is None. Only available when shots > 0.

  • measurement_counts_copied_from_device (bool, optional) – flag whether measurement_counts were copied from device. If False, measurement_counts are calculated from device data. Default is None. Only available when shots > 0.

  • measurement_probabilities_copied_from_device (bool, optional) – flag whether measurement_probabilities were copied from device. If false, measurement_probabilities are calculated from device data. Default is None. Only available when shots > 0.

task_metadata: Dict[str, Any] = None
result_types: List[Dict[str, str]] = None
values: List[Any] = None
measurements: np.ndarray = None
measured_qubits: List[int] = None
measurement_counts: Counter = None
measurement_probabilities: Dict[str, float] = None
measurements_copied_from_device: bool = None
measurement_counts_copied_from_device: bool = None
measurement_probabilities_copied_from_device: bool = None
get_value_by_result_type(result_type: braket.circuits.result_type.ResultType) → Any[source]

Get value by result type. The result type must have already been requested in the circuit sent to the device for this task result.

Parameters

result_type (ResultType) – result type requested

Returns

Any – value of the result corresponding to the result type

Raises

ValueError – If result type not found in result. Result types must be added to circuit before circuit is run on device.

static measurement_counts_from_measurements(measurements: numpy.ndarray) → Counter[source]

Creates measurement counts from measurements

Parameters

measurements (numpy.ndarray) – 2d array - row is shot, column is qubit.

Returns

Counter

A Counter of measurements. Key is the measurements in a big endian binary

string. Value is the number of times that measurement occurred.

static measurement_probabilities_from_measurement_counts(measurement_counts: Counter) → Dict[str, float][source]

Creates measurement probabilities from measurement counts

Parameters

measurement_counts (Counter) – A Counter of measurements. Key is the measurements in a big endian binary string. Value is the number of times that measurement occurred.

Returns

Dict[str, float]

A dictionary of probabilistic results. Key is the measurements

in a big endian binary string. Value is the probability the measurement occurred.

static measurements_from_measurement_probabilities(measurement_probabilities: Dict[str, float], shots: int) → numpy.ndarray[source]

Creates measurements from measurement probabilities

Parameters
  • measurement_probabilities (Dict[str, float]) – A dictionary of probabilistic results. Key is the measurements in a big endian binary string. Value is the probability the measurement occurred.

  • shots (int) – number of iterations on device

Returns

Dict[str, float]

A dictionary of probabilistic results.

Key is the measurements in a big endian binary string. Value is the probability the measurement occurred.

static from_dict(result: Dict[str, Any])[source]

Create GateModelQuantumTaskResult from dict.

Parameters

result (Dict[str, Any]) – Results dict with GateModelQuantumTaskResult attributes as keys

Returns

GateModelQuantumTaskResult – A GateModelQuantumTaskResult based on the given dict

Raises

ValueError – If neither “Measurements” nor “MeasurementProbabilities” is a key in the result dict

static from_string(result: str)braket.tasks.gate_model_quantum_task_result.GateModelQuantumTaskResult[source]

Create GateModelQuantumTaskResult from string.

Parameters

result (str) – JSON object string, with GateModelQuantumTaskResult attributes as keys.

Returns

GateModelQuantumTaskResult – A GateModelQuantumTaskResult based on the given string

Raises

ValueError – If neither “Measurements” nor “MeasurementProbabilities” is a key in the result dict