コード例 #1
0
 def __init__(self, n_boards, config):
     self._ip_addresses = config.get("Machine", "machineName")
     self._bmp_details = config.get("Machine", "bmp_names")
     self._width = 8
     self._height = 8
     if n_boards != 1:
         raise InvalidParameterType("Not enough machine size")
コード例 #2
0
 def get_value(self, key):
     """ Get a property
     """
     if hasattr(self, key):
         return getattr(self, key)
     raise InvalidParameterType(
         "Type {} does not have parameter {}".format(type(self), key))
コード例 #3
0
ファイル: recorder.py プロジェクト: stjordanis/sPyNNaker8
 def _clear_recording(self, variables):
     for variable in variables:
         if variable == SPIKES:
             self._population._vertex.clear_spike_recording(
                 get_simulator().buffer_manager,
                 get_simulator().placements,
                 get_simulator().graph_mapper)
         elif variable == MEMBRANE_POTENTIAL:
             self._population._vertex.clear_v_recording(
                 get_simulator().buffer_manager,
                 get_simulator().placements,
                 get_simulator().graph_mapper)
         elif variable == GSYN_EXCIT:
             self._population._vertex.clear_gsyn_inhibitory_recording(
                 get_simulator().buffer_manager,
                 get_simulator().placements,
                 get_simulator().graph_mapper)
         elif variable == GSYN_INHIB:
             self._population._vertex.clear_gsyn_excitatory_recording(
                 get_simulator().buffer_manager,
                 get_simulator().placements,
                 get_simulator().graph_mapper)
         else:
             raise InvalidParameterType(
                 "The variable {} is not a recordable value".format(
                     variable))
コード例 #4
0
    def __init__(self,
                 pre_synaptic_population,
                 post_synaptic_population,
                 connector,
                 synapse_type=None,
                 source=None,
                 receptor_type=None,
                 space=None,
                 label=None):
        # pylint: disable=too-many-arguments
        if source is not None:
            raise InvalidParameterType(
                "sPyNNaker8 {} does not yet support multi-compartmental "
                "cells.".format(__version__))

        self._check_population_param(pre_synaptic_population)
        self._check_population_param(post_synaptic_population)

        # set space object if not set
        if space is None:
            space = PyNNSpace()

        # set the simulator object correctly.
        self._simulator = globals_variables.get_simulator()

        if synapse_type is None:
            synapse_type = SynapseDynamicsStatic()

        # move weights and delays over to the connector to satisfy PyNN 8
        # and 7 compatibility
        connector.set_weights_and_delays(synapse_type.weight,
                                         synapse_type.delay)
        connector.set_space(space)

        # as a from list connector can have plastic parameters, grab those (
        # if any and add them to the synapse dynamics object)
        if isinstance(connector, FromListConnector):
            synapse_plastic_parameters = connector.get_extra_parameters()
            if synapse_plastic_parameters is not None:
                for parameter in synapse_plastic_parameters.dtype.names:
                    synapse_type.set_value(
                        parameter, synapse_plastic_parameters[:, parameter])

        # set rng if needed
        rng = None
        if hasattr(connector, "rng"):
            rng = connector.rng

        super(Projection, self).__init__(
            connector=connector,
            synapse_dynamics_stdp=synapse_type,
            target=receptor_type,
            spinnaker_control=self._simulator,
            pre_synaptic_population=pre_synaptic_population,
            post_synaptic_population=post_synaptic_population,
            rng=rng,
            machine_time_step=self._simulator.machine_time_step,
            user_max_delay=self._simulator.max_delay,
            label=label,
            time_scale_factor=self._simulator.time_scale_factor)
コード例 #5
0
 def set_value(self, key, value):
     for obj in [self.__timing_dependence, self.__weight_dependence, self]:
         if hasattr(obj, key):
             setattr(obj, key, value)
             self.__change_requires_mapping = True
             return
     raise InvalidParameterType("Type {} does not have parameter {}".format(
         type(self), key))
コード例 #6
0
 def get_value(self, key):
     """ Get a property of the overall model.
     """
     if key not in self._parameters:
         raise InvalidParameterType(
             "Population {} does not have parameter {}".format(
                 self.__neuron_impl.model_name, key))
     return self._parameters[key]
コード例 #7
0
 def get_value(self, key):
     """ Get a property
     """
     for obj in [self.__timing_dependence, self.__weight_dependence, self]:
         if hasattr(obj, key):
             return getattr(obj, key)
     raise InvalidParameterType(
         "Type {} does not have parameter {}".format(type(self), key))
コード例 #8
0
 def set_value(self, key, value):
     """ Set a property of the overall model.
     """
     if key not in self._parameters:
         raise InvalidParameterType(
             "Population {} does not have parameter {}".format(
                 self.__neuron_impl.model_name, key))
     self._parameters.set_value(key, value)
     self.__change_requires_neuron_parameters_reload = True
コード例 #9
0
    def set_value(self, key, value):
        """ Set a property

        :param key: the name of the parameter to change
        :param value: the new value of the parameter to assign
        """
        if hasattr(self, key):
            setattr(self, key, value)
            self.__change_requires_mapping = True
        raise InvalidParameterType(
            "Type {} does not have parameter {}".format(type(self), key))
コード例 #10
0
 def set_value(self, key, value):
     """ Set a property of the overall model
     """
     for obj in [
             self._neuron_model, self._input_type, self._threshold_type,
             self._synapse_manager.synapse_type, self._additional_input
     ]:
         if hasattr(obj, key):
             setattr(obj, key, value)
             self._change_requires_neuron_parameters_reload = True
             return
     raise InvalidParameterType("Type {} does not have parameter {}".format(
         type(self), key))
コード例 #11
0
    def set_value(self, key, value):
        """ Set a property

        :param key: the name of the parameter to change
        :param value: the new value of the parameter to assign
        """
        for obj in [self.__timing_dependence, self.__weight_dependence, self]:
            if hasattr(obj, key):
                setattr(obj, key, value)
                self.__change_requires_mapping = True
                return
        raise InvalidParameterType(
            "Type {} does not have parameter {}".format(type(self), key))
コード例 #12
0
 def get_units(self, variable):
     # search the model components for the variable
     for obj in [
             self._neuron_model, self._input_type, self._threshold_type,
             self._synapse_manager.synapse_type, self._additional_input
     ]:
         if (hasattr(obj, variable)
                 and isinstance(obj, AbstractContainsUnits)):
             return obj.unit(variable)
     # if not in the components, must be within myself, so call my own units
     if variable in self._units:
         return self._units[variable]
     else:
         raise InvalidParameterType(
             "The parameter {} does not exist in this input "
             "conductance component".format(variable))
コード例 #13
0
    def __init__(self, conn_list, safe=True, verbose=False):
        """
        Creates a new FromListConnector.
        """
        super(FromListConnector, self).__init__(safe, verbose)
        if conn_list is None or not len(conn_list):
            raise InvalidParameterType(
                "The connection list for the FromListConnector must contain"
                " at least a list of tuples, each of which should contain:"
                " (pre_idx, post_idx)")
        self._conn_list = conn_list

        # supports setting these at different times
        self._weights = None
        self._delays = None
        self._converted_weights_and_delays = False
コード例 #14
0
ファイル: recorder.py プロジェクト: ghlim/sPyNNaker
 def _clear_recording(self, variables):
     sim = get_simulator()
     for variable in variables:
         if variable == SPIKES:
             self.__vertex.clear_spike_recording(sim.buffer_manager,
                                                 sim.placements)
         elif variable == MEMBRANE_POTENTIAL:
             self.__vertex.clear_recording(variable, sim.buffer_manager,
                                           sim.placements)
         elif variable == GSYN_EXCIT:
             self.__vertex.clear_recording(variable, sim.buffer_manager,
                                           sim.placements)
         elif variable == GSYN_INHIB:
             self.__vertex.clear_recording(variable, sim.buffer_manager,
                                           sim.placements)
         else:
             raise InvalidParameterType(
                 "The variable {} is not a recordable value".format(
                     variable))
コード例 #15
0
    def __init__(self, conn_list, safe=True, verbose=False):
        """
        :param: conn_list:
            a list of tuples, one tuple for each connection. Each\
            tuple should contain::

                (pre_idx, post_idx, weight, delay)

            where pre_idx is the index (i.e. order in the Population,\
            not the ID) of the presynaptic neuron, and post_idx is\
            the index of the postsynaptic neuron.
        """
        super(FromListConnector, self).__init__(safe, verbose)
        if conn_list is None or not len(conn_list):
            raise InvalidParameterType(
                "The connection list for the FromListConnector must contain"
                " at least a list of tuples, each of which should contain:"
                " (pre_idx, post_idx)")
        self._conn_list = conn_list

        # supports setting these at different times
        self._weights = None
        self._delays = None
        self._converted_weights_and_delays = False
