How to use the netpyne.sim.pc.barrier 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 / subconn.py View on Github external
# updade sec and loc
                        conn['sec'] = newSec
                        conn['loc'] = newLoc

                        # find grouped conns 
                        if subConnParam.get('groupSynMechs', None) and conn['synMech'] in subConnParam['groupSynMechs']:
                            connGroup = connsGroup[i]  # get grouped conn from previously stored dict 
                            connGroup['synMech'] = connGroup['synMech'].split('__grouped__')[1]  # remove '__grouped__' label

                            connGroup['sec'] = newSec
                            connGroup['loc'] = newLoc
                            if newWeightNorm: connGroup['weight'] = connGroup['weight'] / oldWeightNorm * newWeightNorm

                                
        sim.pc.barrier()
github Neurosim-lab / netpyne / netpyne / network.py View on Github external
for cell in cellsUpdate:
                    # Add synMechs, stim and conn NEURON objects
                    cell.addStimsNEURONObj()
                    #cell.addSynMechsNEURONObj()
                    cell.addConnsNEURONObj()

        nodeSynapses = sum([len(cell.conns) for cell in sim.net.cells]) 
        if sim.cfg.createPyStruct:
            nodeConnections = sum([len(set([conn['preGid'] for conn in cell.conns])) for cell in sim.net.cells])   
        else:
            nodeConnections = nodeSynapses

        print(('  Number of connections on node %i: %i ' % (sim.rank, nodeConnections)))
        if nodeSynapses != nodeConnections:
            print(('  Number of synaptic contacts on node %i: %i ' % (sim.rank, nodeSynapses)))
        sim.pc.barrier()
        sim.timing('stop', 'connectTime')
        if sim.rank == 0 and sim.cfg.timing: print(('  Done; cell connection time = %0.2f s.' % sim.timingData['connectTime']))

        return [cell.conns for cell in self.cells]
github Neurosim-lab / netpyne / netpyne / sim / load.py View on Github external
sim.net.cells.append(cell)
                print(('  Created %d cells' % (len(sim.net.cells))))
                print(('  Created %d connections' % (sum([len(c.conns) for c in sim.net.cells]))))
                print(('  Created %d stims' % (sum([len(c.stims) for c in sim.net.cells]))))

                # only create NEURON objs, if there is Python struc (fix so minimal Python struct is created)
                if sim.cfg.createNEURONObj:
                    if sim.cfg.verbose: print("  Adding NEURON objects...")
                    # create NEURON sections, mechs, syns, etc; and associate gid
                    for cell in sim.net.cells:
                        prop = {'secs': cell.secs}
                        cell.createNEURONObj(prop)  # use same syntax as when creating based on high-level specs
                        cell.associateGid()  # can only associate once the hSection obj has been created
                    # create all NEURON Netcons, NetStims, etc
                    sim.pc.barrier()
                    for cell in sim.net.cells:
                        try:
                            cell.addStimsNEURONObj()  # add stims first so can then create conns between netstims
                            cell.addConnsNEURONObj()
                        except:
                            if sim.cfg.verbose: ' Unable to load instantiate cell conns or stims'

                    print(('  Added NEURON objects to %d cells' % (len(sim.net.cells))))

            if sim.rank == 0 and sim.cfg.timing:
                sim.timing('stop', 'loadNetTime')
                print(('  Done; re-instantiate net time = %0.2f s' % sim.timingData['loadNetTime']))
    else:
        print(('  netCells and/or netPops not found in file %s'%(filename)))
github Neurosim-lab / netpyne / netpyne / network / netrxd.py View on Github external
if 'regions' in rxdParams:
            self._addRegions(rxdParams['regions'])
        if 'extracellular' in rxdParams:
            self._addExtracellular(rxdParams['extracellular'])
        if 'species' in rxdParams:
            self._addSpecies(rxdParams['species'])
        if 'states' in rxdParams:
            self._addStates(rxdParams['states'])
        if 'reactions' in rxdParams:
            self._addReactions(rxdParams['reactions'])
        if 'multicompartmentReactions' in rxdParams:
            self._addReactions(rxdParams['multicompartmentReactions'], multicompartment=True)
        if 'rates' in rxdParams:
            self._addRates(rxdParams['rates'])

    sim.pc.barrier()
    sim.timing('stop', 'rxdTime')
    if sim.rank == 0 and sim.cfg.timing: print(('  Done; RxD setup time = %0.2f s.' % sim.timingData['rxdTime']))

    return sim.net.rxd
