How to use the netpyne.sim.timing function in netpyne

To help you get started, we’ve selected a few netpyne examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Neurosim-lab / netpyne / netpyne / network / modify.py View on Github external
def modifyCells (self, params, updateMasterAllCells=False):
    from .. import sim

    # Instantiate network connections based on the connectivity rules defined in params
    sim.timing('start', 'modifyCellsTime')
    if sim.rank==0: 
        print('Modfying cell parameters...')

    for cell in self.cells:
        cell.modify(params)

    if updateMasterAllCells:
        sim._gatherCells()  # update allCells

    sim.timing('stop', 'modifyCellsTime')
    if sim.rank == 0 and sim.cfg.timing: print('  Done; cells modification time = %0.2f s.' % sim.timingData['modifyCellsTime'])
github Neurosim-lab / netpyne / netpyne / network.py View on Github external
def subcellularConn(self, allCellTags, allPopTags):
        from . import sim

        sim.timing('start', 'subConnectTime')
        print('  Distributing synapses based on subcellular connectivity rules...')

        for subConnParamTemp in list(self.params.subConnParams.values()):  # for each conn rule or parameter set
            subConnParam = subConnParamTemp.copy()

            # find list of pre and post cell
            preCellsTags, postCellsTags = self._findPrePostCellsCondition(allCellTags, subConnParam['preConds'], subConnParam['postConds'])

            if preCellsTags and postCellsTags:
                # iterate over postsyn cells to redistribute synapses
                for postCellGid in postCellsTags:  # for each postsyn cell
                    if postCellGid in self.lid2gid:
                        postCell = self.cells[self.gid2lid[postCellGid]] 
                        allConns = [conn for conn in postCell.conns if conn['preGid'] in preCellsTags]
                        if 'NetStim' in [x['cellModel'] for x in list(preCellsTags.values())]: # temporary fix to include netstim conns 
                            allConns.extend([conn for conn in postCell.conns if conn['preGid'] == 'NetStim'])
github Neurosim-lab / netpyne / netpyne / sim / load.py View on Github external
# traces = sim.cfg.recordTraces
        # for ref in traces.keys():
        #     for cellid in sim.allSimData[ref].keys():
        #         dat_file_name = '%s_%s.dat'%(ref,cellid)
        #         dat_file = open(dat_file_name, 'w')
        #         trace = sim.allSimData[ref][cellid]
        #         print("Saving %i points of data on: %s:%s to %s"%(len(trace),ref,cellid,dat_file_name))
        #         for i in range(len(trace)):
        #             dat_file.write('%s\t%s\n'%((i*sim.cfg.dt/1000),trace[i]/1000))

    else:
        print(('Format not recognized for file %s'%(filename)))
        return

    if hasattr(sim, 'rank') and sim.rank == 0 and hasattr(sim, 'cfg') and sim.cfg.timing:
        sim.timing('stop', 'loadFileTime')
        print(('  Done; file loading time = %0.2f s' % sim.timingData['loadFileTime']))

    
    return data
github Neurosim-lab / netpyne / netpyne / network / network.py View on Github external
sim.pc.barrier()
        sim.timing('start', 'createTime')
        if sim.rank==0: 
            print(("\nCreating network of %i cell populations on %i hosts..." % (len(self.pops), sim.nhosts))) 
        
        for ipop in list(self.pops.values()): # For each pop instantiate the network cells (objects of class 'Cell')
            newCells = ipop.createCells() # create cells for this pop using Pop method
            self.cells.extend(newCells)  # add to list of cells
            sim.pc.barrier()
            if sim.rank==0 and sim.cfg.verbose: print(('Instantiated %d cells of population %s'%(len(newCells), ipop.tags['pop'])))  

        if self.params.defineCellShapes: self.defineCellShapes()
  
        print(('  Number of cells on node %i: %i ' % (sim.rank,len(self.cells)))) 
        sim.pc.barrier()
        sim.timing('stop', 'createTime')
        if sim.rank == 0 and sim.cfg.timing: print(('  Done; cell creation time = %0.2f s.' % sim.timingData['createTime']))

        return self.cells
