quantumlib / Stim

A fast stabilizer circuit library.
Apache License 2.0
356 stars 107 forks source link

Bug in `to_tableau` function for SPP gates #846

Closed NnktYoshioka closed 1 month ago

NnktYoshioka commented 1 month ago

It seems that the stim.Circuit.to_tableau is not reflecting the presence of SPP gate now (tried in v1.13.0 and v1.14.0). For instance when I run

print(stim.Circuit("""
H 0
SPP Z0
""").to_tableau())

# not correct
#stim.Tableau.from_conjugated_generators(
#    xs=[
#        stim.PauliString("+Z"),
#    ],
#    zs=[
#        stim.PauliString("+X"),
#    ],
#)

print(stim.Circuit("""
H 0
S 0
""").to_tableau())

# as expected
#stim.Tableau.from_conjugated_generators(
#    xs=[
#        stim.PauliString("+Z"),
#    ],
#    zs=[
#        stim.PauliString("+Y"),
#    ],
#)

The output did not change when I choose SPP X0 or SPP Y0, so I suspect that to_tableau is ignoring SPP gates.

I confirmed that SPP gates are properly working onTableauSimulator, by, e.g., running the following:

tsim = stim.TableauSimulator()
tsim.do(stim.Circuit("""
H 0
SPP Z0
"""))

print(tsim.canonical_stabilizers())

#[stim.PauliString("+Y")]
Strilanc commented 1 month ago

Good catch. It seems like this is caused by SPP not being marked as a unitary gate, so the method skips right over it (as part of the logic for optionally ignoring non-unitary gates).

Strilanc commented 1 month ago

I created a fix (https://github.com/quantumlib/Stim/pull/847). Around a half hour after that PR is merged, you should be able to pip install stim~=1.15.dev and then stim.Circuit("SPP X0").to_tableau() should work.

NnktYoshioka commented 1 month ago

Thanks for the superprompt fix! I pip-installed the PR and confirmed that it is working properly.

Strilanc commented 1 month ago

...what? The fix isn't pushed yet!