9

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.

Sanchayan Dutta
  • 17,945
  • 8
  • 50
  • 112
Henao
  • 123
  • 1
  • 4

3 Answers3

6

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()
met927
  • 3,251
  • 1
  • 10
  • 22
Paul Nation
  • 2,289
  • 9
  • 8
4

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.

James Wootton
  • 11,700
  • 1
  • 35
  • 74
2

When I tried getting data after using job = backend.retrieve_job('JOB_ID'), I got "QiskitError: 'Data for experiment "circuit0" could not be found.'"

When I tried using job_info = provider.circuits.client.get_job(job_id), I got "AttributeError: 'AccountProvider' object has no attribute 'circuits'."

What worked for me was job_info={the entire text of the json file downloaded from Results}, and then proceeding as James described above.

met927
  • 3,251
  • 1
  • 10
  • 22
Jed Brody
  • 95
  • 4