How do I get execution time of jobs (not transpile+queue+python+etc time) on qiskit hardware?

What I have been doing so far is getting the result of the jobs post job completion using qiskit:

from qiskit import IBMQ

IBMQ.load_account()
provider = IBMQ.get_provider(hub='ibm-q', group='open', project='main')
backend = provider.get_backend('ibmq_qasm_simulator')

job_id = backend.jobs()[0].job_id()
print(f'JOBID: {job_id}')

job = backend.retrieve_job(job_id)
time_steps = job.time_per_step()
counts = job.result().get_counts()

print(f'RUNNING: {time_steps["RUNNING"]}')
print(f'COMPLETED: {time_steps["COMPLETED"]}')

RUNTIME = time_steps["COMPLETED"] - time_steps["RUNNING"]
print(f'RUNTIME: {RUNTIME.total_seconds()}')

Is there a better way of doing this within Pennylane so I don’t have to retrieve the information after runs? If I do optimisation on the circuit I will also have quite a few jobs to retrieve the runtime for to get the total runtime. My aim is to compare my algorithm to the best classical alternative experimentally.

Hi @HelloBeastie,

Thanks so much for your question! :slightly_smiling_face:

At the moment this is indeed not something that can be retrieved when using PennyLane-Qiskit. I’ve added a GitHub issue for this and we’ll be looking into making this available.

1 Like

I would like to note that

result = job.result()
counts = result.get_counts()
execution_time = result.time_taken

gets the execution time.

RUNTIME = time_steps["COMPLETED"] - time_steps["RUNNING"]
print(f'RUNTIME: {RUNTIME.total_seconds()}')

includes post-processing such as storing the data in a qiskit db etc and doesn’t actually correspond to any of the times in the image below:

Whilst execution time as above is the Running time.
Thanks so much for responding and for considering this as a feature :grinning: !

PS: can I mark this as the solution or is that weird?

1 Like

Hi @HelloBeastie,

Thanks for the note, that’s really helpful! :slightly_smiling_face:

Sure, marking it as a solution, for now, works fine.