Exemplo n.º 1
0
def _paralleleval_dual_getExpandedExpr(args):
    i = args[0]
    nTerms = args[1]
    product = args[2]
    sumOfProducts = args[3]
    print ">> [MT] Evaluating expansion for " + str(i) + " of " + str(
        nTerms) + ", running deep copy."

    expandedSum = pt.Sum([])
    if isinstance(product, pt.Product):
        for term in sumOfProducts.terms:
            if not isinstance(term, pt.Product) or pt.getDualProductAOrder(
                    product, term) <= 6:
                p = pt.Product([product, term])
                p.reduceTree()
                p = p.getExpandedExpr()
                expandedSum.addTerm(p)
    else:
        for term in sumOfProducts.terms:
            p = pt.Product([product, term])
            p.reduceTree()
            p = p.getExpandedExpr()
            expandedSum.addTerm(p)

    expandedSum = expandedSum.getExpandedExpr()
    return expandedSum
Exemplo n.º 2
0
 def tY01():
     Mup = pt.MatrixM( False, "up" )
     Mdn = pt.MatrixM( False, "dn" )
     Dup = pt.MatrixK( "up" )
     Dup.fourierTransform()
     Dup.indices = 0
     Ddn = pt.MatrixK( "dn" )
     Ddn.fourierTransform()
     Ddn.indices = 0
     A = pt.Product( [pt.CoefficientFloat( 1.0 ), pt.TermA(), pt.DetM( Mup ), pt.DetM( Mdn ), Ddn, Dup ] )
     B = pt.Product( [pt.CoefficientFloat( 2.0 ), pt.TermA(), pt.DetM( Mup ), pt.DetM( Mdn ), Dup, Ddn ] )
     C = pt.Sum( [ A, B ] )
     D = pt.combineLikeTerms( C )
     D.simplify()
     return str( D )
Exemplo n.º 3
0
def execParallelCombineLikeTerms(expr, blockSize=BLOCK_SIZE):
    if not isinstance(expr, pt.Sum):
        raise pt.PTSymbolicException(
            "A Sum instance must be passed to parallel combineLikeTerms().")

    procs = mp.Pool(processes=N_PROCS)

    parallelExprs = []
    oneMoreSet = 0
    if not len(expr.terms) % blockSize == 0:
        oneMoreSet = 1

    for i in range(0, int(len(expr.terms) / blockSize) + oneMoreSet):
        parallelExprs.append(
            [i, pt.Sum(expr.terms[i * blockSize:i * blockSize + blockSize])])

    distributedTerms = procs.map(_paralleleval_combineLikeTerms, parallelExprs)
    result = pt.Sum(distributedTerms)
    result.reduceTree()
    result.simplify()

    if blockSize > len(expr.terms):
        return result
    else:
        print ">> Combining like terms with block size of " + str(
            blockSize * 2) + "."
        return execParallelCombineLikeTerms(result, blockSize * 2)

# if blockSize > len( result.terms ) * 30:
#    return result
#else:
#if sameBlockSizeAttempts > 3:
#    print ">> Combining like terms with block size of " + str( blockSize * 2 ) + "."
#    return execParallelCombineLikeTerms( result, blockSize * 2 )
#else:
#    return execParallelCombineLikeTerms( result, len( result.terms ), sameBlockSizeAttempts + 1, blockSize )
Exemplo n.º 4
0
def execParallelDualExpansion(expr1, expr2):
    print ">> [MT] Evaluating " + str(
        len(expr1.terms) * len(expr2.terms)) + " terms in parallel."
    procs = mp.Pool(processes=N_PROCS)
    counter = atomicCounter()

    parallelExprs = []
    for i in range(0, len(expr1.terms)):
        parallelExprs.append(
            [i, len(expr1.terms),
             deepcopy(expr1.terms[i]),
             deepcopy(expr2)])

    expandedTerms = procs.map(_paralleleval_dual_getExpandedExpr,
                              parallelExprs)

    return pt.Sum(expandedTerms)
