# Pymatching, Parity Check Matrix with Syndrome Measurements and Detection Events

I am running distance 3 surface code with 3 rounds:

Here is the parity check matrix of X stabilizers for distance three surface code:

 H_d3x = csr_matrix(np.array([
[1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1]
]))


My syndrome measurements are as follows:

Round = 0, X syndromes are: (1, 1, 1, 0, 1, 0, )
Round = 1, X syndromes are: (0, 0, 1, 0, 0, 0, )
Round = 2, X syndromes are: (1, 1, 0, 1, 1, 0, )


So the detection events at the end of the third round is: detection_events = [0,0,1,1,0,0] (because at the end of the all rounds, syndrome 1,2,5 and 6 stayed same so they did not get affected by errors so detection is 0. However, syndrome3 and 4 changed) Now in Pymatching: I can simply say:

m3x = Matching(H_d3x)


But then, for decoding errors, should I say

xdecode = list(reversed(m3x.decode(detection_events)))


?

or should I say

xdecode = list(reversed(m3x.decode(Xsyndromes)))


?

I assume that I should put detection events in decode fucntion. However, I see some codes in github, they used syndrome measurements directly so I wanted to double check here

So the detection events at the end of the third round is: detection_events = [0,0,1,1,0,0]

How are you defining your detectors here? If you define your detectors as the parity of subsequent measurements of the same stabilizer, the detection events at the end of the last round for your measured syndromes are: $$[1,1,1,1,1,0]$$

What do you mean with the following?:

syndrome 1,2,5 and 6 stayed same

If you only want to decode one round what you say here is correct:

Now in Pymatching: I can simply say: m3x = Matching(H_d3x)

If you want to decode one round the input to the decoder is the syndromes. If you want to decode multiple rounds you have to input detection events.

• Hey, thanks for the answer! I defined detectors according to the initial and final rounds result. For example, first stabilizer measurement outcome initially 1 and in the second round it became 0. This means that an error occured. But then in the last round it is measured as 1 so the error disappeared and the the stabilizer in the initial and final round was same, this is why no error came to the final round and the detector shows 0. However, if you think detector between each rounds then you are right. Here question is if I should look for each round or look between initial and final rounds? Feb 5, 2023 at 23:21
• It doesn't necessarily mean the error disappeared, a measurement can be flipped due to a measurement error. If you want to use PyMatching you have to define detectors such that they compare closest-in-time measurements. Feb 6, 2023 at 9:01