2

I am executing a quantum circuit on an IBM quantum device and I need to start a timer as soon as the job in the queue starts running. I have already used:

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

but in this particular case what I need is more like a "signal", like a variable that is switched on as soon as the queue is over and causes the timer to start. I tried using the job status but it didn't seem to work.

glS
  • 27,510
  • 7
  • 37
  • 125
Alfred
  • 93
  • 7

2 Answers2

2

result.time_taken is the execution time. There is also job.time_per_step() that gives you the timestamps of each step of the job's life cycle.

If you're looking to set some variable locally in your program, the best you can do is probably use job status. job.wait_for_final_state() supports a callback function that you can use to set the variable when status changes.

jyu00
  • 849
  • 4
  • 5
2

It seems these attributes are deprecated since v0.42.0 of Qiskit SDK. In Qiskit SDK v1.4.2 (Runtime client v0.37.0), you have access through the job object:

from qiskit_ibm_runtime import SamplerV2
sampler = SamplerV2(backend)
job = sampler.run(circuit)

job.usage_estimation --> time usage estimation (in s) job.usage() --> real time usage (in s) job.metrics() --> several metrics on execution (dict)

Through result you have:

result = job.result()
result.metadata["execution"]["execution_spans"][0]

You can look here for further details: https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/runtime-job-v2

gravlax
  • 21
  • 2