mango.optimize.DistributedMetricEvaluator

class mango.optimize.DistributedMetricEvaluator(funcObj, comm=<mpi4py.MPI.Intracomm object at 0x7f72206bdb70>, root=0)

Wrapper class for functions which are evaluated by combining (MPI-reducing) a result from each MPI process. See also the distributed_minimize() function.

Example:

import mango.mpi
import mango.optimize
import scipy as sp
import scipy.optimize

def my_func(x):
   return (mango.mpi.world.Get_rank()+1) * (x * x + x + 1)

# dfunc sums/reduces (rank+1)*(x*x + x + 1) from all processes to the dfunc.root process
dfunc = mango.optimize.DistributedMetricEvaluator(my_func) 

if (dfunc.comm.Get_rank() == dfunc.root):
    x0 = 8
    res = scipy.optimize.minimize(dfunc, x0, method="Powell")
    dfunc.rootTerminate()
    print("res.x = %s, res.fun = %s" % (res.x, res.fun))
else:
    dfunc.waitForEvaluate()

Methods

__init__(funcObj[, comm, root])
calcReduction(localVal) Converts the local result localVal returned from the evaluate() method to a MPI-reduced result.
evaluate(x) Evaluate the function at x on the local MPI process.
rootEvaluate(x) Broadcasts x to all processes and then does local evaluation (self.evaluate(x)).
rootTerminate() Issues a (self.TERMINATE,x) broadcast so other processes exit the waitForEvaluate() loop.
waitForEvaluate() Loops waiting for an self.EVALUATE broadcast of the x parameter from the self.root-rank process.

Attributes

EVALUATE Instruction to evaluate local MPI function value, see waitForEvaluate()
TERMINATE Instruction to terminate the wait-loop in waitForEvaluate()

Previous topic

mango.optimize.distributed_minimize

Next topic

mango.optimize.DistributedMetricEvaluator.__init__

This Page