I am trying to do MWPM with pymatching for a rotated surface code with distance $L$, but I can't figure out how to initialize the Matching object in a simple way. I only want a single round of decoding. For $L=3$, I have 9 qubits with the following numbering scheme (X marks the checkerboard square acted on by the X stabilizers)
0 --- 1 --- 2
| X | | X
3 --- 4 --- 5
X | | X |
6 --- 7 --- 8
Following the tutorial provided for the toric code, I generate a CSS-style parity check matrix for these stabilizers:
[[1 1 0 1 1 0 0 0 0]
[0 0 0 0 1 1 0 1 1]
[0 0 1 0 0 1 0 0 0]
[0 0 0 1 0 0 1 0 0]]
And then generate an example error and try to decode using pymatching:
matching = Matching(Hx)
noise = np.array([0, 0, 0, 1, 0, 0, 0, 0, 0]) # Z error on qubit '3'
s = Hx @ noise % 2 # correctly evaluates to [1, 0, 0, 1]
c = matching.decode(s) # predicts [0, 0, 0, 0, 0, 0, 0, 0, 0]
The prediction (regardless of what logical operators I use) doesn't see the error. As far as I can tell, pymatching is generating a graph that is mishandling the boundaries of the code. What did I do wrong, and what is the correct way to set up MWPM with pymatching for this rotated surface code?
Also I would appreciate any additional tutorial material for pymatching - without stim preferably :) I don't want/need to model circuit-level behavior or ancillary qubits.
