quantumlib / Stim

A fast stabilizer circuit library.
Apache License 2.0
341 stars 101 forks source link

Incorrect Tableau definition for S and SDAG #819

Closed lag47 closed 1 month ago

lag47 commented 1 month ago

In src/stim/gates/gate_data_period_4.cc the S gate is defined as taking X to +Y and Z to +Z while SDAG is defined as taking X to -Y and Z to +Z

However, with the standard unitary matrix definition of S as [1 0; 0 i], you can compute that these definitions should be swapped. S^-1 X S = -Y S^-1 Z S = Z

Sdag ^-1 X Sdag = Y Sdag ^-1 Z Sdag = Z

Strilanc commented 1 month ago

The conjugation of P by U is computed as U P U^-1, not as U^-1 P U. If that's not what the conjugation actually is, then it's not the function I want. The function I want is intended to represent "if I have P before the gate U in a circuit, what is the equivalent P2 after the gate U in the circuit?". You can verify that the kickback from a Y gate after an S gate undoes the kickback from an X gate before an S gate. Thus S performs X->Y, not X->-Y.

Circuit:

image

If you try Y->X across S you find that the kickback is not cancelled out, instead it turns into a deterministic flip of the control meaning the sign is -1 so Y->-X instead of Y->X:

image

lag47 commented 1 month ago

In that case, I believe you need to fix the documentation for the __call__ method on the stim.Tableau class. An an excerpt of the documentation

"The conjugation of P by C is equal to C-1 P C. If P is a Pauli product before C, then P2 = C-1 P C is an equivalent Pauli product after C."

This documentation is defined in src/stim/stabilizers/tableau.pybind.cc at line 1886.