def test_get_multiple_inhomogeneous_params_with_gather(self, sim=sim): p1 = sim.Population( 4, sim.IF_cond_exp(tau_m=12.3, tau_syn_E=[0.987, 0.988, 0.989, 0.990], tau_syn_I=lambda i: 0.5 + 0.1 * i)) p2 = sim.Population( 3, sim.EIF_cond_exp_isfa_ista(tau_m=12.3, tau_syn_E=[0.991, 0.992, 0.993], tau_syn_I=lambda i: 0.5 + 0.1 * (i + 4))) a = p1 + p2 tau_syn_E, tau_m, tau_syn_I = a.get( ('tau_syn_E', 'tau_m', 'tau_syn_I'), gather=True) self.assertIsInstance(tau_m, float) self.assertIsInstance(tau_syn_E, np.ndarray) assert_array_equal( tau_syn_E, np.array([0.987, 0.988, 0.989, 0.990, 0.991, 0.992, 0.993])) self.assertAlmostEqual(tau_m, 12.3) assert_array_almost_equal(tau_syn_I, np.array([0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1]), decimal=12)
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
def test_can_record(self, sim=sim): p = sim.Population(17, sim.EIF_cond_exp_isfa_ista()) assert p.can_record('v') assert p.can_record('w') assert p.can_record('gsyn_inh') assert p.can_record('spikes') assert not p.can_record('foo')
def test_initialize(self): p = sim.Population(17, sim.EIF_cond_exp_isfa_ista()) v_init = numpy.linspace(-70.0, -60.0, num=p.size) w_init = 0.1 p.initialize(v=v_init, w=w_init) assert_array_equal(p.initial_values['v'].evaluate(simplify=True), v_init) assert_array_equal(p.initial_values['w'].evaluate(simplify=True), w_init)
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_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() p.mean_spike_count.assert_called()
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_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_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_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_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_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, 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_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_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_record_gsyn(self, sim=sim): p = sim.Population(2, sim.EIF_cond_exp_isfa_ista()) p.record = Mock() p.record_gsyn("arg1") p.record.assert_called_with(['gsyn_exc', 'gsyn_inh'], "arg1")
def test_record_v(self, sim=sim): p = sim.Population(2, sim.EIF_cond_exp_isfa_ista()) p.record = Mock() p.record_v("arg1") p.record.assert_called_with('v', "arg1")