我有一个现有的多处理池,可用于我想传递给差分进化的其他功能,但我似乎无法正确设置工作人员输入。这可能吗?文档说workers
应该是
...类似于地图的可调用对象,例如用于并行评估总体的 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'
谢谢。