Exemplo n.º 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
Exemplo n.º 2
0
 def _init_comms(self, name, icomm_kws=None, ocomm_kws=None, **kwargs):
     r"""Parse keyword arguments for input/output comms."""
     if icomm_kws is None:
         icomm_kws = dict()
     if ocomm_kws is None:
         ocomm_kws = dict()
     # Input communicator
     self.debug("Creating input comm")
     icomm_kws['direction'] = 'recv'
     icomm_kws['dont_open'] = True
     icomm_kws['reverse_names'] = True
     icomm_kws['close_on_eof_recv'] = False
     icomm_kws.setdefault('comm', self._icomm_type)
     icomm_kws.setdefault('name', name)
     if self._is_input:
         ikws = get_comm_class(icomm_kws['comm'])._schema
         for k in ikws:
             if (k not in icomm_kws) and (k in kwargs):
                 icomm_kws[k] = kwargs[k]
     self.icomm = new_comm(icomm_kws.pop('name'), **icomm_kws)
     self.icomm_kws = icomm_kws
     self.env.update(**self.icomm.opp_comms)
     # Output communicator
     self.debug("Creating output comm")
     ocomm_kws['direction'] = 'send'
     ocomm_kws['dont_open'] = True
     ocomm_kws['reverse_names'] = True
     ocomm_kws.setdefault('comm', self._ocomm_type)
     ocomm_kws.setdefault('name', name)
     if self._is_output:
         okws = get_comm_class(ocomm_kws['comm'])._schema
         for k in okws:
             if (k not in ocomm_kws) and (k in kwargs):
                 ocomm_kws[k] = kwargs[k]
     try:
         self.ocomm = new_comm(ocomm_kws.pop('name'), **ocomm_kws)
     except BaseException:
         self.icomm.close()
         raise
     self.ocomm_kws = ocomm_kws
     self.env.update(**self.ocomm.opp_comms)
Exemplo n.º 3
0
    def opp_comm_kwargs(self):
        r"""Get keyword arguments to initialize communication with opposite
        comm object.

        Returns:
            dict: Keyword arguments for opposite comm object.

        """
        kwargs = super(ServerComm, self).opp_comm_kwargs()
        kwargs['comm'] = get_comm_class("ClientComm")
        kwargs['request_comm'] = self.icomm.comm_class
        kwargs['response_kwargs'] = self.response_kwargs
        return kwargs
Exemplo n.º 4
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)
Exemplo n.º 5
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 input comm.
                Defaults to None.

        """
        args = [name]
        icomm_class = get_comm_class(request_comm)
        kwargs['direction'] = 'recv'
        if 'address' not in kwargs:
            iargs, kwargs = icomm_class.new_comm_kwargs(name, **kwargs)
        kwargs['request_comm'] = request_comm
        return args, kwargs
Exemplo n.º 6
0
def is_comm_installed(comm, language=None):
    r"""Check to see if cis_interface 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 cis_interface import communication
    cmm = communication.get_comm_class(comm)
    return cmm.is_installed(language=language)
Exemplo n.º 7
0
def ErrorComm(name, base_comm='CommBase', **kwargs):
    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
Exemplo n.º 8
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
Exemplo n.º 9
0
 def comm_count(cls):
     r"""int: Number of communication connections."""
     return get_comm_class().comm_count()
Exemplo n.º 10
0
 def underlying_comm_class(self):
     r"""str: Name of underlying communication class."""
     return get_comm_class().underlying_comm_class()
Exemplo n.º 11
0
    def new_comm_kwargs(cls,
                        name,
                        address=None,
                        icomm_name=None,
                        ocomm_name=None,
                        icomm_comm=None,
                        ocomm_comm=None,
                        icomm_kwargs=None,
                        ocomm_kwargs=None,
                        **kwargs):
        r"""Initialize communication with new comms.

        Args:
            name (str): Name for new comm.
            address (str, optional): Communication info. Default to None and
                address is taken from combination of input/output comm addresses
                that are provided or generated.
            icomm_name (str, optional): Name for new input comm. Defaults to
                name + '_IN'. This will be overriden if 'name' is in
                icomm_kwargs.
            ocomm_name (str, optional): Name for new output comm. Defaults to
                name + '_OUT'. This will be overriden if 'name' is in
                ocomm_kwargs.
            icomm_comm (str, optional): Name of class for new input comm.
                Defaults to None. This will be overrriden if 'comm' is in
                icomm_kwargs.
            ocomm_comm (str, optional): Name of class for new output comm.
                Defaults to None. This will be overrriden if 'comm' is in
                ocomm_kwargs.
            icomm_kwargs (dict, optional): Keyword arguments for the icomm_comm
                new_comm_kwargs class method.
            ocomm_kwargs (dict, optional): Keyword arguments for the ocomm_comm
                new_comm_kwargs class method.

        """
        args = [name]
        if icomm_kwargs is None:
            icomm_kwargs = dict()
        if ocomm_kwargs is None:
            ocomm_kwargs = dict()
        if icomm_name is None:
            icomm_name = name
        if ocomm_name is None:
            ocomm_name = name
        icomm_name = icomm_kwargs.pop('name', icomm_name)
        ocomm_name = ocomm_kwargs.pop('name', ocomm_name)
        icomm_comm = icomm_kwargs.pop('comm', icomm_comm)
        ocomm_comm = ocomm_kwargs.pop('comm', ocomm_comm)
        icomm_class = get_comm_class(icomm_comm)
        ocomm_class = get_comm_class(ocomm_comm)
        icomm_kwargs['direction'] = 'recv'
        ocomm_kwargs['direction'] = 'send'
        ikwargs = copy.deepcopy(kwargs)
        okwargs = copy.deepcopy(kwargs)
        ikwargs.update(**icomm_kwargs)
        okwargs.update(**ocomm_kwargs)
        if address is None:
            if 'address' not in icomm_kwargs:
                iargs, ikwargs = icomm_class.new_comm_kwargs(
                    icomm_name, **icomm_kwargs)
            if 'address' not in ocomm_kwargs:
                oargs, okwargs = ocomm_class.new_comm_kwargs(
                    ocomm_name, **ocomm_kwargs)
        else:
            kwargs['address'] = address
            ikwargs['address'], okwargs['address'] = address.split(
                _rpc_address_split)
        ikwargs['name'] = icomm_name
        okwargs['name'] = ocomm_name
        ikwargs['comm'] = icomm_comm
        okwargs['comm'] = ocomm_comm
        kwargs['icomm_kwargs'] = ikwargs
        kwargs['ocomm_kwargs'] = okwargs
        return args, kwargs
Exemplo n.º 12
0
 def is_installed(cls):
     r"""bool: Is the comm installed."""
     return get_comm_class().is_installed()