sporco.mpiutil¶
Utility functions that make use of MPI for parallel computing.
Functions
|
Grid search for optimal parameters of a specified function. |
Function Descriptions¶
- sporco.mpiutil.grid_search(fn, grid, comm=None, mpidtype=None, fmin=True)[source]¶
Grid search for optimal parameters of a specified function.
Perform a grid search for optimal parameters of a specified function. In the simplest case the function returns a float value, and a single optimum value and corresponding parameter values are identified. If the function returns a tuple of values, each of these is taken to define a separate function on the search grid, with optimum function values and corresponding parameter values being identified for each of them. The computation of the function at the grid points is computed in parallel using MPI, as opposed to
util.grid_search
, which usesmultiprocessing
for parallelisation.The mpi4py package is required for use of the
mpiutil.grid_search
function. It is also necessary to run Python with thempiexec
command; for example, ifmpiscript.py
calls this function, use:mpiexec -n 8 python mpiscript.pyto distribute the grid search over 8 processors.
- Parameters
- fnfunction
Function to be evaluated. It should take a tuple of parameter values as an argument, and return a float value or a tuple of float values.
- gridtuple of array_like
A tuple providing an array of sample points for each axis of the grid on which the search is to be performed.
- commMPI communicator object, optional (default None)
Topology of network (number of processes and rank). If None,
MPI.COMM_WORLD
is used.- mpidtypeMPI data type, optional (default None)
Desired data type for consolidation operations. If None,
MPI.DOUBLE
is used- fminbool, optional (default True)
Determine whether optimal function values are selected as minima or maxima. If fmin is True then minima are selected.
- Returns
- sprmndarray
Optimal parameter values on each axis. If fn is multi-valued, sprm is a matrix with rows corresponding to parameter values and columns corresponding to function values.
- sfvlfloat or ndarray
Optimum function value or values
- fvmxndarray
Function value(s) on search grid
- sidxtuple of int or tuple of ndarray
Indices of optimal values on parameter grid