qsharp-runtime icon indicating copy to clipboard operation
qsharp-runtime copied to clipboard

The trace simulator uses a non-optimal decomposition of the `CCNOT` operation

Open jond01 opened this issue 2 years ago • 0 comments

Please describe what you would like the maintenance work to be.

The trace simulator uses the following decomposition for CCNOT (CCNOT == CCX):

  1. https://github.com/microsoft/qsharp-runtime/blob/e58a90cb50daf7cd573417929b616eecb59ebed5/src/Simulation/Simulators/QCTraceSimulator/Circuits/CCX.qs#L18-L23
  2. https://github.com/microsoft/qsharp-runtime/blob/e58a90cb50daf7cd573417929b616eecb59ebed5/src/Simulation/Simulators/QCTraceSimulator/Circuits/CCZ.qs#L19-L38

However, this decomposition is naive and far from ideal. A better decomposition is provided here:

  1. https://github.com/microsoft/qsharp-runtime/blob/e58a90cb50daf7cd573417929b616eecb59ebed5/src/Simulation/TargetDefinitions/Decompositions/CCNOTFromCCZ.qs#L22-L31
  2. https://github.com/microsoft/qsharp-runtime/blob/e58a90cb50daf7cd573417929b616eecb59ebed5/src/Simulation/TargetDefinitions/Decompositions/Utils.qs#L101-L116

The above is equivalent to the following circuit: image

Indeed, when using the trace simulator with the latter decomposition - the depth is reduced from 15 to 8, and the T-depth is reduced from 5 to 4:

Metric Plain trace simulator Trace simulator with a custom decomposition
Depth 15 8
T-depth 5 4

See the complete code here: https://gist.github.com/jond01/59d6e6732c55d8702479f8c6555e450c

This improvement is remarkable when estimating the resources (depth) required for a large quantum algorithm. Is there any relevant reason for this inconsistency between the decompositions?

jond01 avatar Jun 08 '22 21:06 jond01