Closed nathanieltornow closed 1 month ago
Hi @nathanieltornow, Thank you for sharing the code and detailed configurations, it is helpful to us.
This behavior is expected. If measurements are performed only at the end of the simulation, the resulting state vector is consistent and we can reuse it for multiple sampling shots. On the other hand, for simulations with mid-circuit measurements, the simulation is executed once per shot because the state vector can be different after measuring it. In this case, the entire execution time will increase linearly to the number of shots.
The example code has an option --disable-cusvaer
to use a different backend, in which we can see similar performance difference.
Hi @ymagchi, Thank you for your fast reply! This makes total sense.
Is it worth exploring a potential speed-up for this case? This could be, for example, achieved by computing a statevector for each possible mid-circuit measurement scenario and then computing the final counts using these statevectors. I saw this python-code that uses such an approach.
This would, however, mean having to compute $2^m$ statevectors where $m$ is the number of mid-circuit measurements. This could allow a significant speedup if $2^m < \text{shots}$. The property $2^m < \text{shots}$ could be checked before executing; if false we'd use the current, if true we'd use the proposed approach.
Let me know if you think this would be worth including in the code. If yes, I'd be happy to help :)
Is it worth exploring a potential speed-up for this case?
I think it works for your case above. For general cases, memory usage and data transfers to keep all state vectors will need to be taken into consideration.
When using mid-circuit measurement(s), the cusvaer backend seems to get orders of magnitude slower. Is this expected behavior, or can I do something to speed up mid-circuit measurements?
To show this, here is a slightly modified version of the qiskit example.
Without the mid-circuit measurement, it is really fast:
However, with mid-circuit measurement:
For 25 qubits:
Specs: