1
$\begingroup$

This might seem like a simple question, but is there a way to tell how many shots I have ran over all time without manually going into my jobs list and counting. Seeing the total number of jobs is easy enough (86538 as of right now), but those include simulator runs and sometimes I run different jobs with a different number of shots. If not, is there an easy way to query the IBMQ site (perhaps using python or something) and get the data on all the jobs. At least then I would be able to perform the data analysis myself.

$\endgroup$

1 Answer 1

2
$\begingroup$

This script can do the job for you. May be there is a faster way, but I couldn't find one.

Note that, if you want to include the jobs from retired backends and you know their names, add them to retired_backend_names:

from qiskit import IBMQ
from qiskit.providers import JobStatus
from qiskit.providers.ibmq.api.clients.account import AccountClient
from qiskit.providers.ibmq.ibmqbackend import IBMQRetiredBackend

retired_backend_names = [] # e.g., 'ibmq_yorktown', 'ibmq_vigo', ...

if IBMQ.active_account() is None:
    IBMQ.load_account()

provider = IBMQ.get_provider(hub = 'ibm-q')

total_shots = 0
for provider in IBMQ.providers():

   backends = provider.backends(filters = lambda x: not x.configuration().simulator) # Exclude simulators.

   _credentials = provider.credentials
   _api_client = AccountClient(_credentials, **_credentials.connection_parameters())
   for retired_backend_name in retired_backend_names:
      retired_backend = IBMQRetiredBackend.from_name(retired_backend_name, provider, _credentials, _api_client)
      backends.append(retired_backend)

   for backend in backends:
      for job in backend.jobs():
         if job.status() == JobStatus.DONE: # Exclude cancelled, failed, or ongoing jobs.
            shots = sum(job.result().get_counts().values())
            print(job.job_id(), shots) # For debugging. You may remove this line.
            total_shots += shots

print(total_shots)
$\endgroup$
2
  • $\begingroup$ This is great, the only issue I have (and I'm not sure if there is even a good way of solving this) is that some of the backends I used ages ago no longer exist. I.E. when we query the provider for backends, there are some from 2 years ago that it seems to miss since they have been discontinued. $\endgroup$
    – QC_QAOA
    Commented Jan 31, 2022 at 21:02
  • 1
    $\begingroup$ I updated my answer to include the jobs from retired backends $\endgroup$ Commented Feb 1, 2022 at 7:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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