github Neurosim-lab / netpyne / netpyne / network.py View on Github external
def addStims (self):
        from . import sim

        sim.timing('start', 'stimsTime')
        if self.params.stimSourceParams and self.params.stimTargetParams:
            if sim.rank==0: 
                print('Adding stims...')
                
            if sim.nhosts > 1: # Gather tags from all cells 
                allCellTags = sim._gatherAllCellTags()  
            else:
                allCellTags = {cell.gid: cell.tags for cell in self.cells}
            # allPopTags = {i: pop.tags for i,pop in enumerate(self.pops)}  # gather tags from pops so can connect NetStim pops

            sources = self.params.stimSourceParams

            for targetLabel, target in self.params.stimTargetParams.items():  # for each target parameter set
                if 'sec' not in target: target['sec'] = None  # if section not specified, make None (will be assigned to first section in cell)
                if 'loc' not in target: target['loc'] = None  # if location not specified, make None 
github Neurosim-lab / netpyne / netpyne / network.py View on Github external
def modifyCells (self, params, updateMasterAllCells=False):
        from . import sim

        # Instantiate network connections based on the connectivity rules defined in params
        sim.timing('start', 'modifyCellsTime')
        if sim.rank==0: 
            print('Modfying cell parameters...')

        for cell in self.cells:
            cell.modify(params)

        if updateMasterAllCells:
            sim._gatherCells()  # update allCells

        sim.timing('stop', 'modifyCellsTime')
        if sim.rank == 0 and sim.cfg.timing: print(('  Done; cells modification time = %0.2f s.' % sim.timingData['modifyCellsTime']))
github Neurosim-lab / netpyne / netpyne / network / network.py View on Github external
def createCells (self):
        from .. import sim

        sim.pc.barrier()
        sim.timing('start', 'createTime')
        if sim.rank==0: 
            print(("\nCreating network of %i cell populations on %i hosts..." % (len(self.pops), sim.nhosts))) 
        
        for ipop in list(self.pops.values()): # For each pop instantiate the network cells (objects of class 'Cell')
            newCells = ipop.createCells() # create cells for this pop using Pop method
            self.cells.extend(newCells)  # add to list of cells
            sim.pc.barrier()
            if sim.rank==0 and sim.cfg.verbose: print(('Instantiated %d cells of population %s'%(len(newCells), ipop.tags['pop'])))  

        if self.params.defineCellShapes: self.defineCellShapes()
  
        print(('  Number of cells on node %i: %i ' % (sim.rank,len(self.cells)))) 
        sim.pc.barrier()
        sim.timing('stop', 'createTime')
        if sim.rank == 0 and sim.cfg.timing: print(('  Done; cell creation time = %0.2f s.' % sim.timingData['createTime']))
github Neurosim-lab / netpyne / netpyne / sim / run.py View on Github external
def runSimWithIntervalFunc (interval, func):
    from .. import sim
    sim.pc.barrier()
    sim.timing('start', 'runTime')
    preRun()
    h.finitialize(float(sim.cfg.hParams['v_init']))

    if sim.rank == 0: print('\nRunning with interval func  ...')

    while round(h.t) < sim.cfg.duration:
        sim.pc.psolve(min(sim.cfg.duration, h.t+interval))
        func(h.t) # function to be called at intervals
    
    sim.pc.barrier() # Wait for all hosts to get to this point
    sim.timing('stop', 'runTime')
    if sim.rank==0:
        print(('  Done; run time = %0.2f s; real-time ratio: %0.2f.' %
            (sim.timingData['runTime'], sim.cfg.duration/1000/sim.timingData['runTime'])))
github Neurosim-lab / netpyne / netpyne / sim / save.py View on Github external
def distributedSaveHDF5():
    from .. import sim
    import h5py

    if sim.rank == 0: sim.timing('start', 'saveTimeHDF5')

    sim.compactConnFormat()
    conns = [[cell.gid]+conn for cell in sim.net.cells for conn in cell.conns]
    conns = sim.copyRemoveItemObj(conns, keystart='h', newval=[]) 
    connFormat = ['postGid']+sim.cfg.compactConnFormat
    with h5py.File(sim.cfg.filename+'.h5', 'w') as hf:
        hf.create_dataset('conns', data = conns)
        hf.create_dataset('connsFormat', data = connFormat)

    if sim.rank == 0: sim.timing('stop', 'saveTimeHDF5')