# Pymatching Toric Code vs Surface Code

I am looking the example of toric code in Pymatching.

Here is the code:

 import numpy as np
import matplotlib.pyplot as plt
from scipy.sparse import hstack, kron, eye, csr_matrix, block_diag

def repetition_code(n):

row_ind, col_ind = zip(*((i, j) for i in range(n) for j in (i, (i+1)%n)))
data = np.ones(2*n, dtype=np.uint8)
return csr_matrix((data, (row_ind, col_ind)))

def toric_code_x_stabilisers(L):
Hr = repetition_code(L)
H = hstack(
[kron(Hr, eye(Hr.shape)), kron(eye(Hr.shape), Hr.T)],
dtype=np.uint8
)
H.data = H.data % 2
H.eliminate_zeros()
return csr_matrix(H)

def toric_code_x_logicals(L):

H1 = csr_matrix((, (,)), shape=(1,L), dtype=np.uint8)
H0 = csr_matrix(np.ones((1, L), dtype=np.uint8))
x_logicals = block_diag([kron(H1, H0), kron(H0, H1)])
x_logicals.data = x_logicals.data % 2
x_logicals.eliminate_zeros()
return csr_matrix(x_logicals)

1. I want to test minumum weight perfect matching in Pymatching. I want to run this code in the absence of noise and I want to see what will be the result of pymatching. To do that, I use the following :

H=toric_code_x_stabilisers(4)

matching = pymatching.Matching(H)

matching.draw()

Is that correct? I see nothing, is it because I have no error in the system or is it because there is some issue with matching.draw() function? Then I tried the following code scripts:

 H=toric_code_x_stabilisers(4)
noise = np.array([0,0,0,0]) #no error
z = H@noise % 2
m=Matching(H)
print(m)
m.draw()
c = m.decode(z)


And I got the dimension mismatch error..

1. I want to simulate surface code in the absence of error. It is simply I will initialize my data qubits in zero states and I will use x and z stabilizer. I will measure the stabilizers and I will see the result. For example, when I measure the X stabilizer, they will commute with Z stabilizer etc.. In that case, I am not sure what should change in toric code to make it surface code. It seemed to me that, toric_code_x_stabilisers can stay same. Do we have a small example for surface code?

H=toric_code_x_stabilisers(3)