Measure QPU timing in QAOA

Hi, I am trying to benchmark a QAOA algorithm and would like to know if there is an example or way on how to measure the actual execution time of the QPU (or the closest way of measuring it in a fair way). This would help me to know the proportion of classical vs. QPU timings for QAOA.

I am using ExpvalCost as my cost function, so I would probably need to return the execution time from within this function somehow.

Hi @rossp, welcome to the forum!

I don’t know if any of these options will work for what you need but they are definitely some good starting points:

  1. Here you will find a benchmarking code used on different simulators and with different differentiation methods. If you want to run on hardware you will need to use the parameter-shift differentiation method.
  2. This repo holds some benchmarking tools for PennyLane. Maybe you will find something in there that will be useful for you.
  3. Depending on what specific hardware you want to use, there may be hardware-specific functions that will allow you to find the execution time. Here’s an example of how to find the execution time when you’re using an IBM device:
    import pennylane as qml

    dev = qml.device('qiskit.ibmq', wires=2, backend='ibmq_qasm_simulator')#, ibmqx_token="XXX") = True
    def circuit():
        qml.Hadamard(wires = 0)
        return qml.expval(qml.PauliZ(0))

Please let me know if this helps!

1 Like

Hi @CatalinaAlbornoz, thanks so much for the reply.
I have now decided to use a decorator to measure the execution time of execute and batch_execute of the device class (so dev.execute(...) and dev.batch_execute(...). This should be sufficient for the time being.

Hi @rossp, thank you for sharing your solution with us!

Would you like to share the full code you used or contribute it as a feature to PennyLane? This might be very useful for others in the future too.