Changeset 465
- Timestamp:
- 10/02/08 11:38:28 (2 months ago)
- Files:
-
- trunk/src/__init__.py (modified) (1 diff)
- trunk/src/nest2/__init__.py (modified) (7 diffs)
- trunk/src/neuron/__init__.py (modified) (2 diffs)
- trunk/src/neuron2/__init__.py (modified) (1 diff)
- trunk/src/pcsim/__init__.py (modified) (1 diff)
- trunk/src/pcsim/cells.py (modified) (2 diffs)
- trunk/src/random.py (modified) (1 diff)
- trunk/src/recording.py (modified) (1 diff)
- trunk/test/rngtests.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/__init__.py
r458 r465 2 2 __all__ = ["common", "random", "nest1", "nest2", "neuron", "neuron2", "pcsim", 'brian' ] 3 3 4 # trunk/src/nest2/__init__.py
r462 r465 2 2 """ 3 3 PyNEST v2 implementation of the PyNN API. 4 $Id :__init__.py 188 2008-01-29 10:03:59Z apdavison$4 $Id$ 5 5 """ 6 __version__ = "$Rev:188 $"7 6 8 7 import nest … … 174 173 return data 175 174 175 def _get_header(self, file_name): 176 header = {} 177 if os.path.exists(file_name): 178 f = open(file_name, 'r') 179 for line in f: 180 if line[0] == '#': 181 key, value = line[1:].split("=") 182 header[key.strip()] = value.strip() 183 else: 184 logging.warning("File %s does not exist, so could not get header." % file_name) 185 return header 186 187 def _strip_header(self, input_file_name, output_file_name): 188 if os.path.exists(input_file_name): 189 fin = open(input_file_name, 'r') 190 fout = open(output_file_name, 'a') 191 for line in fin: 192 if line[0] != '#': 193 fout.write(line) 194 fin.close() 195 fout.close() 196 176 197 def write(self, file=None, gather=False, compatible_output=True): 177 198 if self._device is None: … … 182 203 user_file += '.%d' % rank() 183 204 recording.rename_existing(user_file) 205 logging.debug("Recorder is writing '%s' to file '%s' with gather=%s and compatible_output=%s" % (self.variable, 206 user_file, 207 gather, 208 compatible_output)) 184 209 nest_filename = _merge_files(self._device, gather) 185 210 if compatible_output: … … 189 214 # is escaped while reading the file, there is no problem 190 215 recording.write_compatible_output(nest_filename, user_file, 191 self.variable,192 Recorder.formats[self.variable],193 self.population, get_time_step())216 self.variable, 217 Recorder.formats[self.variable], 218 self.population, get_time_step()) 194 219 else: 195 220 if isinstance(user_file, basestring): … … 201 226 else: 202 227 raise Exception('Must provide a filename or an open file') 203 if gather == True and rank() == 0 and num_processes() > 1: 228 np = num_processes() 229 logging.debug("num_processes() = %s" % np) 230 if gather == True and rank() == 0 and np > 1: 204 231 root_file = file or self.filename 232 logging.debug("Gathering files generated by different nodes into %s" % root_file) 233 n_cells = 0 205 234 recording.rename_existing(root_file) 206 for node in xrange(num_processes()): 207 node_file = root_file + '.%d' % node 235 for node in xrange(np): 236 node_file = root_file + '.%d' % node 237 logging.debug("node_file = %s" % node_file) 208 238 if os.path.exists(node_file): 209 os.system('cat %s >> %s' % (node_file, root_file)) 239 # merge headers 240 header = self._get_header(node_file) 241 logging.debug(str(header)) 242 if header.has_key('n'): 243 n_cells += int(header['n']) 244 #os.system('cat %s >> %s' % (node_file, root_file)) 245 self._strip_header(node_file, root_file) 210 246 os.system('rm %s' % node_file) 247 # write header for gathered file 248 f = open("tmp_header", 'w') 249 header['n'] = n_cells 250 for k,v in header.items(): 251 f.write("# %s = %s\n" % (k,v)) 252 f.close() 253 os.system('cat %s >> tmp_header' % root_file) 254 os.system('mv tmp_header %s' % root_file) 211 255 # don't want to remove nest_filename at this point in case the user wants to access the data 212 256 # a second time (e.g. with both getSpikes() and printSpikes()), but we should … … 340 384 except nest.NESTError: 341 385 nest.SetStatus([0], {'data_path':tempdir,}) 342 # set resolution 343 nest.SetStatus([0], {'resolution': timestep}) 386 344 387 345 388 # set kernel RNG seeds … … 363 406 'max_delay': max_delay}) 364 407 408 # set resolution 409 nest.SetStatus([0], {'resolution': timestep}) 365 410 return nest.Rank() 366 411 trunk/src/neuron/__init__.py
r444 r465 8 8 __version__ = "$Rev$" 9 9 10 from neuron import hoc , Vector10 from neuron import hoc 11 11 h = hoc.HocObject() 12 12 from pyNN import __path__ as pyNN_path … … 113 113 for name, val in parameters.items(): 114 114 if hasattr(val, '__len__'): 115 setattr(cell, name, Vector(val).hoc_obj) 115 #setattr(cell, name, Vector(val).hoc_obj) 116 setattr(cell, name, h.Vector(val)) 116 117 else: 117 118 setattr(cell, name, val) trunk/src/neuron2/__init__.py
r463 r465 135 135 all_ids = numpy.array([id for id in range(first_id, last_id+1)], ID) 136 136 # mask_local is used to extract those elements from arrays that apply to the cells on the current node 137 mask_local = all_ids%num_processes()== 0# round-robin distribution of cells between nodes137 mask_local = all_ids%num_processes()==rank() # round-robin distribution of cells between nodes 138 138 for i,(id,is_local) in enumerate(zip(all_ids, mask_local)): 139 139 if is_local: trunk/src/pcsim/__init__.py
r332 r465 921 921 nProj = 0 922 922 923 #class ConnectionDict:924 #925 # def __init__(self, parent):926 # self.parent = parent927 #928 # def __getitem__(self, id):929 # """Returns a connection id.930 # Suppose we have a 2D Population (5x3) projecting to a 3D Population (4x5x7).931 # Total number of possible connections is 5x3x4x5x7 = 2100.932 # Therefore valid calls are:933 # connection[2099] - 2099th possible connection (may not exist)934 # connection[14,139] - connection between 14th pre- and 139th postsynaptic neuron (may not exist)935 # connection[(4,2),(3,4,6)] - connection between presynaptic neuron with address (4,2)936 # and post-synaptic neuron with address (3,4,6) (may not exist).937 # """938 # if isinstance(id, int): # linear mapping939 # preID = id/self.parent.post.size; postID = id%self.parent.post.size940 # return self.__getitem__((preID, postID))941 # elif isinstance(id, tuple): # (pre, post)942 # if len(id) == 2:943 # pre = id[0]944 # post = id[1]945 # if isinstance(pre, int) and isinstance(post, int):946 # pre_coords = self.parent.pre.locate(pre)947 # post_coords = self.parent.post.locate(post)948 # return self.__getitem__((pre_coords, post_coords))949 # elif isinstance(pre, tuple) and isinstance(post, tuple): # should also allow lists950 # if len(pre) == self.parent.pre.ndim and len(post) == self.parent.post.ndim:951 # fmt = "[%d]"*(len(pre)+len(post))952 # address = fmt % (pre+post)953 # else:954 # raise common.InvalidDimensionsError955 # else:956 # raise KeyError957 # else:958 # raise common.InvalidDimensionsError959 # else:960 # raise KeyError #most appropriate?961 #962 # return address963 #964 965 923 def __init__(self, presynaptic_population, postsynaptic_population, method='allToAll', method_parameters=None, source=None, target=None, synapse_dynamics=None, label=None, rng=None): 966 924 """ trunk/src/pcsim/cells.py
r281 r465 89 89 90 90 91 class IF_cond_exp(common.IF_cond_ alpha):91 class IF_cond_exp(common.IF_cond_exp): 92 92 """Leaky integrate and fire model with fixed threshold and 93 93 exponentially-decaying post-synaptic conductance.""" … … 112 112 113 113 def __init__(self, parameters): 114 common.IF_cond_ alpha.__init__(self, parameters)114 common.IF_cond_exp.__init__(self, parameters) 115 115 self.parameters['Inoise'] = 0.0 116 116 self.simObjFactory = LIFCondExpNeuron(**self.parameters) trunk/src/random.py
r421 r465 99 99 # This assumption is not true for NEST 100 100 rarr = rarr[numpy.arange(self.rank, len(rarr), self.num_processes)] 101 return rarr 101 if len(rarr) == 1: 102 return rarr[0] 103 else: 104 return rarr 102 105 103 106 class GSLRNG(AbstractRNG): trunk/src/recording.py
r463 r465 186 186 user_file.write(data_array, metadata) 187 187 else: 188 logging.warning("%s is empty" % sim_filename)188 logging.warning("%s is empty" % data_source) 189 189 190 190 def readArray(filename, sepchar=None, skipchar='#'): trunk/test/rngtests.py
r11 r465 29 29 30 30 def testNonPositiveN(self): 31 """Calling next(m) where m < =0 should raise a ValueError."""31 """Calling next(m) where m < 0 should raise a ValueError.""" 32 32 for rng in self.rnglist: 33 self.assertRaises(ValueError,rng.next,0)34 33 self.assertRaises(ValueError,rng.next,-1) 34 35 def testNZero(self): 36 """Calling next(0) should return an empty array.""" 37 for rng in self.rnglist: 38 self.assertEqual(len(rng.next(0)), 0) 35 39 36 40 # ==============================================================================

