1
$\begingroup$

Here is the toric code example which I found from :https://pymatching.readthedocs.io/en/latest/toric-code-example.html

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):
    """
    Sparse check matrix for the X stabilisers of a toric code with
    lattice size L, constructed as the hypergraph product of
    two repetition codes.
    """
    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)
    

My problem is I want to switch this code to the surface code but I do not know how. I do not want to use STIM. In surface code, we have x and z stabilizers. I will add also a Z stabilizer function. This is fine but I do not know what will be different in this code to make it a surface code. It seemed to me X stabilizers can stay same. Probably I should change something(which can be boundaries) in the repetition code function, but I do not know how.

Can someone explain to me what I should change and how? Thanks

$\endgroup$
2
  • $\begingroup$ I'm curious; what made you say that stim isn't allowed? $\endgroup$ Oct 26, 2022 at 6:39
  • $\begingroup$ because you wrote a great library so when I asked this question, everyone answers me "use STIM" but I am not working with clifford circuits so I can't use STIM. Also I wonder how to switch this code without using STIM. $\endgroup$
    – quest
    Oct 26, 2022 at 7:09

2 Answers 2

1
$\begingroup$

The code sniplet in your question constructs the toric code as a hypergraph product (HGP) code using the non full-rank matrix of the repetition code : this is an $n \times n$ matrix with rank $n-1$. If you remove one of the rows (say the last one) then you have a full rank $n-1 \times n$ matrix. If you substitute this matrix for $Hr$ in the toric code routine, you'll get a surface code instead of toric code. This paper https://arxiv.org/abs/1202.0928 has the details : examples 5 and 6 on page 4.

$\endgroup$
1
  • $\begingroup$ thanks, I will try that $\endgroup$
    – quest
    Oct 27, 2022 at 6:11
1
$\begingroup$

It's almost always the case that it's easier to make the donut version of a code, rather than the planar version, because the planar version needs boundaries whereas the donut version can be all bulk.

The way that I create codes with periodic boundaries is usually by overlapping coordinates. So, for example, to make a circular repetition code, I would create a "normal" repetition code over qubits 1 to 11, but then "surprise!" qubit 11 is actually the same qubit as qubit 1.

To make a toric code from a surface code I would take the surface code, cut off the crust where all the weird bits are, then attach the left/right cuts and top/bottom cuts to each other. If you're doing it with some sort of check matrix, this would correspond to deleting the rows and columns corresponding to things at the sides, then merging certain columns (or was it rows? I can never keep that straight) to stitch the sides to each other.

$\endgroup$
1
  • $\begingroup$ thanks for the answer ! $\endgroup$
    – quest
    Oct 27, 2022 at 6:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.