コード例 #1
0
ファイル: parallel.py プロジェクト: mhgharieb/PolyBoRi
def _decode_ring(code):
    import os
    (identifier, data, varnames, blocks) = code

    global _polybori_parallel_rings
    try:
        _polybori_parallel_rings
    except NameError:
        _polybori_parallel_rings = dict()

    for key in [
            key for key in _polybori_parallel_rings
            if not _polybori_parallel_rings[key][0]()
    ]:
        del _polybori_parallel_rings[key]

    if identifier in _polybori_parallel_rings:
        ring = _polybori_parallel_rings[identifier][0]()
    else:
        ring = None

    if not ring:
        varnames = decompress(varnames).split('\n')
        (nvars, ordercode) = data
        ring = Ring(nvars, ordercode, names=varnames, blocks=blocks)
        storage_data = (WeakRingRef(ring), code)
        _polybori_parallel_rings[identifier] = storage_data
        _polybori_parallel_rings[(ring.id(), os.getpid())] = storage_data

    return ring
コード例 #2
0
ファイル: blocks.py プロジェクト: ohanar/PolyBoRi
def main():
    r = Ring(1000)
    ablock = AlternatingBlock(["a", "b", "c"], 100)
    declare_block_scheme([ablock], globals())
    for i in range(10):
        print r.variable(i)

    print list(ablock)
    declare_block_scheme([
    Block(var_name="x", size=100),
    HigherOrderBlock("y", (3, 4, 11, 2)),
    AlternatingBlock(["a", "b", "c"], 100)],
    globals())
    for i in range(10):
        print x(i)
    print y(0, 0, 0, 0)
    print y(0, 0, 0, 1)
    print y(0, 0, 1, 0)
    print y(0, 0, 1, 1)
    print a(0), a(1), a(2), b(0), b(1), c(0)
    declare_block_scheme([
    Block(var_name="x", size=100, reverse=True),
    HigherOrderBlock("y", (3, 4, 11, 2), reverse=True),
    AlternatingBlock(["a", "b", "c"], 100, reverse=True)],
    globals())
    for i in range(10):
        print x(i)
    print y(0, 0, 0, 0)
    print y(0, 0, 0, 1)
    print y(0, 0, 1, 0)
    print y(0, 0, 1, 1)
    print a(0), a(1), a(2), b(0), b(1), c(0)
    declare_block_scheme(["a", "b", "c"], globals())
    print a, b, c
コード例 #3
0
def _decode_ring(code):
    import os
    (identifier, data, varnames, blocks) = code

    global _polybori_parallel_rings
    try:
        _polybori_parallel_rings
    except NameError:
        _polybori_parallel_rings = dict()

    for key in [key for key in _polybori_parallel_rings 
                if not _polybori_parallel_rings[key][0]()]:
        del _polybori_parallel_rings[key]

    if identifier in _polybori_parallel_rings:
        ring = _polybori_parallel_rings[identifier][0]()
    else:
        ring = None

    if not ring:
        varnames = decompress(varnames).split('\n')
        (nvars, ordercode) = data
        ring = Ring(nvars, ordercode, names=varnames, blocks=blocks)
        storage_data = (WeakRingRef(ring), code)
        _polybori_parallel_rings[identifier] = storage_data
        _polybori_parallel_rings[(ring.id(), os.getpid())] = storage_data

    return ring
コード例 #4
0
ファイル: blocks.py プロジェクト: mhgharieb/PolyBoRi
def main():
    r = Ring(1000)
    ablock = AlternatingBlock(["a", "b", "c"], 100)
    declare_block_scheme([ablock], globals())
    for i in range(10):
        print r.variable(i)

    print list(ablock)
    declare_block_scheme([
        Block(var_name="x", size=100),
        HigherOrderBlock("y", (3, 4, 11, 2)),
        AlternatingBlock(["a", "b", "c"], 100)
    ], globals())
    for i in range(10):
        print x(i)
    print y(0, 0, 0, 0)
    print y(0, 0, 0, 1)
    print y(0, 0, 1, 0)
    print y(0, 0, 1, 1)
    print a(0), a(1), a(2), b(0), b(1), c(0)
    declare_block_scheme([
        Block(var_name="x", size=100, reverse=True),
        HigherOrderBlock("y", (3, 4, 11, 2), reverse=True),
        AlternatingBlock(["a", "b", "c"], 100, reverse=True)
    ], globals())
    for i in range(10):
        print x(i)
    print y(0, 0, 0, 0)
    print y(0, 0, 0, 1)
    print y(0, 0, 1, 0)
    print y(0, 0, 1, 1)
    print a(0), a(1), a(2), b(0), b(1), c(0)
    declare_block_scheme(["a", "b", "c"], globals())
    print a, b, c
コード例 #5
0
def main():
    r = Ring(1000)
    x = Variable = VariableFactory(r)
    from os import system
    from polybori.specialsets import all_monomials_of_degree_d, power_set
    full_set = list(power_set([Variable(i) for i in xrange(15)]))
    from random import Random
    generator = Random(123)
    random_set = sum(generator.sample(full_set, 30))
    full_polynomial = list(
        all_monomials_of_degree_d(3, [Variable(i) for i in xrange(30)]))
    random_poly = sum(generator.sample(full_polynomial, 30))
    polynomials = [
        x(1) * x(2) + x(3), (x(1) + 1) * (x(2) + x(3)),
        (x(1) + 1) * (x(2) + 1) * (x(3) + 1),
        x(1) * x(2) + x(2) * x(3) + x(1) * x(3) + x(1),
        x(0) + x(1) + x(2) + x(3) + x(4) + x(5),
        all_monomials_of_degree_d(3, [x(i) for i in xrange(10)]),
        power_set([x(i) for i in xrange(10)]), random_poly, random_set,
        Polynomial(all_monomials_of_degree_d(3, [x(i) for i in xrange(10)])) +
        Polynomial(power_set([x(i) for i in xrange(10)])),
        Polynomial(power_set([x(i) for i in xrange(10)])) + 1
    ]
    for colored in [True, False]:
        if colored:
            colored_suffix = "_colored"
        else:
            colored_suffix = ""
        for format in ["png", "svg"]:
            for (i, p) in enumerate(polynomials):

                #dot_file=str(i) +colored_suffix+".dot"
                #f=open(dot_file, "w")
                #f.write(dot)
                #f.close()
                out_file = str(i) + colored_suffix + "." + format
                plot(p, out_file, colored=colored, format=format)
コード例 #6
0
ファイル: blocks.py プロジェクト: mhgharieb/PolyBoRi
def declare_ring(blocks, context=None):
    """Declare Ring is the preferred function to create a ring and declare a variable scheme,
  the number of variables is automatically determined,
  usually you pass globals() as context argument to store the ring and the variable mapping.
  Example
  declare_ring([Block("x",10),Block("y",5)],globals())
  gives  a ring with x(0..9),y(0..4) and registers the ring as r,
  and the variable blocks x and y in the context dictionary globals(), which consists of the global variables of the python module
  """
    if context is None:
        context = sys.modules['__main__'].__dict__

    def canonicalize(blocks):
        for elt in blocks:
            if isinstance(elt, str):
                yield elt
            else:
                for subelt in elt:
                    yield subelt

    blocks = list(blocks)
    n = 0

    for b in blocks:
        if isinstance(b, str):
            n = n + 1
        else:
            n = n + len(b)

    r = Ring(n, names=canonicalize(blocks))

    context["internalVariable"] = VariableFactory(r)
    #  context["Monomial"] = MonomialFactory(r)
    context["r"] = r
    declare_block_scheme(blocks, context)
    return r