def test_print_v(self, sim=sim): p = sim.Population(3, sim.IF_curr_alpha()) p.record_v() sim.run(10.0) p.write_data = Mock() p.print_v("foo.txt") p.write_data.assert_called_with('foo.txt', 'v', True)
def test_get_v(self, sim=sim): p = sim.Population(3, sim.IF_curr_alpha()) p.record_v() sim.run(10.0) p.get_data = Mock() p.get_v() p.get_data.assert_called_with('v', True)
def test_meanSpikeCount(self, sim=sim): p = sim.Population(14, sim.EIF_cond_exp_isfa_ista()) p.record('spikes') sim.run(100.0) p.mean_spike_count = Mock() p.meanSpikeCount() self.assertTrue(p.mean_spike_count.called)
def test_meanSpikeCount(self): p = sim.Population(14, sim.EIF_cond_exp_isfa_ista()) p.record("spikes") sim.run(100.0) p.mean_spike_count = Mock() p.meanSpikeCount() p.mean_spike_count.assert_called()
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()
def test_getSpikes(self): p = sim.Population(3, sim.IF_curr_alpha()) p.record("spikes") sim.run(10.0) p.get_data = Mock() p.getSpikes() p.get_data.assert_called_with("spikes", True)
def test_get_gsyn(self, sim=sim): p = sim.Population(3, sim.IF_cond_alpha()) p.record_gsyn() sim.run(10.0) p.get_data = Mock() p.get_gsyn() p.get_data.assert_called_with(['gsyn_exc', 'gsyn_inh'], True)
def test_print_gsyn(self, sim=sim): p = sim.Population(3, sim.IF_cond_alpha()) p.record_gsyn() sim.run(10.0) p.write_data = Mock() p.print_gsyn("foo.txt") p.write_data.assert_called_with('foo.txt', ['gsyn_exc', 'gsyn_inh'], True)
def test_print_gsyn(self): p = sim.Population(3, sim.IF_cond_alpha()) p.record_gsyn() sim.run(10.0) p.write_data = Mock() p.print_gsyn("foo.txt") p.write_data.assert_called_with("foo.txt", ["gsyn_exc", "gsyn_inh"], True)
def test_get_spike_counts(self): p = sim.Population(3, sim.EIF_cond_exp_isfa_ista()) p.record('spikes') sim.run(100.0) self.assertEqual(p.get_spike_counts(), {p.all_cells[0]: 2, p.all_cells[1]: 2, p.all_cells[2]: 2})
def test_printSpikes(self, sim=sim): # TODO: implement assert_deprecated p = sim.Population(3, sim.IF_curr_alpha()) p.record('spikes') sim.run(10.0) p.write_data = Mock() p.printSpikes("foo.txt") p.write_data.assert_called_with('foo.txt', 'spikes', True)
def test_get_spike_counts(self, sim=sim): p = sim.Population(3, sim.EIF_cond_exp_isfa_ista()) p.record('spikes') sim.run(100.0) self.assertEqual(p.get_spike_counts(), {p.all_cells[0]: 2, p.all_cells[1]: 2, p.all_cells[2]: 2})
def test_get_gsyn(self, sim=sim): p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(11, sim.IF_cond_exp()) a = sim.Assembly(p1, p2, label="test") a.record_gsyn() sim.run(10.0) a.get_data = Mock() a.get_gsyn() a.get_data.assert_called_with(['gsyn_exc', 'gsyn_inh'], True)
def test_print_v(self, sim=sim): p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(11, sim.IF_cond_exp()) a = sim.Assembly(p1, p2, label="test") a.record_v() sim.run(10.0) a.write_data = Mock() a.print_v("foo.txt") a.write_data.assert_called_with('foo.txt', 'v', True)
def test_print_gsyn(self): p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(11, sim.IF_cond_exp()) a = sim.Assembly(p1, p2, label="test") a.record_gsyn() sim.run(10.0) a.write_data = Mock() a.print_gsyn("foo.txt") a.write_data.assert_called_with('foo.txt', ['gsyn_exc', 'gsyn_inh'], True)
def test_get_v(self): p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(11, sim.IF_cond_exp()) a = sim.Assembly(p1, p2, label="test") a.record_v() sim.run(10.0) a.get_data = Mock() a.get_v() a.get_data.assert_called_with('v', True)
def test_getSpikes(self, sim=sim): p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(11, sim.IF_cond_exp()) a = sim.Assembly(p1, p2, label="test") a.record('spikes') sim.run(10.0) a.get_data = Mock() a.getSpikes() a.get_data.assert_called_with('spikes', True)
def test_get_spike_counts(self): p = sim.Population(5, sim.EIF_cond_exp_isfa_ista()) pv = p[0, 1, 4] pv.record('spikes') sim.run(100.0) self.assertEqual(p.get_spike_counts(), {p.all_cells[0]: 2, p.all_cells[1]: 2, p.all_cells[4]: 2})
def test_record_with_single_variable(self, sim=sim): p = sim.Population(14, sim.EIF_cond_exp_isfa_ista()) p.record('v') sim.run(12.3) data = p.get_data(gather=True).segments[0] self.assertEqual(len(data.analogsignalarrays), 1) n_values = int(round(12.3 / sim.get_time_step())) + 1 self.assertEqual(data.analogsignalarrays[0].name, 'v') self.assertEqual(data.analogsignalarrays[0].shape, (n_values, p.size))
def test_get_spike_counts(self, sim=sim): p = sim.Population(5, sim.EIF_cond_exp_isfa_ista()) pv = p[0, 1, 4] pv.record('spikes') sim.run(100.0) self.assertEqual(p.get_spike_counts(), {p.all_cells[0]: 2, p.all_cells[1]: 2, p.all_cells[4]: 2})
def test_mean_spike_count(self, sim=sim): p1 = sim.Population(14, sim.EIF_cond_exp_isfa_ista()) p2 = sim.Population(37, sim.IF_cond_alpha()) a = p1 + p2 p1.record('spikes') p2.record('spikes') #a.record('spikes') sim.run(100.0) self.assertEqual(a.mean_spike_count(), 2.0) # mock backend always produces two spikes per population
def test_printSpikes(self, sim=sim): # TODO: implement assert_deprecated p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(11, sim.IF_cond_exp()) a = sim.Assembly(p1, p2, label="test") a.record('spikes') sim.run(10.0) a.write_data = Mock() a.printSpikes("foo.txt") a.write_data.assert_called_with('foo.txt', 'spikes', True)
def test_record_with_v_and_spikes(self, sim=sim): p = sim.Population(2, sim.EIF_cond_exp_isfa_ista()) p.record(('v', 'spikes')) sim.run(10.0) data = p.get_data(gather=True).segments[0] self.assertEqual(len(data.analogsignalarrays), 1) n_values = int(round(10.0 / sim.get_time_step())) + 1 names = set(arr.name for arr in data.analogsignalarrays) self.assertEqual(names, set(('v'))) for arr in data.analogsignalarrays: self.assertEqual(arr.shape, (n_values, p.size))
def test_record_with_multiple_variables(self): p = sim.Population(2, sim.EIF_cond_exp_isfa_ista()) p.record(("v", "w", "gsyn_exc")) sim.run(10.0) data = p.get_data(gather=True).segments[0] self.assertEqual(len(data.analogsignalarrays), 3) n_values = int(round(10.0 / sim.get_time_step())) + 1 names = set(arr.name for arr in data.analogsignalarrays) self.assertEqual(names, set(("v", "w", "gsyn_exc"))) for arr in data.analogsignalarrays: self.assertEqual(arr.shape, (n_values, p.size))
def test_record_with_multiple_variables(self, sim=sim): p = sim.Population(4, sim.EIF_cond_exp_isfa_ista()) pv = p[0, 3] pv.record(('v', 'w', 'gsyn_exc')) sim.run(10.0) data = p.get_data(gather=True).segments[0] self.assertEqual(len(data.analogsignals), 3) n_values = int(round(10.0 / sim.get_time_step())) + 1 names = set(arr.name for arr in data.analogsignals) self.assertEqual(names, set(('v', 'w', 'gsyn_exc'))) for arr in data.analogsignals: self.assertEqual(arr.shape, (n_values, pv.size))
def test_get_spikes_with_gather(self, sim=sim): t1 = 12.3 t2 = 13.4 t3 = 14.5 p = sim.Population(14, sim.EIF_cond_exp_isfa_ista()) p.record('v') sim.run(t1) sim.run(t2) sim.reset() p.record('spikes') p.record('w') sim.run(t3) data = p.get_data(gather=True) self.assertEqual(len(data.segments), 2) seg0 = data.segments[0] self.assertEqual(len(seg0.analogsignalarrays), 1) self.assertEqual(len(seg0.spiketrains), 0) seg1 = data.segments[1] self.assertEqual(len(seg1.analogsignalarrays), 2) self.assertEqual(len(seg1.spiketrains), p.size) assert_array_equal( seg1.spiketrains[7], numpy.array([p.first_id + 7, p.first_id + 7 + 5]) % t3)
def test_get_data_with_gather(self, sim=sim): t1 = 12.3 t2 = 13.4 t3 = 14.5 p = sim.Population(14, sim.EIF_cond_exp_isfa_ista()) pv = p[::3] pv.record('v') sim.run(t1) # what if we call p.record between two run statements? # would be nice to get an AnalogSignal with a non-zero t_start # but then need to make sure we get the right initial value sim.run(t2) sim.reset() pv.record('spikes') pv.record('w') sim.run(t3) data = p.get_data(gather=True) self.assertEqual(len(data.segments), 2) seg0 = data.segments[0] self.assertEqual(len(seg0.analogsignals), 1) self.assertEqual(len(seg0.spiketrains), 0) seg1 = data.segments[1] self.assertEqual(len(seg1.analogsignals), 2) self.assertEqual(len(seg1.spiketrains), pv.size) assert_array_equal(seg1.spiketrains[2], numpy.array([p.first_id + 6, p.first_id + 6 + 5]) % t3)
def test_get_data_with_gather(self): t1 = 12.3 t2 = 13.4 t3 = 14.5 p = sim.Population(14, sim.EIF_cond_exp_isfa_ista()) pv = p[::3] pv.record('v') sim.run(t1) # what if we call p.record between two run statements? # would be nice to get an AnalogSignalArray with a non-zero t_start # but then need to make sure we get the right initial value sim.run(t2) sim.reset() pv.record('spikes') pv.record('w') sim.run(t3) data = p.get_data(gather=True) self.assertEqual(len(data.segments), 2) seg0 = data.segments[0] self.assertEqual(len(seg0.analogsignalarrays), 1) v = seg0.analogsignalarrays[0] self.assertEqual(v.name, 'v') num_points = int(round((t1 + t2)/sim.get_time_step())) + 1 self.assertEqual(v.shape, (num_points, pv.size)) self.assertEqual(v.t_start, 0.0*pq.ms) self.assertEqual(v.units, pq.mV) self.assertEqual(v.sampling_period, 0.1*pq.ms) self.assertEqual(len(seg0.spiketrains), 0) seg1 = data.segments[1] self.assertEqual(len(seg1.analogsignalarrays), 2) w = seg1.filter(name='w')[0] self.assertEqual(w.name, 'w') num_points = int(round(t3/sim.get_time_step())) + 1 self.assertEqual(w.shape, (num_points, pv.size)) self.assertEqual(v.t_start, 0.0) self.assertEqual(len(seg1.spiketrains), pv.size) assert_array_equal(seg1.spiketrains[2], numpy.array([p.first_id+6, p.first_id+6+5]) % t3)
def test_get_data_with_gather(self): t1 = 12.3 t2 = 13.4 t3 = 14.5 p = sim.Population(14, sim.EIF_cond_exp_isfa_ista()) p.record('v') sim.run(t1) # what if we call p.record between two run statements? # would be nice to get an AnalogSignalArray with a non-zero t_start # but then need to make sure we get the right initial value sim.run(t2) sim.reset() p.record('spikes') p.record('w') sim.run(t3) data = p.get_data(gather=True) self.assertEqual(len(data.segments), 2) seg0 = data.segments[0] self.assertEqual(len(seg0.analogsignalarrays), 1) v = seg0.analogsignalarrays[0] self.assertEqual(v.name, 'v') num_points = int(round((t1 + t2) / sim.get_time_step())) + 1 self.assertEqual(v.shape, (num_points, p.size)) self.assertEqual(v.t_start, 0.0 * pq.ms) self.assertEqual(v.units, pq.mV) self.assertEqual(v.sampling_period, 0.1 * pq.ms) self.assertEqual(len(seg0.spiketrains), 0) seg1 = data.segments[1] self.assertEqual(len(seg1.analogsignalarrays), 2) w = seg1.filter(name='w')[0] self.assertEqual(w.name, 'w') num_points = int(round(t3 / sim.get_time_step())) + 1 self.assertEqual(w.shape, (num_points, p.size)) self.assertEqual(v.t_start, 0.0) self.assertEqual(len(seg1.spiketrains), p.size) assert_array_equal( seg1.spiketrains[7], numpy.array([p.first_id + 7, p.first_id + 7 + 5]) % t3)
def test_get_data_with_gather(self, sim=sim): t1 = 12.3 t2 = 13.4 t3 = 14.5 p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(6, sim.IF_cond_alpha()) p3 = sim.Population(3, sim.EIF_cond_exp_isfa_ista()) a = sim.Assembly(p3, p1, p2) a.record('v') sim.run(t1) # what if we call p.record between two run statements? # would be nice to get an AnalogSignal with a non-zero t_start # but then need to make sure we get the right initial value sim.run(t2) sim.reset() a.record('spikes') p3.record('w') sim.run(t3) data = a.get_data(gather=True) self.assertEqual(len(data.segments), 2) seg0 = data.segments[0] self.assertEqual(len(seg0.analogsignals), 1) v = seg0.filter(name='v')[0] self.assertEqual(v.name, 'v') num_points = int(round((t1 + t2) / sim.get_time_step())) + 1 self.assertEqual(v.shape, (num_points, a.size)) self.assertEqual(v.t_start, 0.0 * pq.ms) self.assertEqual(v.units, pq.mV) self.assertEqual(v.sampling_period, 0.1 * pq.ms) self.assertEqual(len(seg0.spiketrains), 0) seg1 = data.segments[1] self.assertEqual(len(seg1.analogsignals), 2) w = seg1.filter(name='w')[0] self.assertEqual(w.name, 'w') num_points = int(round(t3 / sim.get_time_step())) + 1 self.assertEqual(w.shape, (num_points, p3.size)) self.assertEqual(v.t_start, 0.0) self.assertEqual(len(seg1.spiketrains), a.size)
def test_get_spikes_with_gather(self, sim=sim): t1 = 12.3 t2 = 13.4 t3 = 14.5 p = sim.Population(14, sim.EIF_cond_exp_isfa_ista()) p.record('v') sim.run(t1) sim.run(t2) sim.reset() p.record('spikes') p.record('w') sim.run(t3) data = p.get_data(gather=True) self.assertEqual(len(data.segments), 2) seg0 = data.segments[0] self.assertEqual(len(seg0.analogsignalarrays), 1) self.assertEqual(len(seg0.spiketrains), 0) seg1 = data.segments[1] self.assertEqual(len(seg1.analogsignalarrays), 2) self.assertEqual(len(seg1.spiketrains), p.size) assert_array_equal(seg1.spiketrains[7], numpy.array([p.first_id + 7, p.first_id + 7 + 5]) % t3)
def test_run(self): sim.setup() self.assertEqual(sim.run(1000.0), 1000.0) self.assertEqual(sim.run(1000.0), 2000.0)
def test_mean_spike_count(self, sim=sim): p = sim.Population(14, sim.EIF_cond_exp_isfa_ista()) p.record('spikes') sim.run(100.0) # mock backend always produces two spikes per population self.assertEqual(p.mean_spike_count(), 2.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)
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_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.setup() sim.run(1000.0) sim.reset() self.assertEqual(sim.get_current_time(), 0.0)
def test_mean_spike_count(self): p = sim.Population(14, sim.EIF_cond_exp_isfa_ista()) p.record("spikes") sim.run(100.0) self.assertEqual(p.mean_spike_count(), 2.0)
def test_mean_spike_count(self, sim=sim): p = sim.Population(14, sim.EIF_cond_exp_isfa_ista()) pv = p[2::3] pv.record('spikes') sim.run(100.0) self.assertEqual(p.mean_spike_count(), 2.0)
def test_mean_spike_count(self, sim=sim): p = sim.Population(14, sim.EIF_cond_exp_isfa_ista()) p.record('spikes') sim.run(100.0) self.assertEqual(p.mean_spike_count(), 2.0)
def test_mean_spike_count(self, sim=sim): p = sim.Population(14, sim.EIF_cond_exp_isfa_ista()) p.record('spikes') sim.run(100.0) self.assertEqual(p.mean_spike_count(), 2.0) # mock backend always produces two spikes per population