unitaryfund / qrack

Comprehensive, GPU accelerated framework for developing universal virtual quantum processors
https://qrack.readthedocs.io/en/latest/
GNU Lesser General Public License v3.0
176 stars 38 forks source link

Expectation value calculation optimization #862

Closed WrathfulSpatula closed 3 years ago

WrathfulSpatula commented 3 years ago

There doesn't seem to be any obvious downside to parallelizing sum-over-amplitude methods, when they contain enough summands to benefit from it.

WrathfulSpatula commented 3 years ago

(Sorry for the careless branching.)

There was a point where I noticed that QEngineOCL::ParSum() was slower when parallelized, long ago, if there weren't enough summand terms. This is no longer the case, since ParallelFor() sets a better threshold for parallelism, internally, and it will execute in serial instead if the summand count is below the threshold. Also, I check for that same threshold within these two methods, before attempting to dispatch in parallel.

WrathfulSpatula commented 3 years ago

I reconsidered: the parallelization is less important than the memory usage and redundancy.