defrcd(g,ancilla):# Maybe some Check Up here if g is of correct format # Creating GraphG=Graph(g,boundary=ancilla)# Required Matrix and Vector Space, p-list and FieldF=GF(2)p=G.vertices()MS=MatrixSpace(F,G.order())V=VectorSpace(F,G.order())forxinG.get_boundary():p.remove(x)# Creating subspaceSemiSubSpace=V.basis_matrix().matrix_from_rows(p).row_space()SubSpace=SemiSubSpace.direct_sum(SemiSubSpace)# Creating Generator Matrix and Stabilizer Spaceadj=MS(G.adjacency_matrix())Mgenerator=block_matrix([MS.identity_matrix(),adj],ncols=2)Stabilizer=Mgenerator.row_space()# Projection onto spanned subspaceTraceOut=Stabilizer.intersection(SubSpace)returnTraceOut