Пример #1
0
    def _get_io_info(self):
        """Returns a tuple of (inputs, outputs) where inputs and outputs are
        lists of tuples of the form (name, meta) for each parameter.
        """
        params = []
        if self.parametric_geometry:
            paraminfos = self.parametric_geometry.list_parameters()
            cnames = self._class_names
            inter = []
            for p in paraminfos:
                if p[0] in cnames:
                    inter.append(p[0])
                elif self._eligible(p[0]):
                    params.append(p)
            if inter:
                logger.warning("the following variables already exist in "
                               "GeomComponent and will be ignored: %s" % inter)

        ins = []
        outs = []
        for p in params:
            try:
                io = p[1]['iotype']
            except KeyError:
                raise RuntimeError("parameter %s has no iotype metadata" % p[0])
            if io == 'in':
                ins.append(p)
            elif io == 'out':
                outs.append(p)
            else:
                raise RuntimeError("parameter %s does not have valid iotype metadata (iotype='%s'), must be 'in' or 'out'"
                                   % (p[0], p[1]['iotype']))
        return (ins, outs)
Пример #2
0
def _get_trait_from_meta(name, meta):
    """Create a Variable object based on the contents
    of meta, which contains a 'value', plus possibly
    other information, e.g., 'type'.
    """
    if name == 'geom_out': 
        typ = IStaticGeometry
        return Geom(IStaticGeometry, **meta)
    else: 
        meta = meta.copy()
        val = meta['value']
        try:
            # if 'type' is provided in the metadata, use that
            if 'type' in meta:
                typ = _ttdict[meta['type']]
            else:  # otherwise just infer the Variable type from the value type
                typ = _ttdict[type(val)]
        except KeyError:
            if isinstance(val, list):
                typ = List
            elif isinstance(val, dict):
                typ = Dict
            else:
                logger.warning("no Variable type found for key of type %s (value=%s), using Python Variable type, which performs no validation" % (type(val),val))
                typ = Python   # FIXME
                
        try: 
            del meta['value']  # don't include value in trait metadata
        except KeyError: 
            pass #wasn't in there to delete it
        return typ(val, **meta)
Пример #3
0
def _get_trait_from_meta(name, meta):
    """Create a Variable object based on the contents
    of meta, which contains a 'value', plus possibly
    other information, e.g., 'type'.
    """
    meta = meta.copy()
    val = meta['value']

    try:
        # if 'type' is provided in the metadata, use that
        if 'type' in meta:
            typ = _ttdict[meta['type']]
        else:  # otherwise just infer the Variable type from the value type
            typ = _ttdict[type(val)]
    except KeyError:
        if isinstance(val, list):
            typ = List
        elif isinstance(val, dict):
            typ = Dict
        else:
            logger.warning(
                "no Variable type found for key of type %s (value=%s), using Python Variable type, which performs no validation"
                % (type(val), val))
            typ = Python  # FIXME

    del meta['value']  # don't include value in trait metadata
    return typ(val, **meta)
    def __init__(self, *args, **kwargs):
        """ Deprecated."""

        logger.warning('ComponentwithDerivatives is deprecated. You can ' +
                       'use Component instead.')

        super(ComponentWithDerivatives, self).__init__(*args, **kwargs)
Пример #5
0
    def _get_io_info(self):
        """Returns a tuple of (inputs, outputs) where inputs and outputs are
        lists of tuples of the form (name, meta) for each parameter.
        """
        params = []
        if self.parametric_geometry:
            paraminfos = self.parametric_geometry.list_parameters()
            cnames = self._class_names
            inter = []
            for p in paraminfos:
                if p[0] in cnames:
                    inter.append(p[0])
                elif self._eligible(p[0]):
                    params.append(p)
            if inter:
                logger.warning("the following variables already exist in "
                               "GeomComponent and will be ignored: %s" % inter)

        ins = []
        outs = []
        for p in params:
            try:
                io = p[1]['iotype']
            except KeyError:
                raise RuntimeError("parameter %s has no iotype metadata" %
                                   p[0])
            if io == 'in':
                ins.append(p)
            elif io == 'out':
                outs.append(p)
            else:
                raise RuntimeError(
                    "parameter %s does not have valid iotype metadata (iotype='%s'), must be 'in' or 'out'"
                    % (p[0], p[1]['iotype']))
        return (ins, outs)
 def __init__(self, *args, **kwargs):
     """ Deprecated."""
     
     logger.warning('DriverUsesDerivatives is deprecated. You can '
                    'use Driver instead.')
     
     super(DriverUsesDerivatives, self).__init__(*args, **kwargs)        
 def __init__(self, *args, **kwargs):
     """ Deprecated."""
     
     logger.warning('ComponentwithDerivatives is deprecated. You can ' + 
                     'use Component instead.')
     
     super(ComponentWithDerivatives, self).__init__(*args, **kwargs)
Пример #8
0
    def execfile(self, fname, digest=None):
        # first, make sure file has been imported
        __import__(get_module_path(fname))
        newdigest = file_md5(fname)
        if digest and digest != newdigest:
            logger.warning("file '%s' has been modified since the last time"
                           " it was exec'd" % fname)
        with open(fname) as f:
            contents = f.read()
        node = add_init_monitors(parse(contents, fname, mode='exec'))
        exec compile(node, fname, 'exec') in self._model_globals

        # make the recorded execfile command use the current md5 hash
        self._cmds_to_save.append("execfile('%s', '%s')" % (fname, newdigest))
Пример #9
0
 def _update_io_names(self):
     if self.parametric_geometry:
         params = self.parametric_geometry.listParameters()
         inter = self._class_names.intersection([p[0] for p in params])
         if inter:
             logger.warning("the following variables already exist in "
                            "GeomComponent and will be ignored: %s" % 
                            list(inter))
         params = [p for p in params if self._eligible(p[0]) and 
                                    p[0] not in self._class_names]
         self._input_var_names = set([p[0] for p in params
                                      if p[1]['iotype']=='in'])
         self._output_var_names = set([p[0] for p in params
                                      if p[1]['iotype']=='out'])
     else:
         self._input_var_names = set()
         self._output_var_names = set()