#!/usr/bin/env python # -*- coding: utf-8; -*- #Call this with one of four arguments, r (turn right), l (turn left), #R (turn toward the pyramid which is on the right), or L (turn #toward the pyramid with is on the left). #This topology works for two runs of each input. Works means that #the correct action spikes, and the incorrect action does not. None #of the CAs persist. import sys import numpy as np from pyhalbe import HICANN import pyhalbe.Coordinate as C from pysthal.command_line_util import init_logger import pyhmf as pynn from pymarocco import PyMarocco, Defects from pymarocco.runtime import Runtime from pymarocco.coordinates import LogicalNeuron from pymarocco.results import Marocco # ——— change low-level parameters before configuring hardware ————————————————— def set_sthal_params(wafer, gmax, gmax_div): for hicann in wafer.getAllocatedHicannCoordinates(): fgs = wafer[hicann].floating_gates for ii in xrange(fgs.getNoProgrammingPasses()): cfg = fgs.getFGConfig(C.Enum(ii)) cfg.fg_biasn = 0 cfg.fg_bias = 0 fgs.setFGConfig(C.Enum(ii), cfg) for block in C.iter_all(C.FGBlockOnHICANN): fgs.setShared(block, HICANN.shared_parameter.V_gmax0, gmax) fgs.setShared(block, HICANN.shared_parameter.V_gmax1, gmax) fgs.setShared(block, HICANN.shared_parameter.V_gmax2, gmax) fgs.setShared(block, HICANN.shared_parameter.V_gmax3, gmax) for block in C.iter_all(C.FGBlockOnHICANN): fgs.setShared(block, HICANN.shared_parameter.V_dllres, 275) fgs.setShared(block, HICANN.shared_parameter.V_ccas, 800) for driver in C.iter_all(C.SynapseDriverOnHICANN): for row in C.iter_all(C.RowOnSynapseDriver): wafer[hicann].synapses[driver][row].set_gmax_div( C.left, gmax_div) wafer[hicann].synapses[driver][row].set_gmax_div( C.right, gmax_div) def setFourBitWeights(projections, digitalWeight): for proj in projections: projItems = runtime.results().synapse_routing.synapses().find(proj) for projItem in projItems: synapse = projItem.hardware_synapse() proxy = runtime.wafer()[synapse.toHICANNOnWafer()].synapses[synapse] proxy.weight = HICANN.SynapseWeight(digitalWeight) #---main init_logger("WARN", [ ("guidebook", "DEBUG"), #("marocco", "TRACE"), #("calibtic", "DEBUG"), ]) import pylogging logger = pylogging.get("guidebook") args = sys.argv numberArgs = args.__len__() command = 'default' if (numberArgs == 2): if (args[1] == 'r'): command = 'right' elif (args[1] == 'l'): command = 'left' elif (args[1] == 'R'): command = 'turnPyrRight' elif (args[1] == 'L'): command = 'turnPyrLeft' print 'command', command marocco = PyMarocco() marocco.neuron_placement.default_neuron_size(4) marocco.neuron_placement.minimize_number_of_sending_repeaters(False) marocco.merger_routing.strategy(marocco.merger_routing.one_to_one) marocco.bkg_gen_isi = 125 marocco.pll_freq = 125e6 marocco.backend = PyMarocco.Hardware marocco.calib_backend = PyMarocco.XML marocco.defects.path = marocco.calib_path = "/wang/data/calibration/ITL_2016" marocco.defects.backend = Defects.XML marocco.default_wafer = C.Wafer(33) marocco.param_trafo.use_big_capacitors = True marocco.input_placement.consider_firing_rate(True) marocco.input_placement.bandwidth_utilization(0.8) runtime = Runtime(marocco.default_wafer) pynn.setup(marocco=marocco, marocco_runtime=runtime) # ——— set up network —————————————————————————————————————————————————————————— neuron_parameters = {'v_thresh':-10.0, #'v_thresh':-55.0 play 'tau_m': 20.,# 'tau_m': 20., play 'tau_syn_E': 10.0, # 'tau_syn_E': 5.0, play 'v_rest':-65.0, 'e_rev_I': -70., 'e_rev_E': 0., 'cm': 0.2, 'tau_refrac': 0.1 , 'v_reset':-70.0, #hdbrgs 'tau_syn_I': 5., 'i_offset':0.0} #ignored by hicann #'e_rev_I': -100.} #hdbrgs numNeurons = 15 #10 leftPop = pynn.Population(numNeurons, pynn.IF_cond_exp, neuron_parameters) rightPop = pynn.Population(numNeurons, pynn.IF_cond_exp, neuron_parameters) turnToPyrPop = pynn.Population(numNeurons, pynn.IF_cond_exp, neuron_parameters) leftPop.record() rightPop.record() turnToPyrPop.record() #360, 361, 362, 363,364,365,367,372,373,374,375,376,378 hicann1 = C.HICANNOnWafer(C.Enum(364)) marocco.manual_placement.on_hicann(leftPop, hicann1) hicann2 = C.HICANNOnWafer(C.Enum(365)) marocco.manual_placement.on_hicann(rightPop, hicann2) hicann3 = C.HICANNOnWafer(C.Enum(367)) marocco.manual_placement.on_hicann(turnToPyrPop, hicann3) commandSpikeTimes = [200,210,220,230,240,250,260] locationSpikeTimes = [300,310,320,330,340,350,360] duration = 1000.0 commandStimulus = pynn.Population(numNeurons, pynn.SpikeSourceArray, { 'spike_times': commandSpikeTimes}) locationStimulus = pynn.Population(numNeurons, pynn.SpikeSourceArray, { 'spike_times': locationSpikeTimes}) defWeight = 1 # defaultFloatWeights which should be ignored inputConnector = [] for fromNeuron in range (0,numNeurons): for toNeuron in range (0,numNeurons): inputConnector = inputConnector+[[fromNeuron,toNeuron,defWeight,1.0]] inputConnList = pynn.FromListConnector(inputConnector) if (command == 'right'): inputProjections = [pynn.Projection(commandStimulus,rightPop,inputConnList, target='excitatory')] elif (command == 'left'): inputProjections = [pynn.Projection(commandStimulus,leftPop,inputConnList, target='excitatory')] elif (command == 'turnPyrRight') or (command == 'turnPyrLeft'): inputProjections = [pynn.Projection(commandStimulus,turnToPyrPop, inputConnList,target='excitatory')] inputVisConnector = [] for fromNeuron in range (0,numNeurons): for toNeuron in range (0,numNeurons): inputVisConnector = inputVisConnector+[[fromNeuron,toNeuron,defWeight, 1.0]] inputVisConnList = pynn.FromListConnector(inputVisConnector) if (command == 'turnPyrRight'): inputVisProjections = [pynn.Projection(locationStimulus,rightPop, inputConnList,target='excitatory')] elif (command == 'turnPyrLeft'): inputVisProjections = [pynn.Projection(locationStimulus,leftPop, inputConnList,target='excitatory')] else: inputVisProjections = 'none' intraConnector = [] for fromNeuron in range (0,numNeurons): for toNeuron in range (0,numNeurons): if (fromNeuron != toNeuron): intraConnector=intraConnector+[[fromNeuron,toNeuron,defWeight,1.0]] intraConnList = pynn.FromListConnector(intraConnector) CAProjectionsLeft = [pynn.Projection(leftPop, leftPop, intraConnList, target='excitatory')] CAProjectionsRight = [pynn.Projection(rightPop, rightPop, intraConnList, target='excitatory')] CAProjectionsTurnPyr=[pynn.Projection(turnToPyrPop, turnToPyrPop,intraConnList, target='excitatory')] primeConnector = [] for fromNeuron in range (0,numNeurons): for toNeuron in range (0,numNeurons): primeConnector = primeConnector+[[fromNeuron,toNeuron,defWeight,1.0]] primeConnList = pynn.FromListConnector(primeConnector) primeProjectionsPyrToRight= [pynn.Projection(turnToPyrPop, rightPop, primeConnList, target='excitatory')] primeProjectionsPyrToLeft= [pynn.Projection(turnToPyrPop, leftPop, primeConnList, target='excitatory')] # ——— run mapping ————————————————————————————————————————————————————————————— marocco.skip_mapping = False marocco.backend = PyMarocco.None pynn.reset() pynn.run(duration) set_sthal_params(runtime.wafer(), gmax=1023, gmax_div=1) marocco.skip_mapping = True marocco.backend = PyMarocco.Hardware # Full configuration during first step marocco.hicann_configurator = PyMarocco.HICANNv4Configurator logger.info("running measurement with digital weight ") inputWeight = 13 intraCAWeight = 14 primeWeight = 3 stopWeight = 15 setFourBitWeights(inputProjections, inputWeight) setFourBitWeights(CAProjectionsLeft, intraCAWeight) setFourBitWeights(CAProjectionsRight, intraCAWeight) setFourBitWeights(CAProjectionsTurnPyr, intraCAWeight) setFourBitWeights(primeProjectionsPyrToRight, primeWeight) setFourBitWeights(primeProjectionsPyrToLeft, primeWeight) if (inputVisProjections != 'none'): setFourBitWeights(inputVisProjections, primeWeight) pynn.run(duration) #np.savetxt("membrane_w{}.txt".format(digital_weight), pop.get_v()) np.savetxt("spikesLeftA.txt", leftPop.getSpikes()) np.savetxt("spikesRightA.txt", rightPop.getSpikes()) np.savetxt("spikesTurnPyrA.txt", turnToPyrPop.getSpikes()) pynn.reset() pynn.run(duration) np.savetxt("spikesLeftB.txt", leftPop.getSpikes()) np.savetxt("spikesRightB.txt", rightPop.getSpikes()) np.savetxt("spikesTurnPyrB.txt", turnToPyrPop.getSpikes()) pynn.reset()