API

class multipoint.multiPointSparse.multiPointSparse(gcomm)[source]

Create the multiPoint class on the provided comm.

Parameters
gcommMPI.Intracomm

Global MPI communicator from which all processor groups are created. It is usually MPI_COMM_WORLD but may be another intraCommunicator that has already been created.

Notes

multiPointSparse requires useGroups=True (default) when creating the optProb (Optimization instance).

Examples

We will setup a multipoint problem with two procSets: a ‘cruise’ set with 3 members and 32 procs each, and a maneuver set with two members with 10 and 20 procs respectively. Our script will have to define 5 python functions:

  1. Evaluate functions for cruise:

    def cruiseObj(x):
        funcs = {} # Fill up with functions
        ...
        return funcs
    
  2. Evaluate functions for maneuver:

    def maneuverObj(x):
        funcs = {} # Fill up with functions
        ...
        return funcs
    
  3. Evaluate function sensitivity for cruise:

    def cruiseSens(x, funcs):
        funcSens = {}
        ...
        return funcSens
    
  4. Evaluate function sensitivity for cruise:

    def maneuverSens(x, funcs):
         funcSens = {}
         ...
         return funcSens
    
  5. Function to compute addition functions:

    def objCon(funcs):
         funcs['new_func'] = combination_of_funcs
         ...
         return funcs
    
>>> MP = multiPointSparse.multiPoint(MPI.COMM_WORLD)
>>> MP.addProcessorSet('cruise', 3, 32)
>>> MP.addProcessorSet('maneuver', 2, [10, 20])
>>> # Possibly create directories
>>> ptDirs = MP.createDirectories('/home/user/output/')
>>> # Get the communicators and flags
>>> comm, setComm, setFlags, groupFlags, ptID = MP.createCommunicators()
>>> # Setup problems and python functions
>>> ....
>>> MP.setProcSetObjFunc('cruise', cruiseObj)
>>> MP.setProcSetObjFunc('maneuver', maneuverObj)
>>> MP.setProcSetSensFunc('cruise', cruiseSens)
>>> MP.setProcSetSensFunc('maneuver', maneuverSens)
>>> MP.setObjCon(objCon)
>>> # Create optimization problem using MP.obj
>>> optProb = Optimization('opt', MP.obj)
>>> # Setup optimization problem
>>> # MP needs the optProb after everything is setup.
>>> MP.setOptProb(optProb)
>>> # Create optimizer and use MP.sens for the sensitivity function on opt call
>>> snopt(optProb, sens=MP.sens, ...)
addConsAsObjConInputs(cons)[source]

This function allows functions to be used both as constraints, as well as inputs to the ObjCon, therefore no longer bypassed.

Parameters
consstring or list of strings

The constraint names the user wants to use as ObjCon inputs

addDVsAsFunctions(dvs)[source]

This function allows you to specify a list of design variables to be explicitly used as functions. Essentially, we just copy the values of the DVs directly into keys in ‘funcs’ and automatically generate an identity Jacobian. This allows the remainder of the objective/sensitivity computations to be proceed as per usual.

Parameters
dvsstring or list of strings

The DV names the user wants to use directly as functions

addProcSetObjFunc(setName, func)[source]

Add an additional python function handle to compute the functionals

Parameters
setNamestr

Name of set we are setting the function for

funcPython function

Python function handle

addProcSetSensFunc(setName, func)[source]

Add an additional python function handle to compute the derivative of the functionals

Parameters
setNamestr

Name of set we are setting the function for

funcPython function

Python function handle

addProcessorSet(setName, nMembers, memberSizes)[source]

A Processor set is defined as one or more groups of processors that use the same obj() and sens() routines. Members of processor sets typically, but not necessarily, return the same number of functions. In all cases, the function names must be unique.

Parameters
setNamestr

Name of process set. Process set names must be unique.

nMembersint

Number of members in the set.

memberSizesint, iteratable

Number of processors on each set. If an integer is supplied all members use the same number of processors. If a list or array is provided, a different number of processors on each member can be specified.

