1
$\begingroup$

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[1])), kron(eye(Hr.shape[0]), 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(([1], ([0],[0])), 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?
$\endgroup$

1 Answer 1

0
$\begingroup$

Here is the working code example:

H=toric_code_x_stabilisers(3)
noise = np.array([0,0,0,0]) #no error
z = H@noise % 2
m=Matching(H)
print(m)
m.draw()
#c = m.decode(z)#since there is no error, no decoding too. I simply closed the line
$\endgroup$

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.