Exemplo n.º 1
0
 def hz2hx(self, i=0, j=0):
     Lx, Lz, Hx, Tz, Hz, Tx = (
         self.Lx, self.Lz, self.Hx,
         self.Tz, self.Hz, self.Tx)
     opx, opz = Tx[i], Hz[i]
     self.Tx, self.Hz = pop2(Tx, i), pop2(Hz, i)
     self.Hx, self.Tz = insert2(Hx, j, opx), insert2(Tz, j, opz)
     self.mz -= 1
     self.mx += 1
     self.do_check()
Exemplo n.º 2
0
 def hx2hz(self, i=0, j=0):
     Lx, Lz, Hx, Tz, Hz, Tx = (
         self.Lx, self.Lz, self.Hx,
         self.Tz, self.Hz, self.Tx)
     opx, opz = Hx[i], Tz[i]
     self.Hx, self.Tz = pop2(Hx, i), pop2(Tz, i)
     self.Tx, self.Hz = insert2(Tx, j, opx), insert2(Hz, j, opz)
     self.mz += 1
     self.mx -= 1
     self.do_check()
Exemplo n.º 3
0
 def logop2hz(self, i=0, j=0):
     "move the i-th z type logical operator into Hz"
     Lx, Lz, Hx, Tz, Hz, Tx = (
         self.Lx, self.Lz, self.Hx,
         self.Tz, self.Hz, self.Tx)
     lx, lz = Lx[i], Lz[i]
     self.Lx, self.Lz = pop2(Lx, i), pop2(Lz, i)
     self.Tx, self.Hz = insert2(Tx, j, lx), insert2(Hz, j, lz)
     self.k -= 1
     self.mz += 1
     self.do_check()
Exemplo n.º 4
0
def stabweights(U, L, verbose=False):

    U = U.copy()
    L = L.copy()

    # Shorten stabilizers -------------

    n = U.shape[0]
    m = n//2
    Hz, Tz = U[:m], U[m:]
    Tx, Hx = L[:m], L[m:]

#    print shortstrx(Hx, Hz)

    #Lx, Lz = zeros2(0, n), zeros2(0, n)
    #code = CSSCode(Lx, Lz, Hx, Tz, Hz, Tx, build=False)
    #print code
    #print code.weightstr()

    ws = []
    for i in range(m):
        Hz1 = pop2(Hz, i)
        graph = Tanner(Hz1)
        #write("i=%d w=%d "%(i, Lz[i].sum()))
        op = graph.localmin(Hz[i], verbose=verbose)
        if op.sum() < Hz[i].sum():
            Hz[i] = op
            write('.')
        else:
            write(choice('\/'))
        ws.append(op.sum())

    for i in range(m):
        Hx1 = pop2(Hx, i)
        graph = Tanner(Hx1)
        #write("i=%d w=%d "%(i, Lx[i].sum()))
        op = graph.localmin(Hx[i], verbose=verbose)
        if op.sum() < Hx[i].sum():
            Hx[i] = op
            write('.')
        else:
            write(choice('\/'))
        ws.append(op.sum())

#    print ws
#    print shortstrx(Hx, Hz)

    return ws

    code = CSSCode(Lx, Lz, Hx, None, Hz, None, build=False)
    print(code)
    print(code.weightstr())

    return code
Exemplo n.º 5
0
def hpack(n, j=4, k=1, check=True, verbose=False):

    write("hpack...")

    U = identity2(n) # upper triangular
    L = identity2(n) # lower triangular
    I = identity2(n)

    for count in range(j*n):

        i = randint(0, n-1)
        j = randint(0, n-1)
        if i==j:
            continue

        U[i] = (U[i] + U[j])%2
        L[j] = (L[j] - L[i])%2

    assert solve.rank(U) == n
    assert solve.rank(L) == n

    assert eq2(dot2(U, L.transpose()), I)

    if verbose:
        print()
        print(shortstrx(U, L))
        print()

    ws = [n] * n
    ws = stabweights(U, L)

    for i in range(n):
        w = min(U[i].sum(), L[i].sum())
        ws[i] = min(ws[i], w)
    ws = list(enumerate(ws))
    ws.sort(key = lambda item : -item[1])

    idxs = [ws[i][0] for i in range(k)]
    idxs.sort()

    Lx, Lz = zeros2(0, n), zeros2(0, n)

    for idx in reversed(idxs):

        Lz = append2(Lz, U[idx:idx+1])
        Lx = append2(Lx, L[idx:idx+1])
        U = pop2(U, idx)
        L = pop2(L, idx)

    m = (n-k)//2
    Hz, Tz = U[:m], U[m:]
    Tx, Hx = L[:m], L[m:]

    if verbose:
        print()
        print(shortstrx(Hx, Hz))

    write("done.\n")

    code = CSSCode(Lx, Lz, Hx, Tz, Hz, Tx, check=check, verbose=verbose)

    return code