Ejemplo n.º 1
0
Archivo: glue.py Proyecto: punkdit/qupy
def test_universal():

    for trial in range(100):

        m, n = 3, 4
        J = rand2(m, n)
        K = rand2(m, n)

        a = Chain([J])
        b = Chain([K])
        amorph = a.from_zero()
        bmorph = b.from_zero()

        am, bm, c, u = chain.pushout(amorph, bmorph)
        assert u is None

        C = c[0]
        mm, nn = C.shape

        f = rand_full_rank(nn - 2, nn)
        g, H, _ = solve.pushout(C, f)

        _c = Chain([H])
        m = Morphism(c, _c, [g, f])
        assert m * am is not None
        assert m * bm is not None

        _, _, _, u = chain.pushout(amorph, bmorph, m * am, m * bm, _c)
        assert u is not None
        assert u == m
Ejemplo n.º 2
0
Archivo: glue.py Proyecto: punkdit/qupy
def test_colimit():

    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])
    B = Chain([zeros2(0, 0)])
    C = Chain([array2([[1]])])

    CAm = zeros2(m, 1)
    CAm[0, 0] = 1
    CAm[m - 1, 0] = 1
    CAn = zeros2(n, 1)
    CAn[0, 0] = 1
    CAn[n - 1, 0] = 1
    CA = Morphism(C, A, [CAm, CAn])

    CBm = zeros2(0, 1)
    CBn = zeros2(0, 1)
    CB = Morphism(C, B, [CBm, CBn])

    AD, BD, D, _ = chain.pushout(CA, CB)
    assert eq2(D[0], array2([[1, 1, 1], [0, 1,
                                         1]]))  # glue two checks at a bit

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

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

    CAn = zeros2(n, 1)
    CAn[0, 0] = 1
    CAn[n - 1, 0] = 1
    CAm = zeros2(m, 0)
    CA = Morphism(C, A, [CAn, CAm])

    CBn = zeros2(0, 1)
    CBm = zeros2(0, 0)
    CB = Morphism(C, B, [CBn, CBm])

    AD, BD, D, _ = chain.pushout(CA, CB)
    D = D[0]
    #print(D)
    assert eq2(D, array2([[1, 0, 1], [1, 1, 0], [0, 1, 1]]))  # glue two bits
Ejemplo n.º 3
0
Archivo: glue.py Proyecto: punkdit/qupy
def glue_quantum(Hx1, Hz1, Hx2, Hz2, pairs):

    mx1, n1 = Hx1.shape
    mx2, n2 = Hx2.shape
    mz1, _ = Hz1.shape
    mz2, _ = Hz2.shape
    k = len(pairs)

    A1 = Chain([Hz1, Hx1.transpose()])
    A2 = Chain([Hz2, Hx2.transpose()])
    C = Chain([identity2(k), zeros2(k, 0)])

    C1n = zeros2(n1, k)
    for idx, pair in enumerate(pairs):
        i, j = pair
        C1n[i, idx] = 1
    C1m = dot2(Hz1, C1n)
    C1 = Morphism(C, A1, [C1m, C1n, zeros2(mx1, 0)])

    C2n = zeros2(n2, k)
    for idx, pair in enumerate(pairs):
        i, j = pair
        C2n[j, idx] = 1
    C2m = dot2(Hz2, C2n)
    C2 = Morphism(C, A2, [C2m, C2n, zeros2(mx2, 0)])

    AD, BD, D, _ = chain.pushout(C1, C2)

    Hz, Hxt = D[0], D[1]
    #print(H.shape)
    #print(H)

    return Hz, Hxt.transpose()
