braket.tasks.gate_model_quantum_task_result module

class braket.tasks.gate_model_quantum_task_result.GateModelQuantumTaskResult(task_metadata: TaskMetadata, additional_metadata: AdditionalMetadata, result_types: list[ResultTypeValue] | None = None, values: list[Any] | None = None, measurements: ndarray | None = None, measured_qubits: list[int] | None = None, measurement_counts: Counter | None = None, measurement_probabilities: dict[str, float] | None = None, measurements_copied_from_device: bool | None = None, measurement_counts_copied_from_device: bool | None = None, measurement_probabilities_copied_from_device: bool | None = None, _result_types_indices: dict[str, int] | None = 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 (TaskMetadata) – Quantum task metadata.

  • additional_metadata (AdditionalMetadata) – Additional metadata about the quantum task

  • 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 and 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. Note that the keys in Counter are unordered.

  • 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: TaskMetadata
additional_metadata: AdditionalMetadata
result_types: list[ResultTypeValue] = None
values: list[Any] = None
measurements: 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: 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 quantum 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 is not found in result. Result types must be added to the circuit before the circuit is run on a device.

get_compiled_circuit() str | None[source]

Get the compiled circuit, if one is available.

Returns:

Optional[str] – The compiled circuit or None.

static measurement_counts_from_measurements(measurements: ndarray) Counter[source]

Creates measurement counts from measurements

Parameters:

measurements (np.ndarray) – 2d array - row is shot and 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) 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:

np.ndarray – A dictionary of probabilistic results. Key is the measurements in a big endian binary string. Value is the probability the measurement occurred.

static from_object(result: GateModelTaskResult) GateModelQuantumTaskResult[source]

Create GateModelQuantumTaskResult from GateModelTaskResult object.

Parameters:

result (GateModelTaskResult) – GateModelTaskResult object

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) 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

static cast_result_types(gate_model_task_result: GateModelTaskResult) None[source]

Casts the result types to the types expected by the SDK.

Parameters:

gate_model_task_result (GateModelTaskResult) – GateModelTaskResult representing the results.