def test_popview_on_hicann(self, size): pynn.setup(marocco=self.marocco) neuron_size = 4 self.marocco.neuron_placement.default_neuron_size(neuron_size) hicann = C.HICANNOnWafer(Enum(122)) hicann_1 = C.HICANNOnWafer(Enum(123)) hicann_2 = C.HICANNOnWafer(Enum(124)) hicann_3 = C.HICANNOnWafer(Enum(125)) pop = pynn.Population(size, pynn.IF_cond_exp, {}) pop_1 = pynn.Population(size, pynn.IF_cond_exp, {}) pop_view = pynn.PopulationView(pop,list(range(0,size,2))) pop_view_1 = pynn.PopulationView(pop,list(range(1,size,2))) pop_1_view = pynn.PopulationView(pop_1,list(range(1,size//2))) pop_1_view_1 = pynn.PopulationView(pop_1,list(range(size-2,size//2,-1))) pop_auto_placement = pynn.PopulationView(pop_1,[0,size//2,size-1]) self.marocco.manual_placement.on_hicann(pop_view, hicann) self.marocco.manual_placement.on_hicann(pop_view_1, hicann_1) self.marocco.manual_placement.on_hicann(pop_1_view, hicann_2) self.marocco.manual_placement.on_hicann(pop_1_view_1, hicann_3) if neuron_size * size//2 > C.NeuronOnHICANN.enum_type.size: with self.assertRaises(RuntimeError): pynn.run(0) pynn.end() return pynn.run(0) pynn.end() results = self.load_results() for nrn in pop_view: placement_item, = results.placement.find(nrn) logical_neuron = placement_item.logical_neuron() for denmem in logical_neuron: self.assertEqual(hicann, denmem.toHICANNOnWafer()) for nrn in pop_view_1: placement_item, = results.placement.find(nrn) logical_neuron = placement_item.logical_neuron() for denmem in logical_neuron: self.assertEqual(hicann_1, denmem.toHICANNOnWafer()) for nrn in pop_1_view: placement_item, = results.placement.find(nrn) logical_neuron = placement_item.logical_neuron() for denmem in logical_neuron: self.assertEqual(hicann_2, denmem.toHICANNOnWafer()) for nrn in pop_1_view_1: placement_item, = results.placement.find(nrn) logical_neuron = placement_item.logical_neuron() for denmem in logical_neuron: self.assertEqual(hicann_3, denmem.toHICANNOnWafer()) for nrn in pop_auto_placement: placement_item, = results.placement.find(nrn) logical_neuron = placement_item.logical_neuron() for denmem in logical_neuron: self.assertIsNotNone(denmem.toHICANNOnWafer())
def test_popview_on_neuron(self): pynn.setup(marocco=self.marocco) pop = pynn.Population(4, pynn.IF_cond_exp, {}) neuron_block = C.NeuronBlockOnWafer(C.NeuronBlockOnHICANN(3)) neuron_block_1 = C.NeuronBlockOnWafer(C.NeuronBlockOnHICANN(2)) logical_neuron = (LogicalNeuron.on(neuron_block) .add(C.NeuronOnNeuronBlock(X(3), Y(0)), 2) .add(C.NeuronOnNeuronBlock(X(3), Y(1)), 2) .done()) logical_neuron_1 = (LogicalNeuron.on(neuron_block_1) .add(C.NeuronOnNeuronBlock(X(4), Y(0)), 2) .add(C.NeuronOnNeuronBlock(X(4), Y(1)), 2) .done()) popview = pynn.PopulationView(pop,[0]) popview_1 = pynn.PopulationView(pop,[2]) popview_auto_placement= pynn.PopulationView(pop,[1,3]) self.marocco.manual_placement.on_neuron(popview, logical_neuron) self.marocco.manual_placement.on_neuron(popview_1, logical_neuron_1) pynn.run(0) pynn.end() results = self.load_results() placement_item, = results.placement.find(popview[0]) self.assertEqual(logical_neuron, placement_item.logical_neuron()) placement_item, = results.placement.find(popview_1[0]) self.assertEqual(logical_neuron_1, placement_item.logical_neuron()) for nrn in popview_auto_placement: placement_item, = results.placement.find(nrn) self.assertIsNotNone(placement_item.logical_neuron())
def test_Constructor(self): import numpy import pymarocco marocco = pymarocco.PyMarocco() marocco.calib_backend = pymarocco.PyMarocco.CalibBackend.Default pynn.setup(marocco=marocco) N = 10 model = pynn.IF_cond_exp selector = numpy.array( [random.choice([True, False]) for x in range(0, N)]) pop = pynn.Population(N, model) pv = pynn.PopulationView(pop, selector) self.assertEqual(len(pv), len(numpy.where(selector == True)[0])) # now a selection with wrong size is given wrong_selector = numpy.array( [random.choice([True, False]) for x in range(0, 2 * N)]) with self.assertRaises(RuntimeError): pv = pynn.PopulationView(pop, wrong_selector) pynn.run(100)
def test_same_popview_on_hicann(self, size): pynn.setup(marocco=self.marocco) neuron_size = 4 self.marocco.neuron_placement.default_neuron_size(neuron_size) hicann = C.HICANNOnWafer(Enum(123)) hicann_1 = C.HICANNOnWafer(Enum(122)) pop = pynn.Population(size, pynn.IF_cond_exp, {}) pop_view = pynn.PopulationView(pop,[0]) pop_view_1 = pynn.PopulationView(pop,[0]) self.marocco.manual_placement.on_hicann(pop_view, hicann) self.marocco.manual_placement.on_hicann(pop_view_1, hicann_1) with self.assertRaises(RuntimeError): pynn.run(0) pynn.end()
def test_popview_external_source(self): pynn.setup(marocco=self.marocco) neuron_size = 4 self.marocco.neuron_placement.default_neuron_size(neuron_size) size = 10 pop_ext = pynn.Population(size, pynn.SpikeSourcePoisson, {'rate':2}) pop_ext_1 = pynn.Population(size, pynn.SpikeSourcePoisson, {'rate':2}) pop = pynn.Population(size, pynn.IF_cond_exp, {}) connector = pynn.AllToAllConnector(weights=1) projections = [ pynn.Projection(pop_ext, pop, connector, target='excitatory'), pynn.Projection(pop_ext_1, pop, connector, target='excitatory'), ] hicann = C.HICANNOnWafer(Enum(121)) hicann_1 = C.HICANNOnWafer(Enum(122)) pop_view = pynn.PopulationView(pop_ext,list(range(1,size,2))) pop_view_1 = pynn.PopulationView(pop_ext,list(range(0,size,2))) pop_1_view = pynn.PopulationView(pop_ext_1,list(range(1,size//2))) pop_1_view_1 = pynn.PopulationView(pop_ext_1,list(range(size-2,size//2,-1))) pop_1_auto_placement = pynn.PopulationView(pop_ext_1,[0,size//2,size-1]) self.marocco.manual_placement.on_hicann(pop_view, hicann) self.marocco.manual_placement.on_hicann(pop_view_1, hicann_1) self.marocco.manual_placement.on_hicann(pop_1_view, hicann) self.marocco.manual_placement.on_hicann(pop_1_view_1, hicann_1) pynn.run(0) pynn.end() results = self.load_results() for nrn in pop_view: placement_item, = results.placement.find(nrn) self.assertEqual(hicann, placement_item.dnc_merger().toHICANNOnWafer()) for nrn in pop_view_1: placement_item, = results.placement.find(nrn) self.assertEqual(hicann_1, placement_item.dnc_merger().toHICANNOnWafer()) for nrn in pop_1_view: placement_item, = results.placement.find(nrn) self.assertEqual(hicann, placement_item.dnc_merger().toHICANNOnWafer()) for nrn in pop_1_view_1: placement_item, = results.placement.find(nrn) self.assertEqual(hicann_1, placement_item.dnc_merger().toHICANNOnWafer()) for nrn in pop_1_auto_placement: placement_item, = results.placement.find(nrn) self.assertIsNotNone(placement_item.dnc_merger().toHICANNOnWafer())
def test_population_view(self): size = random.randint(1, 1000) text = '%ds till the end' % size celltype = pyhmf.IF_cond_exp selector = numpy.array( [random.choice([True, False]) for x in range(0, size)]) pop = pyhmf.Population(size, celltype, label=text) pv = pyhmf.PopulationView(pop, selector) size_selector = len(numpy.where(selector == True)[0]) pynn_text = 'view of \"%ds till the end\" containing %d' % ( size, size_selector) self.assertEqual(size_selector, len(list(pv.__iter__()))) self.assertEqual(size_selector, len(list(pv.all()))) self.assertEqual(size_selector, len(pv)) self.assertEqual(size_selector, pv.size) self.assertEqual(pynn_text, pv.label) self.assertEqual(celltype, pv.celltype) pv2_label = "test custom label" pv2 = pyhmf.PopulationView(pop, selector, label=pv2_label) self.assertEqual(pv2_label, pv2.label)
def test_popview_combinations(self, view_number): # tests all possible combinations of mask lengths for different number of PopulationViews import pylogging from pymarocco import PyMarocco, Defects from pymarocco.results import Marocco pop_size = 5 hicanns = [C.HICANNOnWafer(Enum(180 + view)) for view in range(view_number)] # generate possible mask lengths for Population Views pool = tuple(i for i in range(1, pop_size - view_number + 2)) # generate all possible mask lengths for each PopulationView for a given total number of neurons # [[lengths_of_Popviews],number_of_used_neurons] view_lengths = [([], 0)] for _ in range(view_number): view_lengths = [(x+[y], csum+y) for x, csum in view_lengths for y in pool if csum <= pop_size - y] neurons = list(range(pop_size)) for length in view_lengths: marocco = PyMarocco() marocco.backend = PyMarocco.Without marocco.persist = "results.bin" marocco.defects.backend = Defects.Backend.Without neuron_size = 4 marocco.neuron_placement.default_neuron_size(neuron_size) pynn.setup(marocco=marocco) pop = pynn.Population(pop_size, pynn.IF_cond_exp, {}) pop_views = [] index = 0 for view in range(view_number): # generate PopulationViews with all possible mask lengths # no permutations of neurons are tested pop_views.append(pynn.PopulationView(pop,neurons[index:index+length[0][view]])) marocco.manual_placement.on_hicann(pop_views[view],hicanns[view]) index += length[0][view] pynn.run(0) pynn.end() results = Marocco.from_file(marocco.persist) for view in range(view_number): for nrn in pop_views[view]: placement_item, = results.placement.find(nrn) logical_neuron = placement_item.logical_neuron() for denmem in logical_neuron: self.assertEqual(hicanns[view], denmem.toHICANNOnWafer())
marocco = PyMarocco() marocco.calib_backend = PyMarocco.CalibBackend.Default marocco.defects.backend = Defects.Backend.None marocco.neuron_placement.skip_hicanns_without_neuron_blacklisting(False) marocco.persist = "results.xml.gz" pynn.setup(marocco=marocco) # place the full population to a specific HICANN pop = pynn.Population(1, pynn.IF_cond_exp) marocco.manual_placement.on_hicann(pop, HICANNOnWafer(X(5), Y(5)), 4) # place only parts of a population pop2 = pynn.Population(3, pynn.IF_cond_exp) marocco.manual_placement.on_hicann(pynn.PopulationView(pop2, [0]), HICANNOnWafer(Enum(5))) marocco.manual_placement.on_hicann(pynn.PopulationView(pop2, [1]), HICANNOnWafer(Enum(1))) # the third neuron will be automatically placed pynn.run(10) pynn.end() results = Marocco.from_file(marocco.persist) for denmem in get_denmems(pop, results): print denmem for denmem in get_denmems(pop2, results): print denmem
for denmem in item.logical_neuron(): yield denmem marocco = PyMarocco() marocco.calib_backend = PyMarocco.CalibBackend.Default marocco.defects.backend = Defects.Backend.None marocco.neuron_placement.skip_hicanns_without_neuron_blacklisting(False) marocco.persist = "results.xml.gz" pynn.setup(marocco = marocco) # place the full population to a specific HICANN pop = pynn.Population(1, pynn.IF_cond_exp) marocco.manual_placement.on_hicann(pop, C.HICANNOnWafer(C.X(5), C.Y(5)), 4) # place only parts of a population pop2 = pynn.Population(3, pynn.IF_cond_exp) marocco.manual_placement.on_hicann(pynn.PopulationView(pop2, [0]), C.HICANNOnWafer(C.Enum(5))) marocco.manual_placement.on_hicann(pynn.PopulationView(pop2, [1]), C.HICANNOnWafer(C.Enum(1))) # the third neuron will be automatically placed pynn.run(10) pynn.end() results = Marocco.from_file(marocco.persist) for denmem in get_denmems(pop, results): print denmem for denmem in get_denmems(pop2, results): print denmem
'cm': 0.2, # nF 'v_reset': -30, # mV 'v_rest': -20, # mV 'v_thresh': -16, # mV 'e_rev_I': -40, # mV 'e_rev_E': 0, # mV 'tau_m': 10, # ms 'tau_refrac': 1, # ms 'tau_syn_E': 5, # ms 'tau_syn_I': 5, # ms } population = pynn.Population(2, pynn.IF_cond_exp, neuron_parameters) population.record() neuron0 = pynn.PopulationView(population, [0]) neuron0.record_v() neuron1 = pynn.PopulationView(population, [1]) neuron1.record_v() stimulus_0 = pynn.Population(1, pynn.SpikeSourceArray, {"spike_times" : [10,50,55,60,65,105,110,115,120,125]}) # in ms stimulus_1 = pynn.Population(1, pynn.SpikeSourceArray, {"spike_times" : [300,310,320,325,330,335,340,345]}) # in ms marocco.manual_placement.on_hicann(stimulus_1, C.HICANNOnWafer(C.Enum(98))) pynn.Projection(stimulus_0, neuron0, pynn.AllToAllConnector(weights=0.005), target="excitatory") # weight in uS pynn.Projection(stimulus_0, neuron1, pynn.AllToAllConnector(weights=0.005), target="excitatory") # weight in uS pynn.Projection(stimulus_1, neuron0, pynn.AllToAllConnector(weights=0.1), target="excitatory") # weight in uS pynn.Projection(stimulus_1, neuron1, pynn.AllToAllConnector(weights=0.1), target="excitatory") # weight in uS