def test__getitem__tuple(self, sim=sim): p = sim.Population(23, sim.HH_cond_exp()) pv1 = p[1, 5, 6, 8, 11, 12, 15, 16, 19, 20] pv2 = pv1[(3, 5, 7)] self.assertEqual(pv2.parent, pv1) assert_array_almost_equal(pv2.all_cells, p.all_cells[[8, 12, 16]])
def test__getitem__slice(self, sim=sim): # Should return a PopulationView with the correct parent and value # of all_cells p = sim.Population(17, sim.HH_cond_exp()) pv = p[3:9] self.assertEqual(pv.parent, p) assert_array_almost_equal(pv.all_cells, p.all_cells[3:9])
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 setUp(self): sim.setup(num_processes=2, rank=1, min_delay=0.123) self.p1 = sim.Population(9, sim.IF_cond_exp(), structure=space.Grid2D(aspect_ratio=1.0, dx=1.0, dy=1.0)) self.p2 = sim.Population(9, sim.HH_cond_exp(), structure=space.Grid2D(aspect_ratio=1.0, dx=1.0, dy=1.0)) assert_array_equal(self.p2._mask_local, numpy.array([1,0,1,0,1,0,1,0,1], dtype=bool))
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)) random.mpi_rank = 1 random.num_processes = 2
def test___add__three(self, sim=sim): # adding three population views should give an Assembly pv1 = sim.Population(6, sim.IF_curr_exp())[0:3] pv2 = sim.Population(17, sim.IF_cond_exp())[1, 5, 14] pv3 = sim.Population(9, sim.HH_cond_exp())[3:8] assembly = pv1 + pv2 + pv3 self.assertIsInstance(assembly, sim.Assembly) self.assertEqual(assembly.populations, [pv1, pv2, pv3])
def setUp(self, sim=sim, **extra): sim.setup(num_processes=2, rank=1, min_delay=0.123, **extra) 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.p1._mask_local, np.array([0, 1, 0, 1], dtype=bool)) assert_array_equal(self.p2._mask_local, np.array([0, 1, 0, 1, 0], dtype=bool))
def test___add__three(self, sim=sim): # adding three populations should give an Assembly p1 = sim.Population(6, sim.IF_curr_exp()) p2 = sim.Population(17, sim.IF_cond_exp()) p3 = sim.Population(9, sim.HH_cond_exp()) assembly = p1 + p2 + p3 self.assertIsInstance(assembly, sim.Assembly) self.assertEqual(assembly.populations, [p1, p2, p3])
def test_create_with_slice_selector(self, sim=sim): p = sim.Population(11, sim.HH_cond_exp()) mask1 = slice(0, 9, 1) pv1 = sim.PopulationView(parent=p, selector=mask1) assert_array_equal(pv1.all_cells, p.all_cells[0:9]) mask2 = slice(3, 9, 2) pv2 = sim.PopulationView(parent=pv1, selector=mask2) self.assertEqual(pv2.parent, pv1) # or would it be better to resolve the parent chain up to an actual Population? assert_array_equal(pv2.all_cells, numpy.array([p.all_cells[3], p.all_cells[5], p.all_cells[7]]))
def setUp(self, sim=sim, **extra): sim.setup(min_delay=0.123, **extra) self.p1 = sim.Population(4, sim.IF_cond_exp(), structure=space.Line()) self.p2 = sim.Population(5, sim.HH_cond_exp(), structure=space.Line()) 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 ]
def test__getitem__slice(self, sim=sim): # Should return a PopulationView with the correct parent and value # of all_cells p = sim.Population(17, sim.HH_cond_exp()) pv1 = p[1, 5, 6, 8, 11, 12, 15, 16] pv2 = pv1[2:6] self.assertEqual(pv2.parent, pv1) self.assertEqual(pv2.grandparent, p) assert_array_equal(pv2.all_cells, pv1.all_cells[[2, 3, 4, 5]]) assert_array_equal(pv2.all_cells, p.all_cells[[6, 8, 11, 12]])
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)) 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 ]
def setUp(self): sim.setup(num_processes=2, rank=0) self.p1 = sim.Population(5, sim.IF_cond_exp()) self.p2 = sim.Population(5, sim.HH_cond_exp()) assert_array_equal(self.p2._mask_local, numpy.array([0,1,0,1,0], dtype=bool))
def test_set_invalid_name(self, sim=sim): p = sim.Population(9, sim.HH_cond_exp()) self.assertRaises(errors.NonExistentParameterError, p.set, foo=13.2)
def test__getitem__tuple(self, sim=sim): p = sim.Population(23, sim.HH_cond_exp()) pv = p[(3, 5, 7)] self.assertEqual(pv.parent, p) assert_array_almost_equal(pv.all_cells, p.all_cells[[3, 5, 7]])
def test__getitem__list(self, sim=sim): p = sim.Population(23, sim.HH_cond_exp()) pv = p[list(range(3, 9))] self.assertEqual(pv.parent, p) assert_array_almost_equal(pv.all_cells, p.all_cells[3:9])
def setUp(self, sim=sim, **extra): sim.setup(nmin_delay=0.123, **extra) self.p1 = sim.Population(5, sim.IF_cond_exp(), structure=space.Line()) self.p2 = sim.Population(5, sim.HH_cond_exp(), structure=space.Line())
def setUp(self, sim=sim, **extra): sim.setup(**extra) self.p1 = sim.Population(5, sim.IF_cond_exp()) self.p2 = sim.Population(5, sim.HH_cond_exp())