Esempio n. 1
0
def outputExprToLatexFormat( expr ):
    if not isinstance( expr, pt.Sum ):
        raise pt.PTSymbolicException( "Expression passed to outputExprToLatexFormat() must be an instance of a fully-distributed Sum." )
    
    s = ""
    for term in expr.terms:
        if not isinstance( term, pt.Product ):
            raise pt.PTSymbolicException( "Each term in the Sum passed to outputExprToLatexFormat() must be a single Product." )
        
        line = ""
        AOrder = 0
        for factor in term.terms:
            if isinstance( factor, pt.TermA ):
                AOrder += 1
            elif isinstance( factor, pt.MatrixK ):
                line += " D" + str( factor.flavorLabel ) + "," + str( factor.indices[0] ) + "," + str( factor.indices[1] ) + "} "
            elif isinstance( factor, pt.FourierSum ):
                line += "{F,"
                for index in factor.indices:
                    line += str( index[0] ) + "," + str( index[1] ) + ","
                line = line[:-1] + "} "  # Remove the trailing comma on the last index.
            elif isinstance( factor, pt.CoefficientFloat ):
                line += "{C," + str( factor.eval() ) + "} "
            
        s += "{A," + str( AOrder ) + "} " + line + '\n'
    
    return s
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
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 )