Exemplo n.º 5
0
def execParallelSumExpansion(expr):
    if not isinstance(expr, pt.Sum):
        raise pt.PTSymbolicException(
            "A Sum instance must be passed to parallel getExpandedExpr() (single)."
        )

    procs = mp.Pool(processes=N_PROCS)

    parallelExprs = []
    for i in range(0, len(expr.terms)):
        parallelExprs.append([i, len(expr.terms), expr.terms[i]])

    distributedTerms = procs.map(_paralleleval_single_getExpandedExpr,
                                 parallelExprs)
    result = pt.Sum(distributedTerms)
    result.reduceTree()
    return result
Exemplo n.º 6
0
 def tY04():
     Mup = pt.MatrixM( False, "up" )
     Mdn = pt.MatrixM( False, "dn" )
     Dup = pt.MatrixK( "up" )
     Dup.fourierTransform()
     Dup.indices = 0
     Ddn = pt.MatrixK( "dn" )
     Ddn.fourierTransform()
     Ddn.indices = 0
     A1 = pt.Product( [pt.CoefficientFloat( 1.0 ), pt.TermA(), pt.DetM( Mup ), pt.DetM( Mdn ), Ddn, Dup ] )
     A2 = pt.Product( [pt.CoefficientFloat( 9.0 ), pt.TermA(), pt.DetM( Mup ), pt.DetM( Mdn ), Dup, Dup ] )
     A3 = pt.Product( [pt.CoefficientFloat( 2.0 ), pt.TermA(), pt.DetM( Mup ), pt.DetM( Mdn ), Dup, Ddn ] )
     A4 = pt.Product( [pt.CoefficientFloat( 5.0 ), pt.TermA(), pt.DetM( Mup ), pt.DetM( Mdn ), Dup, Dup ] )
     D = pt.Sum( [ A3, A2, A4, A1 ] )
     E = pt.combineLikeTerms( D )
     E.simplify()
     return str( E )
Exemplo n.º 7
0
def execParallelTraceDistribution(expr):
    if not isinstance(expr, pt.Sum):
        raise pt.PTSymbolicException(
            "A Sum instance must be passed to parallel distributeAllTraces().")

    print ">> [MT] Evaluating trace distribution and simplification for " + str(
        len(expr.terms)) + "."
    procs = mp.Pool(processes=N_PROCS)

    parallelExprs = []
    for i in range(0, len(expr.terms)):
        parallelExprs.append([i, len(expr.terms), expr.terms[i]])

    distributedTerms = procs.map(_paralleleval_distributeAllTraces,
                                 parallelExprs)
    result = pt.Sum(distributedTerms)
    result.reduceTree()
    return result
Exemplo n.º 8
0
# D8dn = D7dn.derivative()
# D8up.reduceTree()
# D8dn.reduceTree()
# print ">> Expanding..."
# D8up = D8up.getExpandedExpr()
# D8dn = D8dn.getExpandedExpr()
# D8up.reduceTree()
# D8dn.reduceTree()
# print ">> Distributing traces..."
# D8up = pt.distributeAllTraces( D8up )
# D8dn = pt.distributeAllTraces( D8dn )
# D8up.reduceTree()
# D8dn.reduceTree()

print "Rewriting derivatives in KS formalism..."
D1up = pt.rewriteExprInKSFormalism(pt.Sum([D1up]))
D1dn = pt.rewriteExprInKSFormalism(pt.Sum([D1dn]))
D1up.reduceTree()
D1dn.reduceTree()
D2up = pt.rewriteExprInKSFormalism(D2up)
D2dn = pt.rewriteExprInKSFormalism(D2dn)
D2up.reduceTree()
D2dn.reduceTree()
D3up = pt.rewriteExprInKSFormalism(D3up)
D3dn = pt.rewriteExprInKSFormalism(D3dn)
D3up.reduceTree()
D3dn.reduceTree()
D4up = pt.rewriteExprInKSFormalism(D4up)
D4dn = pt.rewriteExprInKSFormalism(D4dn)
D4up.reduceTree()
D4dn.reduceTree()
Exemplo n.º 9
0
 def pA01():
     A = pt.Sum( [GenericTestTerm(0,0), GenericTestTerm(1,0), GenericTestTerm(2,0), GenericTestTerm(3,0)] )
     B = pt.Sum( [GenericTestTerm(4,0), GenericTestTerm(5,0), GenericTestTerm(6,0), GenericTestTerm(7,0)] )
     C = ptmt.execParallelDualExpansion( A, B )
     return str( C )