quantumlib / Stim

A fast stabilizer circuit library.
Apache License 2.0
329 stars 95 forks source link

Fix time_reversed_for_flows handling feedback incorrectly #764

Open Strilanc opened 5 months ago

Strilanc commented 5 months ago
import stim
c = stim.Circuit("""
    R 1
    M 1
    CX rec[-1] 0
""")
p = stim.PauliString("Z")
f = stim.Flow(input=p, output=p)
assert c.has_flow(f)
c_inv, (f_inv,) = c.time_reversed_for_flows([f])
assert c_inv.has_flow(f_inv)

Currently raises an exception instead of succeeding.

Strilanc commented 5 months ago

This ends up being pretty complicated to solve. Because the time reversal flips the order of the feedback and the measurement, it's necessary to push the reversed feedback forward in time so that it occurs after the measurement again. It might be easiest to add flow support to "with_inlined_feedback" and then use that to remove any feedback before time reversing.