aromanro / QCSim

Quantum computing simulator
GNU General Public License v3.0
28 stars 5 forks source link

Execute improvement - avoid repeating the execution of the same circuit for many measurements #13

Closed aromanro closed 11 months ago

aromanro commented 11 months ago

Many algorithms are probabilistic and need repeating the measurement many times, which requires reinitialization of the register and executing again the algorithm... but there is a shortcut in simulation (unlike the real case, where you cannot copy a quantum state: No Cloning Theorem): the register state can be saved and then after the measurement (with the collapse, of course) it can be initialized back to the saved value.

This would allow avoiding repeating the algorithm many times, doing instead only repeated measurements.

In fact, the register already has a RepeatedMeasure implementation, this enhancement would just need a RepeatedExecute, similar with the Execute function, but with a RepeatedMeasure at the end instead of the single Measure.

Not a big deal to implement, but I'll postpone it for a while, there are more interesting things to do :)

aromanro commented 11 months ago

The Quantum Counting algorithm has now an example of implementation, this should be added to all algorithms that need repeated measurements but the execution is identical (that is, during execution there isn't something changed/picked at random/etc).

aromanro commented 11 months ago

Currently the 'repeated measurement' implementation uses the regular measurement implementation (letting it collapse the state) and then reinitialises the state using the previously saved state.

There is no need to save the state and collapse it and then reinitialize it, the whole thing can be done without altering the state. This is going to improve the speed, especially when doing 'partial' measurements (that is, only on a subset of the qubits).

aromanro commented 11 months ago

I think I covered most algorithms that can be improved by this, so I'm closing it.