def test_current_time_two_runs(self, sim=sim):
     sim.setup(timestep=0.1, **self.extra)
     sim.run(10.1)
     self.assertAlmostEqual(sim.get_current_time(), 10.1)
     sim.run(23.4)
     self.assertAlmostEqual(sim.get_current_time(), 33.5)
     sim.end()
Example #2
0
 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_callbacks(self, sim=sim):
        total_time = 100.
        callback_steps = [10., 10., 20., 25.]

        # callbacks are called at 0. and after every step
        expected_callcount = [11, 11, 6, 5]
        num_callbacks = len(callback_steps)
        callback_callcount = [0] * num_callbacks

        def make_callback(idx):
            def callback(time):
                callback_callcount[idx] += 1
                return time + callback_steps[idx]

            return callback

        callbacks = [make_callback(i) for i in range(num_callbacks)]
        sim.setup(timestep=0.1, min_delay=0.1, **self.extra)
        sim.run_until(total_time, callbacks=callbacks)

        self.assertTrue(
            all(callback_callcount[i] == expected_callcount[i]
                for i in range(num_callbacks)))

        sim.end()
 def test_current_time_two_runs(self, sim=sim):
     sim.setup(timestep=0.1, **self.extra)
     sim.run(10.1)
     self.assertAlmostEqual(sim.get_current_time(), 10.1)
     sim.run(23.4)
     self.assertAlmostEqual(sim.get_current_time(), 33.5)
     sim.end()
Example #5
0
    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
Example #6
0
 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))
Example #7
0
 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))
Example #8
0
    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=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))
Example #10
0
 def setUp(self):
     sim.setup()
     self.p1 = sim.Population(7, sim.IF_cond_exp())
     self.p2 = sim.Population(4, sim.IF_cond_exp())
     self.p3 = sim.Population(5, sim.IF_curr_alpha())
     self.syn1 = sim.StaticSynapse(weight=0.123, delay=0.5)
     self.random_connect = sim.FixedNumberPostConnector(n=2)
     self.syn2 = sim.StaticSynapse(weight=0.456, delay=0.4)
     self.all2all = sim.AllToAllConnector()
Example #11
0
 def setUp(self):
     sim.setup()
     self.p1 = sim.Population(7, sim.IF_cond_exp())
     self.p2 = sim.Population(4, sim.IF_cond_exp())
     self.p3 = sim.Population(5, sim.IF_curr_alpha())
     self.syn1 = sim.StaticSynapse(weight=0.123, delay=0.5)
     self.random_connect = sim.FixedNumberPostConnector(n=2)
     self.syn2 = sim.StaticSynapse(weight=0.456, delay=0.4)
     self.all2all = sim.AllToAllConnector()
Example #12
0
 def setUp(self, sim=sim, **extra):
     sim.setup(**extra)
     self.p1 = sim.Population(7, sim.IF_cond_exp())
     self.p2 = sim.Population(4, sim.IF_cond_exp())
     self.p3 = sim.Population(5, sim.IF_curr_alpha())
     self.syn1 = sim.StaticSynapse(weight=0.006, delay=0.5)
     self.random_connect = sim.FixedNumberPostConnector(n=2)
     self.syn2 = sim.StaticSynapse(weight=0.012, delay=0.4)
     self.all2all = sim.AllToAllConnector()
     self.syn3 = sim.TsodyksMarkramSynapse(weight=0.012, delay=0.6, U=0.2, tau_rec=50)
Example #13
0
 def setUp(self, sim=sim, **extra):
     sim.setup(**extra)
     self.p1 = sim.Population(7, sim.IF_cond_exp())
     self.p2 = sim.Population(4, sim.IF_cond_exp())
     self.p3 = sim.Population(5, sim.IF_curr_alpha())
     self.syn1 = sim.StaticSynapse(weight=0.006, delay=0.5)
     self.random_connect = sim.FixedNumberPostConnector(n=2)
     self.syn2 = sim.StaticSynapse(weight=0.012, delay=0.4)
     self.all2all = sim.AllToAllConnector()
     self.syn3 = sim.TsodyksMarkramSynapse(weight=0.012, delay=0.6, U=0.2, tau_rec=50)
 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
     ]
Example #15
0
 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
         ]
Example #16
0
 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=sim, **extra):
     self.MIN_DELAY = 0.123
     sim.setup(num_processes=2, rank=1, min_delay=self.MIN_DELAY, **extra)
     self.p1 = sim.Population(7, sim.IF_cond_exp())
     self.p2 = sim.Population(4, sim.IF_cond_exp())
     self.p3 = sim.Population(5, sim.IF_curr_alpha())
     self.projections = {"cond": {}, "curr": {}}
     for psr, post in (("cond", self.p2), ("curr", self.p3)):
         for rt in ("excitatory", "inhibitory"):
             self.projections[psr][rt] = sim.Projection(
                 self.p1,
                 post,
                 sim.AllToAllConnector(safe=True),
                 sim.StaticSynapse(),
                 receptor_type=rt)
Example #18
0
    def test_callbacks(self):
        total_time = 100.
        callback_steps = [10., 10., 20., 25.]

        # callbacks are called at 0. and after every step
        expected_callcount = [11, 11, 6, 5]
        num_callbacks = len(callback_steps)
        callback_callcount = [0] * num_callbacks

        def make_callback(idx):
            def callback(time):
                callback_callcount[idx] += 1
                return time + callback_steps[idx]
            return callback

        callbacks = [make_callback(i) for i in range(num_callbacks)]
        sim.setup(timestep=0.1, min_delay=0.1)
        sim.run_until(total_time, callbacks=callbacks)

        self.assertTrue(all(callback_callcount[i] == expected_callcount[i]
            for i in range(num_callbacks)))