github Neurosim-lab / netpyne / netpyne / network / stim.py View on Github external
if 'originalFormat' in source and source['originalFormat'] == 'NeuroML2':
                        if 'weight' in target:
                            params['weight'] = target['weight']

                    for sourceParam in source: # copy source params
                        params[sourceParam] = strParams[sourceParam+'List'][postCellGid] if sourceParam+'List' in strParams else source.get(sourceParam)

                    if source['type'] == 'NetStim':
                        self._addCellStim(params, postCell)  # call method to add connections (sort out synMechs first)
                    else:
                        postCell.addStim(params)  # call cell method to add connection

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

    return [cell.stims for cell in self.cells]
github Neurosim-lab / netpyne / netpyne / sim / utils.py View on Github external
def clearAll ():
    from .. import sim

    # clean up
    sim.pc.barrier()
    sim.pc.gid_clear()                    # clear previous gid settings

    # clean cells and simData in all nodes
    sim.clearObj([cell.__dict__ if hasattr(cell, '__dict__') else cell for cell in sim.net.cells])
    if 'stims' in list(sim.simData.keys()):
        sim.clearObj([stim for stim in sim.simData['stims']])

    for key in list(sim.simData.keys()): del sim.simData[key]
    for c in sim.net.cells: del c
    for p in sim.net.pops: del p
    del sim.net.params


    # clean cells and simData gathered in master node
    if sim.rank == 0:
        if hasattr(sim.net, 'allCells'):
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 / gather.py View on Github external
def _gatherCells ():
    from .. import sim

    ## Pack data from all hosts
    if sim.rank==0:
        print('\nUpdating sim.net.allCells...')

    if sim.nhosts > 1:  # only gather if >1 nodes
        nodeData = {'netCells': [c.__getstate__() for c in sim.net.cells]}
        data = [None]*sim.nhosts
        data[0] = {}
        for k,v in nodeData.items():
            data[0][k] = v
        gather = sim.pc.py_alltoall(data)
        sim.pc.barrier()
        if sim.rank == 0:
            allCells = []

            # fill in allSimData taking into account if data is dict of h.Vector (code needs improvement to be more generic)
            for node in gather:  # concatenate data from each node
                allCells.extend(node['netCells'])  # extend allCells list
            sim.net.allCells =  sorted(allCells, key=lambda k: k['gid'])

        # clean to avoid mem leaks
        for node in gather:
            if node:
                node.clear()
                del node
        for item in data:
            if item:
                item.clear()
github Neurosim-lab / netpyne / netpyne / sim / gather.py View on Github external
def _gatherAllCellTags ():
    from .. import sim

    data = [{cell.gid: cell.tags for cell in sim.net.cells}]*sim.nhosts  # send cells data to other nodes
    gather = sim.pc.py_alltoall(data)  # collect cells data from other nodes (required to generate connections)
    sim.pc.barrier()
    allCellTags = {}
    for dataNode in gather:
        allCellTags.update(dataNode)

    # clean to avoid mem leaks
    for node in gather:
        if node:
            node.clear()
            del node
    for item in data:
        if item:
            item.clear()
            del item

    return allCellTags
github Neurosim-lab / netpyne / netpyne / sim / save.py View on Github external
sim.pc.barrier()    
    
    gatherLFP=True
    simDataVecs = ['spkt','spkid','stims']+list(sim.cfg.recordTraces.keys())
    singleNodeVecs = ['t']
        
    netPopsCellGids = {popLabel: list(pop.cellGids) for popLabel,pop in sim.net.pops.items()}

    # gather only sim data
    nodeData = {'simData': sim.simData}
    data = [None]*sim.nhosts
    data[0] = {}
    for k,v in nodeData.items():
        data[0][k] = v
    gather = sim.pc.py_alltoall(data)
    sim.pc.barrier()
    if sim.rank == 0: # simData
        print('  Gathering only sim data in master...')
        sim.allSimData = Dict()
        for k in list(gather[0]['simData'].keys()):  # initialize all keys of allSimData dict
            if gatherLFP and k == 'LFP':
                sim.allSimData[k] = np.zeros((gather[0]['simData']['LFP'].shape))
            else:
                sim.allSimData[k] = {}
        for key in singleNodeVecs: # store single node vectors (eg. 't')
            sim.allSimData[key] = list(nodeData['simData'][key])
        # fill in allSimData taking into account if data is dict of h.Vector (code needs improvement to be more generic)
        for node in gather:  # concatenate data from each node
            for key,val in node['simData'].items():  # update simData dics of dics of h.Vector
                if key in simDataVecs:          # simData dicts that contain Vectors
                    if isinstance(val, dict):
                        for cell,val2 in val.items():