IBMCompositeJob.result#
- IBMCompositeJob.result(timeout=None, wait=5, partial=False, refresh=False)[source]#
Return the result of the job.
Note
This method blocks until all sub-jobs finish.
Note
Some IBM Quantum job results can only be read once. A second attempt to query the server for the same job will fail, since the job has already been “consumed”.
The first call to this method in an
IBMCompositeJob
instance will query the server and consume any available job results. Subsequent calls to that instance’sresult()
will also return the results, since they are cached. However, attempting to retrieve the results again in another instance or session might fail due to the job results having been consumed.Note
When partial=True, this method will attempt to retrieve partial results of failed jobs. In this case, precaution should be taken when accessing individual experiments, as doing so might cause an exception. The
success
attribute of the returnedResult
instance can be used to verify whether it contains partial results.For example, if one of the circuits in the job failed, trying to get the counts of the unsuccessful circuit would raise an exception since there are no counts to return:
try: counts = result.get_counts("failed_circuit") except QiskitError: print("Circuit execution failed!")
If the job failed, you can use
error_message()
to get more information.- Parameters:
timeout (
Optional
[float
]) – Number of seconds to wait for job.wait (
float
) – Time in seconds between queries.partial (
bool
) – IfTrue
, return partial results if possible. Partial results refer to experiments within a sub-job, not individual sub-jobs. That is, this method will still block until all sub-jobs finish even if partial is set toTrue
.refresh (
bool
) – IfTrue
, re-query the server for the result. Otherwise return the cached value.
- Return type:
- Returns:
Job result.
- Raises:
IBMJobInvalidStateError – If the job was cancelled.
IBMJobFailureError – If the job failed.
IBMJobApiError – If an unexpected error occurred when communicating with the server.