コード例 #16
0
    def conn_list(self, conn_list):
        if conn_list is None or not len(conn_list):
            self.__conn_list = numpy.zeros((0, 2), dtype="uint32")
        else:
            self.__conn_list = numpy.array(conn_list)

        # If the shape of the conn_list is 2D, numpy has been able to create
        # a 2D array which means every entry has the same number of values.
        # If this was not possible, raise an exception!
        if len(self.__conn_list.shape) != 2:
            raise InvalidParameterType(
                "Each tuple in the connection list for the"
                " FromListConnector must have the same number of elements")

        # This tells us how many columns are in the list
        n_columns = self.__conn_list.shape[1]
        if n_columns < 2:
            raise InvalidParameterType(
                "Each tuple in the connection list for the"
                " FromListConnector must have at least 2 elements")
        if (self.__column_names is not None
                and n_columns != len(self.__column_names) + _FIRST_PARAM):
            raise InvalidParameterType(
                "The number of column names must match the number of"
                " additional elements in each tuple in the connection list,"
                " not including the pre_idx or post_idx")

        # Get the column names if not specified
        column_names = self.__column_names
        if self.__column_names is None:
            if n_columns == 4:
                column_names = ('weight', 'delay')
            elif n_columns == 2:
                column_names = ()
            else:
                raise TypeError(
                    "Need to set 'column_names' for n_columns={}".format(
                        n_columns))

        # Set the source and targets
        self.__sources = self.__conn_list[:, _SOURCE]
        self.__targets = self.__conn_list[:, _TARGET]

        # Find any weights
        self.__weights = None
        try:
            weight_column = column_names.index('weight') + _FIRST_PARAM
            self.__weights = self.__conn_list[:, weight_column]
        except ValueError:
            pass

        # Find any delays
        self.__delays = None
        try:
            delay_column = column_names.index('delay') + _FIRST_PARAM
            machine_time_step = globals_variables.get_simulator(
            ).machine_time_step
            self.__delays = (
                numpy.rint(
                    numpy.array(self.__conn_list[:, delay_column]) *
                    (MICRO_TO_MILLISECOND_CONVERSION / machine_time_step)) *
                (machine_time_step / MICRO_TO_MILLISECOND_CONVERSION))
        except ValueError:
            pass

        # Find extra columns
        extra_columns = list()
        for i, name in enumerate(column_names):
            if name not in ('weight', 'delay'):
                extra_columns.append(i + _FIRST_PARAM)

        # Check any additional parameters have single values over the whole
        # set of connections (as other things aren't currently supported
        for i in extra_columns:
            # numpy.ptp gives the difference between the maximum and
            # minimum values of an array, so if 0, all values are equal
            if numpy.ptp(self.__conn_list[:, i]):
                raise ValueError(
                    "All values in column {} ({}) of a FromListConnector must"
                    " have the same value".format(
                        i, column_names[i - _FIRST_PARAM]))

        # Store the extra data
        self.__extra_parameters = None
        self.__extra_parameter_names = None
        if extra_columns:
            self.__extra_parameters = self.__conn_list[:, extra_columns]
            self.__extra_parameter_names = [
                column_names[i - _FIRST_PARAM] for i in extra_columns
            ]
コード例 #17
0
    def __init__(self,
                 pre_synaptic_population,
                 post_synaptic_population,
                 connector,
                 synapse_type=None,
                 source=None,
                 receptor_type=None,
                 space=None,
                 label=None):
        # pylint: disable=too-many-arguments
        if source is not None:
            raise InvalidParameterType(
                "sPyNNaker8 {} does not yet support multi-compartmental "
                "cells.".format(__version__))

        self._check_population_param(pre_synaptic_population)
        self._check_population_param(post_synaptic_population)

        # set space object if not set
        if space is None:
            space = PyNNSpace()

        # set the simulator object correctly.
        self.__simulator = globals_variables.get_simulator()

        # set label
        self.__label = label
        if label is None:
            # set the projection's label here, but allow the edge label
            # to be set lower down if necessary
            self.__label = "from pre {} to post {} with connector {}".format(
                pre_synaptic_population.label, post_synaptic_population.label,
                connector)

        if synapse_type is None:
            synapse_type = SynapseDynamicsStatic()

        # set the space function as required
        connector.set_space(space)

        # as a from list connector can have plastic parameters, grab those (
        # if any and add them to the synapse dynamics object)
        if isinstance(connector, FromListConnector):
            synapse_plastic_parameters = connector.get_extra_parameters()
            if synapse_plastic_parameters is not None:
                for i, parameter in enumerate(
                        connector.get_extra_parameter_names()):
                    synapse_type.set_value(parameter,
                                           synapse_plastic_parameters[:, i])

        # set rng if needed
        rng = None
        if hasattr(connector, "rng"):
            rng = connector.rng

        super(Projection, self).__init__(
            connector=connector,
            synapse_dynamics_stdp=synapse_type,
            target=receptor_type,
            spinnaker_control=self.__simulator,
            pre_synaptic_population=pre_synaptic_population,
            post_synaptic_population=post_synaptic_population,
            rng=rng,
            machine_time_step=self.__simulator.machine_time_step,
            user_max_delay=self.__simulator.max_delay,
            label=label,
            time_scale_factor=self.__simulator.time_scale_factor)
コード例 #18
0
 def set_value(self, key, value):
     if hasattr(self, key):
         setattr(self, key, value)
         self.__change_requires_mapping = True
     raise InvalidParameterType("Type {} does not have parameter {}".format(
         type(self), key))