Ejemplo n.º 4
0
Archivo: glue.py Proyecto: punkdit/qupy
def glue_pairs(H1, H2, pairs):

    m1, n1 = H1.shape
    m2, n2 = H2.shape
    k = len(pairs)

    A1 = Chain([H1])
    A2 = Chain([H2])
    C = Chain([identity2(k)])

    C1n = zeros2(n1, k)
    for idx, pair in enumerate(pairs):
        i, j = pair
        C1n[i, idx] = 1
    C1m = dot2(H1, C1n)
    C1 = Morphism(C, A1, [C1m, C1n])

    C2n = zeros2(n2, k)
    for idx, pair in enumerate(pairs):
        i, j = pair
        C2n[j, idx] = 1
    C2m = dot2(H2, C2n)
    C2 = Morphism(C, A2, [C2m, C2n])

    AD, BD, D, _ = chain.pushout(C1, C2)

    H = D[0]
    #print(H.shape)
    #print(H)
    return H
Ejemplo n.º 5
0
Archivo: glue.py Proyecto: punkdit/qupy
def test_glue():

    m = argv.get("m", 9)
    n = argv.get("n", 10)

    d = argv.get("d", 0)
    p = argv.get("p", 0.5)
    weight = argv.weight

    H1 = rand2(m, n, p, weight)
    G1 = find_kernel(H1)
    G1t = G1.transpose()
    H1t = H1.transpose()
    A1 = Chain([G1, H1t])
    k1 = len(G1)

    print("H1")
    print(fstr(H1))
    print()
    print(fstr(G1))

    w = wenum(H1)
    print("wenum:", [len(wi) for wi in w])

    H2 = rand2(m, n, p, weight)
    H2t = H2.transpose()
    G2 = find_kernel(H2)
    G2t = G2.transpose()
    A2 = Chain([G2, H2t])
    k2 = len(G2)

    print("H2")
    print(fstr(H2))
    print()
    print(fstr(G2))

    w = wenum(H2)
    print("wenum:", [len(wi) for wi in w])

    if k1 != k2:
        return
    k = k1

    I = identity2(k)
    B = Chain([I, zeros2(k, 0)])

    a = zeros2(n, k)
    for i in range(k):
        a[i, i] = 1
    f1 = Morphism(B, A1, [dot2(G1, a), a, zeros2(m, 0)])
    f2 = Morphism(B, A2, [dot2(G2, a), a, zeros2(m, 0)])

    a, b, C, _ = chain.pushout(f1, f2)

    H = C[1].transpose()
    print("H:")
    print(fstr(H))

    w = wenum(H)
    print("wenum:", [len(wi) for wi in w])
Ejemplo n.º 6
0
Archivo: glue.py Proyecto: punkdit/qupy
def glue2(H1, H2, i1, i2):

    m1, n1 = H1.shape
    m2, n2 = H2.shape

    A1 = Chain([H1])
    A2 = Chain([H2])
    C = Chain([array2([[1]])])

    C1n = zeros2(n1, 1)
    C1n[i1, 0] = 1
    C1m = dot2(H1, C1n)
    C1 = Morphism(C, A1, [C1m, C1n])

    C2n = zeros2(n2, 1)
    C2n[i2, 0] = 1
    C2m = dot2(H2, C2n)
    C2 = Morphism(C, A2, [C2m, C2n])

    AD, BD, D, _ = chain.pushout(C1, C2)

    H = D[0]
    #print(H.shape)
    #print(H)
    return H
Ejemplo n.º 7
0
Archivo: glue.py Proyecto: punkdit/qupy
def test_selfdual():

    HxA = array2([[1, 1, 1, 1]])
    HzA = array2([[1, 1, 1, 1]])
    A = Chain([HxA, HzA.transpose()])

    HxB = array2([[1, 1, 1, 1]])
    HzB = array2([[1, 1, 1, 1]])
    B = Chain([HxB, HzB.transpose()])

    HzC = zeros2(0, 2)
    HxC = array2([[1, 1]])
    C = Chain([HxC, HzC.transpose()])

    #HzC = zeros2(0, 2)
    #HxC = zeros2(0, 2)
    #C = Chain([HxC, HzC.transpose()])

    # Chain map from C -> A
    CAz = zeros2(1, 0)
    CAn = zeros2(4, 2)
    CAn[0, 0] = 1
    CAn[1, 1] = 1
    CAx = array2([[1]])
    CA = Morphism(C, A, [CAx, CAn, CAz])

    # Chain map from C -> B
    CBz = CAz
    CBn = CAn
    CBx = CAx
    CB = Morphism(C, B, [CBx, CBn, CBz])

    AD, BD, D, _ = chain.pushout(CA, CB)
    code = D.get_code()
