Consider the decoding of noisy syndrome using pymatching (as shown here) for the repetition code. The logical operator in this case is simply identity matrix. One could write the python code as
def repetition_stabilisers(N):
check_matrix = np.zeros((N-1, N), dtype=int)
for i in range(N-1):
check_matrix[i, i] = 1
check_matrix[i, i+1] = 1
return check_matrix
def x_logicals(L):
return np.eye(L,dtype = int) # np.ones((1,L),dtype = int)
L = 10
repetitions = L
H = repetition_stabilisers(L)
logicals = x_logicals(L)
num_stabilisers, num_qubits = H.shape
num_errors = 0
for i in range(num_shots):
noise_new = (np.random.rand(num_qubits, repetitions) < p).astype(np.uint8)
noise_cumulative = (np.cumsum(noise_new, 1) % 2).astype(np.uint8)
noise_total = noise_cumulative[:,-1]
syndrome = H@noise_cumulative % 2
syndrome_error = (np.random.rand(num_stabilisers, repetitions) < q).astype(np.uint8)
syndrome_error[:,-1] = 0 # Perfect measurements in last round to ensure even parity
noisy_syndrome = (syndrome + syndrome_error) % 2
# Convert to difference syndrome
noisy_syndrome[:,1:] = (noisy_syndrome[:,1:] - noisy_syndrome[:,0:-1]) % 2
predicted_logicals_flipped = matching.decode(noisy_syndrome)
actual_logicals_flipped = noise_total@logicals.T % 2
if not np.array_equal(predicted_logicals_flipped, actual_logicals_flipped):
num_errors += 1
Interestingly, if you consider the cases where it fails, I found that the predicted logical flipped are exactly logical NOT of correct logical flipped. Is there any particular reason for this?