quantumlib / Stim

A fast stabilizer circuit library.
Apache License 2.0
305 stars 88 forks source link

Issue with decoding in distance 2 codes #781

Closed ymuv1 closed 4 weeks ago

ymuv1 commented 1 month ago

Decoding using detector error models may fail in distance 2 codes, with the success rate depending on the order of instructions. For example, the following code is for a distance 2 surface code circuit generated by stim.Circuit.generated("surface_code:rotated_memory_z", rounds=2, distance=2).flattened(), with the addition of 4 depolarizing errors, of which only one has a non-negligible parameter: stim.Circuit(''' QUBIT_COORDS(1, 1) 1 QUBIT_COORDS(2, 0) 2 QUBIT_COORDS(3, 1) 3 QUBIT_COORDS(1, 3) 6 QUBIT_COORDS(2, 2) 7 QUBIT_COORDS(3, 3) 8 QUBIT_COORDS(2, 4) 12 R 1 3 6 8 2 7 12 TICK H 2 12 TICK CX 2 3 8 7 TICK CX 2 1 3 7 TICK CX 12 8 6 7 TICK CX 12 6 1 7 TICK H 2 12 TICK MR 2 7 12 DETECTOR(2, 2, 0) rec[-2] DEPOLARIZE1(8.33323e-08) 1 3 DEPOLARIZE1(0.749983) 6 DEPOLARIZE1(8.33323e-08) 8 TICK H 2 12 TICK CX 2 3 8 7 TICK CX 2 1 3 7 TICK CX 12 8 6 7 TICK CX 12 6 1 7 TICK H 2 12 TICK MR 2 7 12 DETECTOR(2, 0, 1) rec[-3] rec[-6] DETECTOR(2, 2, 1) rec[-2] rec[-5] DETECTOR(2, 4, 1) rec[-1] rec[-4] M 1 3 6 8 DETECTOR(2, 2, 2) rec[-1] rec[-2] rec[-3] rec[-4] rec[-6] OBSERVABLE_INCLUDE(0) rec[-3] rec[-4] ''') This circuit's DEM is: stim.DetectorErrorModel(''' error(5.55549e-08) D1 error(5.55549e-08) D1 D2 L0 error(0.49762) D2 error(0.49762) D2 D3 error(5.55549e-08) D2 L0 error(0.49762) D3 detector(2, 2, 0) D0 detector(2, 0, 1) D1 detector(2, 2, 1) D2 detector(2, 4, 1) D3 detector(2, 2, 2) D4 ''') When sampling the circuit and decoding with the DEM, the success rate is ~50% instead of the expected ~100%. If I change the order of the lines in the DEM such that the high probability instructions come first, I recover the ~100% rate.

Strilanc commented 4 weeks ago

This sounds like a bug in your decoder, not in stim. A detector error model is still correct if you re-order the errors. Probably your decoder is just breaking ties (where the same detection events are associated with multiple different logical syndromes) by setting the logical syndrome to match the first error instead of the most likely error.

I am going to close this issue because I think it's a bug in the decoder. You should report the bug to that decoder's repo. For example, if you're using pymatching, report it to https://github.com/oscarhiggott/pyMatching