1

I have an existing multiprocessing pool that I use for other functions that I'd like to pass to differential_evolution but I can't seem to get the worker input set correctly. Is this possible? The docs say that workers should be

...a map-like callable, such as multiprocessing.Pool.map for evaluating the population in parallel.

I tried:

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'

Thanks.

Tim Jim
  • 620
  • 5
  • 19

1 Answers1

1

For me your second solution is working

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

output

     fun: 0.0
 message: 'Optimization terminated successfully.'
    nfev: 51006
     nit: 679
 success: True
       x: array([1., 1., 1., 1., 1.])

my scipy version is

import scipy
print(scipy.__version__)
1.6.1
Max Pierini
  • 2,027
  • 11
  • 17