Example #1
0
    def add(self, target, id, *args, **kwargs):
        assert issubclass(target, Module)
        argnames = mpi.getargnames(target.__init__)

        # Selectors must be passed to the module upon instantiation;
        # the module manager must know about them to assess compatibility:
        if not self.validate_args(target):
            raise ValueError('class constructor missing required args')

        # Need to associate an ID and the routing table with each module class
        # to instantiate:
        kwargs['id'] = id
        kwargs['routing_table'] = self.routing_table
        kwargs['rank_to_id'] = self.rank_to_id
        kwargs['pm_all'] = self.pm_all
        rank = super(base_gpu_onesided.Manager,
                     self).add(target, *args, **kwargs)
        self.rank_to_id[rank] = id

        # Save BasePortMapper describing mapping between module interface and
        # integer indices:
        self.pm_all['gpot'][id] = BasePortMapper(
            self._kwargs[rank]['sel_gpot'])
        self.pm_all['spike'][id] = BasePortMapper(
            self._kwargs[rank]['sel_spike'])
Example #2
0
    def validate_args(self, target):
        """
        Check whether a class' constructor has specific arguments.

        Parameters
        ----------
        target : Module
            Module class to instantiate and run.
        
        Returns
        -------
        result : bool
            True if all of the required arguments are present, False otherwise.
        """

        arg_names = set(mpi.getargnames(target.__init__))
        for required_arg in self.required_args:
            if required_arg not in arg_names:
                return False
        return True
Example #3
0
    def validate_args(self, target):
        """
        Check whether a class' constructor has specific arguments.

        Parameters
        ----------
        target : Module
            Module class to instantiate and run.
        
        Returns
        -------
        result : bool
            True if all of the required arguments are present, False otherwise.
        """

        arg_names = set(mpi.getargnames(target.__init__))
        for required_arg in self.required_args:
            if required_arg not in arg_names:
                return False
        return True
Example #4
0
    def add(self, target, id, *args, **kwargs):
        """
        Add a module class to the emulation.

        Parameters
        ----------
        target : Module
            Module class to instantiate and run.
        id : str
            Identifier to use when connecting an instance of this class
            with an instance of some other class added to the emulation.
        args : sequence
            Sequential arguments to pass to the constructor of the class
            associated with identifier `id`.
        kwargs : dict
            Named arguments to pass to the constructor of the class
            associated with identifier `id`.
        """

        if not issubclass(target, Module):
            raise ValueError('target class is not a Module subclass')
        argnames = mpi.getargnames(target.__init__)

        # Selectors must be passed to the module upon instantiation;
        # the module manager must know about them to assess compatibility:
        # XXX: keep this commented out for the time being because it interferes
        # with instantiation of child classes (such as those in LPU.py):
        # if not self.validate_args(target):
        #    raise ValueError('class constructor missing required args')

        # Need to associate an ID and the routing table with each module class
        # to instantiate; because the routing table's can potentially occupy
        # lots of space, we don't add it to the argument dict here - it is
        # broadcast to all processes separately and then added to the argument
        # dict in mpi_backend.py:
        kwargs['id'] = id
        kwargs['rank_to_id'] = self.rank_to_id
        rank = super(Manager, self).add(target, *args, **kwargs)
        self.rank_to_id[rank] = id
Example #5
0
    def add(self, target, id, *args, **kwargs):
        """
        Add a module class to the emulation.

        Parameters
        ----------
        target : Module
            Module class to instantiate and run.
        id : str
            Identifier to use when connecting an instance of this class
            with an instance of some other class added to the emulation.
        args : sequence
            Sequential arguments to pass to the constructor of the class
            associated with identifier `id`.
        kwargs : dict
            Named arguments to pass to the constructor of the class
            associated with identifier `id`.
        """

        if not issubclass(target, Module):
            raise ValueError('target class is not a Module subclass')
        argnames = mpi.getargnames(target.__init__)

        # Selectors must be passed to the module upon instantiation;
        # the module manager must know about them to assess compatibility:
        # XXX: keep this commented out for the time being because it interferes
        # with instantiation of child classes (such as those in LPU.py):
        # if not self.validate_args(target):
        #    raise ValueError('class constructor missing required args')

        # Need to associate an ID and the routing table with each module class
        # to instantiate; because the routing table's can potentially occupy
        # lots of space, we don't add it to the argument dict here - it is
        # broadcast to all processes separately and then added to the argument
        # dict in mpi_backend.py:
        kwargs['id'] = id
        kwargs['rank_to_id'] = self.rank_to_id
        rank = super(Manager, self).add(target, *args, **kwargs)
        self.rank_to_id[rank] = id
Example #6
0
    def add(self, target, id, *args, **kwargs):
        assert issubclass(target, Module)
        argnames = mpi.getargnames(target.__init__)

        # Selectors must be passed to the module upon instantiation;
        # the module manager must know about them to assess compatibility:
        if not self.validate_args(target):
            raise ValueError('class constructor missing required args')

        # Need to associate an ID and the routing table with each module class
        # to instantiate:
        kwargs['id'] = id
        kwargs['routing_table'] = self.routing_table
        kwargs['rank_to_id'] = self.rank_to_id
        kwargs['pm_all'] = self.pm_all
        rank = super(base_gpu_onesided.Manager, self).add(target, *args, **kwargs)
        self.rank_to_id[rank] = id

        # Save BasePortMapper describing mapping between module interface and
        # integer indices:
        self.pm_all['gpot'][id] = BasePortMapper(self._kwargs[rank]['sel_gpot'])
        self.pm_all['spike'][id] = BasePortMapper(self._kwargs[rank]['sel_spike'])