quantumlib / Stim

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

Error while time reversing a chunk #845

Closed AlexBourassa closed 1 month ago

AlexBourassa commented 1 month ago

Here is the chunk I tried to time reverse:

gen.Chunk(
    q2i={2j: 0, (1+1j): 1, (1+3j): 2, (1+5j): 3, (2+2j): 4, (2+4j): 5, (2+6j): 6, (3+1j): 7, (3+3j): 8, (3+5j): 9, (4+0j): 10, (4+2j): 11, (4+4j): 12, (5+1j): 13, (5+3j): 14, (5+5j): 15, (6+2j): 16, (6+4j): 17, (7+1j): 18, (7+3j): 19, (7+5j): 20, (8+0j): 21, (8+2j): 22, (8+4j): 23, (8+6j): 24, (9+1j): 25, (9+3j): 26, (9+5j): 27, (10+2j): 28, (10+4j): 29, (11+1j): 30, (11+3j): 31, (11+5j): 32, (12+4j): 33},
    circuit=stim.Circuit('''
        QUBIT_COORDS(0, 2) 0
        QUBIT_COORDS(1, 1) 1
        QUBIT_COORDS(1, 3) 2
        QUBIT_COORDS(1, 5) 3
        QUBIT_COORDS(2, 2) 4
        QUBIT_COORDS(2, 4) 5
        QUBIT_COORDS(2, 6) 6
        QUBIT_COORDS(3, 1) 7
        QUBIT_COORDS(3, 3) 8
        QUBIT_COORDS(3, 5) 9
        QUBIT_COORDS(4, 0) 10
        QUBIT_COORDS(4, 2) 11
        QUBIT_COORDS(4, 4) 12
        QUBIT_COORDS(5, 1) 13
        QUBIT_COORDS(5, 3) 14
        QUBIT_COORDS(5, 5) 15
        QUBIT_COORDS(6, 2) 16
        QUBIT_COORDS(6, 4) 17
        QUBIT_COORDS(7, 1) 18
        QUBIT_COORDS(7, 3) 19
        QUBIT_COORDS(7, 5) 20
        QUBIT_COORDS(8, 0) 21
        QUBIT_COORDS(8, 2) 22
        QUBIT_COORDS(8, 4) 23
        QUBIT_COORDS(8, 6) 24
        QUBIT_COORDS(9, 1) 25
        QUBIT_COORDS(9, 3) 26
        QUBIT_COORDS(9, 5) 27
        QUBIT_COORDS(10, 2) 28
        QUBIT_COORDS(10, 4) 29
        QUBIT_COORDS(11, 1) 30
        QUBIT_COORDS(11, 3) 31
        QUBIT_COORDS(11, 5) 32
        QUBIT_COORDS(12, 4) 33
        R 0 4 5 6 10 11 12 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
        TICK
        H 18 20 26 30 32
    '''),
    flows=(Flow(start=gen.PauliMap({}), end=gen.PauliMap({2j: 'Z'}), measurement_indices=(), flags=[], obs_key=None, center=2j, sign=None, Flow(start=gen.PauliMap({(1+1j): 'Z', (1+3j): 'X'}), end=gen.PauliMap({2j: 'Z', (1+1j): 'Z', (1+3j): 'X'}), measurement_indices=(), flags=[], obs_key=None, center=2j, sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(2+2j): 'Z'}), measurement_indices=(), flags=[], obs_key=None, center=(2+2j), sign=None, Flow(start=gen.PauliMap({(1+1j): 'X', (1+3j): 'Z', (3+1j): 'Z', (3+3j): 'X'}), end=gen.PauliMap({(1+1j): 'X', (1+3j): 'Z', (2+2j): 'Z', (3+1j): 'Z', (3+3j): 'X'}), measurement_indices=(), flags=[], obs_key=None, center=(2+2j), sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(2+4j): 'Z'}), measurement_indices=(), flags=[], obs_key=None, center=(2+4j), sign=None, Flow(start=gen.PauliMap({(1+3j): 'X', (1+5j): 'Z', (3+3j): 'Z', (3+5j): 'X'}), end=gen.PauliMap({(1+3j): 'X', (1+5j): 'Z', (2+4j): 'Z', (3+3j): 'Z', (3+5j): 'X'}), measurement_indices=(), flags=[], obs_key=None, center=(2+4j), sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(2+6j): 'Z'}), measurement_indices=(), flags=[], obs_key=None, center=(2+6j), sign=None, Flow(start=gen.PauliMap({(1+5j): 'X', (3+5j): 'Z'}), end=gen.PauliMap({(1+5j): 'X', (2+6j): 'Z', (3+5j): 'Z'}), measurement_indices=(), flags=[], obs_key=None, center=(2+6j), sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(4+0j): 'Z'}), measurement_indices=(), flags=[], obs_key=None, center=(4+0j), sign=None, Flow(start=gen.PauliMap({(3+1j): 'Z', (5+1j): 'X'}), end=gen.PauliMap({(3+1j): 'Z', (4+0j): 'Z', (5+1j): 'X'}), measurement_indices=(), flags=[], obs_key=None, center=(4+0j), sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(4+2j): 'Z'}), measurement_indices=(), flags=[], obs_key=None, center=(4+2j), sign=None, Flow(start=gen.PauliMap({(3+1j): 'X', (3+3j): 'Z', (5+1j): 'Z', (5+3j): 'X'}), end=gen.PauliMap({(3+1j): 'X', (3+3j): 'Z', (4+2j): 'Z', (5+1j): 'Z', (5+3j): 'X'}), measurement_indices=(), flags=[], obs_key=None, center=(4+2j), sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(4+4j): 'Z'}), measurement_indices=(), flags=[], obs_key=None, center=(4+4j), sign=None, Flow(start=gen.PauliMap({(3+3j): 'X', (3+5j): 'Z', (5+3j): 'Z', (5+5j): 'X'}), end=gen.PauliMap({(3+3j): 'X', (3+5j): 'Z', (4+4j): 'Z', (5+3j): 'Z', (5+5j): 'X'}), measurement_indices=(), flags=[], obs_key=None, center=(4+4j), sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(6+2j): 'Z'}), measurement_indices=(), flags=[], obs_key=None, center=(6+2j), sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(6+4j): 'Z'}), measurement_indices=(), flags=[], obs_key=None, center=(6+4j), sign=None, Flow(start=gen.PauliMap({(5+3j): 'X', (5+5j): 'Z'}), end=gen.PauliMap({(5+3j): 'X', (5+5j): 'Z', (6+4j): 'Z', (7+3j): 'Z', (7+5j): 'X'}), measurement_indices=(), flags=[], obs_key=None, center=(6+4j), sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(8+0j): 'Z'}), measurement_indices=(), flags=[], obs_key=None, center=(8+0j), sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(7+1j): 'Z', (8+0j): 'Z', (9+1j): 'X'}), measurement_indices=(), flags=[], obs_key=None, center=(8+0j), sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(8+2j): 'Z'}), measurement_indices=(), flags=[], obs_key=None, center=(8+2j), sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(7+1j): 'X', (7+3j): 'Z', (8+2j): 'Z', (9+1j): 'Z', (9+3j): 'X'}), measurement_indices=(), flags=[], obs_key=None, center=(8+2j), sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(8+4j): 'Z'}), measurement_indices=(), flags=[], obs_key=None, center=(8+4j), sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(7+3j): 'X', (7+5j): 'Z', (8+4j): 'Z', (9+3j): 'Z', (9+5j): 'X'}), measurement_indices=(), flags=[], obs_key=None, center=(8+4j), sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(8+6j): 'Z'}), measurement_indices=(), flags=[], obs_key=None, center=(8+6j), sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(7+5j): 'X', (8+6j): 'Z', (9+5j): 'Z'}), measurement_indices=(), flags=[], obs_key=None, center=(8+6j), sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(10+2j): 'Z'}), measurement_indices=(), flags=[], obs_key=None, center=(10+2j), sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(9+1j): 'X', (9+3j): 'Z', (10+2j): 'Z', (11+1j): 'Z', (11+3j): 'X'}), measurement_indices=(), flags=[], obs_key=None, center=(10+2j), sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(10+4j): 'Z'}), measurement_indices=(), flags=[], obs_key=None, center=(10+4j), sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(9+3j): 'X', (9+5j): 'Z', (10+4j): 'Z', (11+3j): 'Z', (11+5j): 'X'}), measurement_indices=(), flags=[], obs_key=None, center=(10+4j), sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(12+4j): 'Z'}), measurement_indices=(), flags=[], obs_key=None, center=(12+4j), sign=None, Flow(start=gen.PauliMap({}), end=gen.PauliMap({(11+3j): 'X', (11+5j): 'Z', (12+4j): 'Z'}), measurement_indices=(), flags=[], obs_key=None, center=(12+4j), sign=None, Flow(start=gen.PauliMap({(1+3j): 'X', (3+3j): 'Z', (5+3j): 'X'}), end=gen.PauliMap({(1+3j): 'X', (3+3j): 'Z', (5+3j): 'X', (7+3j): 'Z', (7+5j): 'X'}), measurement_indices=(), flags=[], obs_key='obs(red)', center=None, sign=None, Flow(start=gen.PauliMap({(3+1j): 'Z', (3+3j): 'X', (3+5j): 'Z'}), end=gen.PauliMap({(3+1j): 'Z', (3+3j): 'X', (3+5j): 'Z'}), measurement_indices=(), flags=[], obs_key='obs(blue)', center=None, sign=None),
    discarded_outputs=(gen.PauliMap({(5+1j): 'X', (5+3j): 'Z', (6+2j): 'Z', (7+1j): 'Z', (7+3j): 'X'}),),
)

And this is the error I got:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[1025], line 1
----> 1 c.time_reversed()

File ~/pyle/src/pyle/util/gen/_chunk/_chunk.py:597, in Chunk.time_reversed(self)
    593         out[self.q2i[q]] = p
    594     stim_flows.append(
    595         stim.Flow(input=inp, output=out, measurements=flow.measurement_indices)
    596     )
--> 597 rev_circuit, rev_flows = self.circuit.time_reversed_for_flows(stim_flows)
    598 nm = rev_circuit.num_measurements
    599 return Chunk(
    600     circuit=rev_circuit,
    601     q2i=self.q2i,
   (...)
    614     discarded_outputs=self.discarded_inputs,
    615 )

ValueError: While running backwards through the circuit, during reverse-execution of the instruction
    R 0 4 5 6 10 11 12 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
the following detecting region vs dissipation anticommutations occurred
    L30 vs stim.target_x(32)
Therefore invalid detectors/observables are present in the circuit.
Strilanc commented 1 month ago

Wrong place to report this @AlexBourassa .