I want to simulate the error correction procedure for a CNOT gate on surface code and RHG cube, made by the lattice surgery process of "merge and split".

In this case, the code has an H-shape, with four "Z" (smooth) surface boundaries (two in spatial directions and two in the time direction), four "X" (rough) surface boundaries in the time direction, and two "X" (rough) surface boundaries in the spatial direction.

How should I define the logical error chains in this situation? Can I use Pymatching in this situation? How can I verify whether the decoding produced a logical error?


1 Answer 1


There's nothing fundamentally different about getting pymatching to decode lattice surgery instead of memory. Make a stim circuit describing the exact operations that implement the surface codes being merged and split, declaring the measurements compared to get detection events, declaring the logical observables being verified, and including noise instructions. Then use pymatching.Matching.from_stim_circuit to get a decoder, get detection events and observable flips from stim.Circuit.compiled_detector_sampler().sample(separate_observables=True), and feed the detection events into the decoder to get its predictions of the observable flips which you can compare to the actual ones. It's the exact same workflow as a memory experiment, just with more time asymmetry in the circuit.

(In case you're worried you've missed detectors or observables, an easy way to check is to verify circuit.num_detectors + circuit.num_observables == stim.Circuit.count_determined_measurements(). You can also verify that len(circuit.shortest_graphlike_error()) is the expected code distance.)

You can see an example of checking lattice surgery in the code associated with the paper "less bacon more threshold".

  • $\begingroup$ But in merge-split, there are several possible logical error chains, and also the problem of the parity measurement result, as described in arxiv.org/abs/2109.02746. In this paper, they also provide a decoding algorithm with some modifications to the regular algorithm used for surface codes. If this situation is exactly the same, why is this modified algorithm required? $\endgroup$ Aug 7, 2023 at 6:41
  • 1
    $\begingroup$ @YaronJarach Multiple possible logical error chains isn't an issue because the decoder is solving for the physical errors regardless of what boundaries they span between, and you can always recover the correction from the physical errors. The "modifications" made in that paper aren't actually changing the decoding problem, they're just explaining the details of the problem to the decoder. Stim/pymatching do all this stuff automatically if you just give them the circuit annotated with detectors, observables, and noise. Because it's not a fundamentally different problem; it's the same problem. $\endgroup$ Aug 7, 2023 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.