Changeset 48
- Timestamp:
- 05/11/07 11:35:19 (2 years ago)
- Files:
-
- branches/0.3/common.py (modified) (2 diffs)
- branches/0.3/doc/lowlevelapi.txt (modified) (3 diffs)
- branches/0.3/doc/standardmodels.txt (modified) (1 diff)
- branches/0.3/facetsml.py (modified) (3 diffs)
- branches/0.3/hoc/standardCells.hoc (modified) (2 diffs)
- branches/0.3/nest.py (modified) (9 diffs)
- branches/0.3/neuron.py (modified) (6 diffs)
- branches/0.3/oldneuron.py (modified) (4 diffs)
- branches/0.3/pcsim.py (modified) (21 diffs)
- branches/0.3/test/IF_cond_alpha.py (modified) (1 diff)
- branches/0.3/test/IF_curr_exp.py (modified) (1 diff)
- branches/0.3/test/pyNNPcsimLowLevelTest.py (modified) (5 diffs)
- branches/0.3/test/runtests.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/0.3/common.py
r36 r48 149 149 150 150 class IF_cond_alpha(StandardCellType): 151 #"""Leaky integrate and fire model with fixed threshold and alpha-function-152 #shaped post-synaptic conductance."""153 #151 """Leaky integrate and fire model with fixed threshold and alpha-function- 152 shaped post-synaptic conductance.""" 153 154 154 default_parameters = { 155 155 'v_rest' : -65.0, # Resting membrane potential in mV. … … 218 218 both be individual cells or lists of cells, in which case all possible 219 219 connections are made with probability p, using either the random number 220 generator supplied, or the default rng otherwise.""" 220 generator supplied, or the default rng otherwise. 221 Weights should be in nA or uS.""" 221 222 pass 222 223 branches/0.3/doc/lowlevelapi.txt
r29 r48 2 2 Neurons and Connections 3 3 ======================= 4 5 Initialising the simulator 6 ========================== 7 8 Before using any other functions or classes from PyNN, the user must call the ``setup()`` function:: 9 10 >>> setup() 11 12 ``setup()`` takes various optional arguments: setting the simulation timestep (there is currently no support in the API for variable timestep methods although native simulator code can be used to select this option where the simulator supports it), setting the minimum and maximum synaptic delays, and turning debugging output on and off, e.g.:: 13 14 >>> setup(timestep=0.1, min_delay=0.1, max_delay=0.1, debug=False) 15 16 Debugging information is written to a log file in the working directory. 4 17 5 18 Creating neurons … … 55 68 >>> connect(spike_source, cells) 56 69 57 In this case we connect a spike-generating mechanism (``SpikeSourceArray`` is a 'standard cell' model that emits spikes at times specified by the ``spiketimes`` parameter) to each cell in the list ``cells` , i.e. we create 10 connections at once.70 In this case we connect a spike-generating mechanism (``SpikeSourceArray`` is a 'standard cell' model that emits spikes at times specified by the ``spiketimes`` parameter) to each cell in the list ``cells``, i.e. we create 10 connections at once. 58 71 For clarity, we could also have specified the argument names:: 59 72 … … 110 123 Recording spikes and membrane potential 111 124 ======================================= 125 126 To record action potentials use the ``record()`` function and to record membrane potential use the ``record_v()`` function. 127 The arguments for both functions are a cell id or list of ids, and a filename, e.g.:: 128 129 >>> record(cell, "spikes.dat") 130 >>> record_v(cell_list, "allspikes.dat") 131 132 By default, all simulators write data files in the same format. 133 134 The beginning of a typical spike file looks like:: 135 136 # dt = 0.1 137 # n = 1000 138 0.0 2 139 0.3 5 140 0.4 3 141 0.9 2 142 1.0 1 143 . . . 144 145 The beginning of a typical membrane potential file looks like:: 146 147 # dt = 0.1 148 # n = 1000 149 -65.0 0 150 -64.9 0 151 -64.7 0 152 -64.5 0 153 . . . 154 155 Both file types begin with header lines giving the timestep (there is currently no support for variable-time step recording) and the number of data points [per cell or total?] in the file. 156 Each line of the spike file then gives the occurence time of a spike (in ms) and the id of the neuron in which it was recorded. 157 Each line of the membrane potential file gives the membrane potential (in mV) followed by the id of the neuron in which it was recorded. 158 In both cases, whether the file is sorted by cell id or by time depends on the simulator: it is not standardised. 159 160 In some cases it is more efficient to write files in the simulator's native format, rather than the standard PyNN format. 161 In this case, use the ``compatible_output=False`` argument to the ``end()`` function. 162 163 Considerable enhancements to file formats are planned for future releases of PyNN, including recording to binary (HDF5) rather than text files, support for variable time-step recording, and user-specified output formats. 164 165 Running a simulation 166 ==================== 167 168 The ``run()`` function runs the simulation for a given number of milliseconds, e.g.:: 169 170 >>> run(1000.0) 171 172 Finishing up 173 ============ 174 175 Just as a simulation must be begun with a call to ``setup()``, it must be ended with a call to ``end()``. 176 177 Example 178 ======= 179 180 We now give a full example of a PyNN simulation script:: 181 182 from pyNN.nest import * 183 184 <insert IF_curr_alpha.py here (with line numbers?)> 185 186 To run the script with NEURON, replace the first line with:: 187 188 from pyNN.neuron import * 189 190 and to run the script with PCSIM:: 191 192 from pyNN.pcsim import * 193 branches/0.3/doc/standardmodels.txt
r28 r48 2 2 Standard models 3 3 =============== 4 5 Standard models are neuron models that are available in at least two of the simulation engines supported by PyNN. 6 PyNN performs automatic translation of parameter names, types and units. 7 Only a handful of models are currently available, but the list will be expanded in future releases. 8 9 Integrate-and-fire neurons 10 ========================== 11 12 IF_curr_alpha 13 ------------- 14 15 Leaky integrate and fire model with fixed threshold and alpha-function-shaped post-synaptic current. 16 17 Availability: NEST, NEURON, PCSIM 18 19 ============== ============= ===== ======================================== 20 Name Default value Units Description 21 ============== ============= ===== ======================================== 22 ``v_rest`` -65.0 mV Resting membrane potential 23 ``cm`` 1.0 nF Capacity of the membrane 24 ``tau_m`` 20.0 ms Membrane time constant 25 ``tau_refrac`` 0.0 ms Duration of refractory period 26 ``tau_syn`` 5.0 ms Rise time of the synaptic alpha function 27 ``i_offset`` 0.0 nA Offset current 28 ``v_reset`` -65.0 mV Reset potential after a spike 29 ``v_thresh`` -50.0 mV Spike threshold 30 ``v_init`` -65.0 mV Membrane potential at ``t`` = 0 31 ============== ============= ===== ======================================== 32 33 34 IF_curr_exp 35 ----------- 36 37 Leaky integrate and fire model with fixed threshold and decaying-exponential post-synaptic current. 38 (Separate synaptic currents for excitatory and inhibitory synapses. 39 40 Availability: NEST, NEURON, PCSIM 41 42 ============== ============= ===== ========================================= 43 Name Default value Units Description 44 ============== ============= ===== ========================================= 45 ``v_rest`` -65.0 mV Resting membrane potential 46 ``cm`` 1.0 nF Capacity of the membrane 47 ``tau_m`` 20.0 ms Membrane time constant 48 ``tau_refrac`` 0.0 ms Duration of refractory period 49 ``tau_syn_E`` 5.0 ms Decay time of excitatory synaptic current 50 ``tau_syn_I`` 5.0 ms Decay time of inhibitory synaptic current 51 ``i_offset`` 0.0 nA Offset current 52 ``v_reset`` -65.0 mV Reset potential after a spike 53 ``v_thresh`` -50.0 mV Spike threshold 54 ``v_init`` -65.0 mV Membrane potential ``t`` = 0 55 ============== ============= ===== ========================================= 56 57 58 IF_cond_alpha 59 _____________ 60 61 Leaky integrate and fire model with fixed threshold and alpha-function-shaped post-synaptic conductance. 62 63 Availability: NEST, NEURON, PCSIM 64 65 ============== ============= ===== =================================================== 66 Name Default value Units Description 67 ============== ============= ===== =================================================== 68 ``v_rest`` -65.0 mV Resting membrane potential 69 ``cm`` 1.0 nF Capacity of the membrane 70 ``tau_m`` 20.0 ms Membrane time constant 71 ``tau_refrac`` 0.0 ms Duration of refractory period 72 ``tau_syn_E`` 5.0 ms Rise time of the excitatory synaptic alpha function 73 ``tau_syn_I`` 5.0 ms Rise time of the inhibitory synaptic alpha function 74 ``e_rev_E`` 0.0 mV Reversal potential for excitatory input 75 ``e_rev_I`` -70.0 mV Reversal potential for inhibitory input 76 ``v_thresh`` -50.0 mV Spike threshold 77 ``v_reset`` -65.0 mV Reset potential after a spike 78 ``i_offset`` 0.0 nA Offset current 79 ``v_init`` -65.0 mV Membrane potential at ``t`` = 0 80 ============== ============= ===== =================================================== 81 82 83 84 Spike sources 85 ============= 86 87 SpikeSourcePoisson 88 ------------------ 89 90 Spike source, generating spikes according to a Poisson process. 91 92 Availability: NEST, NEURON, PCSIM 93 [note problems with this in NEST] 94 95 ============ ============= ====== ========================== 96 Name Default value Units Description 97 ============ ============= ====== ========================== 98 ``rate` 0.0 s^`-1` Mean spike frequency 99 ``start`` 0.0 ms Start time 100 ``duration`` 10^9 ms Duration of spike sequence 101 ============ ============= ====== ========================== 102 103 104 SpikeSourceArray 105 ---------------- 106 Spike source generating spikes at the times given in the ``spike_times`` array. 107 108 Availability: NEST, NEURON, PCSIM 109 110 =============== ============= ====== ========================== 111 Name Default value Units Description 112 =============== ============= ====== ========================== 113 ``spike_times`` ``[]`` ms list or numpy array containing spike times 114 =============== ============= ====== ========================== branches/0.3/facetsml.py
r5 r48 5 5 6 6 import common 7 import numpy, types, sys, shutil7 #import numpy, types, sys, shutil 8 8 import RandomArray 9 from xml.dom import * 10 from xml.dom.minidom import * 11 from xml.dom.ext import * 12 9 13 10 14 open_files = [] 11 15 12 16 dt = 0.1 17 xmldoc = Document() 18 19 """ 20 warning : 21 in order to write xml in a format which respects the namespaces, you must use xml.dom.ext.PrettyPrint 22 namespaces allowed are : 23 neuromlNode.setAttribute('xmlns:net','http://morphml.org/networkml/schema') 24 neuromlNode.setAttribute('xmlns:mml','http://morphml.org/morphml/schema') 25 neuromlNode.setAttribute('xmlns:meta','http://morphml.org/metadata/schema') 26 neuromlNode.setAttribute('xmlns:bio','http://morphml.org/biophysics/schema') 27 neuromlNode.setAttribute('xmlns:cml','http://morphml.org/channelml/schema') 28 29 """ 30 31 def initDocument(parentElementNS,parentElementName,prefix=''): 32 """ 33 create the root element <neuroml> if doesn't exist 34 and the specified parentElement just below <neuroml> if doesn't exist 35 returns the parentElement node 36 """ 37 neuromlNodes = xmldoc.getElementsByTagNameNS('http://morphml.org/neuroml/schema','neuroml') 38 #if the <neuroml> markup is not yet created 39 if(neuromlNodes.length == 0): 40 #seems createElementNS doesn't create the xmlns attribute 41 neuromlNode = xmldoc.createElementNS('http://morphml.org/neuroml/schema','neuroml') 42 xmldoc.appendChild(neuromlNode) 43 else: 44 neuromlNode = neuromlNodes[0] 45 parentElementNodes = neuromlNode.getElementsByTagNameNS(parentElementNS,parentElementName) 46 if(parentElementNodes.length == 0): 47 if(prefix == ''): 48 parentElementNode = xmldoc.createElementNS(parentElementNS,parentElementName) 49 else: 50 parentElementNode = xmldoc.createElementNS(parentElementNS,prefix + ":" + parentElementName) 51 neuromlNode.appendChild(parentElementNode) 52 else: 53 parentElementNode = parentElementNodes[0] 54 return parentElementNode 13 55 14 56 … … 222 264 nPop = 0 223 265 224 def __init__(self,dims,cell type,cellparams=None,label=None):266 def __init__(self,dims,cellclass,cellparams=None,label=None): 225 267 """ 226 268 dims should be a tuple containing the population dimensions, or a single … … 232 274 constructor 233 275 label is an optional name for the population. 234 """ 235 236 common.Population.__init__(self,dims,celltype,cellparams,label) 276 277 example of NeuroML (completeNetwork.xml with CellGroupC example added) : 278 <net:populations> 279 <net:population name="CellGroupA"> 280 <net:cell_type>CellA</net:cell_type> 281 <net:instances> 282 <net:instance id="0"><net:location x="0" y="0" z="0"/></net:instance> 283 <net:instance id="1"><net:location x="0" y="10" z="0"/></net:instance> 284 <net:instance id="2"><net:location x="0" y="20" z="0"/></net:instance> 285 </net:instances> 286 </net:population> 287 <net:population name="CellGroupB"> 288 <net:cell_type>CellA</net:cell_type> 289 <net:instances> 290 <net:instance id="0"><net:location x="0" y="100" z="0"/></net:instance> 291 <net:instance id="1"><net:location x="20" y="100" z="0"/></net:instance> 292 </net:instances> 293 </net:population> 294 <net:population name="CellGroupC"> 295 <net:cell_type>CellC</net:cell_type> 296 <net:pop_location reference="aeag"> 297 <net:grid_arrangement> 298 <net:rectangular_location name="aefku"> 299 <meta:corner x="0" y="0" z="0"/> 300 <meta:size depth="10" height="100" width="100"/> 301 </net:rectangular_location> 302 <net:spacing x="10" y="10" z="10"/> 303 </net:grid_arrangement> 304 </net:pop_location> 305 </net:population> 306 </net:populations> 307 308 309 310 """ 311 312 common.Population.__init__(self,dims,cellclass,cellparams,label) 237 313 238 self.translate = getattr(StandardCells,self.celltype) # move this to common.Population.__init__()?239 314 240 315 if not self.label: 241 316 self.label = 'population%d' % Population.nPop 242 243 raise "Not yet implemented." 317 318 319 populationsNode = initDocument('http://morphml.org/networkml/schema','populations','net') 320 321 populationNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','net:population') 322 populationNode.setAttribute('name',label) 323 populationsNode.appendChild(populationNode) 324 325 cell_typeNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','net:cell_type') 326 #coming from neuron.py 327 if isinstance(cellclass, type): 328 self.celltype = cellclass(cellparams) 329 self.cellparams = self.celltype.parameters 330 hoc_name = self.celltype.hoc_name 331 elif isinstance(cellclass, str): # not a standard model 332 hoc_name = cellclass 333 #end of coming 334 335 cell_typeTextNode = xmldoc.createTextNode(hoc_name) 336 cell_typeNode.appendChild(cell_typeTextNode) 337 populationNode.appendChild(cell_typeNode) 338 """ 339 the minimal neuroml to add there is : 340 <net:pop_location reference="aReference"> 341 <net:grid_arrangement> 342 <net:rectangular_location name="aName"> 343 <meta:corner x="0" y="0" z="0"/> 344 <meta:size depth="10" height="100" width="100"/> 345 </net:rectangular_location> 346 <net:spacing x="10" y="10" z="10"/> 347 </net:grid_arrangement> 348 349 </net:pop_location> 350 """ 351 pop_locationNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','net:pop_location') 352 pop_locationNode.setAttribute('reference','aReference') 353 populationNode.appendChild(pop_locationNode) 354 355 grid_arrangementNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','net:grid_arrangement') 356 pop_locationNode.appendChild(grid_arrangementNode) 357 358 rectangular_locationNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','net:rectangular_location') 359 rectangular_locationNode.setAttribute('name','aName') 360 grid_arrangementNode.appendChild(rectangular_locationNode) 361 362 cornerNode = xmldoc.createElementNS('http://morphml.org/metadata/schema','meta:corner') 363 cornerNode.setAttribute('x','0') 364 cornerNode.setAttribute('y','0') 365 cornerNode.setAttribute('z','0') 366 rectangular_locationNode.appendChild(cornerNode) 367 368 sizeNode = xmldoc.createElementNS('http://morphml.org/metadata/schema','meta:size') 369 #neuroml is always in 3D adding 0 for non covered dimensions 370 sizeNode.setAttribute('depth',str(10*dims[0])) 371 sizeNode.setAttribute('height',str(10*dims[1])) 372 if(dims.__len__() > 2): 373 sizeNode.setAttribute('width',str(10*dims[2])) 374 else: 375 sizeNode.setAttribute('width','0') 376 rectangular_locationNode.appendChild(sizeNode) 377 378 spacingNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','net:spacing') 379 spacingNode.setAttribute('x','10') 380 spacingNode.setAttribute('y','10') 381 spacingNode.setAttribute('z','10') 382 grid_arrangementNode.appendChild(spacingNode) 383 384 385 #cellparams would be defined in a <cell> markup which would define precisely the neuron model 386 387 388 #raise "Not yet implemented." 244 389 245 390 246 391 Population.nPop += 1 392 PrettyPrint(xmldoc) 393 247 394 248 395 def set(self,param,val): branches/0.3/hoc/standardCells.hoc
r20 r48 32 32 if ($o1.has_key("t_refrac")) { t_refrac = $o1.get("t_refrac") } else { t_refrac = 2 } // (ms) 33 33 if ($o1.has_key("i_offset")) { i_offset = $o1.get("i_offset") } else { i_offset = 0 } // (nA) 34 if ($o1.has_key("v_init")) { v_init = $o1.get("v_init") } else { v_init = v_rest } // (mV) 34 35 if ($o1.has_key("tau_syn")) { 35 36 tau_e = $o1.get("tau_syn") … … 46 47 if ($o1.has_key("e_i")) { e_i = $o1.get("e_i") } else { e_i = -70 } // (mV) 47 48 } 48 v_init = v_rest49 49 fih = new FInitializeHandler("memb_init()",this) 50 50 fih2 = new FInitializeHandler("param_update()", this) branches/0.3/nest.py
r34 r48 97 97 class IF_cond_alpha(common.IF_cond_alpha): 98 98 """Leaky integrate and fire model with fixed threshold and alpha-function- 99 shaped post-synaptic c urrent."""99 shaped post-synaptic conductance.""" 100 100 101 101 translations = { … … 109 109 'v_thresh' : ('Theta' , "parameters['v_thresh']"), 110 110 'i_offset' : ('I0' , "parameters['i_offset']*1000.0"), # I0 is in pA, i_offset in nA 111 'v_init' : ('u' , "parameters['v_init']"),112 111 'e_rev_E' : ('V_reversal_E', "parameters['e_rev_E']"), 113 112 'e_rev_I' : ('V_reversal_I', "parameters['e_rev_I']"), 113 'v_init' : ('u' , "parameters['v_init']"), 114 114 } 115 115 nest_name = "iaf_cond_neuron" … … 265 265 if p < 1: 266 266 if rng: # use the supplied RNG 267 rarr = self.rng.uniform(0,1,len(target))267 rarr = rng.rng.uniform(0,1,len(target)) 268 268 else: # use the default RNG 269 269 rarr = numpy.random.uniform(0,1,len(target)) … … 376 376 if (len(single_line) > 1) and (single_line[1] != '-'): 377 377 neuron = int(single_line[0]) 378 result.write("% g\t%d\n" %(float(single_line[1]), neuron))378 result.write("%s\t%d\n" %(single_line[1], neuron)) 379 379 else: 380 380 f = open(tempfilename.replace('/','_'),'r',100) … … 456 456 raise IndexError, 'Invalid cell address %s' % str(addr) 457 457 return id 458 459 def __getitems__(self,addrs): 460 """Returns the ids of neurons. Input should have format: 461 n = number of synapses; nd = number of dimensions 462 shape(addrs) == (n,nd) 463 """ 464 #if isinstance(addr,int): 465 # addr = (addr,) 466 ids = [] 467 if len(addrs[0]) == self.ndim: 468 for addr in range(len(addrs)): 469 try: 470 ids.append(self.cell[tuple(addrs[addr,:])]) 471 except IndexError: 472 pass 473 else: 474 raise common.InvalidDimensionsError, "Population has %d dimensions. Address was %s" % (self.ndim,str(len(addrs))) 475 return ids 476 477 # for syn_nr in range(len(target_position_x)): 478 # try: 479 # target_id.append(self.post[(target_position_x[syn_nr],target_position_y[syn_nr],target_position_z[syn_nr])]) 480 # except IndexError: 481 # target_id.append(False) 482 458 483 459 484 def __len__(self): … … 726 751 random values. 727 752 """ 728 cells = numpy.reshape(self.cell,self.cell.size) 729 rvals = rand_distr.next(n=self.cell.size) 730 for node, v_init in zip(cells,rvals): 731 pynest.setDict([node],{'u': v_init}) 753 self.rset('v_init',rand_distr) 754 #cells = numpy.reshape(self.cell,self.cell.size) 755 #rvals = rand_distr.next(n=self.cell.size) 756 #for node, v_init in zip(cells,rvals): 757 # pynest.setDict([node],{'u': v_init}) 732 758 733 759 def print_v(self,filename,gather=True, compatible_output=True): … … 781 807 line = line.rstrip() 782 808 single_line = line.split("\t", 2) 783 neuron = int(single_line[0]) - padding 784 result.write("%s\t%d\n" %(single_line[1], neuron)) 809 if (len(single_line) > 1) and (single_line[1] != '-'): 810 neuron = int(single_line[0]) - padding 811 result.write("%s\t%d\n" %(single_line[1], neuron)) 785 812 else: 786 813 f = open(tempfilename.replace('/','_'),'r',1) … … 1166 1193 sigma: sigma of the Gauss 1167 1194 """ 1195 1196 #def get_ids(self,parameters): 1197 #ids = [] 1198 #if len(addrs) == self.ndim: 1199 # 1200 #for addr in range(len(parameters['x'])): 1201 # try: 1202 # ids = numpy.append(ids,post.cell[addr]) 1203 # except IndexError: 1204 # pass 1205 #else: 1206 # raise common.InvalidDimensionsError, "Population has %d dimensions. Address was %s" % (self.ndim,str(addrs)) 1207 #return ids.astype('int') 1208 1168 1209 1169 1210 def rcf_3D(parameters): … … 1180 1221 r = rng.normal(scale=sigma,size=n) 1181 1222 # for z 1182 h = rng.uniform(size=n)*post_dim[2] 1183 1184 target_position_x = numpy.floor(pre_position[1]+r*numpy.cos(phi)) 1185 target_position_y = numpy.floor(pre_position[0]+r*numpy.sin(phi)) 1223 h = rng.uniform(size=n)*post_dim[2] # here post dim because it does not metter where it comes from in pre dim 1224 1225 target_position_x = numpy.floor(pre_position[1]+r*numpy.cos(phi)).astype('int') 1226 target_position_y = numpy.floor(pre_position[0]+r*numpy.sin(phi)).astype('int') 1186 1227 target_position_z = numpy.floor(h).astype('int') 1187 1228 1188 1229 target_id = [] 1230 # __getitems__ version 1231 1232 1189 1233 for syn_nr in range(len(target_position_x)): 1190 1234 try: 1191 target_id.append(self.post [(target_position_x[syn_nr],target_position_y[syn_nr],target_position_z[syn_nr])])1235 target_id.append(self.post.cell[(target_position_x[syn_nr],target_position_y[syn_nr],target_position_z[syn_nr])]) 1192 1236 except IndexError: 1193 target_id.append(False) 1237 pass 1238 #target_id.append(False) 1194 1239 1195 1240 pynest.divConnect(pre_id,target_id,[weight],[delay]) branches/0.3/neuron.py
r34 r48 149 149 return hoc_commands, argstr.strip().strip(',') 150 150 151 def _translate_synapse_type(synapse_type): 151 def _translate_synapse_type(synapse_type,weight=None): 152 """ 153 If synapse_type is given (not None), it is used to determine whether the 154 synapse is excitatory or inhibitory. 155 Otherwise, the synapse type is inferred from the sign of the weight. 156 Much testing needed to check if this behaviour matches nest and pcsim. 157 """ 158 152 159 if synapse_type: 153 160 if synapse_type == 'excitatory': … … 161 168 syn_objref = synapse_type 162 169 else: 163 syn_objref = "esyn" 170 if weight is None or weight >= 0.0: 171 syn_objref = "esyn" 172 else: 173 syn_objref = "isyn" 164 174 return syn_objref 165 175 … … 268 278 class IF_cond_alpha(common.IF_cond_alpha): 269 279 """Leaky integrate and fire model with fixed threshold and alpha-function- 270 shaped post-synaptic c urrent."""280 shaped post-synaptic conductance.""" 271 281 272 282 translations = { … … 484 494 if weight is None: weight = 0.0 485 495 if delay is None: delay = _min_delay 486 syn_objref = _translate_synapse_type(synapse_type )496 syn_objref = _translate_synapse_type(synapse_type,weight) 487 497 nc_start = ncid 488 498 hoc_commands = [] … … 562 572 hoc_execute(hoc_commands, "--- set() ---") 563 573 564 def record(source,filename , compatible_output=True):574 def record(source,filename): 565 575 """Record spikes to a file. source can be an individual cell or a list of 566 576 cells.""" … … 579 589 hoc_execute(hoc_commands, "---record() ---") 580 590 581 def record_v(source,filename , compatible_output=True):591 def record_v(source,filename): 582 592 """ 583 593 Record membrane potential to a file. source can be an individual cell or branches/0.3/oldneuron.py
r34 r48 136 136 return hoc_commands, argstr.strip().strip(',') 137 137 138 def _translate_synapse_type(synapse_type): 138 def _translate_synapse_type(synapse_type,weight=None): 139 """ 140 If synapse_type is given (not None), it is used to determine whether the 141 synapse is excitatory or inhibitory. 142 Otherwise, the synapse type is inferred from the sign of the weight. 143 Much testing needed to check if this behaviour matches nest and pcsim. 144 """ 145 139 146 if synapse_type: 140 147 if synapse_type == 'excitatory': … … 145 152 # More sophisticated treatment needed once we have more sophisticated synapse 146 153 # models, e.g. NMDA... 147 raise common.InvalidParameterValueError, synapse_type, "valid types are 'excitatory' or 'inhibitory'" 154 #raise common.InvalidParameterValueError, synapse_type, "valid types are 'excitatory' or 'inhibitory'" 155 syn_objref = synapse_type 148 156 else: 149 syn_objref = "esyn" 157 if weight is None or weight >= 0.0: 158 syn_objref = "esyn" 159 else: 160 syn_objref = "isyn" 150 161 return syn_objref 151 162 … … 259 270 class IF_cond_alpha(common.IF_cond_alpha): 260 271 """Leaky integrate and fire model with fixed threshold and alpha-function- 261 shaped post-synaptic c urrent."""272 shaped post-synaptic conductance.""" 262 273 263 274 translations = { … … 425 436 if weight is None: weight = 0.0 426 437 if delay is None: delay = _min_delay 427 syn_objref = _translate_synapse_type(synapse_type )438 syn_objref = _translate_synapse_type(synapse_type, weight) 428 439 nc_start = hoc_netcons 429 440 hoc_commands = [] branches/0.3/pcsim.py
r36 r48 85 85 86 86 class SpikesMultiChannelRecorder(object): 87 recordings = []87 #recordings = [] 88 88 89 89 def __init__(self, source, filename = None, source_indices = None, gather = False): … … 98 98 Add celllist list to the list of the cells for which spikes 99 99 are recorded by this spikes multi recorder 100 """ 100 """ 101 if type(sources) != types.ListType: 102 sources = [sources] 101 103 if not src_indices: 102 104 src_indices = range(len(self.recordings), len(self.recordings) + len(sources)) … … 149 151 150 152 class FieldMultiChannelRecorder: 151 recordings = []153 #recordings = [] 152 154 153 155 def __init__(self,sources,filename = None,src_indices = None, gather = False, fieldname = "Vm"): 154 156 self.filename = filename 155 157 self.fieldname = fieldname 156 self.gather = gather 158 self.gather = gather 159 self.recordings = [] 157 160 self.record(sources, src_indices) 158 161 … … 162 165 Add celllist to the list of the cells for which field values 163 166 are recorded by this field multi recorder 164 """ 167 """ 168 if type(sources) != types.ListType: 169 sources = [sources] 165 170 if not src_indices: 166 171 src_indices = range(len(self.recordings), len(self.recordings) + len(sources)) 167 172 global pcsim_globals 168 if type(sources) != types.ListType:169 sources = [sources]170 173 for i,src in zip(src_indices, sources): 171 174 src_id = SimObject.ID(src) … … 174 177 if (src_id.node == pcsim_globals.net.mpi_rank()): 175 178 self.recordings += [ (i, rec, src) ] 176 177 179 178 180 def saveValuesH5(self, filename = None): … … 188 190 h5file.close() 189 191 190 def saveValuesText(self, filename = None ):192 def saveValuesText(self, filename = None, compatible_output=True): 191 193 if filename: 192 194 self.filename = filename … … 195 197 f = file(self.filename, "w") 196 198 all_spikes = [] 197 for i, rec, src in self.recordings: 198 analog_values = [i] + pcsim_globals.net.object(rec).getRecordedValues() 199 for v in analog_values: 200 f.write("%s " % v) 201 f.write("\n") 199 if compatible_output: 200 f.write("# dt = %g\n" % pcsim_globals.dt) 201 f.write("# n = %d\n" % len(pcsim_globals.net.object(self.recordings[0][1]).getRecordedValues())) 202 for i, rec, src in self.recordings: 203 analog_values = pcsim_globals.net.object(rec).getRecordedValues() 204 for v in analog_values: 205 f.write("%g %d\n" % (float(v)*1000.0,i)) # convert from mV to V 206 207 else: 208 for i, rec, src in self.recordings: 209 analog_values = [i] + pcsim_globals.net.object(rec).getRecordedValues() 210 for v in analog_values: 211 f.write("%s " % v) 212 f.write("\n") 202 213 f.close() 203 214 … … 211 222 212 223 translations = { 213 'tau_m' : ('taum' , "parameters['tau_m'] " ) ,214 'cm' : ('Cm' , "parameters['cm'] "),215 'v_rest' : ('Vresting', "parameters['v_rest'] "),216 'v_thresh' : ('Vthresh' , "parameters['v_thresh'] "),217 'v_reset' : ('Vreset' , "parameters['v_reset'] "),218 'tau_refrac': ('Trefract', "parameters['tau_refrac'] "),219 'i_offset' : ('Iinject' , "parameters['i_offset'] "),220 'tau_syn' : ('TauSyn' , "parameters['tau_syn'] "),221 'v_init' : ('Vinit' , "parameters['v_init'] ")224 'tau_m' : ('taum' , "parameters['tau_m']*1e-3" ) , 225 'cm' : ('Cm' , "parameters['cm']*1e-9"), 226 'v_rest' : ('Vresting', "parameters['v_rest']*1e-3"), 227 'v_thresh' : ('Vthresh' , "parameters['v_thresh']*1e-3"), 228 'v_reset' : ('Vreset' , "parameters['v_reset']*1e-3"), 229 'tau_refrac': ('Trefract', "parameters['tau_refrac']*1e-3"), 230 'i_offset' : ('Iinject' , "parameters['i_offset']*1e-9"), 231 'tau_syn' : ('TauSyn' , "parameters['tau_syn']*1e-3"), 232 'v_init' : ('Vinit' , "parameters['v_init']*1e-3") 222 233 } 223 234 pcsim_name = "LIFCurrAlphaNeuron" … … 232 243 Cm = self.parameters['Cm'], 233 244 Vresting = self.parameters['Vresting'], 234 Vthresh = self.parameters['Vthresh'], 245 Vthresh = self.parameters['Vthresh'], 246 Vreset = self.parameters['Vreset'], 235 247 Trefract = self.parameters['Trefract'], 236 248 Iinject = self.parameters['Iinject'], … … 247 259 248 260 translations = { 249 'tau_m' : ('taum' , "parameters['tau_m'] "),250 'cm' : ('Cm' , "parameters['cm'] "),251 'v_rest' : ('Vresting', "parameters['v_rest'] "),252 'v_thresh' : ('Vthresh' , "parameters['v_thresh'] "),253 'v_reset' : ('Vreset' , "parameters['v_reset'] "),254 'tau_refrac': ('Trefract', "parameters['tau_refrac'] "),255 'i_offset' : ('Iinject' , "parameters['i_offset'] "),256 'v_init' : ('Vinit' , "parameters['v_init'] "),257 'tau_syn_E' : ('TauSynExc', "parameters['tau_syn_E'] "),258 'tau_syn_I' : ('TauSynInh', "parameters['tau_syn_I'] "),261 'tau_m' : ('taum' , "parameters['tau_m']*1e-3"), 262 'cm' : ('Cm' , "parameters['cm']*1e-9"), 263 'v_rest' : ('Vresting', "parameters['v_rest']*1e-3"), 264 'v_thresh' : ('Vthresh' , "parameters['v_thresh']*1e-3"), 265 'v_reset' : ('Vreset' , "parameters['v_reset']*1e-3"), 266 'tau_refrac': ('Trefract', "parameters['tau_refrac']*1e-3"), 267 'i_offset' : ('Iinject' , "parameters['i_offset']*1e-9"), # i_offset in nA, Iinject in A 268 'v_init' : ('Vinit' , "parameters['v_init']*1e-3"), 269 'tau_syn_E' : ('TauSynExc', "parameters['tau_syn_E']*1e-3"), 270 'tau_syn_I' : ('TauSynInh', "parameters['tau_syn_I']*1e-3"), 259 271 } 260 272 … … 269 281 self.simObjFactory = LIFCurrExpNeuron(taum = self.parameters['taum'], 270 282 Cm = self.parameters['Cm'], 271 Vresting = self.parameters['Vresting'], 283 Vresting = self.parameters['Vresting'], 284 Vreset = self.parameters['Vreset'], 272 285 Vthresh = self.parameters['Vthresh'], 273 286 Trefract = self.parameters['Trefract'], … … 278 291 TauSynInh = self.parameters['TauSynInh']) 279 292 293 294 #class IF_cond_alpha(common.IF_cond_alpha): 295 # """Leaky integrate and fire model with fixed threshold and alpha-function- 296 # shaped post-synaptic conductance.""" 297 # 298 # translations = { 299 # 'tau_m' : ('taum', "parameters['tau_m']*1e-3" ) , 300 # 'cm' : ('Cm', "parameters['cm']*1e-9"), 301 # 'v_rest' : ('Vresting', "parameters['v_rest']*1e-3"), 302 # 'v_thresh' : ('Vthresh', "parameters['v_thresh']*1e-3"), 303 # 'v_reset' : ('Vreset', "parameters['v_reset']*1e-3"), 304 # 'tau_refrac': ('Trefract', "parameters['tau_refrac']*1e-3"), 305 # 'i_offset' : ('Iinject', "parameters['i_offset']*1e-9"), 306 # 'tau_syn_E' : ('TauSynExc', "parameters['tau_syn_E']*1e-3"), 307 # 'tau_syn_I' : ('TauSynInh', "parameters['tau_syn_I']*1e-3"), 308 # 'e_rev_E' : ('ErevExc', "parameters['e_rev_E']*1e-3"), 309 # 'e_rev_I' : ('ErevInh', "parameters['e_rev_I']*1e-3"), 310 # 'v_init' : ('Vinit', "parameters['v_init']*1e-3"), 311 # } 312 # 313 # pcsim_name = "LIFCondAlphaNeuron" 314 # simObjFactory = None 315 # 316 # 317 # def __init__(self, parameters): 318 # common.IF_cond_alpha.__init__(self, parameters) # checks supplied parameters and adds default # values for not-specified parameters. 319 # self.parameters = self.translate(self.parameters) 320 # self.parameters['Inoise'] = 0.0 321 # self.simObjFactory = LIFCondAlphaNeuron(taum = self.parameters['taum'], 322 # Cm = self.parameters['Cm'], 323 # Vresting = self.parameters['Vresting'], 324 # Vthresh = self.parameters['Vthresh'], 325 # Vreset = self.parameters['Vreset'], 326 # Trefract = self.parameters['Trefract'], 327 #
