Beispiel #1
0
def glue_self(Hx, Hz, pairs):
    mx, n = Hx.shape
    mz, _ = Hz.shape
    k = len(pairs)

    A = Chain([Hz, Hx.transpose()])
    C = Chain([identity2(k), zeros2(k, 0)])

    fn = zeros2(n, k)
    for idx, pair in enumerate(pairs):
        i1, i2 = pair
        fn[i1, idx] = 1
    fm = dot2(Hz, fn)
    f = Morphism(C, A, [fm, fn, zeros2(mx, 0)])

    gn = zeros2(n, k)
    for idx, pair in enumerate(pairs):
        i1, i2 = pair
        gn[i2, idx] = 1
    gm = dot2(Hz, gn)
    g = Morphism(C, A, [gm, gn, zeros2(mx, 0)])

    _, _, D = chain.equalizer(f, g)

    Hz, Hxt = D[0], D[1]
    return Hxt.transpose(), Hz
Beispiel #2
0
def glue_self_classical(Hz, pairs):
    mz, n = Hz.shape
    k = len(pairs)

    A = Chain([Hz])
    C = Chain([identity2(k)])

    fn = zeros2(n, k)
    for idx, pair in enumerate(pairs):
        i1, i2 = pair
        fn[i1, idx] = 1
    fm = dot2(Hz, fn)
    f = Morphism(C, A, [fm, fn])

    gn = zeros2(n, k)
    for idx, pair in enumerate(pairs):
        i1, i2 = pair
        gn[i2, idx] = 1
    gm = dot2(Hz, gn)
    g = Morphism(C, A, [gm, gn])

    _, _, D = chain.equalizer(f, g)

    Hz = D[0]
    return Hz
Beispiel #3
0
    def glue(self, i1, i2):
        assert i1!=i2

        Hx = self.Hx
        Hz = self.Hz
        mx, n = Hx.shape
        mz, _ = Hz.shape
        k = 1 
    
        A = Chain([Hz, Hx.transpose()])
        C  = Chain([identity2(k), zeros2(k, 0)])
    
        fn = zeros2(n, 1)
        fn[i1, 0] = 1 
        fm = dot2(Hz, fn) 
        f = Morphism(C, A, [fm, fn, zeros2(mx, 0)])
    
        gn = zeros2(n, 1)
        gn[i2, 0] = 1 
        gm = dot2(Hz, gn) 
        g = Morphism(C, A, [gm, gn, zeros2(mx, 0)])
    
        _, _, D = equalizer(f, g)
    
        Hz, Hxt = D[0], D[1]
        Hx = Hxt.transpose()
        code = CSSCode(Hx=Hx, Hz=Hz)
        return code
Beispiel #4
0
def test_equalizer():

    n = 4
    m = n - 1
    H = zeros2(m, n)
    for i in range(m):
        H[i, i] = 1
        H[i, i + 1] = 1

    A = Chain([H])
    C = Chain([array2([[1]])])

    fm = zeros2(m, 1)
    fm[m - 1, 0] = 1
    fn = zeros2(n, 1)
    fn[n - 1, 0] = 1
    f = Morphism(C, A, [fm, fn])

    gm = zeros2(m, 1)
    gm[0, 0] = 1
    gn = zeros2(n, 1)
    gn[0, 0] = 1
    g = Morphism(C, A, [gm, gn])

    AD, BD, D = chain.equalizer(f, g)
    assert eq2(D[0], array2([[1, 1, 1], [0, 1,
                                         1]]))  # glue two checks at a bit

    # --------------------------

    A = Chain([H.transpose()])
    C = Chain([zeros2(1, 0)])

    fn = zeros2(n, 1)
    fn[0, 0] = 1
    fm = zeros2(m, 0)
    f = Morphism(C, A, [fn, fm])

    gn = zeros2(n, 1)
    gn[n - 1, 0] = 1
    gm = zeros2(m, 0)
    g = Morphism(C, A, [gn, gm])

    AD, BD, D = chain.equalizer(f, g)
    D = D[0]
    #print(D)
    assert eq2(D, array2([[1, 0, 1], [1, 1, 0], [0, 1, 1]]))  # glue two bits
Beispiel #5
0
def glue1(H, i1, i2):

    m, n = H.shape

    A = Chain([H])
    C = Chain([array2([[1]])])

    fn = zeros2(n, 1)
    fn[i1, 0] = 1
    fm = dot2(H, fn)
    f = Morphism(C, A, [fm, fn])

    gn = zeros2(n, 1)
    gn[i2, 0] = 1
    gm = dot2(H, gn)
    g = Morphism(C, A, [gm, gn])

    _, _, D = chain.equalizer(f, g)

    H = D[0]
    #print(H.shape)
    #print(H)
    return H
Beispiel #6
0
def glue1_quantum(Hx, Hz, i1, i2):
    assert i1 != i2

    mx, n = Hx.shape
    mz, _ = Hz.shape
    k = 1

    A = Chain([Hz, Hx.transpose()])
    C = Chain([identity2(k), zeros2(k, 0)])

    fn = zeros2(n, 1)
    fn[i1, 0] = 1
    fm = dot2(Hz, fn)
    f = Morphism(C, A, [fm, fn, zeros2(mx, 0)])

    gn = zeros2(n, 1)
    gn[i2, 0] = 1
    gm = dot2(Hz, gn)
    g = Morphism(C, A, [gm, gn, zeros2(mx, 0)])

    _, _, D = chain.equalizer(f, g)

    Hz, Hxt = D[0], D[1]
    return Hxt.transpose(), Hz