Пример #1
0
 def comm_count(self):
     r"""int: The number of comms."""
     out = 0
     for k in self.cleanup_comm_classes:
         cls = get_comm_class(k)
         out += cls.comm_count()
     return out
Пример #2
0
 def _init_single_comm(self, name, io, comm_kws, **kwargs):
     r"""Parse keyword arguments for input/output comm."""
     self.debug("Creating %s comm", io)
     s = get_schema()
     if comm_kws is None:
         comm_kws = dict()
     if io == 'input':
         direction = 'recv'
         comm_type = self._icomm_type
         touches_model = self._is_output
         attr_comm = 'icomm'
         comm_kws['close_on_eof_recv'] = False
     else:
         direction = 'send'
         comm_type = self._ocomm_type
         touches_model = self._is_input
         attr_comm = 'ocomm'
     comm_kws['direction'] = direction
     comm_kws['dont_open'] = True
     comm_kws['reverse_names'] = True
     comm_kws.setdefault('comm', {'comm': comm_type})
     assert (name == self.name)
     comm_kws.setdefault('name', name)
     if not isinstance(comm_kws['comm'], list):
         comm_kws['comm'] = [comm_kws['comm']]
     for i, x in enumerate(comm_kws['comm']):
         if x is None:
             comm_kws['comm'][i] = dict()
         elif not isinstance(x, dict):
             comm_kws['comm'][i] = dict(comm=x)
         comm_kws['comm'][i].setdefault('comm', comm_type)
     any_files = False
     all_files = True
     if not touches_model:
         comm_kws['no_suffix'] = True
         ikws = []
         for x in comm_kws['comm']:
             if get_comm_class(x['comm']).is_file:
                 any_files = True
                 ikws += s['file'].get_subtype_properties(x['comm'])
             else:
                 all_files = False
                 ikws += s['comm'].get_subtype_properties(x['comm'])
         ikws = list(set(ikws))
         for k in ikws:
             if (k not in comm_kws) and (k in kwargs):
                 comm_kws[k] = kwargs.pop(k)
         if ('comm_env' in kwargs) and ('comm_env' not in comm_kws):
             comm_kws['env'] = kwargs.pop('comm_env')
     if any_files and (io == 'input'):
         kwargs.setdefault('timeout_send_1st', 60)
     self.debug('%s comm_kws:\n%s', attr_comm, self.pprint(comm_kws, 1))
     setattr(self, attr_comm, new_comm(comm_kws.pop('name'), **comm_kws))
     setattr(self, '%s_kws' % attr_comm, comm_kws)
     if touches_model:
         self.env.update(getattr(self, attr_comm).opp_comms)
     elif not all_files:
         self.comm_env.update(getattr(self, attr_comm).opp_comms)
     return kwargs
Пример #3
0
    def is_installed(cls, language=None):
        r"""Determine if the necessary libraries are installed for this
        communication class.

        Args:
            language (str, optional): Specific language that should be checked
                for compatibility. Defaults to None and all languages supported
                on the current platform will be checked.

        Returns:
            bool: Is the comm installed.

        """
        return get_comm_class().is_installed(language=language)
Пример #4
0
    def new_comm_kwargs(cls, name, request_comm=None, **kwargs):
        r"""Initialize communication with new comms.

        Args:
            name (str): Name for new comm.
            request_comm (str, optional): Name of class for new output comm.
                Defaults to None.

        """
        args = [name]
        ocomm_class = get_comm_class(request_comm)
        kwargs['direction'] = 'send'
        if 'address' not in kwargs:
            oargs, kwargs = ocomm_class.new_comm_kwargs(name, **kwargs)
        kwargs['request_comm'] = request_comm
        return args, kwargs
Пример #5
0
def is_comm_installed(comm, language=None):
    r"""Check to see if yggdrasil can use a communication mechanism on the
    current machine.

    Args:
        comm (str): Communication mechanism to check.
        language (str, optional): Specific programming language that
            communication mechanism should be check for. Defaults to None and
            all supported languages will be checked.

    Returns:
        bool: True if the communication mechanism can be used on the current
            machine, False otherwise.

    """
    from yggdrasil import communication
    cmm = communication.get_comm_class(comm)
    return cmm.is_installed(language=language)
Пример #6
0
def ErrorComm(name, base_comm='CommBase', **kwargs):  # pragma: debug
    r"""Wrapper to return errored version of a comm class.

    Args:
        name (str): The environment variable where communication address is
            stored.
        base_comm (str, optional): Name of the base comm that should be used.
            Defaults to 'CommBase'.
        **kwargs: Additional keyword arguments are passed to the class
            constructor.

    Returns:
        ErrorClass: Instance of a comm class that will raise an error at the
            requested locaiton.

    """
    base_class = get_comm_class(base_comm)
    out = ErrorClass(base_class, name, **kwargs)
    if base_comm is None:
        base_comm = str(base_class).split("'")[1].split(".")[-1]
    out._comm_class = base_comm
    return out
Пример #7
0
 def new_comm_kwargs(cls, name, *args, **kwargs):
     r"""Get keyword arguments for new comm."""
     if 'address' not in kwargs:
         addresses = []
         comm = kwargs.get('comm', None)
         ncomm = kwargs.pop('ncomm', 0)
         if comm is None:
             comm = [None for i in range(ncomm)]
         assert (isinstance(comm, list))
         ncomm = len(comm)
         for i in range(ncomm):
             x = comm[i]
             if x is None:
                 x = {}
             iname = x.pop('name', get_comm_name(name, i))
             icls = get_comm_class(x.get('comm', None))
             _, ickw = icls.new_comm_kwargs(iname, **x)
             ickw['name'] = iname
             comm[i] = ickw
             addresses.append(ickw['address'])
         kwargs['comm'] = comm
         kwargs['address'] = addresses
     args = tuple([name] + list(args))
     return args, kwargs
 def ocomm_import_cls(self):
     r"""class: Class used for connection output comm."""
     return get_comm_class(self.ocomm_name)
Пример #9
0
 def comm_count(cls):
     r"""int: Number of communication connections."""
     return get_comm_class().comm_count()
Пример #10
0
 def underlying_comm_class(self):
     r"""str: Name of underlying communication class."""
     return get_comm_class().underlying_comm_class()