1
$\begingroup$

I want to find the runtime of my program, i.e. the time it is in the quantum computer without queue time. However, I am using an optimizer so the code is a little different.

from qiskit.utils import algorithm_globals




algorithm_globals.random_seed = 1234
backend = provider.get_backend('ibmq_belem')

#backend = Aer.get_backend('statevector_simulator')

cobyla = COBYLA()
cobyla.set_options(maxiter=1)
ry = TwoLocal(num_assets, 'ry', 'cz', reps=3, entanglement='full')
quantum_instance = QuantumInstance(backend=backend, seed_simulator=seed, seed_transpiler=seed)
vqe_mes = VQE(ry, optimizer=cobyla, quantum_instance=quantum_instance)
vqe = MinimumEigenOptimizer(vqe_mes)
result = vqe.solve(qp)



print(result)
#print_result(result)

How do I figure out the runtime? Printing result only shows

optimal function value: -0.01488461311339271
optimal value: [1. 0. 0. 1.]
status: SUCCESS
$\endgroup$

1 Answer 1

1
$\begingroup$

I made a start and end_operation point with the method now(). At the end of the operation it will display the time it needed:

from qiskit.utils import algorithm_globals
from time import time as now



algorithm_globals.random_seed = 1234
backend = provider.get_backend('ibmq_belem')

#backend = Aer.get_backend('statevector_simulator')

cobyla = COBYLA()
cobyla.set_options(maxiter=1)
ry = TwoLocal(num_assets, 'ry', 'cz', reps=3, entanglement='full')
quantum_instance = QuantumInstance(backend=backend, seed_simulator=seed, seed_transpiler=seed)
start_operation = now()
vqe_mes = VQE(ry, optimizer=cobyla, quantum_instance=quantum_instance)
vqe = MinimumEigenOptimizer(vqe_mes)
end_operation = now()
result = vqe.solve(qp)

    
    process_time = (
end_operation - start_operation
)
print(f"Operation took {process_time:.2f} seconds in machine")



print(result)
#print_result(result)

Another possibility to meassure the program is to use the command rep_time:

rep_time (int) – Time per program execution in seconds. Must be from the list provided by the backend (backend.configuration().rep_times). Defaults to the first entry.

In your specific case you need to add it in your code like this:

...
quantum_instance = QuantumInstance(backend=backend, rep_time=rep_time, seed_simulator=seed, seed_transpiler=seed)
...
$\endgroup$
15
  • $\begingroup$ I think the difference is that I'm using an optimizer as opposed to the typical job architecture $\endgroup$
    – Bob
    Jul 28, 2021 at 19:13
  • $\begingroup$ Traceback (most recent call last): File "<ipython-input-22-96ed0737ee6d>", line 17, in <module> vqe.status() AttributeError: 'MinimumEigenOptimizer' object has no attribute 'status' Use %tb to get the full traceback. $\endgroup$
    – Bob
    Jul 28, 2021 at 19:28
  • $\begingroup$ This is the error with the updated answer, and yes I am using qiskit $\endgroup$
    – Bob
    Jul 28, 2021 at 19:28
  • $\begingroup$ This gives me Generated circuits in 61.79 seconds optimal function value: -0.01488461311339271 optimal value: [1. 0. 0. 1.] status: SUCCESS $\endgroup$
    – Bob
    Jul 28, 2021 at 19:38
  • $\begingroup$ This is good, but I want to know how long it is in the quantum computer itself, not including the queue time. Through the status timeline I can see it was only in the quantum computer for 3.7 seconds. I want to run hundreds of tests and can't manually check the sidebar everytime $\endgroup$
    – Bob
    Jul 28, 2021 at 19:39

Your Answer

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

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