quantumlib/Stim

Fix time_reversed_for_flows handling feedback incorrectly

Opened this issue · 1 comments

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.

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.