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_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())
} # We create a Population with 1 neuron of our neuron model N1 = pynn.Population(size=neuron_count, cellclass=neuron_model, cellparams=neuron_parameters) # A spike source array with spike times given in a list spktimes = [10., 50., 65., 89., 233., 245., 255., 345., 444.4] spike_source = pynn.Population(1, pynn.SpikeSourceArray, {'spike_times': spktimes}) # Connect the Spike source to our neuron pynn.Projection(spike_source, N1, pynn.OneToOneConnector(weights=0.0138445), target='excitatory') # record the membrane voltage of all neurons of the population N1.record_v() # record the spikes of all neurons of the population N1.record() # run the simulation for 500 ms duration = 500. pynn.run(duration) # After the simulation, we get Spikes spike_times = N1.getSpikes() for pair in spike_times: print "Neuron ", int(pair[0]), " spiked at ", pair[1]
def test_basic(self): """ tests the routing and parameter trafo of a IF_multicond_exp neuron with 4 different synaptic input settings. For 4 synaptic targets and hardware neuron size 4, the mapping of synapse types is as follows: Denmem: | 0 | 1 | Synapse Type: |0 1|2 3| (left and right input) Build a minimal network with 1 neuron and 4 spike sources each connecting to different synaptic target on the neuron. Then check that the configuration of the synapse driver and synapses is as expected. Furthermore, check that the different parameters for e_rev and tau_syn are correctly transformed by getting the FG values (qualitatively). """ marocco = pymarocco.PyMarocco() marocco.backend = pymarocco.PyMarocco.Without marocco.calib_backend = pymarocco.PyMarocco.CalibBackend.Default marocco.defects.backend = pymarocco.Defects.Backend.Without marocco.neuron_placement.default_neuron_size(4) marocco.wafer_cfg = os.path.join(self.temporary_directory, "wafer.bin") marocco.persist = os.path.join(self.temporary_directory, "results.bin") used_hicann = HICANNGlobal(Enum(0)) pynn.setup(marocco=marocco) p1 = pynn.Population(1, pynn.IF_multicond_exp) # we use 4 different time constants and reversal potentials p1.set('e_rev', [0., -10, -80, -100]) p1.set('tau_syn', [2, 3, 4, 5]) # place to a certain HICANN to be able to extract config data afterwards topleft = NeuronOnWafer(NeuronOnHICANN(X(0), Y(0)), used_hicann) logical_neuron = LogicalNeuron.rectangular(topleft, size=4) marocco.manual_placement.on_neuron(p1, logical_neuron) s1 = pynn.Population(1, pynn.SpikeSourcePoisson, {'rate': 5.}) s2 = pynn.Population(1, pynn.SpikeSourcePoisson, {'rate': 5.}) s3 = pynn.Population(1, pynn.SpikeSourcePoisson, {'rate': 5.}) s4 = pynn.Population(1, pynn.SpikeSourcePoisson, {'rate': 5.}) prj1 = pynn.Projection(s1, p1, pynn.OneToOneConnector(weights=0.01), target="0") prj2 = pynn.Projection(s2, p1, pynn.OneToOneConnector(weights=0.01), target="1") prj3 = pynn.Projection(s3, p1, pynn.OneToOneConnector(weights=0.01), target="2") prj4 = pynn.Projection(s4, p1, pynn.OneToOneConnector(weights=0.01), target="3") p1.record() pynn.run(1.) h = debug_config.load_hicann_cfg(marocco.wafer_cfg, used_hicann) # routing config active_drivers = [] driver_c = None for driver in iter_all(SynapseDriverOnHICANN): drv_cfg = h.synapses[driver] if drv_cfg.is_enabled(): active_drivers.append(drv_cfg) driver_c = driver assert len(active_drivers) == 1 act_drv = active_drivers[0] # two different synaptic input sides are used on the synapse driver syn_input_top = debug_config.get_syn_in_side( act_drv[RowOnSynapseDriver(top)]) syn_input_bot = debug_config.get_syn_in_side( act_drv[RowOnSynapseDriver(bottom)]) self.assertNotEqual(syn_input_top, syn_input_bot) # assumed column and input side: exptected_mapping = [(s1, SynapseColumnOnHICANN(0), left), (s2, SynapseColumnOnHICANN(0), right), (s3, SynapseColumnOnHICANN(1), left), (s4, SynapseColumnOnHICANN(1), right)] results = Marocco.from_file(marocco.persist) for (src, col, side) in exptected_mapping: items = list(results.placement.find(src[0])) self.assertEqual(1, len(items)) item = items[0] addr = item.address().toL1Address() syns = debug_config.find_synapses(h.synapses, driver_c, addr) self.assertEqual(1, len(syns)) syn = syns[0] # check synapse column self.assertEqual(syn.toSynapseColumnOnHICANN(), col) # check synaptic input side row_addr = syn.toSynapseRowOnHICANN() self.assertEqual( debug_config.get_syn_in_side( act_drv[row_addr.toRowOnSynapseDriver()]), side) # FG values nrn_left = NeuronOnHICANN(X(0), Y(0)) nrn_right = NeuronOnHICANN(X(1), Y(0)) fgs = h.floating_gates # e_rev params are montonic decreasing E1 = fgs.getNeuron(nrn_left, nrn_param.E_synx) E2 = fgs.getNeuron(nrn_left, nrn_param.E_syni) E3 = fgs.getNeuron(nrn_right, nrn_param.E_synx) E4 = fgs.getNeuron(nrn_right, nrn_param.E_syni) E = [E1, E2, E3, E4] for k, l in zip(E, E[1:]): self.assertGreater(k, l) # tau_syn params are montonic increasing T1 = fgs.getNeuron(nrn_left, nrn_param.V_syntcx) T2 = fgs.getNeuron(nrn_left, nrn_param.V_syntci) T3 = fgs.getNeuron(nrn_right, nrn_param.V_syntcx) T4 = fgs.getNeuron(nrn_right, nrn_param.V_syntci) T = [T1, T2, T3, T4] # HICANN V4: The lower the DAC-Value, the higher the time constant for k, l in zip(T, T[1:]): self.assertGreater(k, l)
'tau_w' : 144.0, # adaptation time constant 'v_reset' : -70.6, # reset potential in mV 'v_rest' : -70.6, # resting potential in mV 'v_spike' : -40.0, # spike detection voltage in mV 'v_thresh' : -50.4, # spike initiaton threshold voltage in mV } # We create a Population with 1 neuron of our neuron model N1 = pynn.Population(size=neuron_count, cellclass=neuron_model, cellparams=neuron_parameters) # A spike source array with spike times given in a list spktimes = [10., 50., 65., 89., 233., 245.,255.,345.,444.4] spike_source = pynn.Population(1, pynn.SpikeSourceArray, {'spike_times':spktimes}) # Connect the Spike source to our neuron pynn.Projection(spike_source, N1, pynn.OneToOneConnector(weights=0.0138445), target='excitatory') # record the membrane voltage of all neurons of the population N1.record_v() # record the spikes of all neurons of the population N1.record() # run the simulation for 500 ms duration = 500. pynn.run(duration) # After the simulation, we get Spikes spike_times = N1.getSpikes() for pair in spike_times: print "Neuron ", int(pair[0]), " spiked at ", pair[1]
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]))
def test_OneToOneConnector(self): pynn.setup() conn = pynn.OneToOneConnector(weights=0.01, delays=1.0)
def build(self): # set populations self.populations = {} # calculate indegrees from connection probability self.indegrees = self.get_indegrees() for layer, exIn in par.num_neurons.items(): # [:1] to remove the first "L" self.populations[layer[1:] + "e"] = pynn.Population( int(exIn["E"] * self.scale), self.model) self.populations[layer[1:] + "i"] = pynn.Population( int(exIn["I"] * self.scale), self.model) # Create projections self.projections = [] self.projectionLabels = [] for targetIndex, targetPop in enumerate(par.label): for sourceIndex, sourcePop in enumerate(par.label): if sourcePop.endswith("e"): target = "excitatory" else: target = "inhibitory" sourceSize = self.populations[sourcePop].size targetSize = self.populations[targetPop].size # In-degree scaling as described in Albada et al. (2015) "Scalability of Asynchronous Networks # Is Limited by One-to-One Mapping between Effective Connectivity and Correlations" # Number of inputs per target neuron (in-degree) for full scale model is scaled with k_scale # To receive total connection number it is multiplied with downscaled target population size (scale) # Connection probability is not preserved if scale == k_scale (multiple connections neglected) n_connection = int( round(self.indegrees[targetIndex][sourceIndex] * self.k_scale * targetSize)) self.totalConnections += n_connection if (n_connection == 0): continue # connection matrix [(neuron_pop1,neuron_pop2,weight,delay),(...)] matrix = np.zeros((4, n_connection), dtype=float) np.random.seed(self.seed) matrix[0] = np.random.randint(0, sourceSize, n_connection) matrix[1] = np.random.randint(0, targetSize, n_connection) # The delay and weight is not important for mapping # PyNN requires it to be set to some value matrix[2] = np.repeat(1, n_connection) # arbitrary weight matrix[3] = np.repeat(0, n_connection) # arbitrary delay matrix = matrix.T matrix = [[int(a), int(b), c, d] for a, b, c, d in matrix] connector = pynn.FromListConnector(matrix) self.projections.append( pynn.Projection(self.populations[sourcePop], self.populations[targetPop], connector, target=target, label=sourcePop + "-" + targetPop)) self.projectionLabels.append(sourcePop + "-" + targetPop) print("total connections:", self.totalConnections) # external input: self.externalInputPops = {} # External spikes or external current external_source = par.external_source # will not work for large networks, for now it is not used due to par.external_source if (external_source == "spikeInput"): print("using external input connections") for layer, amount in par.K_ext.items(): # rate is given in model with 8Hz # will not work for large networks, for now it is not used due to par.external_source rate_to_ex = par.bg_rate * amount["E"] * self.k_scale rate_to_in = par.bg_rate * amount["I"] * self.k_scale self.externalInputPops[layer[1:] + "e"] = pynn.Population( self.populations[layer[1:] + "e"].size, pynn.SpikeSourcePoisson, {'rate': rate_to_ex}) self.externalInputPops[layer[1:] + "i"] = pynn.Population( self.populations[layer[1:] + "i"].size, pynn.SpikeSourcePoisson, {'rate': rate_to_in}) # create connections for sourceKey, sourcePop in self.externalInputPops.items(): # set connector for each pop size since RandomDistribution object not supported by pyhmf # arbitrary weight externalConnector = pynn.OneToOneConnector(weights=1) # create connection self.projections.append( pynn.Projection(sourcePop, self.populations[sourceKey], externalConnector, target="excitatory")) self.projectionLabels.append("ext.-" + targetPop)
def test_basic(self): """ tests whether synapses with short term plasticity are routed correctly. Build a minimal network with 1 neuron and 3 spike sources each connecting to with a different STP setting (depression, facilitation, static) to the neuron. Then check that the 3 synapses are routed via 3 different synaspe drivers and that STP mode of the synapse drivers is as expected. """ marocco = pymarocco.PyMarocco() marocco.backend = pymarocco.PyMarocco.None marocco.neuron_placement.default_neuron_size(4) marocco.wafer_cfg = os.path.join(self.temporary_directory, "wafer.bin") marocco.persist = os.path.join(self.temporary_directory, "results.bin") used_hicann = HICANNGlobal(Enum(0)) pynn.setup(marocco=marocco) p1 = pynn.Population(1, pynn.IF_cond_exp) # place to a certain HICANN to be able to extract config data afterwards marocco.manual_placement.on_hicann(p1, used_hicann) s1 = pynn.Population(1, pynn.SpikeSourcePoisson, {'rate': 5.}) s2 = pynn.Population(1, pynn.SpikeSourcePoisson, {'rate': 5.}) s3 = pynn.Population(1, pynn.SpikeSourcePoisson, {'rate': 5.}) depression = pynn.SynapseDynamics(fast=pynn.TsodyksMarkramMechanism( U=0.4, tau_rec=200., tau_facil=0.)) facilitation = pynn.SynapseDynamics(fast=pynn.TsodyksMarkramMechanism( U=0.4, tau_rec=0., tau_facil=200.)) static = None prj1 = pynn.Projection(s1, p1, pynn.OneToOneConnector(weights=0.05), synapse_dynamics=depression, target="excitatory") prj2 = pynn.Projection(s2, p1, pynn.OneToOneConnector(weights=0.05), synapse_dynamics=facilitation, target="excitatory") prj3 = pynn.Projection(s3, p1, pynn.OneToOneConnector(weights=0.05), synapse_dynamics=static, target="excitatory") p1.record() pynn.run(1.) h = debug_config.load_hicann_cfg(marocco.wafer_cfg, used_hicann) # There should be 3 active drivers with 3 different STP modes drivers = {} num_active_drivers = 0 for driver in iter_all(SynapseDriverOnHICANN): drv_cfg = h.synapses[driver] if drv_cfg.is_enabled(): num_active_drivers += 1 if drv_cfg.is_stf(): drivers['facilitation'] = driver elif drv_cfg.is_std(): drivers['depression'] = driver else: drivers['static'] = driver self.assertEqual(num_active_drivers, 3) self.assertEqual(len(drivers), 3) results = Marocco.from_file(marocco.persist) # check that synapses are on the drivers with the correct mode for src, mode in [(s1, 'depression'), (s2, 'facilitation'), (s3, 'static')]: items = list(results.placement.find(src[0])) self.assertEqual(1, len(items)) item = items[0] addr = item.address().toL1Address() syns = debug_config.find_synapses(h.synapses, drivers[mode], addr) self.assertEqual(len(syns), 1) # the addr of the source should be found once