Example #19
0
 def test_reset(self):
     sim.setup()
     sim.run(1000.0)
     sim.reset()
     self.assertEqual(sim.get_current_time(), 0.0)
 def test_reset(self, sim=sim):
     sim.setup(**self.extra)
     sim.run(100.0)
     sim.reset()
     self.assertEqual(sim.get_current_time(), 0.0)
     sim.end()
Example #21
0
 def setUp(self):
     sim.setup()
 def test_time_step(self, sim=sim):
     sim.setup(0.123, min_delay=0.246, **self.extra)
     self.assertAlmostEqual(sim.get_time_step(), 0.123)
     sim.end()
Example #23
0
 def setUp(self, sim=sim, **extra):
     self.MIN_DELAY = 0.123
     sim.setup(num_processes=2, rank=1, min_delay=0.123, **extra)
Example #24
0
 def test_min_delay(self):
     sim.setup(0.123, min_delay=0.246)
     self.assertEqual(sim.get_min_delay(), 0.246)
 def test_run_twice(self, sim=sim):
     sim.setup(**self.extra)
     self.assertAlmostEqual(sim.run(100.0), 100.0)
     self.assertAlmostEqual(sim.run(100.0), 200.0)
     sim.end()
 def test_reset(self, sim=sim):
     sim.setup(**self.extra)
     sim.run(100.0)
     sim.reset()
     self.assertEqual(sim.get_current_time(), 0.0)
     sim.end()
 def test_max_delay(self, sim=sim):
     sim.setup(max_delay=9.87, **self.extra)
     self.assertAlmostEqual(sim.get_max_delay(), 9.87)
     sim.end()
 def test_end(self, sim=sim):
     sim.setup(**self.extra)
     sim.end() # need a better test
 def test_current_time(self):
     sim.setup(timestep=0.1)
     sim.run(10.1)
     self.assertEqual(sim.get_current_time(), 10.1)
     sim.run(23.4)
     self.assertEqual(sim.get_current_time(), 33.5)
 def test_max_delay(self):
     sim.setup(max_delay=9.87)
     self.assertEqual(sim.get_max_delay(), 9.87)
 def test_min_delay(self, sim=sim):
     sim.setup(0.123, min_delay=0.246, **self.extra)
     self.assertEqual(sim.get_min_delay(), 0.246)
     sim.end()
Example #32
0
 def test_current_time(self):
     sim.setup(timestep=0.1)
     sim.run(10.1)
     self.assertEqual(sim.get_current_time(), 10.1)
     sim.run(23.4)
     self.assertEqual(sim.get_current_time(), 33.5)
Example #33
0
 def setUp(self):
     self.MIN_DELAY = 0.123
     sim.setup(num_processes=2, rank=1, min_delay=0.123)
Example #34
0
 def test_time_step(self):
     sim.setup(0.123, min_delay=0.246)
     self.assertEqual(sim.get_time_step(), 0.123)
 def test_run(self):
     sim.setup()
     self.assertEqual(sim.run(1000.0), 1000.0)
     self.assertEqual(sim.run(1000.0), 2000.0)
Example #36
0
 def test_max_delay(self):
     sim.setup(max_delay=9.87)
     self.assertEqual(sim.get_max_delay(), 9.87)
 def test_reset(self):
     sim.setup()
     sim.run(1000.0)
     sim.reset()
     self.assertEqual(sim.get_current_time(), 0.0)
Example #38
0
 def setUp(self, sim=sim, **extra):
     sim.setup(num_processes=2, rank=1, min_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())
     assert_array_equal(self.p2._mask_local, numpy.array([1,0,1,0,1], dtype=bool))
 def test_end(self, sim=sim):
     sim.setup(**self.extra)
     sim.end()  # need a better test
 def test_min_delay(self, sim=sim):
     sim.setup(0.123, min_delay=0.246, **self.extra)
     self.assertEqual(sim.get_min_delay(), 0.246)
     sim.end()
 def test_time_step(self):
     sim.setup(0.123, min_delay=0.246)
     self.assertEqual(sim.get_time_step(), 0.123)
 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())
Example #43
0
 def setUp(self):
     sim.setup()
 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 test_min_delay(self):
     sim.setup(0.123, min_delay=0.246)
     self.assertEqual(sim.get_min_delay(), 0.246)
Example #46
0
 def test_run(self):
     sim.setup()
     self.assertEqual(sim.run(1000.0), 1000.0)
     self.assertEqual(sim.run(1000.0), 2000.0)
 def test_run_twice(self, sim=sim):
     sim.setup(**self.extra)
     self.assertAlmostEqual(sim.run(100.0), 100.0)
     self.assertAlmostEqual(sim.run(100.0), 200.0)
     sim.end()
Example #48
0
 def setUp(self, sim=sim, **extra):
     sim.setup(**extra)
 def test_max_delay(self, sim=sim):
     sim.setup(max_delay=9.87, **self.extra)
     self.assertAlmostEqual(sim.get_max_delay(), 9.87)
     sim.end()
Example #50
0
 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))
Example #51
0
 def test_end(self):
     sim.setup()
     sim.end() # need a better test
 def test_time_step(self, sim=sim):
     sim.setup(0.123, min_delay=0.246, **self.extra)
     self.assertAlmostEqual(sim.get_time_step(), 0.123)
     sim.end()
 def test_end(self):
     sim.setup()
     sim.end()  # need a better test