Changeset 465

Show
Ignore:
Timestamp:
10/02/08 11:38:28 (2 months ago)
Author:
apdavison
Message:

Various minor bug-fixes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/__init__.py

    r458 r465  
    22__all__ = ["common", "random", "nest1", "nest2", "neuron", "neuron2", "pcsim", 'brian' ] 
    33 
     4# 
  • trunk/src/nest2/__init__.py

    r462 r465  
    22""" 
    33PyNEST v2 implementation of the PyNN API. 
    4 $Id:__init__.py 188 2008-01-29 10:03:59Z apdavison
     4$Id
    55""" 
    6 __version__ = "$Rev:188 $" 
    76 
    87import nest 
     
    174173        return data 
    175174     
     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     
    176197    def write(self, file=None, gather=False, compatible_output=True): 
    177198        if self._device is None: 
     
    182203                user_file += '.%d' % rank() 
    183204            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)) 
    184209        nest_filename = _merge_files(self._device, gather) 
    185210        if compatible_output: 
     
    189214            # is escaped while reading the file, there is no problem 
    190215           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()) 
    194219        else: 
    195220            if isinstance(user_file, basestring): 
     
    201226            else: 
    202227                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: 
    204231            root_file = file or self.filename 
     232            logging.debug("Gathering files generated by different nodes into %s" % root_file) 
     233            n_cells = 0 
    205234            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) 
    208238                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) 
    210246                    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) 
    211255        # don't want to remove nest_filename at this point in case the user wants to access the data 
    212256        # a second time (e.g. with both getSpikes() and printSpikes()), but we should 
     
    340384    except nest.NESTError:     
    341385        nest.SetStatus([0], {'data_path':tempdir,}) 
    342     # set resolution 
    343     nest.SetStatus([0], {'resolution': timestep}) 
     386 
    344387 
    345388    # set kernel RNG seeds 
     
    363406                                                'max_delay': max_delay}) 
    364407 
     408    # set resolution 
     409    nest.SetStatus([0], {'resolution': timestep}) 
    365410    return nest.Rank() 
    366411 
  • trunk/src/neuron/__init__.py

    r444 r465  
    88__version__ = "$Rev$" 
    99 
    10 from neuron import hoc, Vector 
     10from neuron import hoc 
    1111h = hoc.HocObject() 
    1212from pyNN import __path__ as pyNN_path 
     
    113113        for name, val in parameters.items(): 
    114114            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)) 
    116117            else: 
    117118                setattr(cell, name, val) 
  • trunk/src/neuron2/__init__.py

    r463 r465  
    135135    all_ids = numpy.array([id for id in range(first_id, last_id+1)], ID) 
    136136    # 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 nodes 
     137    mask_local = all_ids%num_processes()==rank() # round-robin distribution of cells between nodes 
    138138    for i,(id,is_local) in enumerate(zip(all_ids, mask_local)): 
    139139        if is_local: 
  • trunk/src/pcsim/__init__.py

    r332 r465  
    921921    nProj = 0 
    922922     
    923     #class ConnectionDict: 
    924     #         
    925     #    def __init__(self, parent): 
    926     #        self.parent = parent 
    927     # 
    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 mapping 
    939     #            preID = id/self.parent.post.size; postID = id%self.parent.post.size 
    940     #            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 lists 
    950     #                    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.InvalidDimensionsError 
    955     #                else: 
    956     #                    raise KeyError 
    957     #            else: 
    958     #                raise common.InvalidDimensionsError 
    959     #        else: 
    960     #            raise KeyError #most appropriate? 
    961     #         
    962     #        return address 
    963     # 
    964      
    965923    def __init__(self, presynaptic_population, postsynaptic_population, method='allToAll', method_parameters=None, source=None, target=None, synapse_dynamics=None, label=None, rng=None): 
    966924        """ 
  • trunk/src/pcsim/cells.py

    r281 r465  
    8989 
    9090 
    91 class IF_cond_exp(common.IF_cond_alpha): 
     91class IF_cond_exp(common.IF_cond_exp): 
    9292    """Leaky integrate and fire model with fixed threshold and  
    9393    exponentially-decaying post-synaptic conductance.""" 
     
    112112         
    113113    def __init__(self, parameters): 
    114         common.IF_cond_alpha.__init__(self, parameters) 
     114        common.IF_cond_exp.__init__(self, parameters) 
    115115        self.parameters['Inoise'] = 0.0 
    116116        self.simObjFactory = LIFCondExpNeuron(**self.parameters) 
  • trunk/src/random.py

    r421 r465  
    9999            # This assumption is not true for NEST 
    100100            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 
    102105 
    103106class GSLRNG(AbstractRNG): 
  • trunk/src/recording.py

    r463 r465  
    186186        user_file.write(data_array, metadata) 
    187187    else: 
    188         logging.warning("%s is empty" % sim_filename) 
     188        logging.warning("%s is empty" % data_source) 
    189189 
    190190def readArray(filename, sepchar=None, skipchar='#'): 
  • trunk/test/rngtests.py

    r11 r465  
    2929             
    3030    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.""" 
    3232        for rng in self.rnglist: 
    33             self.assertRaises(ValueError,rng.next,0) 
    3433            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) 
    3539 
    3640# ==============================================================================