Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_pp():
from pathos.pools import ParallelPool as PPP
pool = PPP(servers=('localhost:5653','localhost:2414'))
res = timed_pool(pool, items, delay, verbose)
assert res == std
def test_with_pp():
from pathos.pools import ParallelPool
run_with_multipool(ParallelPool)
def main(servers,ncpus):
from mystic.solvers import DifferentialEvolutionSolver2
#from pathos.pools import ProcessPool as Pool
from pathos.pools import ParallelPool as Pool
solver = DifferentialEvolutionSolver2(ND, NP)
solver.SetMapper(Pool().map)
solver.SetRandomInitialPoints(min = [-100.0]*ND, max = [100.0]*ND)
solver.SetEvaluationLimits(generations=MAX_GENERATIONS)
solver.SetGenerationMonitor(VerboseMonitor(30))
solver.enable_signal_handler()
strategy = Best1Exp
#strategy = Best1Bin
solver.SelectServers(servers,ncpus)
solver.Solve(ChebyshevCost, termination=VTR(0.01), strategy=strategy, \
CrossProbability=1.0, ScalingFactor=0.9 , \
sigint_callback=plot_solution)
solution = solver.Solution()
return solution
#!/usr/bin/env python
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 1997-2016 California Institute of Technology.
# Copyright (c) 2016-2020 The Uncertainty Quantification Foundation.
# License: 3-clause BSD. The full license text is available at:
# - https://github.com/uqfoundation/pathos/blob/master/LICENSE
"""
example of using the 'raw' distributed parallel mapper
To run: python pp_map.py
"""
from pathos.pools import ParallelPool as Pool
pool = Pool()
if __name__ == '__main__':
def add(x, y, z):
"""Add three values"""
return x + y + z
def busybeaver(x):
"""This can take a while"""
for num in range(1000000):
x = x + num
return x
# Immediate evaluation example
import time
start = time.time()
if __name__ == '__main__':
x = list(range(500))
delay = 0.01
maxtries = 200
f = busy_add
#f = busy_squared
#f = squared
#from pathos.pools import ProcessPool as Pool
#from pathos.pools import ThreadPool as Pool
from pathos.pools import ParallelPool as Pool
#from pathos.helpers import freeze_support, shutdown
#freeze_support()
pool = Pool(nodes=4)
test_ready( pool, f, maxtries, delay )
# shutdown
pool.close()
pool.join()
pool.clear()
random_seed(123)
#stepmon = VerboseMonitor(100)
stepmon = Monitor()
evalmon = Monitor()
ndim = len(lb) # [(1 + RVend) - RVstart] + 1
solver = DifferentialEvolutionSolver2(ndim,npop)
solver.SetRandomInitialPoints(min=lb,max=ub)
solver.SetStrictRanges(min=lb,max=ub)
solver.SetEvaluationLimits(maxiter,maxfun)
solver.SetEvaluationMonitor(evalmon)
solver.SetGenerationMonitor(stepmon)
solver.SetMapper(Pool().map)
tol = convergence_tol
solver.Solve(cost,termination=CRT(tol,tol),strategy=Best1Exp, \
CrossProbability=crossover,ScalingFactor=percent_change)
print("solved: %s" % solver.bestSolution)
scale = 1.0
diameter_squared = -solver.bestEnergy / scale #XXX: scale != 0
func_evals = solver.evaluations
return diameter_squared, func_evals
def main():
from mystic.solvers import DifferentialEvolutionSolver2
#from pathos.pools import ProcessPool as Pool
from pathos.pools import ParallelPool as Pool
solver = DifferentialEvolutionSolver2(ND, NP)
solver.SetMapper(Pool().map)
solver.SetRandomInitialPoints(min = [-100.0]*ND, max = [100.0]*ND)
solver.SetEvaluationLimits(generations=MAX_GENERATIONS)
solver.SetGenerationMonitor(VerboseMonitor(30))
solver.enable_signal_handler()
strategy = Best1Exp
#strategy = Best1Bin
solver.Solve(ChebyshevCost, termination=VTR(0.01), strategy=strategy, \
CrossProbability=1.0, ScalingFactor=0.9 , \
sigint_callback=plot_solution)
solution = solver.Solution()
return solution
y = MpiPool(nodes).map(sin_diff, x, xp)
print("Output: %s\n" % np.asarray(y))
# map sin_diff to the workers, then print to screen
print("Running multiprocesing on %d processors..." % nodes)
y = ProcessPool(nodes).map(sin_diff, x, xp)
print("Output: %s\n" % np.asarray(y))
# map sin_diff to the workers, then print to screen
print("Running multiprocesing on %d threads..." % nodes)
y = ThreadPool(nodes).map(sin_diff, x, xp)
print("Output: %s\n" % np.asarray(y))
# map sin_diff to the workers, then print to screen
print("Running parallelpython on %d cpus..." % nodes)
y = ParallelPool(nodes).map(sin_diff, x, xp)
print("Output: %s\n" % np.asarray(y))
# ensure all pools shutdown
shutdown()
y = MpiPool(nodes).map(sin2, x)
print("Output: %s\n" % np.asarray(y))
# map sin2 to the workers, then print to screen
print("Running multiprocesing on %d processors..." % nodes)
y = ProcessPool(nodes).map(sin2, x)
print("Output: %s\n" % np.asarray(y))
# map sin2 to the workers, then print to screen
print("Running multiprocesing on %d threads..." % nodes)
y = ThreadPool(nodes).map(sin2, x)
print("Output: %s\n" % np.asarray(y))
# map sin2 to the workers, then print to screen
print("Running parallelpython on %d cpus..." % nodes)
y = ParallelPool(nodes).map(sin2, x)
print("Output: %s\n" % np.asarray(y))
# ensure all pools shutdown
shutdown()