def setUp(self): sim.setup(num_processes=2, rank=1, min_delay=0.123) self.p1 = sim.Population(4, sim.IF_cond_exp(), structure=space.Line()) self.p2 = sim.Population(5, sim.HH_cond_exp(), structure=space.Line()) assert_array_equal(self.p2._mask_local, numpy.array([0, 1, 0, 1, 0], dtype=bool)) connection_list = [ (0, 0, 0.0, 1.0), (3, 0, 0.0, 1.0), (2, 3, 0.0, 1.0), # local (2, 2, 0.0, 1.0), (0, 1, 0.0, 1.0), # local ] list_connector = connectors.FromListConnector(connection_list) syn = sim.StaticSynapse() self.ref_prj = sim.Projection(self.p1, self.p2, list_connector, syn) self.orig_gather_dict = recording.gather_dict # create reference to original function # The gather_dict function in recording needs to be temporarily replaced so it can work with # a mock version of the function to avoid it throwing an mpi4py import error when setting # the rank in pyNN.mock by hand to > 1 def mock_gather_dict(D, all=False): return D recording.gather_dict = mock_gather_dict
def test_connect_with_empty_list(self, sim=sim): connection_list = [] C = connectors.FromListConnector(connection_list) syn = sim.StaticSynapse() prj = sim.Projection(self.p1, self.p2, C, syn) self.assertEqual(prj.get(["weight", "delay"], format='list'), [])
def test_connect_unique_connection_neuron_0_to_neuron_0(self, sim=sim): connection_list = [ (0, 0, 0.1, 0.18) ] C = connectors.FromListConnector(connection_list) syn = sim.StaticSynapse() prj = sim.Projection(self.p1, self.p2, C, syn) self.assertEqual(prj.get(["weight", "delay"], format='list'), [(0, 0, 0.1, 0.18)])
def test_connect_with_out_of_range_index(self): connection_list = [ (0, 0, 0.1, 0.1), # 17 -> 79 (3, 0, 0.2, 0.11), # 20 -> 79 (2, 3, 0.3, 0.12), # 19 -> 82 local (5, 2, 0.4, 0.13), # NON-EXISTENT -> 81 (0, 1, 0.5, 0.14), # 17 -> 80 local ] C = connectors.FromListConnector(connection_list) assert_raises(errors.ConnectionError, C.connect, self.prj)
def test_connect_with_out_of_range_index(self): connection_list = [ (0, 0, 0.1, 0.1), (3, 0, 0.2, 0.11), (2, 3, 0.3, 0.12), # local (5, 1, 0.4, 0.13), # NON-EXISTENT (0, 1, 0.5, 0.14), # local ] C = connectors.FromListConnector(connection_list) syn = sim.StaticSynapse() self.assertRaises(errors.ConnectionError, sim.Projection, self.p1, self.p2, C, syn)
def test_connect_with_valid_list(self): connection_list = [ (0, 0, 0.1, 0.1), (3, 0, 0.2, 0.11), (2, 3, 0.3, 0.12), # local (2, 2, 0.4, 0.13), (0, 1, 0.5, 0.14), # local ] C = connectors.FromListConnector(connection_list) syn = sim.StaticSynapse() prj = sim.Projection(self.p1, self.p2, C, syn) self.assertEqual(prj.get(["weight", "delay"], format='list', gather=False), # use gather False because we are faking the MPI [(0, 1, 0.5, 0.14), (2, 3, 0.3, 0.12)])
def test_with_plastic_synapse(self): connection_list = [ (0, 0, 0.1, 0.1, 100, 400), (3, 0, 0.2, 0.11, 101, 500), (2, 3, 0.3, 0.12, 102, 600), # local (2, 2, 0.4, 0.13, 103, 700), (0, 1, 0.5, 0.14, 104, 800), # local ] C = connectors.FromListConnector(connection_list, column_names=["weight", "delay", "U", "tau_rec"]) syn = sim.TsodyksMarkramSynapse(U=99, tau_facil=88.8) prj = sim.Projection(self.p1, self.p2, C, syn) self.assertEqual(prj.get(["weight", "delay", "tau_facil", "tau_rec", "U"], format='list', gather=False), # use gather False because we are faking the MPI [(0, 1, 0.5, 0.14, 88.8, 800.0, 104.0), (2, 3, 0.3, 0.12, 88.8, 600.0, 102.0)])
def test_connect_with_valid_list(self, sim=sim): connection_list = [ (0, 0, 0.1, 0.18), (3, 0, 0.2, 0.17), (2, 3, 0.3, 0.16), # local (2, 2, 0.4, 0.15), (0, 1, 0.5, 0.14), # local ] C = connectors.FromListConnector(connection_list) syn = sim.StaticSynapse() prj = sim.Projection(self.p1, self.p2, C, syn) self.assertEqual(prj.get(["weight", "delay"], format='list'), [(0, 0, 0.1, 0.18), (3, 0, 0.2, 0.17), (0, 1, 0.5, 0.14), (2, 2, 0.4, 0.15), (2, 3, 0.3, 0.16)])
def test_with_stdp_synapse(self, sim=sim): connection_list = [ (0, 0, 0.1, 0.1, 10.0, 0.4), (3, 0, 0.2, 0.11, 10.1, 0.5), (2, 3, 0.3, 0.12, 10.2, 0.6), # local (2, 2, 0.4, 0.13, 10.3, 0.7), (0, 1, 0.5, 0.14, 10.4, 0.8), # local ] C = connectors.FromListConnector(connection_list, column_names=[ "weight", "delay", "tau_plus", "w_max"]) syn = sim.STDPMechanism(timing_dependence=sim.SpikePairRule(tau_plus=12.3, tau_minus=33.3), weight_dependence=sim.MultiplicativeWeightDependence(w_max=1.11), weight=0.321, delay=0.2) prj = sim.Projection(self.p1, self.p2, C, syn) self.assertEqual(prj.get(["weight", "delay", "tau_plus", "tau_minus", "w_max"], format='list', gather=False), # use gather False because we are faking the MPI [(0, 1, 0.5, 0.14, 10.4, 33.3, 0.8), (2, 3, 0.3, 0.12, 10.2, 33.3, 0.6)])
def test_connect_with_valid_list(self): connection_list = [ (0, 0, 0.1, 0.1), # 17 -> 79 (3, 0, 0.2, 0.11), # 20 -> 79 (2, 3, 0.3, 0.12), # 19 -> 82 local (2, 2, 0.4, 0.13), # 19 -> 81 (0, 1, 0.5, 0.14), # 17 -> 80 local ] C = connectors.FromListConnector(connection_list) C.progressbar = Mock() C.progression = Mock() C.connect(self.prj) # note that ListConnector does not filter out non-local connections assert_equal(self.prj.connections, [(17, 79, 0.1, 0.1), (17, 80, 0.5, 0.14), (19, 82, 0.3, 0.12), (19, 81, 0.4, 0.13), (20, 79, 0.2, 0.11)])