Examples

>>> MP = multiPointSparse.multiPoint(MPI.COMM_WORLD)
>>> MP.addProcessorSet('cruise', 3, 32)
>>> MP.addProcessorSet('maneuver', 2, [10, 20])

The cruise set creates 3 processor groups, each of size 32. and the maneuver set creates 2 processor groups, of size 10 and 20.

createCommunicators()[source]

Create the communicators after all the procSets have been added. All procSets MUST be added before this routine is called.

Returns
commMPI.Intracomm

This is the communicator for the member of the procSet. Basically, this is the communicator that the (parallel) analysis should be created on.

setCommMPI.Intracomm

This is the communicator that spans the entire processor set.

setFlagsdict

This is a dictionary whose entry for setName, as specified in addProcessorSet() is True on a processor belonging to that set.

groupFlagslist

This list is used to distinguish between members within a processor set. This list of of length nMembers and the ith entry is true for the ith group.

ptIDint

This is the index of the group that this processor belongs to.

Examples

>>> MP = multiPointSparse.multiPoint(MPI.COMM_WORLD)
>>> MP.addProcessorSet('cruise', 3, 32)
>>> MP.addProcessorSet('maneuver', 2, [10, 20])
>>> comm, setComm, setFlags, groupFlags, ptID = MP.createCommunicators()

The following will be true for all processors for the second member of the cruise procSet.

>>> setFlags['cruise'] and groupFlags[1] == True
createDirectories(rootDir)[source]

This function can be called only after all the procSets have been added. This can facilitate distinguishing output files when there are a large number of procSets and/or members of procSets.

Parameters
rootDirstr

Root path where directories are to be created

Returns
ptDirsdict

A dictionary of all the created directories. Each dictionary entry has key defined by ‘setName’ and contains a list of size nMembers, each entry of which is the path to the created directory

Examples

>>> MP = multiPointSparse.multiPoint(MPI.COMM_WORLD)
>>> MP.addProcessorSet('cruise', 3, 32)
>>> MP.addProcessorSet('maneuver', 2, [10, 20])
>>> ptDirs = MP.createDirectories('/home/user/output/')
>>> ptDirs
{'cruise': ['/home/user/output/cruise_0',
            '/home/user/output/cruise_1',
            '/home/user/output/cruise_2'],
 'maneuver': ['/home/user/output/maneuver_0',
              '/home/user/output/maneuver_1']}
getSetName()[source]

After MP.createCommunicators is call, this routine may be called to return the name of the set that this processor belongs to. This may result in slightly cleaner script code.

Returns
setNamestr

The name of the set that this processor belongs to.

obj(x)[source]

This is a built-in objective function that is designed to be used directly as an objective function with pyOptSparse. The user should not use this function directly, instead see the class documentation for the intended usage.

Parameters
xdict

Dictionary of variables returned from pyOptSparse

sens(x, funcs)[source]

This is a built-in sensitivity function that is designed to be used directly as a the sensitivity function with pyOptSparse. The user should not use this function directly, instead see the class documentation for the intended usage.

Parameters
xdict

Dictionary of variables returned from pyOptSparse

setObjCon(func)[source]

Set the python function handle to compute the final objective and constraints that are combinations of the functionals.

Parameters
funcPython function

Python function handle

setOptProb(optProb)[source]

Set the optimization problem that this multiPoint object will be used for. This is required for this class to know how to assemble the gradients. If the optProb is not ‘finished’, it will done so here. Therefore, this function is collective on the comm that optProb is built on. multiPoint sparse does not hold a reference to optProb so no additional changes can be made to optProb after this function is called.

Parameters
optProbpyOptSparse optimization problem class

The optProb object to use

setProcSetObjFunc(setName, func)[source]

Set a single python function handle to compute the functionals

Parameters
setNamestr

Name of set we are setting the function for

funcPython function

Python function handle

setProcSetSensFunc(setName, func)[source]

Set the python function handle to compute the derivative of the functionals

Parameters
setNamestr

Name of set we are setting the function for

funcPython function

Python function handle