2
$\begingroup$

I have ran an experiment in one of the IBM processors and the work has finished. However, I can not obtain the data as histograms or counts in the qiskit notebook because the experiment was concluded while I was logged off and therefore now I would need to run the full script again. That is, I would need to run the experiment again. My question is if there is some way to access the results in the notebook without this requirement. I know that the histograms are stored in the section "results" but I specifically want to work with them in the notebook. Thank you.

$\endgroup$
1
$\begingroup$

First, set up your provider

provider = IBMQ.load_account()

From this you can access a list of all your jobs with

provider.circuits.client.get_status_jobs()

Each job is recorded as a dictionary. One of the keys is 'id', which is the job id. To extract this for the first job on the list, for example, use

job_id = provider.circuits.client.get_status_jobs()[0]['id']

You can then use

job_info = provider.circuits.client.get_job(job_id)

To get a JSON which contains all the information about the job, including the results. The counts data for the first circuit in the job, for example, can be found at

job_info['qObjectResult']['results'][0]['data']['counts']

Though note that the strings will be hex strings rather than bit strings, and so will need conversion.

$\endgroup$
  • $\begingroup$ Hi James, thank you for the answer. I followed your instructions and at the end I get some information about the execution of the job. However, I still don't know how to access the results from the notebook. When I introduce something like job.get_counts("some circuit") it tells me that "job" is not defined, so it seems that anyway I would have to execute the job again because for what I know this is the only way I can define it. $\endgroup$ – Henao Aug 29 at 13:38
  • $\begingroup$ @Henao I added a line on how to get counts info. $\endgroup$ – James Wootton Aug 29 at 16:35
  • $\begingroup$ Thanks James, I added the line but then it tells me that "job_info" is not defined. I changed it by job_id, since this is how the circuit was previously identified, and then it tells me that "string indices must be integers". I really don't understand the meaning or function of job_info and 'qObjectResult' in the command, although the other part of it is more intuitive. $\endgroup$ – Henao Sep 1 at 8:03
  • $\begingroup$ Looks like I forgot to define job_info. See my new snippets $\endgroup$ – James Wootton Sep 2 at 11:05
0
$\begingroup$

You can get a previous result by grabbing the corresponding job from the backend you sent it to:

from qiskit import *

provider = IBMQ.load_account()
backend = provider.get_backend('ibmq_BLAH')

#if you know the job ID
job = backend.retrieve_job('JOB_ID')

# if not, get the last 10 jobs on backend
jobs = backend.jobs()
```
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.