我有一个现有的多处理池,用于我想要传递给differential_evolution的其他函数,但我似乎无法正确地获得工人输入集。这个是可能的吗?文档说workers应该是
类似于...a映射的可调用性,例如用于并行计算人口的multiprocessing.Pool.map。
我试过:
import multiprocessing as mp
from scipy.optimize import rosen, differential_evolution
pool = mp.Pool(2) # existing worker pool
bounds = [(0,2), (0, 2), (0, 2), (0, 2), (0, 2)]
result = differential_evolution(rosen, bounds, updating='deferred', workers=pool)
# TypeError: int() argument must be a string, a bytes-like object or a number, not 'Pool'
result = differential_evolution(rosen, bounds, updating='deferred', workers=pool.map)
# RuntimeError: The map-like callable must be of the form f(func, iterable), returning a sequence of numbers the same length as 'iterable'谢谢。
发布于 2021-04-01 09:55:48
对我来说,你的第二个解决方案是有效的。
import multiprocessing as mp
from scipy.optimize import rosen, differential_evolution
pool = mp.Pool(2) # existing worker pool
bounds = [(0,2), (0, 2), (0, 2), (0, 2), (0, 2)]
result = differential_evolution(rosen, bounds, updating='deferred', workers=pool.map)
result输出
fun: 0.0
message: 'Optimization terminated successfully.'
nfev: 51006
nit: 679
success: True
x: array([1., 1., 1., 1., 1.])我的scipy版本是
import scipy
print(scipy.__version__)
1.6.1https://stackoverflow.com/questions/66899561
复制相似问题