243 lines
12 KiB
Plaintext
243 lines
12 KiB
Plaintext
---
|
||
title: Result (v1.2)
|
||
description: API reference for qiskit.result.Result in qiskit v1.2
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: class
|
||
python_api_name: qiskit.result.Result
|
||
---
|
||
|
||
# Result
|
||
|
||
<Class id="qiskit.result.Result" isDedicatedPage={true} github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/result/result.py#L29-L392" signature="qiskit.result.Result(backend_name, backend_version, qobj_id, job_id, success, results, date=None, status=None, header=None, **kwargs)" modifiers="class">
|
||
Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)")
|
||
|
||
Model for Results.
|
||
|
||
### backend\_name
|
||
|
||
<Attribute id="qiskit.result.Result.backend_name">
|
||
backend name.
|
||
|
||
**Type**
|
||
|
||
[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)")
|
||
</Attribute>
|
||
|
||
### backend\_version
|
||
|
||
<Attribute id="qiskit.result.Result.backend_version">
|
||
backend version, in the form X.Y.Z.
|
||
|
||
**Type**
|
||
|
||
[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)")
|
||
</Attribute>
|
||
|
||
### qobj\_id
|
||
|
||
<Attribute id="qiskit.result.Result.qobj_id">
|
||
user-generated Qobj id.
|
||
|
||
**Type**
|
||
|
||
[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)")
|
||
</Attribute>
|
||
|
||
### job\_id
|
||
|
||
<Attribute id="qiskit.result.Result.job_id">
|
||
unique execution id from the backend.
|
||
|
||
**Type**
|
||
|
||
[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)")
|
||
</Attribute>
|
||
|
||
### success
|
||
|
||
<Attribute id="qiskit.result.Result.success">
|
||
True if complete input qobj executed correctly. (Implies each experiment success)
|
||
|
||
**Type**
|
||
|
||
[bool](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)")
|
||
</Attribute>
|
||
|
||
### results
|
||
|
||
<Attribute id="qiskit.result.Result.results">
|
||
corresponding results for array of experiments of the input qobj
|
||
|
||
**Type**
|
||
|
||
[list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)")\[ExperimentResult]
|
||
</Attribute>
|
||
|
||
## Methods
|
||
|
||
### data
|
||
|
||
<Function id="qiskit.result.Result.data" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/result/result.py#L133-L184" signature="data(experiment=None)">
|
||
Get the raw data for an experiment.
|
||
|
||
Note this data will be a single classical and quantum register and in a format required by the results schema. We recommend that most users use the get\_xxx method, and the data will be post-processed for the data type.
|
||
|
||
**Parameters**
|
||
|
||
**experiment** ([*str*](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") *or*[*QuantumCircuit*](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") *or*[*Schedule*](qiskit.pulse.Schedule "qiskit.pulse.Schedule") *or*[*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") *or None*) – the index of the experiment. Several types are accepted for convenience:: \* str: the name of the experiment. \* QuantumCircuit: the name of the circuit instance will be used. \* Schedule: the name of the schedule instance will be used. \* int: the position of the experiment. \* None: if there is only one experiment, returns it.
|
||
|
||
**Returns**
|
||
|
||
A dictionary of results data for an experiment. The data depends on the backend it ran on and the settings of meas\_level, meas\_return and memory.
|
||
|
||
OpenQASM backends return a dictionary of dictionary with the key ‘counts’ and with the counts, with the second dictionary keys containing a string in hex format (`0x123`) and values equal to the number of times this outcome was measured.
|
||
|
||
Statevector backends return a dictionary with key ‘statevector’ and values being a list\[list\[complex components]] list of 2^num\_qubits complex amplitudes. Where each complex number is represented as a 2 entry list for each component. For example, a list of \[0.5+1j, 0-1j] would be represented as \[\[0.5, 1], \[0, -1]].
|
||
|
||
Unitary backends return a dictionary with key ‘unitary’ and values being a list\[list\[list\[complex components]]] list of 2^num\_qubits x 2^num\_qubits complex amplitudes in a two entry list for each component. For example if the amplitude is \[\[0.5+0j, 0-1j], …] the value returned will be \[\[\[0.5, 0], \[0, -1]], …].
|
||
|
||
The simulator backends also have an optional key ‘snapshots’ which returns a dict of snapshots specified by the simulator backend. The value is of the form dict\[slot: dict\[str: array]] where the keys are the requested snapshot slots, and the values are a dictionary of the snapshots.
|
||
|
||
**Return type**
|
||
|
||
[dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.13)")
|
||
|
||
**Raises**
|
||
|
||
[**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") – if data for the experiment could not be retrieved.
|
||
</Function>
|
||
|
||
### from\_dict
|
||
|
||
<Function id="qiskit.result.Result.from_dict" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/result/result.py#L112-L131" signature="from_dict(data)" modifiers="classmethod">
|
||
Create a new ExperimentResultData object from a dictionary.
|
||
|
||
**Parameters**
|
||
|
||
**data** ([*dict*](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.13)")) – A dictionary representing the Result to create. It will be in the same format as output by [`to_dict()`](#qiskit.result.Result.to_dict "qiskit.result.Result.to_dict").
|
||
|
||
**Returns**
|
||
|
||
The `Result` object from the input dictionary.
|
||
|
||
**Return type**
|
||
|
||
[Result](#qiskit.result.Result "qiskit.result.Result")
|
||
</Function>
|
||
|
||
### get\_counts
|
||
|
||
<Function id="qiskit.result.Result.get_counts" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/result/result.py#L240-L290" signature="get_counts(experiment=None)">
|
||
Get the histogram data of an experiment.
|
||
|
||
**Parameters**
|
||
|
||
**experiment** ([*str*](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") *or*[*QuantumCircuit*](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") *or*[*Schedule*](qiskit.pulse.Schedule "qiskit.pulse.Schedule") *or*[*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") *or None*) – the index of the experiment, as specified by `data([experiment])`.
|
||
|
||
**Returns**
|
||
|
||
a dictionary or a list of dictionaries. A dictionary has the counts for each qubit with the keys containing a string in binary format and separated according to the registers in circuit (e.g. `0100 1110`). The string is little-endian (cr\[0] on the right hand side).
|
||
|
||
**Return type**
|
||
|
||
[dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.13)")\[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)"), [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")] or [list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)")\[[dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.13)")\[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)"), [int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")]]
|
||
|
||
**Raises**
|
||
|
||
[**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") – if there are no counts for the experiment.
|
||
</Function>
|
||
|
||
### get\_memory
|
||
|
||
<Function id="qiskit.result.Result.get_memory" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/result/result.py#L186-L238" signature="get_memory(experiment=None)">
|
||
Get the sequence of memory states (readouts) for each shot The data from the experiment is a list of format \[‘00000’, ‘01000’, ‘10100’, ‘10100’, ‘11101’, ‘11100’, ‘00101’, …, ‘01010’]
|
||
|
||
**Parameters**
|
||
|
||
**experiment** ([*str*](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") *or*[*QuantumCircuit*](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") *or*[*Schedule*](qiskit.pulse.Schedule "qiskit.pulse.Schedule") *or*[*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") *or None*) – the index of the experiment, as specified by `data()`.
|
||
|
||
**Returns**
|
||
|
||
Either the list of each outcome, formatted according to registers in circuit or a complex numpy np.ndarray with shape:
|
||
|
||
> | meas\_level | meas\_return | shape |
|
||
> | ----------- | ------------ | ----------------------------------------------------- |
|
||
> | 0 | single | np.ndarray\[shots, memory\_slots, memory\_slot\_size] |
|
||
> | 0 | avg | np.ndarray\[memory\_slots, memory\_slot\_size] |
|
||
> | 1 | single | np.ndarray\[shots, memory\_slots] |
|
||
> | 1 | avg | np.ndarray\[memory\_slots] |
|
||
> | 2 | memory=True | list |
|
||
|
||
**Return type**
|
||
|
||
List\[[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)")] or np.ndarray
|
||
|
||
**Raises**
|
||
|
||
[**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") – if there is no memory data for the circuit.
|
||
</Function>
|
||
|
||
### get\_statevector
|
||
|
||
<Function id="qiskit.result.Result.get_statevector" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/result/result.py#L292-L312" signature="get_statevector(experiment=None, decimals=None)">
|
||
Get the final statevector of an experiment.
|
||
|
||
**Parameters**
|
||
|
||
* **experiment** ([*str*](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") *or*[*QuantumCircuit*](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") *or*[*Schedule*](qiskit.pulse.Schedule "qiskit.pulse.Schedule") *or*[*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") *or None*) – the index of the experiment, as specified by `data()`.
|
||
* **decimals** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")) – the number of decimals in the statevector. If None, does not round.
|
||
|
||
**Returns**
|
||
|
||
list of 2^num\_qubits complex amplitudes.
|
||
|
||
**Return type**
|
||
|
||
[list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)")\[[complex](https://docs.python.org/3/library/functions.html#complex "(in Python v3.13)")]
|
||
|
||
**Raises**
|
||
|
||
[**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") – if there is no statevector for the experiment.
|
||
</Function>
|
||
|
||
### get\_unitary
|
||
|
||
<Function id="qiskit.result.Result.get_unitary" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/result/result.py#L314-L333" signature="get_unitary(experiment=None, decimals=None)">
|
||
Get the final unitary of an experiment.
|
||
|
||
**Parameters**
|
||
|
||
* **experiment** ([*str*](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)") *or*[*QuantumCircuit*](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") *or*[*Schedule*](qiskit.pulse.Schedule "qiskit.pulse.Schedule") *or*[*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") *or None*) – the index of the experiment, as specified by `data()`.
|
||
* **decimals** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")) – the number of decimals in the unitary. If None, does not round.
|
||
|
||
**Returns**
|
||
|
||
**list of 2^num\_qubits x 2^num\_qubits complex**
|
||
|
||
amplitudes.
|
||
|
||
**Return type**
|
||
|
||
[list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)")\[[list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)")\[[complex](https://docs.python.org/3/library/functions.html#complex "(in Python v3.13)")]]
|
||
|
||
**Raises**
|
||
|
||
[**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") – if there is no unitary for the experiment.
|
||
</Function>
|
||
|
||
### to\_dict
|
||
|
||
<Function id="qiskit.result.Result.to_dict" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/result/result.py#L86-L104" signature="to_dict()">
|
||
Return a dictionary format representation of the Result
|
||
|
||
**Returns**
|
||
|
||
The dictionary form of the Result
|
||
|
||
**Return type**
|
||
|
||
[dict](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.13)")
|
||
</Function>
|
||
</Class>
|
||
|