def run(noNeurons): runtime = 1000.0 import numpy as np import pyNN.hardware.spikey as pynn pynn.setup() neurons = pynn.Population(noNeurons, pynn.IF_facets_hardware1) neurons.record() stim = pynn.Population(10, pynn.SpikeSourcePoisson, { 'rate': 20.0, 'duration': runtime }) prj = pynn.Projection(stim, neurons, pynn.AllToAllConnector()) prj.setWeights(pynn.maxExcWeight()) pynn.run(runtime) spikes = neurons.getSpikes([]) # for neuron in np.unique(spikes[:,0]): # print 'neuron', int(neuron), 'has', len(spikes[spikes[:,0] == # neuron]), 'spikes' noSpikes = len(spikes) lost, sent = pynn.getInputSpikes() pynn.end() print 'no neurons / spikes in / lost / out:', noNeurons + 1, sent, lost, noSpikes return noSpikes
def test(): '''mapping of bio index to hardware index should work for networks where not all neurons are recorded''' pynn.setup() if mappingOffset > 0: dummy = pynn.Population(mappingOffset, pynn.IF_facets_hardware1) neuronList = [] for i in range(noNeurons): neuronList.append(pynn.Population(1, pynn.IF_facets_hardware1)) neuronList[-1].record() dummy = pynn.Population(1, pynn.IF_facets_hardware1) stim = pynn.Population(1, pynn.SpikeSourcePoisson) for neuron in neuronList: pynn.Projection(stim, neuron, pynn.AllToAllConnector(weights=pynn.minExcWeight())) pynn.run(1000.0) pynn.end() f = open('spikeyconfig.out') for line in f: for i in range(mappingOffset + 2 * noNeurons): if line.find('w ' + str(192 + i)) >= 0: weight = int(line.split(' ')[256 + 2 - 1]) print 192 + i, weight assert (weight == shouldPatternWeights[i] ), 'results do not fit expectation' f.close()
def maxSpikesIn(runtime): '''Maximum number of spikes that can be sent: Should be limited by memory size on FPGA board (256MB => 256x1024x1024x8/32x3 approx. 200e6 spikes).''' rate = 10.0 weight = 1.0 poissonParam = {'start': 0, 'duration': runtime, 'rate': rate} pynn.setup() stim = pynn.Population(256, pynn.SpikeSourcePoisson, poissonParam) neuron = pynn.Population(192, pynn.IF_facets_hardware1) prj = pynn.Projection(stim, neuron, pynn.AllToAllConnector(weights=pynn.minInhWeight() * weight), target='inhibitory') neuron.record() pynn.run(runtime) spikes = neuron.getSpikes() lost, sent = pynn.getInputSpikes() print 'spikes in / out', sent, len(spikes) pynn.end()
def test_poisson(): """Test with Poisson source.""" import pyNN.hardware.spikey as pynn duration = 1000.0 # ms rate = 5000.0 # 1/s poissonParam = {'start': 0, 'duration': duration, 'rate': rate} limLost = 1.0 # % pynn.setup() stim = pynn.Population(1, pynn.SpikeSourcePoisson, poissonParam) neuron = pynn.Population(1, pynn.IF_facets_hardware1) pynn.Projection(stim, neuron, method=pynn.AllToAllConnector(weights=0), target='inhibitory') neuron.record() pynn.run(duration) lost, sent = pynn.getInputSpikes() print 'Number of input spikes (lost, sent, %lost)', lost, sent, float( lost) / sent * 1e2 assert float(lost) / sent * 1e2 < limLost, 'Too many spikes lost!' pynn.end()
def test_spikey5_allneurons(): ''' Tests mapping and firing of all 384 neurons. ''' runtime = 1000.0 stimRate = 10.0 weight = 7 pynn.setup() neurons = pynn.Population(384, pynn.IF_facets_hardware1) stim = pynn.Population(10, pynn.SpikeSourcePoisson, { 'start': 0, 'duration': runtime, 'rate': stimRate }) prj = pynn.Projection( stim, neurons, method=pynn.AllToAllConnector(weights=pynn.minExcWeight() * weight), target='excitatory') pynn.run(runtime) spikes = neurons.getSpikes() print 'spikes from', len(np.unique(spikes)), 'different neurons' # TODO: check for spikes from all neurons pynn.end()
def test_regular(): """Maximum rate without packing: Each second clock cycle a minimal loaded (filled with 1 spikes) spike packet.""" import numpy as np import pyNN.hardware.spikey as pynn import time np.random.seed(int(time.time())) lineDriverNo = np.random.random_integers(0, 255) print 'Using line driver number', lineDriverNo duration = 1000.0 # ms h = 1e3 / 5000.0 # 0.2 ms pynn.setup() stim = pynn.Population(256, pynn.SpikeSourceArray) stim[lineDriverNo].set_parameters( spike_times=np.arange(0, duration + h / 2.0, h)) neuron = pynn.Population(1, pynn.IF_facets_hardware1) pynn.Projection(stim, neuron, method=pynn.AllToAllConnector(weights=0), target='inhibitory') neuron.record() pynn.run(duration) lost, sent = pynn.getInputSpikes() print 'Number of input spikes (lost, sent)', lost, sent assert lost == 0, 'There should not be any spikes lost!' pynn.end()
def test_regular_packed(): """Maximum rate with packing: Each clock cycle a full (filled with 3 spikes) spike packet.""" import numpy as np import pyNN.hardware.spikey as pynn duration = 1000.0 # ms h = 1e3 / 5000.0 / 2.0 # 0.1 ms spikeTimes = np.arange(0, duration + h / 2.0, h) pynn.setup() stim = pynn.Population(256, pynn.SpikeSourceArray) # spikes have to be distributed over blocks of line drivers for efficient # packing stim[0].set_parameters(spike_times=spikeTimes) stim[64].set_parameters(spike_times=spikeTimes) stim[128].set_parameters(spike_times=spikeTimes) neuron = pynn.Population(1, pynn.IF_facets_hardware1) pynn.Projection(stim, neuron, method=pynn.AllToAllConnector(weights=0), target='inhibitory') neuron.record() pynn.run(duration) lost, sent = pynn.getInputSpikes() print 'Number of input spikes (lost, sent)', lost, sent assert lost == 0, 'There should not be any spikes lost!' pynn.end()
def maxRuntime(runtime): '''Maximum runtime: Limited by wrap around of counter (after approx. 6600s). Can be extended to infinitly long runtimes by considering wrap around. Subtract/Add offset to in/out spike times for each wrap around.''' rate = 1.0 weight = 1.0 poissonParam = {'start': 0, 'duration': runtime, 'rate': rate} pynn.setup() stim = pynn.Population(1, pynn.SpikeSourcePoisson, poissonParam) neuron = pynn.Population(1, pynn.IF_facets_hardware1) prj = pynn.Projection(stim, neuron, pynn.AllToAllConnector(weights=pynn.minInhWeight() * weight), target='inhibitory') neuron.record() pynn.run(runtime) spikes = neuron.getSpikes() lost, sent = pynn.getInputSpikes() print 'spikes in / out', sent, len(spikes) pynn.end()
def testRegularMaxPacked(): '''Maximum rate with packing: Each clock cycle a full (filled with 3 spikes) spike packet.''' import numpy as np import pyNN.hardware.spikey as pynn duration = 10000.0 # ms h = 1e3 / 5000.0 / 2.0 # 10kHz for each of 3 sources = 30kHz spikeTimes = np.arange(0, duration + h / 2.0, h) pynn.setup() stim = pynn.Population(256, pynn.SpikeSourceArray) stim[0].set_parameters(spike_times=spikeTimes) stim[63].set_parameters(spike_times=spikeTimes) stim[127].set_parameters(spike_times=spikeTimes) neuron = pynn.Population(1, pynn.IF_facets_hardware1) pynn.Projection(stim, neuron, method=pynn.AllToAllConnector(weights=0), target='inhibitory') neuron.record() pynn.run(duration) print 'no out spikes:', len(neuron.getSpikes()) lost, sent = pynn.getInputSpikes() print 'no in spikes (lost, sent)', lost, sent assert lost == 0, 'there should not be any spikes lost!' pynn.end()
def run(lowThreshold): runtime = 1000.0 pynn.setup() # set STDP params for low threshold -> fails when vcthigh-vctlow < 0.04 if lowThreshold: pynn.hardware.hwa.setSTDPParams(0.0, default.tpcsec, default.tpcorperiod, 1.0, 1.0, 1.0, 0.98, 2.5) else: pynn.hardware.hwa.setSTDPParams(0.0, default.tpcsec, default.tpcorperiod, 1.0, 1.0, 1.0, 0.85, 2.5) neuron = pynn.Population(1, pynn.IF_facets_hardware1) spikeArray = pynn.Population(1, pynn.SpikeSourceArray) stdp_model = pynn.STDPMechanism( timing_dependence=pynn.SpikePairRule(), weight_dependence=pynn.AdditiveWeightDependence()) prj = pynn.Projection( spikeArray, neuron, method=pynn.AllToAllConnector(weights=pynn.minExcWeight() * 0), target='excitatory', synapse_dynamics=pynn.SynapseDynamics(slow=stdp_model)) pynn.run(runtime) pynn.end()
def withDummyNeurons(mappingOffset, vrest): pynn.setup() if mappingOffset > 0: pynn.Population(mappingOffset, pynn.IF_facets_hardware1) pynn.Population(1, pynn.IF_facets_hardware1, vrest) pynn.run(1000.0) vout = copy.deepcopy(pynn.hardware.hwa.vouts[1, 2:4]) pynn.end() return vout
def build(rateIn): global neurons, stim poissonParams = {'start': 0, 'duration': runtime, 'rate': rateIn} stim = pynn.Population(32, pynn.SpikeSourcePoisson, poissonParams) neurons = pynn.Population(numNeurons, pynn.IF_facets_hardware1) pynn.Projection(stim, neurons, pynn.AllToAllConnector(weights=pynn.minExcWeight() * 5.0), target='excitatory') neurons.record()
def run_network(mappingOffset=0, neuronPermutation=[], noNeurons=-1): pynn.setup(mappingOffset=mappingOffset, neuronPermutation=neuronPermutation) if noNeurons == -1: noNeurons = 384 if pynn.getChipVersion() == 4: noNeurons = 192 a = pynn.Population(noNeurons, pynn.IF_facets_hardware1) b = pynn.Population(10, pynn.SpikeSourcePoisson) prj = pynn.Projection(b, a, method=pynn.AllToAllConnector()) pynn.run(1.0)
def compareSpikesToMembrane(duration): """ Tests the precise timing of digital spikes and spikes extracted from the membrane potential. The neuron is stimulated with Poisson spike sources. """ np.random.seed(int(time.time())) neuronNo = np.random.random_integers(0, 191) print 'Using neuron number', neuronNo poissonParams = {'start': 100.0, 'duration': duration - 100.0, 'rate': 30.0} # offset of 100 ms to get all spikes weightExc = 4 # digital hardware value weightInh = 15 # digital hardware value freqLimit = 1.0 # 1/s meanLimit = 0.2 # ms stdLimit = 0.2 # ms import pyNN.hardware.spikey as pynn pynn.setup(mappingOffset=neuronNo) stimExc = pynn.Population(64, pynn.SpikeSourcePoisson, poissonParams) stimInh = pynn.Population(192, pynn.SpikeSourcePoisson, poissonParams) neuron = pynn.Population(1, pynn.IF_facets_hardware1) prj = pynn.Projection(stimExc, neuron, pynn.AllToAllConnector( weights=weightExc * pynn.minExcWeight()), target='excitatory') prj = pynn.Projection(stimInh, neuron, pynn.AllToAllConnector( weights=weightInh * pynn.minInhWeight()), target='inhibitory') neuron.record() pynn.record_v(neuron[0], '') pynn.run(duration) spikes = neuron.getSpikes()[:, 1] membrane = pynn.membraneOutput memTime = pynn.timeMembraneOutput spikesMem, deriv, thresh = spikesFromMem(memTime, membrane) pynn.end() #plot(memTime, membrane, spikes, spikesMem, deriv, thresh) print 'Spikes and spikes on membrane:', len(spikes), '/', len(spikesMem) assert len(spikes) / duration * 1e3 >= freqLimit, 'Too less spikes.' assert len(spikes) == len(spikesMem), 'Spikes do not match membrane.' spikesDiff = spikesMem - spikes spikesDiffMean = np.mean(spikesDiff) spikesDiffStd = np.std(spikesDiff) print 'Offset between spikes and membrane:', spikesDiffMean, '+-', spikesDiffStd assert spikesDiffMean < meanLimit, 'Spike and membrane have too large offset.' assert spikesDiffStd < stdLimit, 'Time axes of spikes and membrane are different.'
def withMappingOffset(mappingOffset, vrest): pynn.setup(mappingOffset=mappingOffset) pynn.Population(1, pynn.IF_facets_hardware1, vrest) pynn.run(1000.0) vout = copy.deepcopy(pynn.hardware.hwa.vouts[1, 2:4]) pynn.end() return vout
def getMem(self, voltageRest, mappingOffset, calibOutputPins, calibNeuronMems): import pyNN.hardware.spikey as pynn pynn.setup(useUsbAdc=True, avoidSpikes=True, mappingOffset=mappingOffset, calibTauMem=False, calibOutputPins=calibOutputPins, calibNeuronMems=calibNeuronMems) neuron = pynn.Population(1, pynn.IF_facets_hardware1, self.neuronParams) #neuronDummy = pynn.Population(1, pynn.IF_facets_hardware1, self.neuronParams) neuron.set({'v_rest': voltageRest}) #neuronDummy.set({'v_rest': self.voltageRange[0]}) neuron.record() pynn.record_v(neuron[0], '') pynn.run(self.runtime) mem = pynn.membraneOutput spikes = neuron.getSpikes() pynn.end() self.assertTrue( (float(len(spikes)) / self.runtime * 1e3) <= self.limFreq, 'there should not be any (too much) spikes') return mem.mean()
def run(mappingOffset): """ Measures firing rate of one neuron (determined by mappingOffset) in dependence on value of g_leak. If linear fit to these firing rates does not show a significantly large slope, g_leak is assumed to be not set correctly. """ pynn.setup(mappingOffset=mappingOffset, calibTauMem=False, calibSynDrivers=False, calibVthresh=False) # set v_rest over v_reset to get neuron firing neuron = pynn.Population(1, pynn.IF_facets_hardware1, { 'v_rest': pynn.IF_facets_hardware1.default_parameters['v_thresh'] + 10.0 }) neuron.record() rateList = [] for gLeak in gLeakRange: neuron.set({'g_leak': gLeak / default.iLeak_base}) pynn.hardware.hwa._neuronsChanged = True pynn.run(runtime) rateList.append( [gLeak, float(len(neuron.getSpikes())) / runtime * 1e3]) pynn.end() rateList = np.array(rateList) pol = np.polyfit(rateList[:, 0], rateList[:, 1], 1) # linear fit print 'fitted polynom:', pol assert pol[0] > slopeMin, 'rate does not change with g_leak'
def getMemLoop(): result = [] pynn.setup(useUsbAdc=True) neuron = pynn.Population(noNeurons, pynn.IF_facets_hardware1) for j in range(noNeurons): if j % 2 == 0: neuron[j].set_parameters(v_rest=vRestEven) else: neuron[j].set_parameters(v_rest=vRestOdd) neuron.record() for i in range(noNeurons): pynn.record_v(neuron[i], '') pynn.run(runtime) mem = pynn.membraneOutput spikes = neuron.getSpikes() shutil.copy(spikeyconfigFilename, spikeyconfigFilename + extListNo[i]) self.assertTrue( (float(len(spikes)) / runtime * 1e3) <= limFreq, 'there should not be any (too much) spikes') result.append([mem.mean(), mem.std()]) pynn.end() return result
def maxSpikesOut(runtime): '''Maximum number of spikes that can be received: Should be limited by memory size on FPGA board (128MB approx. 100e6 spikes, other half for ADC).''' neuronParams = { 'v_reset': -80.0, # mV 'e_rev_I': -80.0, # mV 'v_rest': -45.0, # mV / rest above threshold 'v_thresh': -55.0, # mV 'g_leak': 20.0, # nS / without Scherzer calib approx. tau_m = 2ms } pynn.setup() neuron = pynn.Population(192, pynn.IF_facets_hardware1, neuronParams) neuron.record() pynn.run(runtime) spikes = neuron.getSpikes()[:, 1] lost, sent = pynn.getInputSpikes() print 'spikes in / out', sent, len(spikes) pynn.end()
def test_noSpikesBug(): import numpy as np import pyNN.hardware.spikey as pynn duration = 10 * 1000.0 # ms neuronParams = { 'v_reset': -80.0, # mV 'e_rev_I': -80.0, # mV 'v_rest': -45.0, # mV / rest above threshold 'v_thresh': -55.0, # mV 'g_leak': 20.0, # nS / without Scherzer calib approx. tau_m = 2ms } noTrials = 100 failCount = 0 for i in range(noTrials): pynn.setup() neuron = pynn.Population(1, pynn.IF_facets_hardware1, neuronParams) neuron.record() pynn.run(duration) spikes = neuron.getSpikes()[:, 1] pynn.end() # comment this out and everything is fine if len(spikes) == 0: failCount += 1 assert failCount == 0, str( float(failCount) / noTrials * 1e2) + ' % of runs did not have spikes'
def test_empty_exp(): """ Initialize hardware and create one neuron. """ pynn.setup() pynn.Population(1, pynn.IF_facets_hardware1) pynn.run(1000.0) pynn.end()
def emulation(doesWork): numberSynapses = 10 runtime = 1000.0 weights = range(0, numberSynapses * numberSynapses) pynn.setup() pre = pynn.Population(numberSynapses, pynn.SpikeSourcePoisson) post = pynn.Population(numberSynapses, pynn.IF_facets_hardware1) if doesWork: conn = pynn.Projection(pre, post, method=pynn.AllToAllConnector()) conn.setWeights(weights) else: conn = pynn.Projection(pre, post, method=pynn.AllToAllConnector(weights=weights)) pynn.run(runtime) pynn.end()
def emulate(): # pynn.setup(useUsbAdc=True) pynn.setup() stimI = pynn.Population(40, pynn.SpikeSourcePoisson, { 'start': 0, 'duration': runtime, 'rate': rate }) stimE = pynn.Population(20, pynn.SpikeSourcePoisson, { 'start': 0, 'duration': runtime, 'rate': rate }) neuron = pynn.Population(192, pynn.IF_facets_hardware1) prjI = pynn.Projection(stimI, neuron, pynn.AllToAllConnector(weights=weight * pynn.minInhWeight()), target='inhibitory') prjE = pynn.Projection(stimE, neuron, pynn.AllToAllConnector(weights=weight * pynn.minExcWeight()), target='excitatory') stimI.record() stimE.record() neuron.record() pynn.record_v(neuron[0], '') pynn.run(runtime) spikesInI = stimI.getSpikes() spikesInE = stimE.getSpikes() spikes = neuron.getSpikes() mem = pynn.membraneOutput print 'spikes out', len(spikes) print 'spikes in', len(spikesInI), len(spikesInE) print 'mem data points', len(mem) pynn.end()
def run(withSTDP): runtime = 1000.0 pynn.setup() stim = pynn.Population(1, pynn.SpikeSourcePoisson, { 'start': 0, 'duration': runtime, 'rate': 100.0}) neuron = pynn.Population(1, pynn.IF_facets_hardware1) if withSTDP: stdp_model = pynn.STDPMechanism(timing_dependence=pynn.SpikePairRule(), weight_dependence=pynn.AdditiveWeightDependence()) pynn.Projection(stim, neuron, method=pynn.AllToAllConnector( weights=pynn.maxExcWeight()), target='excitatory', synapse_dynamics=pynn.SynapseDynamics(slow=stdp_model)) else: pynn.Projection(stim, neuron, method=pynn.AllToAllConnector( weights=pynn.maxExcWeight()), target='excitatory') pynn.run(runtime) pynn.end()
def emulation(seed, connType=0, returnValue=None): numberNeurons = 192 noInputs = 15 pynn.setup() rngPrj = pynn.random.NumpyRNG(seed=seed, parallel_safe=True) # this may not work?! neurons = pynn.Population(numberNeurons, pynn.IF_facets_hardware1) connector = None if connType == 0: connector = pynn.FixedNumberPreConnector(noInputs, weights=pynn.minExcWeight()) elif connType == 1: connector = pynn.FixedNumberPostConnector(noInputs, weights=pynn.minExcWeight()) elif connType == 2: connector = pynn.FixedProbabilityConnector(float(noInputs) / numberNeurons, weights=pynn.minExcWeight()) else: assert False, 'invalid connector type' prj = pynn.Projection(neurons, neurons, method=connector, target='inhibitory', rng=rngPrj) connList = [] for conn in prj.connections(): connList.append(conn) assert len(connList) > 0, 'no connections' assert len(connList) < numberNeurons * \ (numberNeurons - 1), 'all-to-all connection' pynn.run(1.0) pynn.end() if returnValue != None: returnValue = connList else: return connList
# define weights in digital hardware values # --> these should be tuned first to obtain synfire chain behavior! weightStimExcExc = 12 * pynn.minExcWeight() # 12 weightStimExcInh = 12 * pynn.minExcWeight() # 12 weightExcExc = 13 * pynn.minExcWeight() # 8 weightExcInh = 14 * pynn.minExcWeight() # 10 weightInhExc = 9 * pynn.minInhWeight() # 7 # kick starter input pulse(s) #stimSpikes = np.array([100.0]) # to have several kick starter pulses, use (don't forget to reduce to first entry for closed chain): stimSpikes = np.array([100.0, 200.0, 300.0]) stimExc = pynn.Population(popSize['exc'], pynn.SpikeSourceArray, {'spike_times': stimSpikes}) # create neuron populations popCollector = {'exc': [], 'inh': []} for synType in ['exc', 'inh']: for popIndex in range(noPops): pop = pynn.Population(popSize[synType], pynn.IF_facets_hardware1, neuronParams) pop.record() popCollector[synType].append(pop) # connect stimulus pynn.Projection(stimExc, popCollector['exc'][0], pynn.FixedProbabilityConnector(p_connect=probExcExc, weights=weightStimExcExc),
def runTest(self): import numpy as np column = 4 row = 4 n = 20 # number of spike pairs deltaTList = [-1.0, 1.0] # ms deltaTLimit = 0.3 # allowed deviation delay = 2.9 # ms (between stimulus and post) # at beginning in ms (should be larger than max deltaT) experimentOffset = 100.0 deltaTPairs = 100.0 # time between pre-post-pairs in ms noStimulators = 3 weightStimulator = 15 # weight for stimulator neurons weightMeasure = 0 # weight for measured neuron procCorrOffset = 100.0 # time after experiment until correlations are processed in ms for deltaT in deltaTList: stimulus = np.arange(experimentOffset, (n - 0.5) * deltaTPairs + experimentOffset, deltaTPairs) self.assertTrue(len(stimulus) == n) stimulusMeasure = stimulus + delay - deltaT import pyNN.hardware.spikey as pynn import hwconfig_default_s1v2 as default pynn.setup() if column > 0: pynn.Population(column, pynn.IF_facets_hardware1) # stimulated neuron neuron = pynn.Population(1, pynn.IF_facets_hardware1) spikeSourceStim = None spikeSourceMeasure = None # stimulators above measured synapse if row < noStimulators: if row > 0: dummy = pynn.Population(row, pynn.SpikeSourceArray) spikeSourceMeasure = pynn.Population( 1, pynn.SpikeSourceArray, {'spike_times': stimulusMeasure}) spikeSourceStim = pynn.Population(noStimulators, pynn.SpikeSourceArray, {'spike_times': stimulus}) # stimulators below measured synapse if row >= noStimulators: if row > noStimulators: dummy = pynn.Population(row - noStimulators, pynn.SpikeSourceArray) spikeSourceMeasure = pynn.Population( 1, pynn.SpikeSourceArray, {'spike_times': stimulusMeasure}) # connect and record stdp_model = pynn.STDPMechanism( timing_dependence=pynn.SpikePairRule(), weight_dependence=pynn.AdditiveWeightDependence()) pynn.Projection( spikeSourceStim, neuron, method=pynn.AllToAllConnector(weights=pynn.minExcWeight() * weightStimulator), target='excitatory') prj = pynn.Projection( spikeSourceMeasure, neuron, method=pynn.AllToAllConnector(weights=pynn.minExcWeight() * weightMeasure), target='excitatory', synapse_dynamics=pynn.SynapseDynamics(slow=stdp_model)) neuron.record() ####### # RUN # ####### # correlation flags: # 0: no weight change # 1: causal weight change # 2: anti-causal weight change pynn.hardware.hwa.setLUT( [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) lastInputSpike = np.max(np.concatenate( (stimulus, stimulusMeasure))) runtime = lastInputSpike + procCorrOffset pynn.hardware.hwa.autoSTDPFrequency = runtime print 'runtime: ' + str(runtime) + '; last input spike: ' + str( lastInputSpike) + '; STDP readout: ' + str(runtime) pynn.run(runtime) # get flag and spikes corrFlag = ( np.array(prj.getWeightsHW(readHW=True, format='list')) / pynn.minExcWeight())[0] spikes = neuron.getSpikes()[:, 1] print 'stimulus:', stimulus print 'measure:', stimulusMeasure print 'post:', spikes self.assertTrue( len(stimulusMeasure) == len(spikes), 'No proper spiking!') print 'correlation flag: ' + str(corrFlag) print 'deltaT (is / should / limit):', np.mean( spikes - stimulusMeasure), '/', deltaT, '/', deltaTLimit self.assertTrue( abs(np.mean(spikes - stimulusMeasure) - deltaT) <= deltaTLimit, 'No precise spiking!') if deltaT > 0: # causal self.assertTrue(corrFlag == 1, 'Wrong correlation flag!') else: # anti-causal self.assertTrue(corrFlag == 2, 'Wrong correlation flag!') pynn.end()
def runTest(self): with_figure = False import numpy import pyNN.hardware.spikey as pynn if with_figure: import pylab # some test parameters neuron_param_even = { 'g_leak': 1.0, # nS 'tau_syn_E': 5.0, # ms 'tau_syn_I': 5.0, # ms 'v_reset': -100.0, # mV 'e_rev_I': -100.0, # mV, 'v_rest': -65.0, # mV 'v_thresh': -62.0 # mV } neuron_param_uneven = { 'g_leak': 1.0, # nS 'tau_syn_E': 5.0, # ms 'tau_syn_I': 5.0, # ms 'v_reset': -100.0, # mV 'e_rev_I': -100.0, # mV, 'v_rest': -65.0, # mV 'v_thresh': 0.0 # mV } stim_offset = 100.0 # ms stim_isi = 500.0 # ms stim_num = 10 # Number of external input spikes stim_weight = 8.0 # in units of pyn.minExcWeight stim_pop_size = 10 # size of stimulating population duration = stim_offset + ((stim_num + 1) * stim_isi) # neuron order: {0, 2, ..., 190, 1, 3, ..., 191, 192, 193, ... 343} neuron_order = range(0, 191, 2) + range(1, 192, 2) + range(192, 384, 1) if with_figure: pynn.setup(neuronPermutation=neuron_order, useUsbAdc=True) else: pynn.setup(neuronPermutation=neuron_order) # create the population with an even hardware neuron index even_population = pynn.Population(96, pynn.IF_facets_hardware1, neuron_param_even) # create the population with an uneven hardware neuron index uneven_population = pynn.Population(96, pynn.IF_facets_hardware1, neuron_param_uneven) if with_figure: pynn.record_v(even_population[0], '') # create the external stimulus stim_times = numpy.arange(stim_offset, stim_num * stim_isi, stim_isi) stim_pop = pynn.Population(stim_pop_size, pynn.SpikeSourceArray, {'spike_times': stim_times}) # connect the external simulus stim_con = pynn.AllToAllConnector(weights=stim_weight * pynn.minExcWeight()) stim_prj_even = pynn.Projection(stim_pop, even_population, stim_con) stim_prj_uneven = pynn.Projection(stim_pop, uneven_population, stim_con) # record spikes of all involved neurons even_population.record() uneven_population.record() # run the emulation pynn.run(duration) # get the spike data pre_swap_spikes_even = even_population.getSpikes() pre_swap_spikes_uneven = uneven_population.getSpikes() if with_figure: plotVoltageAndSpikes(pylab, pynn.timeMembraneOutput, pynn.membraneOutput, pre_swap_spikes_even, pre_swap_spikes_uneven) # swap the configurations pynn.set(even_population[0], pynn.IF_facets_hardware1, {'v_thresh': 0.0}) pynn.set(uneven_population[0], pynn.IF_facets_hardware1, {'v_thresh': -62.0}) # run the emulation pynn.run(duration) # get the spike data pst_swap_spikes_even = even_population.getSpikes() pst_swap_spikes_uneven = uneven_population.getSpikes() if with_figure: plotVoltageAndSpikes(pylab, pynn.timeMembraneOutput, pynn.membraneOutput, pst_swap_spikes_even, pst_swap_spikes_uneven) pre_spikes_count_even = float(len(pre_swap_spikes_even[:, 0])) pre_spikes_count_uneven = float(len(pre_swap_spikes_uneven[:, 0])) pst_spikes_count_even = float(len(pst_swap_spikes_even[:, 0])) pst_spikes_count_uneven = float(len(pst_swap_spikes_uneven[:, 0])) # let's see what we've got assert (pre_spikes_count_even > 0) assert (pst_spikes_count_uneven > 0) assert (pre_spikes_count_uneven / pre_spikes_count_even < 0.01) assert (pst_spikes_count_even / pst_spikes_count_uneven < 0.01) assert (pre_spikes_count_uneven / pst_spikes_count_uneven < 0.01) assert (pst_spikes_count_even / pre_spikes_count_even < 0.01)
def runTest(self): with_figure = False import numpy import pyNN.hardware.spikey as pynn if with_figure: import pylab # some test parameters neuron_param = { 'g_leak': 1.0, # nS 'tau_syn_E': 5.0, # ms 'tau_syn_I': 5.0, # ms 'v_reset': -100.0, # mV 'e_rev_I': -100.0, # mV, 'v_rest': -65.0, # mV 'v_thresh': -62.0 # mV } stim_offset = 100.0 # ms stim_isi = 500.0 # ms stim_num = 10 # Number of external input spikes stim_weight = 8.0 # in units of pyn.minExcWeight stim_pop_size = 10 # size of stimulating population duration = stim_offset + ((stim_num + 1) * stim_isi) # neuron order: {0, 2, ..., 190, 1, 3, ..., 191, 192, 193, .., 383} neuron_order = range(0, 191, 2) + range(1, 192, 2) + range(192, 384, 1) if with_figure: pynn.setup(neuronPermutation=neuron_order, useUsbAdc=True) else: pynn.setup(neuronPermutation=neuron_order) # create first population with an even hardware neuron index fst_population = pynn.Population(48, pynn.IF_facets_hardware1, neuron_param) # create second population with an even hardware neuron index snd_population = pynn.Population(48, pynn.IF_facets_hardware1, neuron_param) if with_figure: pynn.record_v(fst_population[0], '') # create the external stimulus stim_times = numpy.arange(stim_offset, stim_num * stim_isi, stim_isi) stim_pop = pynn.Population(stim_pop_size, pynn.SpikeSourceArray, {'spike_times': stim_times}) # connect the external simulus stim_con = pynn.AllToAllConnector(weights=stim_weight * pynn.minExcWeight()) stim_prj_fst = pynn.Projection(stim_pop, fst_population, stim_con) stim_prj_snd = pynn.Projection(stim_pop, snd_population, stim_con) # record spikes of all involved neurons fst_population.record() snd_population.record() # run the emulation pynn.run(duration) # get the spike data pre_change_spikes_fst = fst_population.getSpikes() pre_change_spikes_snd = snd_population.getSpikes() if with_figure: plotVoltageAndSpikes(pylab, pynn.timeMembraneOutput, pynn.membraneOutput, pre_change_spikes_fst, pre_change_spikes_snd, nrn_idx_lim=[0, 96]) # change the configuration for the first group # desired behaviour: change the configuration for all even neurons # "set" should be stronger than "previous setting in even/uneven group" pynn.set(fst_population[0], pynn.IF_facets_hardware1, {'v_thresh': 0.0}) # run the emulation pynn.run(duration) # get the spike data lidx_change_spikes_fst = fst_population.getSpikes() lidx_change_spikes_snd = snd_population.getSpikes() if with_figure: plotVoltageAndSpikes(pylab, pynn.timeMembraneOutput, pynn.membraneOutput, lidx_change_spikes_fst, lidx_change_spikes_snd, nrn_idx_lim=[0, 96]) pre_spikes_count_fst = float(len(pre_change_spikes_fst[:, 0])) pre_spikes_count_snd = float(len(pre_change_spikes_snd[:, 0])) lidx_spikes_count_fst = float(len(lidx_change_spikes_fst[:, 0])) lidx_spikes_count_snd = float(len(lidx_change_spikes_snd[:, 0])) # let's see what we've got assert (pre_spikes_count_fst > 0) assert (pre_spikes_count_snd > 0) assert (lidx_spikes_count_fst / pre_spikes_count_fst < 0.01) assert (lidx_spikes_count_snd / pre_spikes_count_snd < 0.01)
# for plotting without X-server import matplotlib as mpl mpl.use('Agg') import pyNN.hardware.spikey as pynn import numpy as np pynn.setup() # set resting potential over spiking threshold runtime = 1000.0 #ms popSize = 192 weight = 7.0 * pynn.minExcWeight() neuronParams = {'v_rest': -40.0} neurons = pynn.Population(popSize, pynn.IF_facets_hardware1, neuronParams) pynn.Projection(neurons, neurons, pynn.FixedNumberPreConnector(15, weights=weight), target='inhibitory') neurons.record() pynn.run(runtime) spikes = neurons.getSpikes() pynn.end() # visualize print 'mean firing rate:', round(len(spikes) / runtime / popSize * 1000.0, 1), '1/s'