#This makes a 2 state FSA. It does it without calling any of the #FSA test functions. It should have the same results as testFSASmall.py. #State 0, with input 1, turns on state 2. 2 turns off 1 and 0. import nealParams as nealParameters #get the simulator if (nealParameters.simulator=="spinnaker"): import pyNN.spiNNaker as sim elif (nealParameters.simulator=="nest"): import pyNN.nest as sim import cPickle as pickle import numpy as np from nealCoverClass import NealCoverFunctions from stateMachineClass import FSAHelperFunctions #---Below here are functions to test the system--- RUN_DURATION = 200 #initialize the simulator. def init(): #print "spin" or nest sim.setup(timestep=nealParameters.DELAY, min_delay=nealParameters.DELAY, max_delay=nealParameters.DELAY, debug=0) def printPklSpikes(fileName): fileHandle = open(fileName) neoObj = pickle.load(fileHandle) segments = neoObj.segments segment = segments[0] spikeTrains = segment.spiketrains neurons = len(spikeTrains) for neuronNum in range (0,neurons): if (len(spikeTrains[neuronNum])>0): spikes = spikeTrains[neuronNum] for spike in range (0,len(spikes)): print neuronNum, spikes[spike] fileHandle.close() def createTwoInputs(): inputSpikeTimes0 = [10.0] inputSpikeTimes1 = [50.0] spikeArray0 = {'spike_times': [inputSpikeTimes0]} spikeGen0=sim.Population(1,sim.SpikeSourceArray,spikeArray0, label='inputSpikes_0') spikeArray1 = {'spike_times': [inputSpikeTimes1]} spikeGen1=sim.Population(1, sim.SpikeSourceArray, spikeArray1, label='inputSpikes_1') return [spikeGen0,spikeGen1] def createNeurons(): if (nealParameters.simulator == 'nest'): numNeurons = fsa.CA_SIZE * 3 elif (nealParameters.simulator == 'spinnaker'): numNeurons = 100 cells=sim.Population(numNeurons,sim.IF_cond_exp,fsa.CELL_PARAMS) return cells def setupRecording(cells): if (nealParameters.simulator == 'nest'): cells.record({'spikes','v'}) elif (nealParameters.simulator == 'spinnaker'): cells.record() cells.record_v() def printResults(simCells): #print if (nealParameters.simulator == 'nest'): simCells.printSpikes('temp.pkl') #printPklSpikes('temp.pkl') elif (nealParameters.simulator == 'spinnaker'): simCells.printSpikes('temp.sp') simCells.print_v('temp.volts') ##--main--- neal = NealCoverFunctions(nealParameters.simulator) fsa = FSAHelperFunctions(nealParameters.simulator) init() spikeGenerators = createTwoInputs() firstSpikeGenerator = spikeGenerators[0] secondSpikeGenerator = spikeGenerators[1] stateCells = createNeurons() setupRecording(stateCells) #Build the FSA fsa.turnOnStateFromSpikeSource(firstSpikeGenerator,stateCells,0) fsa.turnOnStateFromSpikeSource(secondSpikeGenerator,stateCells,1) fsa.makeCA(stateCells,0) fsa.makeCA(stateCells,1) fsa.makeCA(stateCells,2) fsa.stateHalfTurnsOnState(stateCells,0,stateCells,2) fsa.stateTurnsOffState(stateCells,2,stateCells,0) #comment below out to check state 0 alone does not turn on state 2 fsa.stateHalfTurnsOnState(stateCells,1,stateCells,2) fsa.stateTurnsOffState(stateCells,2,stateCells,1) sim.run(RUN_DURATION) printResults(stateCells)