Ejemplo n.º 8
0
Archivo: glue.py Proyecto: punkdit/qupy
def test_color():

    HxA = array2([[1, 1, 0, 0], [1, 0, 1, 0], [1, 1, 1, 1]])
    HzA = array2([[1, 1, 1, 1]])
    A = Chain([HxA, HzA.transpose()])

    HxB = HxA
    HzB = HzA
    B = Chain([HxB, HzB.transpose()])

    HzC = zeros2(0, 2)
    HxC = array2([[1, 0], [0, 1]])
    C = Chain([HxC, HzC.transpose()])

    # Chain map from C -> A
    CAz = zeros2(1, 0)
    CAn = zeros2(4, 2)
    CAn[0, 0] = 1
    CAn[1, 1] = 1
    CAx = dot2(HxA, CAn)
    #print(CAx)
    CA = Morphism(C, A, [CAx, CAn, CAz])

    # Chain map from C -> B
    CBz = CAz
    CBn = CAn
    CBx = CAx
    CB = Morphism(C, B, [CBx, CBn, CBz])

    AD, BD, D, _ = chain.pushout(CA, CB)
    code = D.get_code()
    print(code)
    print("A --> D")
    print(fstr(AD[0]))
    print("-----------")
    print(fstr(AD[1]))
    print("B --> D")
    print(fstr(BD[0]))
    print("-----------")
    print(fstr(BD[1]))
    print("Hx:")
    print(fstr(code.Hx))
Ejemplo n.º 9
0
Archivo: glue.py Proyecto: punkdit/qupy
def test():

    HxA = array2([[1, 1, 1, 0, 0], [0, 0, 1, 1, 1]])
    HzA = array2([[1, 0, 1, 1, 0], [0, 1, 1, 0, 1]])
    A = Chain([HxA, HzA.transpose()])

    HxB = array2([[1, 1, 1, 0, 0], [0, 0, 1, 1, 1]])
    HzB = array2([[1, 0, 1, 1, 0], [0, 1, 1, 0, 1]])
    B = Chain([HxB, HzB.transpose()])

    HzC = zeros2(0, 2)
    HxC = array2([[1, 1]])
    C = Chain([HxC, HzC.transpose()])

    # Chain map from C -> A
    CAz = array2(shape=(2, 0))
    CAn = array2([[0, 0], [0, 0], [0, 0], [1, 0], [0, 1]])
    CAx = array2([[0], [1]])
    CA = Morphism(C, A, [CAx, CAn, CAz])

    # Chain map from C -> B
    CBz = CAz
    CBn = CAn
    CBx = CAx
    CB = Morphism(C, B, [CBx, CBn, CBz])

    AD, BD, D, _ = chain.pushout(CA, CB)
    code = D.get_code()
    assert code.mx == 3
    assert code.mz == 4
    assert code.k == 1

    #print(code.longstr())

    # Chain map from C -> D
    CDz = zeros2(4, 0)
    CDn = zeros2(8, 2)
    CDn[4, 0] = 1
    CDn[3, 1] = 1
    CDx = zeros2(3, 1)
    CDx[1, 0] = 1
    CD = Morphism(C, D, [CDx, CDn, CDz])

    _, _, E, _ = chain.pushout(CA, CD)
    code = E.get_code()
    #print(code.longstr())

    return

    #dual = code.dual()
    #print(css.lookup_distance(code))
    print("Hz:")
    print(code.Hz)
    print("Hx:")
    print(code.Hx)
    print("Lx:")
    print(code.Lx)
    print()

    #H = numpy.concatenate((code.Lx, code.Hx))
    u = code.Lx
    H = code.Hx
    #print(H)
    d = H.shape[1]
    for v in image(H.transpose()):
        v = (u + v) % 2
        d = min(d, v.sum()) or d
        if v.sum() == 4:
            print(v)
    print("distance:", d)