def test_on_neurons(self, pop_size): pynn.setup(marocco=self.marocco) pop = pynn.Population(pop_size, pynn.IF_cond_exp, {}) neuron_block = C.NeuronBlockOnWafer(C.NeuronBlockOnHICANN(3)) logical_neurons = [ (LogicalNeuron.on(neuron_block) .add(C.NeuronOnNeuronBlock(X(3), Y(0)), 2) .add(C.NeuronOnNeuronBlock(X(3), Y(1)), 2) .done()), (LogicalNeuron.on(neuron_block) .add(C.NeuronOnNeuronBlock(X(11), Y(0)), 2) .add(C.NeuronOnNeuronBlock(X(11), Y(1)), 2) .done()), ] self.marocco.manual_placement.on_neuron(pop, logical_neurons) if pop_size != len(logical_neurons): with self.assertRaises(RuntimeError): pynn.run(0) pynn.end() return pynn.run(0) pynn.end() results = self.load_results() for nrn, logical_neuron in zip(pop, logical_neurons): placement_item, = results.placement.find(nrn) self.assertEqual(logical_neuron, placement_item.logical_neuron())
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_on_neuron_wrong_shape(self): pynn.setup(marocco=self.marocco) pop = pynn.Population(1, pynn.IF_cond_exp, {}) neuron_block = C.NeuronBlockOnWafer(C.NeuronBlockOnHICANN(3)) logical_neuron = (LogicalNeuron.on(neuron_block) .add(C.NeuronOnNeuronBlock(X(2), Y(0)), 4) .add(C.NeuronOnNeuronBlock(X(3), Y(1)), 2) .done()) self.marocco.manual_placement.on_neuron(pop, logical_neuron) with self.assertRaises(RuntimeError): pynn.run(0) pynn.end()
def test(self): wafer = 99999 # a wafer for which no redman data is availale hicann = 82 neuron_number = 12 marocco = PyMarocco() marocco.neuron_placement.default_neuron_size(4) marocco.backend = PyMarocco.Without marocco.default_wafer = C.Wafer(wafer) used_hicann = C.HICANNGlobal(C.HICANNOnWafer(Enum(hicann)), C.Wafer(wafer)) used_hicann # prevent pep8 warning of unused variable pynn.setup(marocco=marocco) pop = pynn.Population(1, pynn.IF_cond_exp) topleft = C.NeuronOnWafer(C.NeuronOnHICANN(X(neuron_number), Y(0)), C.HICANNOnWafer(Enum(hicann))) logical_neuron = LogicalNeuron.rectangular(topleft, size=4) marocco.manual_placement.on_neuron(pop, logical_neuron) with self.assertRaises(RuntimeError): pynn.run(0) pynn.end()
def test_on_neuron(self): pynn.setup(marocco=self.marocco) pop = pynn.Population(1, pynn.IF_cond_exp, {}) neuron_block = C.NeuronBlockOnWafer(C.NeuronBlockOnHICANN(3)) logical_neuron = (LogicalNeuron.on(neuron_block) .add(C.NeuronOnNeuronBlock(X(3), Y(0)), 2) .add(C.NeuronOnNeuronBlock(X(3), Y(1)), 2) .done()) self.marocco.manual_placement.on_neuron(pop, logical_neuron) pynn.run(0) pynn.end() results = self.load_results() placement_item, = results.placement.find(pop[0]) self.assertEqual(logical_neuron, placement_item.logical_neuron())
def parse_dnc(arg): """Helper to parse dnc coordinate, given as <x,y> or as <enum>""" tmp = arg.split(",") if len(tmp) == 1: return DNCOnWafer(Enum(int(tmp[0]))) elif len(tmp) == 2: xcoord, ycoord = tmp return DNCOnWafer(X(int(xcoord)), Y(int(ycoord))) else: raise argparse.ArgumentTypeError( "Please provide --dnc <x,y> or --dnc <enum>")
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 parse_arg(arg): tmp = arg.split(",") if len(tmp) == 1: coord = CoordinateType(Enum(int(tmp[0]))) elif len(tmp) == 2: x, y = tmp coord = CoordinateType(X(int(x)), Y(int(y))) else: raise argparse.ArgumentTypeError( "Please provide {0} <x,y> or {0} <enum>".format( arg_name)) return formatter(coord)
def test_neuronsize(self): import pysthal from pyhalco_common import iter_all, X from pyhalco_hicann_v2 import NeuronOnHICANN, QuadOnHICANN hicann = pysthal.HICANN() sizes = [2**x for x in range(7)] # There and back again for size in sizes[:] + sizes[::-1]: hicann.set_neuron_size(size) hicann.check() active = [ hicann.neurons[neuron].activate_firing() for neuron in iter_all(NeuronOnHICANN) ] self.assertEqual(active.count(True), 512 / size) for quad in iter_all(QuadOnHICANN): self.assertEqual( hicann.neurons[quad].getVerticalInterconnect(X(0)), (size > 1)) self.assertEqual( hicann.neurons[quad].getVerticalInterconnect(X(1)), (size > 1))
def test_on_rectangular_neuron(self): pynn.setup(marocco=self.marocco) pop = pynn.Population(1, pynn.IF_cond_exp, {}) topleft = C.NeuronOnWafer(C.NeuronOnHICANN(X(2), Y(0))) logical_neuron = LogicalNeuron.rectangular(topleft, size=4) self.marocco.manual_placement.on_neuron(pop, logical_neuron) pynn.run(0) pynn.end() results = self.load_results() placement_item, = results.placement.find(pop[0]) self.assertEqual(logical_neuron, placement_item.logical_neuron())
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)
for neuron in pop: for item in results.placement.find(neuron): 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, 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):
def test_NeuronCurrentStimHWTest(self): fgc = HICANN.FGControl() fg_config = HICANN.FGConfig() for block in [Enum(0), Enum(1)]: block = Coordinate.FGBlockOnHICANN(block) HICANN.set_fg_config(self.h, block, fg_config) HICANN.set_fg_values(self.h, block, fgc.getBlock(block)) # 2nd: configure the neuron nrn = HICANN.Neuron() #HICANN.Neuron other_nrn = HICANN.Neuron() nrn.address(HICANN.L1Address(42)) nrn.activate_firing(True) nrn.enable_spl1_output(True) nrn.enable_fire_input(False) nrn.enable_aout(True) nrn.enable_current_input(True) nquad = HICANN.NeuronQuad() nquad[Coordinate.NeuronOnQuad(X(0), Y(0))] = nrn HICANN.set_denmem_quad(self.h, Coordinate.QuadOnHICANN(0), nquad) # NEURON CONFIG nrn_cfg = HICANN.NeuronConfig() nrn_cfg.bigcap.set(Coordinate.top) HICANN.set_neuron_config(self.h, nrn_cfg) # set ANALOG ac = HICANN.Analog() ac.set_membrane_top_even(Coordinate.AnalogOnHICANN(0)) HICANN.set_analog(self.h, ac) # CURRENT STIMULUS fg_config = HICANN.FGConfig() fg_config.pulselength = 15 for block in [Enum(0), Enum(1)]: block = Coordinate.FGBlockOnHICANN(block) HICANN.set_fg_config(self.h, block, fg_config) stimulus = HICANN.FGStimulus() stimulus.setContinuous(True) stimulus[:40] = [800] * 40 stimulus[40:] = [0] * (len(stimulus) - 40) HICANN.set_current_stimulus(self.h, Coordinate.FGBlockOnHICANN(Enum(0)), stimulus) # READOUT PULSES! #configure merger tree, phase tree = HICANN.MergerTree() #default settings are OK HICANN.set_merger_tree(self.h, tree) HICANN.set_phase(self.h) dnc_mergers = HICANN.DNCMergerLine() for i in range(8): # rcv from HICANN mer = Coordinate.DNCMergerOnHICANN(i) dnc_mergers[mer].config = HICANN.Merger.RIGHT_ONLY dnc_mergers[mer].slow = False dnc_mergers[mer].loopback = False HICANN.set_dnc_merger(self.h, dnc_mergers) # DNC and dnc_if: gbit = Coordinate.GbitLinkOnHICANN(0) gl = HICANN.GbitLink() gl.dirs[gbit.value()] = HICANN.GbitLink.Direction.TO_DNC gr = DNC.GbitReticle() gr[self.h.to_HICANNOnDNC()] = gl HICANN.set_gbit_link(self.h, gl) DNC.set_hicann_directions(self.fpga, self.dnc, gr) HICANN.flush(self.h) rec_pulses = FPGA.receive(self.fpga, self.dnc, 10000) # 10 ms print(str(rec_pulses.size()) + " packets received") self.assertGreater(rec_pulses.size(), 0) # Check for correct addrss of spikes for np in range(rec_pulses.size()): pulse = rec_pulses.get(np) self.assertEqual(HICANN.L1Address(42), pulse.getNeuronAddress()) self.assertEqual(gbit, pulse.getChannel()) self.assertEqual(self.hicann, pulse.getChipAddress()) self.assertEqual(self.dnc, pulse.getDncAddress()) #turn off links gl.dirs[0] = HICANN.GbitLink.Direction.OFF gr[Coordinate.HICANNOnDNC(Enum(0))] = gl HICANN.set_gbit_link(self.h, gl) DNC.set_hicann_directions(self.fpga, self.dnc, gr) HICANN.flush(self.h)
def read_fg_cell(self,cell_x,cell_y): ph.HICANN.set_fg_cell(self.h, self.fg_coord, pyhalco_hicann_v2.FGCellOnFGBlock(X(cell_x),Y(cell_y))) ph.HICANN.flush(self.h) ph.ADC.trigger_now(self.adc) raw_trace = ph.ADC.get_trace(self.adc) trace = pylab.array(raw_trace, dtype=pylab.ushort) calibrated_trace = self.adc_calib.apply(self.adc_channel, trace) return calibrated_trace
def test_find_neuron_in_analog_output(self): """ Check if find_neuron_in_analog_output works. """ import pysthal from pyhalco_common import iter_all, X, Y from pyhalco_hicann_v2 import NeuronOnHICANN, AnalogOnHICANN hicann = pysthal.HICANN() NeuronOnHICANN.__repr__ = NeuronOnHICANN.__str__ # Nothing active, this should throw for analog in iter_all(AnalogOnHICANN): with self.assertRaises(RuntimeError): hicann.find_neuron_in_analog_output(analog) # Enable 4 neurons, connected to different analog mux entries, but not # the mux yet, this should throw hicann.neurons[NeuronOnHICANN(X(0), Y(0))].enable_aout(True) hicann.neurons[NeuronOnHICANN(X(1), Y(0))].enable_aout(True) hicann.neurons[NeuronOnHICANN(X(0), Y(1))].enable_aout(True) hicann.neurons[NeuronOnHICANN(X(1), Y(1))].enable_aout(True) for analog in iter_all(AnalogOnHICANN): with self.assertRaises(RuntimeError): hicann.find_neuron_in_analog_output(analog) # Now enable the mux for each of the neurons and check if the correct # neuron was found for analog in iter_all(AnalogOnHICANN): hicann.analog.set_membrane_top_even(analog) self.assertEqual(NeuronOnHICANN(X(0), Y(0)), hicann.find_neuron_in_analog_output(analog)) hicann.analog.set_membrane_top_odd(analog) self.assertEqual(NeuronOnHICANN(X(1), Y(0)), hicann.find_neuron_in_analog_output(analog)) hicann.analog.set_membrane_bot_even(analog) self.assertEqual(NeuronOnHICANN(X(0), Y(1)), hicann.find_neuron_in_analog_output(analog)) hicann.analog.set_membrane_bot_odd(analog) self.assertEqual(NeuronOnHICANN(X(1), Y(1)), hicann.find_neuron_in_analog_output(analog)) hicann.analog.disable(analog) # Now enable 4 more, each connected to different analog mux entries, # now it should fail, because two neurons are connected hicann.neurons[NeuronOnHICANN(X(30), Y(0))].enable_aout(True) hicann.neurons[NeuronOnHICANN(X(41), Y(0))].enable_aout(True) hicann.neurons[NeuronOnHICANN(X(10), Y(1))].enable_aout(True) hicann.neurons[NeuronOnHICANN(X(255), Y(1))].enable_aout(True) for analog in iter_all(AnalogOnHICANN): hicann.analog.set_membrane_top_even(analog) with self.assertRaises(RuntimeError): hicann.find_neuron_in_analog_output(analog) hicann.analog.set_membrane_top_odd(analog) with self.assertRaises(RuntimeError): hicann.find_neuron_in_analog_output(analog) hicann.analog.set_membrane_bot_even(analog) with self.assertRaises(RuntimeError): hicann.find_neuron_in_analog_output(analog) hicann.analog.set_membrane_bot_odd(analog) with self.assertRaises(RuntimeError): hicann.find_neuron_in_analog_output(analog) hicann.analog.disable(analog) # Now disable the first 4 neurons, and everything should be fine again hicann.neurons[NeuronOnHICANN(X(0), Y(0))].enable_aout(False) hicann.neurons[NeuronOnHICANN(X(1), Y(0))].enable_aout(False) hicann.neurons[NeuronOnHICANN(X(0), Y(1))].enable_aout(False) hicann.neurons[NeuronOnHICANN(X(1), Y(1))].enable_aout(False) for analog in iter_all(AnalogOnHICANN): hicann.analog.set_membrane_top_even(analog) self.assertEqual(NeuronOnHICANN(X(30), Y(0)), hicann.find_neuron_in_analog_output(analog)) hicann.analog.set_membrane_top_odd(analog) self.assertEqual(NeuronOnHICANN(X(41), Y(0)), hicann.find_neuron_in_analog_output(analog)) hicann.analog.set_membrane_bot_even(analog) self.assertEqual(NeuronOnHICANN(X(10), Y(1)), hicann.find_neuron_in_analog_output(analog)) hicann.analog.set_membrane_bot_odd(analog) self.assertEqual(NeuronOnHICANN(X(255), Y(1)), hicann.find_neuron_in_analog_output(analog)) hicann.analog.disable(analog)