def build(self): # Set the neurons self.neuronsVisible = pynn.Population(self.Nvisible, self.model) self.neuronsHidden = pynn.Population(self.Nhidden, self.model) # in the fully connected rbm each neuron from the visible layer # projects to each neuron of the hidden layer (and vice versa) # both inhibitory and excitatory to enable switching the sing of the # connection during eventual training # self connections are excluded # This model only sets the skeleton of the BM without the noise sources connector = pynn.AllToAllConnector(weights=0.003, allow_self_connections=False) pynn.Projection(self.neuronsVisible, self.neuronsHidden, connector, target='excitatory') pynn.Projection(self.neuronsVisible, self.neuronsHidden, connector, target='inhibitory') pynn.Projection(self.neuronsHidden, self.neuronsVisible, connector, target='excitatory') pynn.Projection(self.neuronsHidden, self.neuronsVisible, connector, target='inhibitory')
def build_network(num_pops, pop_size, marocco): from pymarocco import PyMarocco import pyhmf as pynn logging.info("num_pops: %d, pop_size: %d, total size: %d" % (num_pops, pop_size, num_pops * pop_size)) pynn.setup(marocco=marocco) pops = [ pynn.Population(pop_size, pynn.EIF_cond_exp_isfa_ista) for x in range(num_pops) ] for idx, pop in enumerate(pops): connector = pynn.AllToAllConnector(allow_self_connections=True, weights=1.) # build ring like network topology pynn.Projection(pop, pops[(idx + 1) % len(pops)], connector, target='excitatory') # add poisson stimulus source = pynn.Population(1, pynn.SpikeSourcePoisson, {'rate': 2}) pynn.Projection(source, pop, connector, target='excitatory') pynn.run(1) pynn.end() stats = marocco.getStats() loss = float(stats.getSynapseLoss()) / stats.getSynapses() return (num_pops, pop_size, loss)
def test_issue2053(self): p1 = pyhmf.Population(1000, pyhmf.EIF_cond_exp_isfa_ista) p2 = pyhmf.Population(1000, pyhmf.EIF_cond_exp_isfa_ista) rand_distr = numpy.zeros(1000) if self.API_VERSION == "0.8": prj = pyhmf.Projection(p1, p2, pyhmf.AllToAllConnector(), pyhmf.StaticSynapse(weight=0.05, delay=0.5)) prj.get('weight', format='list', with_address=False) prj.set(delay=rand_distr) prj.set(tau_rec=50.0) prj.save('weight', 'exc_weights.txt', format='array') prj.save('all', 'exc_conn.txt', format='list') weights, delays = prj.get(['weight', 'delay'], format='array') prj.set(weight=rand_distr, delay=0.4) elif self.API_VERSION == "0.7": prj = pyhmf.Projection( p1, p2, pyhmf.AllToAllConnector(weights=0.05, delays=0.5)) prj.getWeights(format='list') prj.randomizeDelays(rand_distr) prj.setSynapseDynamics('tau_rec', 50.0) prj.printWeights('exc_weights.txt', format='array') prj.saveConnections('exc_conn.txt') weights, delays = prj.getWeights('array'), prj.getDelays('array') prj.randomizeWeights(rand_distr) prj.setDelays(0.4)
def test_projection_weights(self): import numpy from numpy.testing import assert_equal, assert_almost_equal, assert_array_equal import pyhmf as pynn size = (100, 300) noC = size[0] * size[1] p1, p2 = pynn.Population(size[0], pynn.EIF_cond_exp_isfa_ista), pynn.Population(size[1], pynn.EIF_cond_exp_isfa_ista) prj1 = pynn.Projection(p1, p2, pynn.AllToAllConnector() ) prj1.setWeights(4.0) assert_array_equal(numpy.ones(noC) * 4.0, prj1.getWeights()) assert_array_equal(numpy.ones(size) * 4.0, prj1.getWeights("matrix") ) prj1.setWeights( numpy.ones(noC) * 3.0 ) assert_array_equal(numpy.ones(noC) * 3.0, prj1.getWeights() ) assert_array_equal(numpy.ones(size) * 3.0, prj1.getWeights("matrix") ) prj1.setWeights( numpy.ones(size) * 2.0 ) assert_array_equal(numpy.ones(noC) * 2.0, prj1.getWeights() ) assert_array_equal(numpy.ones(size) * 2.0, prj1.getWeights("matrix") ) prj2 = pynn.Projection(p1, p2, pynn.AllToAllConnector(delays = 2.5, weights = numpy.ones(size))) assert_array_equal(numpy.ones(noC) * 2.5, prj2.getDelays() ) assert_array_equal(numpy.ones(size) * 2.5, prj2.getDelays("matrix") ) assert_array_equal(numpy.ones(noC) * 1.0, prj2.getWeights() ) assert_array_equal(numpy.ones(size) * 1.0, prj2.getWeights("matrix") )
def test_issue2051(self): p1 = pyhmf.Population(1000, pyhmf.EIF_cond_exp_isfa_ista) p2 = pyhmf.Population(1000, pyhmf.EIF_cond_exp_isfa_ista) if self.API_VERSION == "0.8": prj = pyhmf.Projection(p1, p2, pyhmf.AllToAllConnector(), pyhmf.StaticSynapse(weight=0.05, delay=0.5)) params = { 'U': 0.04, 'tau_rec': 100.0, 'tau_facil': 1000.0, 'weight': 0.01 } facilitating = pyhmf.TsodyksMarkramSynapse(**params) prj = pyhmf.Projection( p1, p2, pyhmf.FixedProbabilityConnector(p_connect=0.1), synapse_type=facilitating) elif self.API_VERSION == "0.7": prj = pyhmf.Projection( p1, p2, pyhmf.AllToAllConnector(weights=0.05, delays=0.5)) params = {'U': 0.04, 'tau_rec': 100.0, 'tau_facil': 1000.0} facilitating = pyhmf.SynapseDynamics( fast=pyhmf.TsodyksMarkramMechanism(**params)) prj = pyhmf.Projection(p1, p2, pyhmf.FixedProbabilityConnector( p_connect=0.1, weights=0.01), synapse_dynamics=facilitating)
def test_get_denmems(self): pop_size = 2 for neuron_size in [4, 8, 12, 16, 32]: self.marocco.neuron_placement.default_neuron_size(neuron_size) pynn.setup(marocco=self.marocco) target = pynn.Population(pop_size, pynn.IF_cond_exp, {}) populations = [target] for i in range(3): p1 = pynn.Population(pop_size, pynn.SpikeSourceArray, {'spike_times': [1.]}) p2 = pynn.Population(pop_size, pynn.IF_cond_exp, {}) pynn.Projection(p1, target, pynn.OneToOneConnector(weights=0.004)) pynn.Projection(p2, target, pynn.OneToOneConnector(weights=0.004)) populations.append(p2) pynn.run(0) pynn.end() mapstats = self.marocco.getStats() results = Marocco.from_file(self.marocco.persist) for pop in populations: for nrn in range(pop_size): for item in results.placement.find(pop[nrn]): self.assertFalse(item.logical_neuron().is_external()) self.assertEqual(neuron_size, item.logical_neuron().size())
def test(self): import pyhmf as pynn from pymarocco import PyMarocco import pylogging, pyhalbe pyhalbe.Debug.change_loglevel(2) pylogging.set_loglevel(pylogging.get("marocco"), pylogging.LogLevel.TRACE) pylogging.set_loglevel(pylogging.get("sthal"), pylogging.LogLevel.DEBUG) marocco = PyMarocco() marocco.neuron_placement.default_neuron_size(4) pynn.setup(marocco=marocco) neuron1 = pynn.Population(1, pynn.IF_cond_exp) inh = pynn.Population(1, pynn.SpikeSourceArray, {'spike_times': [0]}) exc = pynn.Population(1, pynn.SpikeSourceArray, {'spike_times': [0]}) exc_2 = pynn.Population(1, pynn.SpikeSourceArray, {'spike_times': [0]}) exc_3 = pynn.Population(1, pynn.SpikeSourceArray, {'spike_times': [0]}) c_exc = pynn.FixedProbabilityConnector(p_connect=1.0, weights=1) proj1 = pynn.Projection(inh, neuron1, c_exc, target='excitatory') proj2 = pynn.Projection(exc, neuron1, c_exc, target='excitatory') proj3 = pynn.Projection(exc_2, neuron1, c_exc, target='excitatory') proj4 = pynn.Projection(exc_3, neuron1, c_exc, target='inhibitory') pynn.run(10000) pynn.end()
def test_L1_detour_at_side_switch_usage(self): """ [155] 191 [223] 224 225 x226x {227} test detour and predecessor settings at the edge of a wafer """ pylogging.set_loglevel(pylogging.get("marocco"), pylogging.LogLevel.TRACE) pylogging.set_loglevel(pylogging.get("Calibtic"), pylogging.LogLevel.ERROR) self.marocco.persist = '' # or add test suite TestWithRuntime? runtime = Runtime(self.marocco.default_wafer) pynn.setup(marocco=self.marocco, marocco_runtime=runtime) settings = pysthal.Settings.get() settings.synapse_switches.max_switches_per_column_per_side = 1 settings.crossbar_switches.max_switches_per_row = 1 source = pynn.Population(1, pynn.IF_cond_exp, {}) target1 = pynn.Population(1, pynn.IF_cond_exp, {}) target2 = pynn.Population(1, pynn.IF_cond_exp, {}) proj = pynn.Projection( source, target1, pynn.AllToAllConnector(weights=1.)) proj = pynn.Projection( source, target2, pynn.AllToAllConnector(weights=1.)) source_hicann = C.HICANNOnWafer(Enum(227)) target1_hicann = C.HICANNOnWafer(Enum(155)) target2_hicann = C.HICANNOnWafer(Enum(225)) self.marocco.manual_placement.on_hicann(source, source_hicann) self.marocco.manual_placement.on_hicann(target1, target1_hicann) self.marocco.manual_placement.on_hicann(target2, target2_hicann) disabled_hicanns = [226, 263] wafer = self.marocco.default_wafer self.marocco.defects.set(pyredman.Wafer(runtime.wafer().index())) for hicann in C.iter_all(C.HICANNOnWafer): if hicann.toEnum().value() in disabled_hicanns: self.marocco.defects.wafer().hicanns().disable(C.HICANNGlobal(hicann, wafer)) continue pynn.run(0) pynn.end() for hicann in runtime.wafer().getAllocatedHicannCoordinates(): h = runtime.wafer()[hicann] print(hicann, h.check()) self.assertEqual(h.check(), "")
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 big_network(self): pynn.setup(marocco=self.marocco) synapses = 0 numberOfPopulations = random.randint(100, 150) logging.debug("number of populations: %d" % (numberOfPopulations)) #print "numPops: %d" % (numberOfPopulations) # FIXME: spuouriously fails, why? #pops = [ Population(random.randint(50, 85), EIF_cond_exp_isfa_ista) for x in #range(numberOfPopulations) ] pops = [ pynn.Population(80, pynn.EIF_cond_exp_isfa_ista) for x in range(numberOfPopulations) ] for idx, pop in enumerate(pops): connectorE = pynn.FixedProbabilityConnector( p_connect=0.20, allow_self_connections=True, weights=1.) connectorI = pynn.FixedProbabilityConnector( p_connect=0.10, allow_self_connections=True, weights=1.) # build ring like network topology proj = pynn.Projection(pop, pops[(idx + 1) % len(pops)], connectorE, target='excitatory') synapses += np.count_nonzero(proj.getWeights()) proj = pynn.Projection(pop, pops[(idx + 1) % len(pops)], connectorI, target='inhibitory') synapses += np.count_nonzero(proj.getWeights()) # add poisson stimulus source = pynn.Population(1, pynn.SpikeSourcePoisson, {'rate': 2}) proj = pynn.Projection(source, pop, connectorE, target='excitatory') synapses += np.count_nonzero(proj.getWeights()) pynn.run(100) pynn.end() logging.debug("synapses counted in python: %d", synapses) return synapses
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 random_network(self): pynn.setup(marocco=self.marocco) NUM_POPS = random.randint(10, 100) POP_SIZE = random.randint(1, 100) PROJ_PROB = 0.2 pops = [ pynn.Population(POP_SIZE, pynn.EIF_cond_exp_isfa_ista) for x in range(NUM_POPS) ] connector = pynn.AllToAllConnector( allow_self_connections=True, weights=1.) for src in pops: for trg in pops: target_type = 'inhibitory' if random.random() < 0.2 else 'excitatory' if random.random() < PROJ_PROB: pynn.Projection(src, trg, connector, target=target_type) pynn.run(1) pynn.end() stats = self.marocco.getStats() print("python synapse loss: ", stats.getSynapseLoss())
def test_hw_merging_spl1_should_merge_some(self): """ some DNCs shall be merged, but not all, because of syndriver requirements on each NB. 2 neurons will be placed (same HICANN). A fully connected network is built. This results in 8*2 = 16 synapses being routed to each neuron. With neuron size 4 and chain length 3 -> 12 synapses can be realised on each neuron. As a result at maximum 12 synapses shall be on the same L1Route. The merger tries to merge them and will fail, then spit it and merge 8 to each merger [3,5]. The result is a better L1 utilisation compared to one-to-one mapping, 2 instead of 8 routes, while staying within hardware constrains, compared to merge all (16 synapses requiring 4 drivers, 1 driver will be lost). """ pynn.setup(marocco=self.marocco) neuron_size = 4 self.marocco.neuron_placement.default_neuron_size(neuron_size) self.marocco.merger_routing.strategy( self.marocco.merger_routing.minimize_as_possible) # restrict to 3 driver, so that this test is hardware agnostic self.marocco.synapse_routing.driver_chain_length(3) hicann = C.HICANNOnWafer(Enum(123)) pops = [] # All but the first neuron block are occupied. for nb in range(C.NeuronBlockOnHICANN.end): pop = pynn.Population(2, pynn.IF_cond_exp, {}) self.marocco.manual_placement.on_neuron_block( pop, C.NeuronBlockOnWafer(C.NeuronBlockOnHICANN(nb), hicann)) pops.append(pop) for p in pops: for other_p in pops: pynn.Projection(p, other_p, pynn.AllToAllConnector(weights=1.)) pynn.run(0) pynn.end() merged_dncs = [3, 3, 3, 3, 5, 5, 5, 5] results = self.load_results() for pop in pops: nrn = pop[0] placement_item, = results.placement.find(nrn) logical_neuron = placement_item.logical_neuron() self.assertEqual(neuron_size, logical_neuron.size()) for denmem in logical_neuron: self.assertEqual(hicann, denmem.toHICANNOnWafer()) address = placement_item.address() # some DNCs shall be merged. dnc = C.DNCMergerOnHICANN(merged_dncs[pop.euter_id()]) self.assertEqual(hicann, address.toHICANNOnWafer()) self.assertEqual(dnc, address.toDNCMergerOnHICANN()) self.assertEqual(C.DNCMergerOnWafer(dnc, hicann), address.toDNCMergerOnWafer())
def test_small_network(self, neuron_size): self.marocco.neuron_placement.default_neuron_size(neuron_size) pynn.setup(marocco=self.marocco) target = pynn.Population(1, pynn.IF_cond_exp, {}) p1 = pynn.Population(2, pynn.SpikeSourceArray, {'spike_times': [1.]}) p2 = pynn.Population(5, pynn.IF_cond_exp, {}) pops = [target, p1, p2] proj1 = pynn.Projection(p1, target, pynn.AllToAllConnector(weights=0.004)) proj2 = pynn.Projection(p2, target, pynn.AllToAllConnector(weights=0.004)) projections = [proj1, proj2] pynn.run(0) pynn.end() results = self.load_results() self.assertEqual(sum(map(len, pops)), len(list(results.placement))) for pop in pops: for n in xrange(len(pop)): items = results.placement.find(pop[n]) self.assertTrue(isinstance(items, list)) self.assertEqual(1, len(items)) item = items[0] bio_neuron = item.bio_neuron() self.assertEqual(pop.euter_id(), bio_neuron.population()) self.assertEqual(n, bio_neuron.neuron_index()) logical_neuron = item.logical_neuron() if pop.celltype == pynn.SpikeSourceArray: self.assertTrue(logical_neuron.is_external()) self.assertIsNone(item.neuron_block()) else: self.assertFalse(logical_neuron.is_external()) self.assertIsNotNone(item.neuron_block()) self.assertEqual(neuron_size, logical_neuron.size()) # Every placed population should have an address. self.assertIsNotNone(item.dnc_merger()) address = item.address() self.assertIsNotNone(address)
def test_issue1565(self): # although there is only 1 synapse column per neuron (of size 2), a 2nd synapse is used self.marocco.neuron_placement.default_neuron_size(2) con = pynn.FixedProbabilityConnector(p_connect=1.0, weights=0.004) pynn.setup(marocco=self.marocco) pop1 = pynn.Population(10, pynn.IF_cond_exp, {}) ipu1 = pynn.Population(2, pynn.SpikeSourceArray, {'spike_times': []}) pro1 = pynn.Projection(ipu1, pop1, con, target='excitatory') pynn.run(0)
def test_stimulated_network(self): con = pynn.FixedProbabilityConnector(p_connect=1.0, weights=0.004) pop_size = 100 ipu_size = 20 pynn.setup(marocco=self.marocco) ipu1 = pynn.Population(ipu_size, pynn.SpikeSourceArray, {'spike_times': []}) pop1 = pynn.Population(pop_size, pynn.IF_cond_exp, {}) pro1 = pynn.Projection(ipu1, pop1, con, target='excitatory') ipu2 = pynn.Population(ipu_size, pynn.SpikeSourceArray, {'spike_times': []}) pop2 = pynn.Population(pop_size, pynn.IF_cond_exp, {}) pro2 = pynn.Projection(ipu2, pop2, con, target='excitatory') pynn.run(0) all_pops = [pop1, ipu1, pop2, ipu2] map(self.helper_test_mapping, all_pops) pynn.end()
def main(): """ create small network with synapse loss. The synapse loss happens due to a maximum syndriver chain length of 5 and only 4 denmems per neuron. After mapping, the synapse loss per projection is evaluated and plotted for one projection. The sum of lost synapses per projection is compared to the overall synapse loss returnd by the mapping stats. """ marocco = PyMarocco() marocco.neuron_placement.default_neuron_size(4) marocco.synapse_routing.driver_chain_length(5) marocco.continue_despite_synapse_loss = True marocco.calib_backend = PyMarocco.CalibBackend.Default marocco.neuron_placement.skip_hicanns_without_neuron_blacklisting(False) pynn.setup(marocco=marocco) neuron = pynn.Population(50, pynn.IF_cond_exp) source = pynn.Population(50, pynn.SpikeSourcePoisson, {'rate': 2}) connector = pynn.FixedProbabilityConnector(allow_self_connections=True, p_connect=0.5, weights=0.00425) proj_stim = pynn.Projection(source, neuron, connector, target="excitatory") proj_rec = pynn.Projection(neuron, neuron, connector, target="excitatory") pynn.run(1) print marocco.stats total_syns = 0 lost_syns = 0 for proj in [proj_stim, proj_rec]: l, t = projectionwise_synapse_loss(proj, marocco) total_syns += t lost_syns += l assert total_syns == marocco.stats.getSynapses() assert lost_syns == marocco.stats.getSynapseLoss() plot_projectionwise_synapse_loss(proj_stim, marocco) pynn.end()
def test_vertical(self): pylogging.set_loglevel(pylogging.get("marocco"), pylogging.LogLevel.TRACE) marocco = self.marocco user_strat = placer() user_strat.m_hicann_on_wafer_ordering = user_strat.vertical user_strat.m_spiral_center = user_strat.spiral_neighbours marocco.neuron_placement.default_placement_strategy(user_strat) pynn.setup(marocco=marocco) pops = {} pops[0] = pynn.Population(128, pynn.IF_cond_exp, {}) pops[1] = pynn.Population(128, pynn.IF_cond_exp, {}) pops[2] = pynn.Population(128, pynn.IF_cond_exp, {}) proj1 = pynn.Projection(pops[0], pops[1], pynn.OneToOneConnector(weights=0.01)) proj2 = pynn.Projection(pops[1], pops[2], pynn.OneToOneConnector(weights=0.01)) h = {} h[pops[0]] = C.HICANNOnWafer(Enum(100)) # the next free hicann (vertical order) h[pops[1]] = C.HICANNOnWafer(Enum(72)) h[pops[2]] = C.HICANNOnWafer(Enum(48)) marocco.manual_placement.on_hicann(pops[0], h[pops[0]]) pynn.run(0) pynn.end() result = self.load_results() for key in pops: pop = pops[key] for nrn in pop: placement_item, = result.placement.find(nrn) logical_neuron = placement_item.logical_neuron() for denmem in logical_neuron: self.assertEqual(h[pop].toEnum(), denmem.toHICANNOnWafer().toEnum())
def test_TwoNeuron(self): if True: pynn.setup(marocco=self.marocco) # create neuron with v_rest below v_thresh source = pynn.Population(1, pynn.EIF_cond_exp_isfa_ista, { 'v_rest': -50., 'v_thresh': -60., 'v_reset': -70.6, }) N = 8 # number of target populations p = [ pynn.Population(1, pynn.EIF_cond_exp_isfa_ista) for i in range(N) ] # place source on HICANN 0 source_hicann = self.chip(0) self.marocco.manual_placement.on_hicann(source, source_hicann) # place targets on all HICANNs on same reticle but random neurons nrns = self.shuffle(255) for ii, pop in enumerate(p): hicann = HICANNGlobal(X(int(source_hicann.x()) + ii % 4), Y(int(source_hicann.y()) + ii // 4)) self.marocco.manual_placement.on_hicann(pop, hicann) print(pop, hicann) connector = pynn.AllToAllConnector(allow_self_connections=True, weights=1.) store = [] # connect source to targets for trg in p: proj = pynn.Projection(source, trg, connector, target='excitatory') weights = copy.deepcopy(proj.getWeights()) store.append((proj, weights)) # start simulation pynn.run(10) # in ms pynn.end() # make sure we have no synapse loss self.assertEqual(0, self.marocco.stats.getSynapseLoss()) # assert weights are the same (at least as long as we don't send be # the transformed digital weights) for proj, weights in store: self.assertEqual(self.marocco.stats.getWeights(proj), weights)
def build(self): # Set the neurons self.neurons = pynn.Population(self.N, self.model) # in the fully visible BM there each neuron projects to each neuron # both inhibitory and excitatory to enable switching the sing of the # connection during eventual training # self connections are excluded # This model only sets the skeleton of the BM without the noise sources connector = pynn.AllToAllConnector(weights=0.003, allow_self_connections=False) pynn.Projection(self.neurons, self.neurons, connector, target='excitatory') pynn.Projection(self.neurons, self.neurons, connector, target='inhibitory')
def build(self): weights = self._create_nn_unit_weights(self.linearsize, self.dimension) self.neurons = [ pynn.Population(1, self.model) for _ in range(self.linearsize**self.dimension) ] self.noise = pynn.Population(self.nsources, pynn.IF_cond_exp) self.biasneurons = pynn.Population(self.nbiasneurons, self.model) connector = pynn.FixedNumberPreConnector(n=30, weights=0.3, allow_self_connections=False) pynn.Projection(self.noise, self.noise, connector, target='inhibitory') connector = pynn.FixedNumberPreConnector(n=self.ksources, weights=0.3) pynn.Projection(self.noise, self.neurons, connector, target='excitatory', rng=pynn.NativeRNG(42)) pynn.Projection(self.noise, self.neurons, connector, target='inhibitory', rng=pynn.NativeRNG(43)) connector = pynn.FixedNumberPreConnector(n=self.kbiasneurons, weights=0.4) pynn.Projection(self.biasneurons, self.neurons, connector, target='inhibitory', rng=pynn.NativeRNG(44)) for ipre, ipost, w in weights: connector = pynn.AllToAllConnector(weights=1) pynn.Projection(self.neurons[ipre], self.neurons[ipost], connector, target="excitatory")
def build(self): weights = self._create_nn_unit_weights(self.linearsize, self.dimension) self.neurons = [ pynn.Population(1, self.model) for _ in range(self.linearsize**self.dimension) ] self.exsources = pynn.Population(self.nsources, pynn.SpikeSourcePoisson, {'rate': self.sourcerate}) self.insources = pynn.Population(self.nsources, pynn.SpikeSourcePoisson, {'rate': self.sourcerate}) self.biasneurons = pynn.Population(self.nbiasneurons, self.model) connector = pynn.FixedNumberPreConnector(n=self.ksources, weights=0.3) proj = pynn.Projection(self.exsources, self.neurons, connector, target='excitatory', rng=pynn.NativeRNG(42)) proj = pynn.Projection(self.exsources, self.neurons, connector, target='inhibitory', rng=pynn.NativeRNG(42)) connector = pynn.FixedNumberPreConnector(n=self.nbiasneurons, weights=0.4) proj = pynn.Projection(self.biasneurons, self.neurons, connector, target='inhibitory', rng=pynn.NativeRNG(42)) for ipre, ipost, w in weights: connector = pynn.AllToAllConnector(weights=1) proj = pynn.Projection(self.neurons[ipre], self.neurons[ipost], connector, target="excitatory")
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_external_sources_projections(self, params): nprojections = params[0] nsources = params[1] print((nprojections, nsources)) """ An external sources has multiple projections so it should be split if it wuld not be of size 1 so unfortunately the users would need to live with that. """ pylogging.set_loglevel(pylogging.get("marocco"), pylogging.LogLevel.TRACE) pylogging.set_loglevel(pylogging.get("Calibtic"), pylogging.LogLevel.ERROR) pynn.setup(marocco=self.marocco) self.marocco.neuron_placement.default_neuron_size(4) # ensure a limited synapse driver chain length. self.marocco.synapse_routing.driver_chain_length(3) # we expect synapse loss, but we dont care, as the source cant be split. # we want this tests not to throw exceptions. self.marocco.continue_despite_synapse_loss = True target = pynn.Population(1, pynn.IF_cond_exp, {}) hicann = C.HICANNOnWafer(Enum(100)) self.marocco.manual_placement.on_hicann(target, hicann) exsource = pynn.Population(nsources, pynn.SpikeSourcePoisson, {'rate': 1.}) for i in range(nprojections): proj = pynn.Projection(exsource, target, pynn.AllToAllConnector(weights=1.)) # access to proj so flake8 keeps silent proj.size pynn.run(0) pynn.end() results = self.load_results() synapses = results.synapse_routing.synapses() placement = results.placement for dnc in C.iter_all(C.DNCMergerOnWafer): PonDNC = placement.find(dnc) # PopulationOnDNC if PonDNC: ## if driver requirements exceeded, only one source should be ## placed on the DNC, but synapse loss is still expected if (nprojections > 4): # this number is just guessed self.assertTrue(len(PonDNC) <= 1) else: self.assertTrue(len(PonDNC) <= 12)
def build(self): self.neurons = pynn.Population(self.N, self.model) connector = pynn.FixedProbabilityConnector(p_connect=self.prob, allow_self_connections=True, weights=0.003) pynn.Projection(self.neurons, self.neurons, connector, target='excitatory', rng=pynn.NativeRNG(42))
def build(self): self.neurons = pynn.Population(self.N, self.model) connector = pynn.FixedNumberPreConnector(self.K, weights=1, allow_self_connections=False) pynn.Projection(self.neurons, self.neurons, connector, target='excitatory', rng=pynn.NativeRNG(42))
def test_cluster_target(self): marocco = self.marocco user_strat = placer() user_strat.m_spiral_center = user_strat.spiral_neighbours_target marocco.neuron_placement.default_placement_strategy(user_strat) pynn.setup(marocco=marocco) pops = {} pops[0] = pynn.Population(1, pynn.IF_cond_exp, {}) pops[1] = pynn.Population(1, pynn.IF_cond_exp, {}) pops[2] = pynn.Population(1, pynn.IF_cond_exp, {}) proj1 = pynn.Projection(pops[0], pops[1], pynn.AllToAllConnector(weights=0.01)) proj2 = pynn.Projection(pops[1], pops[2], pynn.AllToAllConnector(weights=0.01)) h = {} h[pops[0]] = C.HICANNOnWafer(Enum(100)) # average positon of target h[pops[1]] = C.HICANNOnWafer(Enum(102)) h[pops[2]] = C.HICANNOnWafer(Enum(102)) marocco.manual_placement.on_hicann(pops[0], h[pops[0]]) marocco.manual_placement.on_hicann(pops[2], h[pops[2]]) pynn.run(0) pynn.end() result = self.load_results() for key in pops: pop = pops[key] for nrn in pop: placement_item, = result.placement.find(nrn) logical_neuron = placement_item.logical_neuron() for denmem in logical_neuron: self.assertEqual(h[pop].toEnum(), denmem.toHICANNOnWafer().toEnum())
def test_projection(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) pro = pyhmf.Projection(pop_a, pop_b, pyhmf.AllToAllConnector()) # ECM: iteration over Connections? #self.assertEqual(len(pro), len(list(pro.__iter__()))) #self.assertEqual(len(pro), len(list(pro.all()))) self.assertEqual(size_a * size_b, len(pro)) self.assertEqual(size_a * size_b, pro.size)
def test_issue1681(self): con = pynn.FixedProbabilityConnector(p_connect=1.0, weights=0.004) pynn.setup(marocco=self.marocco) pop1 = pynn.Population(10, pynn.IF_cond_exp, {}) ipu1 = pynn.Population(1, pynn.SpikeSourceArray, {'spike_times': []}) pro1 = pynn.Projection(ipu1, pop1, con, target='excitatory') # Issue 1681 "IndexError after mapping ends" is triggered by adding a # population after a projection: # Expected Output: NO ERROR # Actual Output: "IndexError: vector::_M_range_check" (i.e. abnormal termination) pop2 = pynn.Population(10, pynn.IF_cond_exp, {}) pynn.run(0)
def test_external_sources_drivers(self, nsources): """ A lot external sources are placed no error should be thrown the sources should be split """ pylogging.set_loglevel(pylogging.get("marocco"), pylogging.LogLevel.DEBUG) pylogging.set_loglevel(pylogging.get("Calibtic"), pylogging.LogLevel.ERROR) pynn.setup(marocco=self.marocco) self.marocco.neuron_placement.default_neuron_size(4) # ensure a limited synapse driver chain length. self.marocco.synapse_routing.driver_chain_length(3) # if synapse loss occours we want to handle it on our own self.marocco.continue_despite_synapse_loss = True target = pynn.Population(1, pynn.IF_cond_exp, {}) hicann = C.HICANNOnWafer(Enum(100)) self.marocco.manual_placement.on_hicann(target, hicann) exsource = pynn.Population(nsources, pynn.SpikeSourcePoisson, {'rate': 1.}) proj = pynn.Projection(exsource, target, pynn.AllToAllConnector(weights=1.)) # access to proj so flake8 keeps silent proj.size pynn.run(0) pynn.end() results = self.load_results() synapses = results.synapse_routing.synapses() placement = results.placement # test for synapse loss self.assertEqual(nsources, synapses.size()) for dnc in C.iter_all(C.DNCMergerOnWafer): PonDNC = placement.find(dnc) # PopulationOnDNC if PonDNC: ## with a neuron size of 4 and a chain length of 3, ## around 12 sources can fit into a merger self.assertTrue(len(PonDNC) <= 12)