def test_connector( clist, column_names, weights, delays, expected_clist, expected_weights, expected_delays, expected_extra_parameters, expected_extra_parameter_names): MockSimulator.setup() connector = FromListConnector(clist, column_names=column_names) if expected_clist is not None: assert(numpy.array_equal(connector.conn_list, expected_clist)) else: assert(numpy.array_equal(connector.conn_list, clist)) # Check extra parameters are as expected extra_params = connector.get_extra_parameters() extra_param_names = connector.get_extra_parameter_names() assert(numpy.array_equal(extra_params, expected_extra_parameters)) assert(numpy.array_equal( extra_param_names, expected_extra_parameter_names)) if extra_params is not None: assert(len(extra_params.shape) == 2) assert(extra_params.shape[1] == len(extra_param_names)) for i in range(len(extra_param_names)): assert(extra_params[:, i].shape == (len(clist), )) # Check weights and delays are used or ignored as expected block = connector.create_synaptic_block( weights, delays, [], 0, [], 0, Slice(0, 10), Slice(0, 10), 1) assert(numpy.array_equal(block["weight"], numpy.array(expected_weights))) assert(numpy.array_equal(block["delay"], numpy.array(expected_delays)))
def __init__( self, conn_list, safe=True, verbose=False, column_names=None, callback=None): """ :param conn_list: a list of tuples, one tuple for each connection. Each tuple should contain: `(pre_idx, post_idx, p1, p2, ..., pn)` where `pre_idx` is the index (i.e. order in the Population, not the ID) of the presynaptic neuron, `post_idx` is the index of the postsynaptic neuron, and `p1`, `p2`, etc. are the synaptic parameters (e.g., weight, delay, plasticity parameters). :type conn_list: list(tuple(int,int,...)) or ~numpy.ndarray :param bool safe: if True, check that weights and delays have valid values. If False, this check is skipped. :param bool verbose: Whether to output extra information about the connectivity to a CSV file :param column_names: the names of the parameters `p1`, `p2`, etc. If not provided, it is assumed the parameters are `weight, delay` (for backwards compatibility). :type column_names: tuple(str) or list(str) or None :param callable callback: if given, a callable that display a progress bar on the terminal. .. note:: Not supported by sPyNNaker. """ moved_in_v6("spynnaker8.models.connectors.FromListConnector", "spynnaker.pyNN.models.neural_projections.connectors" ".FromListConnector") _BaseClass.__init__( self, conn_list=conn_list, safe=safe, verbose=verbose, column_names=column_names, callback=callback)
def __init__( self, conn_list, safe=True, verbose=False, column_names=None, callback=None): """ :param conn_list: \ a list of tuples, one tuple for each connection. Each tuple\ should contain: `(pre_idx, post_idx, p1, p2, ..., pn)` where\ `pre_idx` is the index (i.e. order in the Population, not the ID)\ of the presynaptic neuron, `post_idx` is the index of the\ postsynaptic neuron, and `p1`, `p2`, etc. are the synaptic\ parameters (e.g., weight, delay, plasticity parameters). :param column_names: \ the names of the parameters p1, p2, etc. If not provided, it is\ assumed the parameters are weight, delay (for\ backwards compatibility). :param safe: \ if True, check that weights and delays have valid values. If\ False, this check is skipped. :param callback: \ if given, a callable that display a progress bar on the terminal. """ CommonFromListConnector.__init__( self, conn_list=conn_list, safe=safe, verbose=verbose, column_names=column_names) Connector.__init__(self, safe=safe, callback=callback)
def __init__(self, conn_list, safe=True, verbose=False, column_names=None): FromListConnector.__init__(self, conn_list, safe=safe, verbose=verbose, column_names=column_names) self._split_count = 0
def test_connector(clist, column_names, weights, delays, expected_clist, expected_weights, expected_delays, expected_extra_parameters, expected_extra_parameter_names): MockSimulator.setup() connector = FromListConnector(clist, column_names=column_names) if expected_clist is not None: assert (numpy.array_equal(connector.conn_list, expected_clist)) else: assert (numpy.array_equal(connector.conn_list, clist)) # Check extra parameters are as expected extra_params = connector.get_extra_parameters() extra_param_names = connector.get_extra_parameter_names() assert (numpy.array_equal(extra_params, expected_extra_parameters)) assert (numpy.array_equal(extra_param_names, expected_extra_parameter_names)) if extra_params is not None: assert (len(extra_params.shape) == 2) assert (extra_params.shape[1] == len(extra_param_names)) for i in range(len(extra_param_names)): assert (extra_params[:, i].shape == (len(clist), )) # Check weights and delays are used or ignored as expected pre_slice = Slice(0, 10) post_slice = Slice(0, 10) mock_synapse_info = MockSynapseInfo(MockPopulation(10, "Pre"), MockPopulation(10, "Post"), weights, delays) block = connector.create_synaptic_block([pre_slice], 0, [post_slice], 0, pre_slice, post_slice, 1, mock_synapse_info) assert (numpy.array_equal(block["weight"], numpy.array(expected_weights))) assert (numpy.array_equal(block["delay"], numpy.array(expected_delays)))
def test_could_connect(): connector = FromListConnector([[0, 0], [1, 2], [2, 0], [3, 3], [2, 6], [1, 8], [4, 1], [5, 0], [6, 2], [4, 8]]) pre_slices = [Slice(0, 3), Slice(4, 6), Slice(7, 9)] post_slices = [Slice(0, 2), Slice(3, 5), Slice(6, 9)] for pre_slice in pre_slices: for post_slice in post_slices: count = connector.get_n_connections(pre_slices, post_slices, pre_slice.hi_atom, post_slice.hi_atom) if count: assert (connector.could_connect(None, pre_slice, post_slice)) else: assert (not connector.could_connect(None, pre_slice, post_slice))
def test_could_connect(): unittest_setup() connector = FromListConnector([[0, 0], [1, 2], [2, 0], [3, 3], [2, 6], [1, 8], [4, 1], [5, 0], [6, 2], [4, 8]]) pre_slices = [Slice(0, 3), Slice(4, 6), Slice(7, 9)] post_slices = [Slice(0, 2), Slice(3, 5), Slice(6, 9)] for pre_slice in pre_slices: pre_vertex = MockMachineVertex(pre_slice, pre_slices) for post_slice in post_slices: post_vertex = MockMachineVertex(post_slice, post_slices) count = connector.get_n_connections(pre_slices, post_slices, pre_slice.hi_atom, post_slice.hi_atom) if count: assert (connector.could_connect(None, pre_vertex, post_vertex)) else: assert (not connector.could_connect(None, pre_vertex, post_vertex))
def test_connector(clist, column_names, weights, delays, expected_clist, expected_weights, expected_delays, expected_extra_parameters, expected_extra_parameter_names): unittest_setup() connector = FromListConnector(clist, column_names=column_names) if expected_clist is not None: assert (numpy.array_equal(connector.conn_list, expected_clist)) else: assert (numpy.array_equal(connector.conn_list, clist)) # Check extra parameters are as expected extra_params = connector.get_extra_parameters() extra_param_names = connector.get_extra_parameter_names() assert (numpy.array_equal(extra_params, expected_extra_parameters)) assert (numpy.array_equal(extra_param_names, expected_extra_parameter_names)) if extra_params is not None: assert (len(extra_params.shape) == 2) assert (extra_params.shape[1] == len(extra_param_names)) for i in range(len(extra_param_names)): assert (extra_params[:, i].shape == (len(clist), )) # Check weights and delays are used or ignored as expected pre_slice = Slice(0, 10) post_slice = Slice(0, 10) synapse_info = SynapseInformation(connector=None, pre_population=MockPopulation(10, "Pre"), post_population=MockPopulation( 10, "Post"), prepop_is_view=False, postpop_is_view=False, rng=None, synapse_dynamics=None, synapse_type=None, is_virtual_machine=False, weights=weights, delays=delays) block = connector.create_synaptic_block([pre_slice], [post_slice], pre_slice, post_slice, 1, synapse_info) assert (numpy.array_equal(block["weight"], numpy.array(expected_weights))) assert (numpy.array_equal(block["delay"], numpy.array(expected_delays)))
def _split_connections(self, pre_slices, post_slices): split = FromListConnector._split_connections( self, pre_slices, post_slices) if split: self._split_count += 1
def __init__(self, conn_list, safe=True, verbose=False, column_names=None, callback=None): """ :param conn_list: \ a list of tuples, one tuple for each connection. Each tuple\ should contain: `(pre_idx, post_idx, p1, p2, ..., pn)` where\ `pre_idx` is the index (i.e. order in the Population, not the ID)\ of the presynaptic neuron, `post_idx` is the index of the\ postsynaptic neuron, and `p1`, `p2`, etc. are the synaptic\ parameters (e.g., weight, delay, plasticity parameters). :param column_names: \ the names of the parameters p1, p2, etc. If not provided, it is\ assumed the parameters are weight, delay (for\ backwards compatibility). :param safe: \ if True, check that weights and delays have valid values. If\ False, this check is skipped. :param callback: \ if given, a callable that display a progress bar on the terminal. """ # pylint: disable=too-many-arguments 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 at " "least: (pre_idx, post_idx)") conn_list = numpy.array(conn_list) n_columns = 0 if conn_list.size: n_columns = conn_list.shape[1] weights = None delays = None self._extra_conn_data = None if column_names is None: # if no column names, but more not the expected if n_columns == 4: column_names = ('pre_idx', 'post_idx', 'weight', 'delay') conn_list, weights, delays, self._extra_conn_data = \ self._split_conn_list(conn_list, column_names) elif n_columns != 2: raise TypeError("Argument 'column_names' is required.") else: # separate conn list to pre, source, weight, delay and the # other things conn_list, weights, delays, self._extra_conn_data = \ self._split_conn_list(conn_list, column_names) # verify that the rest of the parameters are constant, as we don't # support synapse params changing per atom yet self._verify_extra_data_meets_constraints() # build common from list CommonFromListConnector.__init__(self, conn_list=conn_list, safe=safe, verbose=verbose) Connector.__init__(self, safe=safe, callback=callback) # set weights or / and delays if given if weights is not None or delays is not None: self.set_weights_and_delays(weights, delays)