def test_first_and_last_id(self): p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(6, sim.IF_cond_exp()) p3 = sim.Population(3, sim.EIF_cond_exp_isfa_ista()) a = sim.Assembly(p3, p1, p2) self.assertEqual(a.first_id, p1[0]) self.assertEqual(a.last_id, p3[-1])
def test___add__two(self): # adding two population views should give an Assembly pv1 = sim.Population(6, sim.IF_cond_exp())[2, 3, 5] pv2 = sim.Population(17, sim.IF_cond_exp())[4, 2, 16] assembly = pv1 + pv2 self.assertIsInstance(assembly, sim.Assembly) self.assertEqual(assembly.populations, [pv1, pv2])
def test_positions_property(self): p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(11, sim.IF_cond_exp()) a = sim.Assembly(p1, p2, label="test") assert_array_equal( a.positions, numpy.concatenate((p1.positions, p2.positions), axis=1))
def test___add__two(self): # adding two populations should give an Assembly p1 = sim.Population(6, EIF_cond_exp_isfa_ista()) p2 = sim.Population(17, IF_cond_exp()) assembly = p1 + p2 self.assertIsInstance(assembly, sim.Assembly) self.assertEqual(assembly.populations, [p1, p2])
def test_initialize(self): p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(11, sim.IF_cond_exp()) a = sim.Assembly(p1, p2) v_init = -54.3 a.initialize(v=v_init) assert_array_equal(p2.initial_values['v'].evaluate(simplify=True), v_init)
def test_SpikeSourceArray(self): spike_times = [50.] p = sim.Population(3, sim.SpikeSourceArray(spike_times=spike_times)) p2 = sim.Population(3, sim.Hardware_IF_cond_exp()) syn = sim.StaticSynapse(weight=0.012) con = sim.Projection(p, p2, connector=sim.OneToOneConnector(), synapse_type=syn, receptor_type='excitatory') spike_times_g = p.get('spike_times') p2.record('v') sim.run(100.0) weights = nan_to_num(con.get('weight', format="array")) print weights data = p2.get_data().segments[0] vm = data.filter(name="v")[0] print vm Figure( Panel(weights, data_labels=["ext->cell"], line_properties=[{ 'xticks': True, 'yticks': True, 'cmap': 'Greys' }]), Panel(vm, ylabel="Membrane potential (mV)", data_labels=["excitatory", "excitatory"], line_properties=[{ 'xticks': True, 'yticks': True }]), ).save("result")
def test__homogeneous_synapses(self): p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(6, sim.IF_cond_exp()) p3 = sim.Population(3, sim.EIF_cond_exp_isfa_ista()) a1 = sim.Assembly(p1, p2) a2 = sim.Assembly(p1, p3) self.assertTrue(a1._homogeneous_synapses) self.assertFalse(a2._homogeneous_synapses)
def test_getitem_int(self): p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(6, sim.IF_cond_exp()) p3 = sim.Population(3, sim.EIF_cond_exp_isfa_ista()) a = sim.Assembly(p3, p1, p2) self.assertEqual(a[0], p3[0]) self.assertEqual(a[3], p1[0]) self.assertEqual(a[14], p2[0])
def test_add_inplace_assembly(self): p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(11, sim.IF_cond_exp()) p3 = sim.Population(11, sim.IF_cond_exp()) a1 = sim.Assembly(p1, p2) a2 = sim.Assembly(p2, p3) a1 += a2 self.assertEqual(a1.populations, [p1, p2, p3])
def test___add__three(self): # adding three populations should give an Assembly p1 = sim.Population(6, IF_cond_exp()) p2 = sim.Population(17, EIF_cond_exp_isfa_ista()) p3 = sim.Population(9, sim.SpikeSourceArray()) assembly = p1 + p2 + p3 self.assertIsInstance(assembly, sim.Assembly) self.assertEqual(assembly.populations, [p1, p2, p3])
def test__add__assembly(self): p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(11, sim.IF_cond_exp()) p3 = sim.Population(11, sim.IF_cond_exp()) a1 = sim.Assembly(p1, p2) a2 = sim.Assembly(p2, p3) a3 = a1 + a2 self.assertEqual(a3.populations, [p1, p2, p3]) # or do we want [p1, p2, p3]?
def test__add__population(self): p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(11, sim.IF_cond_exp()) a1 = sim.Assembly(p1) self.assertEqual(a1.populations, [p1]) a2 = a1 + p2 self.assertEqual(a1.populations, [p1]) self.assertEqual(a2.populations, [p1, p2])
def test_all_iterator(self): p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(6, sim.IF_cond_exp()) p3 = sim.Population(3, sim.EIF_cond_exp_isfa_ista()) a = sim.Assembly(p1, p2, p3) assert hasattr(a.all(), "next") ids = list(a.all()) self.assertEqual(ids, p1.all_cells.tolist() + p2.all_cells.tolist() + p3.all_cells.tolist())
def test___add__three(self): # adding three population views should give an Assembly pv1 = sim.Population(6, sim.IF_cond_exp())[0:3] pv2 = sim.Population(17, sim.IF_cond_exp())[1, 5, 14] pv3 = sim.Population(9, sim.EIF_cond_exp_isfa_ista())[3:8] assembly = pv1 + pv2 + pv3 self.assertIsInstance(assembly, sim.Assembly) self.assertEqual(assembly.populations, [pv1, pv2, pv3])
def test_conductance_based(self): p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(6, sim.IF_cond_exp()) p3 = sim.Population(3, sim.EIF_cond_exp_isfa_ista()) a1 = sim.Assembly(p1, p2) a2 = sim.Assembly(p1, p3) self.assertTrue(a1.conductance_based) self.assertFalse(a2.conductance_based)
def runTest(self): import numpy import pyNN.hardware.brainscales as pynn # set-up the simulator pynn.setup( timestep=0.1, useSystemSim=True, speedupFactor=8000, ignoreDatabase=True, ignoreHWParameterRanges=True, hardware=pynn.hardwareSetup['one-hicann'], ) # Set the neuron model class neuron_model = pynn.IF_cond_exp # I&F neuron_parameters = { 'cm': 0.281, # membrane capacitance nF 'e_rev_E': 0.0, # excitatory reversal potential in mV 'e_rev_I': -50.0, # inhibitory reversal potential in mV (HIGHER THAN v_thresh) 'i_offset': 0.0, # offset current 'tau_m': 9.3667, # membrane time constant 'tau_refrac': 1.0, # absolute refractory period 'tau_syn_E': 5.0, # excitatory synaptic time constant 'tau_syn_I': 5.0, # inhibitory synaptic time constant 'v_reset': -70.6, # reset potential in mV 'v_rest': -70.6, # resting potential in mV 'v_thresh': -55., # spike initiaton threshold voltage in mV } # We create a Population with 1 neuron of our N1 = pynn.Population(size=1, cellclass=neuron_model, cellparams=neuron_parameters) spiketimes = numpy.arange(10., 60., 5.) S1 = pynn.Population(1, pynn.SpikeSourceArray, cellparams={'spike_times': spiketimes}) pynn.Projection(S1, N1, pynn.AllToAllConnector(weights=0.010425507084882381), target='excitatory') # max weight in hardware # record the voltage of all neurons of the population N1.record() # run the simulation for 200 ms pynn.run(80.) spikes = N1.getSpikes() pynn.end() self.assertEqual( spikes.shape, (3, 2), "Number of spikes is not as expected") # should have 3 spikes!!
def test_print_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.write_data = Mock() a.print_v("foo.txt") a.write_data.assert_called_with('foo.txt', 'v', True)
def test_get_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.get_data = Mock() a.get_gsyn() a.get_data.assert_called_with(['gsyn_exc', 'gsyn_inh'], True)
def test_get_population(self): p1 = sim.Population(11, sim.IF_cond_exp()) p1.label = "pop1" p2 = sim.Population(11, sim.IF_cond_exp()) p2.label = "pop2" a = sim.Assembly(p1, p2) self.assertEqual(a.get_population("pop1"), p1) self.assertEqual(a.get_population("pop2"), p2) self.assertRaises(KeyError, a.get_population, "foo")
def test_getSpikes(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('spikes') sim.run(10.0) a.get_data = Mock() a.getSpikes() a.get_data.assert_called_with('spikes', True)
def test_id_to_index(self): p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(6, sim.IF_cond_exp()) p3 = sim.Population(3, sim.EIF_cond_exp_isfa_ista()) a = sim.Assembly(p3, p1, p2) self.assertEqual(a.id_to_index(p3[0]), 0) self.assertEqual(a.id_to_index(p1[0]), 3) self.assertEqual(a.id_to_index(p2[0]), 14) assert_array_equal(a.id_to_index([p1[0], p2[0], p3[0]]), [3, 14, 0])
def test_local_cells(self): p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(11, sim.IF_cond_exp()) p3 = sim.Population(11, sim.IF_cond_exp()) a = sim.Assembly(p1, p2, p3) self.assertEqual(a.local_cells.size, p1.local_cells.size + p2.local_cells.size + p3.local_cells.size) self.assertEqual(a.local_cells[0], p1.local_cells[0]) self.assertEqual(a.local_cells[-1], p3.local_cells[-1]) assert_array_equal(a.local_cells, numpy.append(p1.local_cells, (p2.local_cells, p3.local_cells)))
def test_printSpikes(self): # 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_sample(self): p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(6, sim.IF_cond_exp()) p3 = sim.Population(3, sim.EIF_cond_exp_isfa_ista()) a = sim.Assembly(p3, p1, p2) a1 = a.sample(10, rng=MockRNG()) # MockRNG.permutation reverses the order self.assertEqual(len(a1.populations), 2) assert_array_equal(a1.populations[0].all_cells, p1[11:6:-1]) assert_array_equal(a1.populations[1].all_cells, p2[6::-1])
def test_mask_local(self): p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(11, sim.IF_cond_exp()) p3 = sim.Population(11, sim.IF_cond_exp()) a = sim.Assembly(p1, p2, p3) self.assertEqual(a._mask_local.size, p1._mask_local.size + p2._mask_local.size + p3._mask_local.size) self.assertEqual(a._mask_local[0], p1._mask_local[0]) self.assertEqual(a._mask_local[-1], p3._mask_local[-1]) assert_array_equal(a._mask_local, numpy.append(p1._mask_local, (p2._mask_local, p3._mask_local))) assert_array_equal(a.local_cells, a.all_cells[a._mask_local])
def test_create_with_implicit_grid(self): p = sim.Population((11,), IF_cond_exp()) self.assertEqual(p.size, 11) self.assertIsInstance(p.structure, space.Line) p = sim.Population((5, 6), IF_cond_exp()) self.assertEqual(p.size, 30) self.assertIsInstance(p.structure, space.Grid2D) p = sim.Population((2, 3, 4), IF_cond_exp()) self.assertEqual(p.size, 24) self.assertIsInstance(p.structure, space.Grid3D) self.assertRaises(Exception, sim.Population, (2, 3, 4, 5), IF_cond_exp())
def test_getitem_slice(self): p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(6, sim.IF_cond_exp()) p3 = sim.Population(3, sim.EIF_cond_exp_isfa_ista()) a = sim.Assembly(p3, p1, p2) a1 = a[0:3] self.assertIsInstance(a1, sim.Assembly) self.assertEqual(len(a1.populations), 1) assert_array_equal(a1.populations[0].all_cells, p3[:].all_cells) a2 = a[2:8] self.assertEqual(len(a2.populations), 2) assert_array_equal(a2.populations[0].all_cells, p3[2:].all_cells) assert_array_equal(a2.populations[1].all_cells, p1[:5].all_cells)
def test_getitem_array(self): p1 = sim.Population(11, sim.IF_cond_exp()) p2 = sim.Population(6, sim.IF_cond_exp()) p3 = sim.Population(3, sim.EIF_cond_exp_isfa_ista()) a = sim.Assembly(p3, p1, p2) a1 = a[3, 5, 6, 10] self.assertIsInstance(a1, sim.Assembly) self.assertEqual(len(a1.populations), 1) assert_array_equal(a1.populations[0].all_cells, [p1[0], p1[2], p1[3], p1[7]]) a2 = a[17, 2, 10, 11, 19] self.assertEqual(len(a2.populations), 3) assert_array_equal(a2.populations[0].all_cells, p3[2:].all_cells) assert_array_equal(a2.populations[1].all_cells, p1[7:9].all_cells) assert_array_equal(a2.populations[2].all_cells, p2[3, 5].all_cells)
def test_save_positions(self): import os p1 = sim.Population(2, sim.IF_cond_exp()) p2 = sim.Population(2, sim.IF_cond_exp()) p1.positions = numpy.arange(0, 6).reshape((2, 3)).T p2.positions = numpy.arange(6, 12).reshape((2, 3)).T a = sim.Assembly(p1, p2, label="test") output_file = Mock() a.save_positions(output_file) assert_array_equal( output_file.write.call_args[0][0], numpy.array([[int(p1[0]), 0, 1, 2], [int(p1[1]), 3, 4, 5], [int(p2[0]), 6, 7, 8], [int(p2[1]), 9, 10, 11]])) self.assertEqual(output_file.write.call_args[0][1], {'assembly': a.label})
def test_get_positions(self): p = sim.Population(11, sim.IF_cond_exp()) ppos = numpy.random.uniform(size=(3, 11)) p._positions = ppos pv = sim.PopulationView(parent=p, selector=slice(3, 9, 2)) assert_array_equal(pv.positions, numpy.array([ppos[:, 3], ppos[:, 5], ppos[:, 7]]).T)