Example: Swapping Components

This example uses a Calculation component to evaluate points in a simple design space, beneath a process component root component, which is to be used to explore that design space. The model has several preconfigured process components using various exploration techniques (DOE, Monte Carlo, Optimization, SDI), each set as a “surrogate” to a Task component (which merely serves as a neutral starting configuration). The model uses the file DynamicSpring.zmf.

  1. Right-click the Task component.

  2. Point to the Change To option. The process components are listed.



    The root component contains a string input parameter, called Selection, that has the names of the surrogate process components (together with the initial value SELECT) as its set of allowed values. You customize the model by selecting a process component name from this set of values. The model customization script gets the process component name from the parameter Selection, finds the process component in the root’s surrogate list, and swaps the Task with that process component.

    # CHOOSE A PRECONFIGURED PROCESS COMPONENT:
    #   The root Task component of this model has four preconfigured 
    surrogate
    #   process components: DOE, MonteCarlo, Optimization, and SDI. 
    To run this            #   model from the Gateway, start a job 
    using the 'Configure and Run Model' menu
    #   option and select the name of the process component you wish 
    to use from 
    #  the allowed values of the root parameter 'Selection'. This
    #  script will find the chosen process component from the 
    #  surrogate list and replace the root Task with that process
    #  component;the job will then run the revised model.
    
    # [Note: Some debugging log messages have been left in the script 
    for illustration]
    
    newRootName = 
    data.getScalar("Selection").getValueObj().getAsString()
    log.logDebug("Selected driver is: " + newRootName)
    root = model.getRootComponent()
    log.logDebug("Current driver is: " + root.getName())
    
    surrList = root.getSurrogateList()
    for i in xrange(surrList.size()):
        surr = surrList.get(i)
        surrName = surr.getName()
        log.logDebug("  Surrogate: " + surrName)
        if newRootName == surrName:
            log.logDebug("  --> Changing to selected driver")
            model.getModelProperties().setModelName("Dynamic " + 
    surrName)
            DtUtils.changeComponent(root,surr,1,0)
            break
    else:
        # If no surrogate driver is selected, do not permit the model 
    to be run:
        raise ValueError, "Unable to find: " + newRootName
    

    So, for example, if you select Configure and Run Model for model execution, set the string parameter value to the Monte Carlo name (Spring Monte Carlo), and click OK, the customized model and its job results will appear as shown below in the Runtime Gateway: