pythonoptimizationscipypython-multiprocessingscipy-optimize

Multiprocessing with SciPy Optimize


Question: Does scipy.optimize have minimizing functions that can divide their workload among multiple processes to save time? If so, where can I find the documentation?

I've looked a fair amount online, including here, for answers:

I could be misunderstanding, but I don't see a clear indication in any of the above posts that the scipy library is informed of the fact that there are multiple processes that it can utilize simultaneously while also providing the minimization functions with all of the arguments needed to determine the minimum.

I also don't see multiprocessing discussed in detail in the scipy docs that I read and I haven't had any luck finding real world examples of optimization gains to justify optimizing versus a parallel brute force effort. Here's a fictional example of what I'd like the scipy.optimize library to do (I know that the differential_evolution function doesn't have a multiprocessing argument):

import multiprocessing as mp
from scipy.optimize import differential_evolution

def objective_function(x):
    return x[0] * 2

pool = mp.Pool(processes=16)

# Perform differential evolution optimization
result = differential_evolution(objective_function, multiprocessing = pool)

Solution

  • With respect to scipy.optimize.differential_evolution, it does seem to offer multiprocessing through multiprocessing.Pool via the optional "workers" call parameter, according to the official documentation at https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.differential_evolution.html#scipy.optimize.differential_evolution

    This may also be offered for other optimization methods but the API documents would need to be examined. The docs also say that the objective function must be pickleable.

    The official docs also have some general remarks on parallel execution with SciPy at https://docs.scipy.org/doc/scipy/tutorial/parallel_execution.html

    The call would look like this for differential_evolution:

    import multiprocessing as mp
    from scipy.optimize import differential_evolution
    
    def objective_function(x):
        return x[0] * 2
    
    my_workers = 16
    
    # Perform differential evolution optimization
    result = differential_evolution(objective_function,  workers = my_workers)