def test_assembly(self): size_a = random.randint(1, 1000) size_b = random.randint(1, 1000) pop_a = pyhmf.Population(size_a, pyhmf.IF_cond_exp) pop_b = pyhmf.Population(size_b, pyhmf.IF_cond_exp) pop_c = pyhmf.Population(1, pyhmf.IF_cond_exp) view = pop_b[0:random.randint(1, size_b)] text = '%ds till the end' % (size_a + size_b) construction_styles = [ pyhmf.Assembly(pop_a, view, label=text), pyhmf.Assembly([pop_a, view], label=text), pyhmf.Assembly((pop_a, view), label=text) ] for asm in construction_styles: self.assertEqual(len(asm), len(list(asm.__iter__()))) self.assertEqual(len(asm), len(list(asm.all()))) self.assertEqual(size_a + len(view), len(asm)) self.assertEqual(size_a + len(view), asm.size) self.assertEqual(text, asm.label) # some more tests ;) pyhmf.Assembly(pop_a), pyhmf.Assembly(pop_a, label=text), pyhmf.Assembly([pop_a]), pyhmf.Assembly([pop_a], label=text), pyhmf.Assembly(pop_c, label=text),
def test_projections(self): pynn.setup(marocco=self.marocco) target = pynn.Population(1, pynn.IF_cond_exp, {}) pop_a = pynn.Population(2, pynn.SpikeSourceArray, {'spike_times': [1.]}) pop_b = pynn.Population(1, pynn.SpikeSourceArray, {'spike_times': [2.]}) pop_ab = pynn.Assembly() pop_ab += pop_a pop_ab += pop_b con = pynn.AllToAllConnector(weights=0.004) proj_a = pynn.Projection(pop_a, target, con) proj_b = pynn.Projection(pop_b, target, con) proj_ab = pynn.Projection(pop_ab, target, con) pynn.run(0) pynn.end() results = self.load_results() synapses = results.synapse_routing.synapses() items_a = synapses.find(proj_a) self.assertEqual(2, len(items_a)) items_b = synapses.find(proj_b) self.assertEqual(1, len(items_b)) items_ab = synapses.find(proj_ab) self.assertEqual(3, len(items_ab)) def to_hw_synapses(items): hw_synapses = set() for item in items: synapse = item.hardware_synapse() if synapse: hw_synapses.add(synapse) return hw_synapses hw_a = to_hw_synapses(items_a) hw_b = to_hw_synapses(items_b) hw_ab = to_hw_synapses(items_ab) self.assertTrue(hw_a.isdisjoint(hw_b)) self.assertTrue(hw_a.isdisjoint(hw_ab)) self.assertTrue(hw_b.isdisjoint(hw_ab)) for source_neuron in pop_a: items = synapses.find(proj_ab, source_neuron, target[0]) self.assertEqual(1, len(items)) self.assertTrue(hw_ab.issuperset(to_hw_synapses(items))) for source_neuron in pop_b: items = synapses.find(proj_ab, source_neuron, target[0]) self.assertEqual(1, len(items)) self.assertTrue(hw_ab.issuperset(to_hw_synapses(items)))
def test_loss_in_wafer_routing(self, mode): h0 = HICANNGlobal(HICANNOnWafer(Enum(0)), Wafer(33)) h1 = HICANNGlobal(HICANNOnWafer(Enum(1)), Wafer(33)) # disable all horizontal buses on h0 hicann = pyredman.Hicann() for hbus in iter_all(HLineOnHICANN): hicann.hbuses().disable(hbus) self.marocco.defects.set(pyredman.Wafer()) self.marocco.defects.wafer().inject(h0, hicann) pynn.setup(marocco=self.marocco) n1 = 100 n2 = 100 p1 = pynn.Population(n1, pynn.EIF_cond_exp_isfa_ista) p2 = pynn.Population(n2, pynn.EIF_cond_exp_isfa_ista) self.marocco.manual_placement.on_hicann(p1, h0) self.marocco.manual_placement.on_hicann(p2, h1) n_post = 10 if mode == "Population": src = p1 tgt = p2 exp_loss = len(src) * n_post elif mode == "PopulationView": src = p1[n1 // 2:n1] tgt = p2[n2 // 2:n2] exp_loss = len(src) * n_post elif mode == "Assembly": src = pynn.Assembly(p1, p2) tgt = p2 exp_loss = len(p1) * n_post conn = pynn.FixedNumberPostConnector(n_post, allow_self_connections=True, weights=1.) proj = pynn.Projection(src, tgt, conn, target='excitatory') pynn.run(100) pynn.end() # check stats self.assertEqual(exp_loss, self.marocco.stats.getSynapseLossAfterL1Routing()) self.assertEqual(exp_loss, self.marocco.stats.getSynapseLoss()) # check weight matrices orig_weights = proj.getWeights(format="array") mapped_weights = self.marocco.stats.getWeights(proj) lost_syns = np.logical_and(np.isfinite(orig_weights), np.isnan(mapped_weights)) self.assertEqual(exp_loss, np.count_nonzero(lost_syns))
def test_Constructor(self): import pymarocco marocco = pymarocco.PyMarocco() marocco.calib_backend = pymarocco.PyMarocco.CalibBackend.Default pynn.setup(marocco=marocco) NPOP = 100 popus = [ pynn.Population(random.randint(10, 100), pynn.IF_cond_exp) for x in range(0, NPOP) ] a = pynn.Assembly(*popus) size = sum([len(p) for p in popus]) self.assertEqual(len(a), size) pynn.run(1000)
def test_cell_ids(self): """ tests that [Population,PopulationView,Assembly].getSpikes() uses the expected cell ids, cf. issue #1955 """ import pymarocco marocco = pymarocco.PyMarocco() marocco.backend = pymarocco.PyMarocco.ESS marocco.experiment_time_offset = 5.e-7 marocco.neuron_placement.skip_hicanns_without_neuron_blacklisting( False) marocco.continue_despite_synapse_loss = True marocco.calib_backend = pymarocco.PyMarocco.CalibBackend.Default marocco.defects.backend = pymarocco.Defects.Backend.None marocco.hicann_configurator = pymarocco.PyMarocco.HICANNConfigurator setup_params = dict() if pynn.__name__ == "pyhmf": setup_params['marocco'] = marocco pynn.setup(**setup_params) # dummy target population p_dummy = pynn.Population(10, pynn.IF_cond_exp) # 1st Input Population p1 = pynn.Population(10, pynn.SpikeSourceArray) input_spikes1 = np.arange(1, 11., 1.).reshape(10, 1) for n, spikes in enumerate(input_spikes1): p1[n:n + 1].set('spike_times', spikes.tolist()) # 2nd Input Population p2 = pynn.Population(10, pynn.SpikeSourceArray) input_spikes2 = np.arange(11., 21., 1.).reshape(10, 1) for n, spikes in enumerate(input_spikes2): p2[n:n + 1].set('spike_times', spikes.tolist()) p1.record() p2.record() # dummy connections otherwise input populations are not mapped. pynn.Projection(p1, p_dummy, pynn.OneToOneConnector()) pynn.Projection(p2, p_dummy, pynn.OneToOneConnector()) pynn.run(25.) # check that cell ids refer to the index in the Population. s_p1 = p1.getSpikes() s_p1 = s_p1[np.argsort(s_p1[:, 1])] # sort by time self.assertTrue(np.array_equal(range(10), s_p1[:, 0])) s_p2 = p2.getSpikes() s_p2 = s_p2[np.argsort(s_p2[:, 1])] # sort by time self.assertTrue(np.array_equal(range(10), s_p2[:, 0])) # for PopulationViews we also expect the index in the parent Population self.assertEqual(set(p2[0:1].getSpikes()[:, 0]), set(range(1))) self.assertEqual(set(p2[1:3].getSpikes()[:, 0]), set(range(1, 3))) # In Assemblies, the cell id is equal to an offset given by the sum of # the Population sizes of the previous items (Population or # PopulationView), plus the index within in the Population. a = pynn.Assembly(p2[0:5], p1) s_a = a.getSpikes() # when sorted, ids should be: range(10,20) + range(5) s_a = s_a[np.argsort(s_a[:, 1])] # sort by time self.assertTrue(np.array_equal(range(10, 20) + range(5), s_a[:, 0]))