diff --git a/netpyne/analysis/spikes.py b/netpyne/analysis/spikes.py index 5235bc00b..2d42e241a 100644 --- a/netpyne/analysis/spikes.py +++ b/netpyne/analysis/spikes.py @@ -70,7 +70,7 @@ def prepareSpikeData( orderBy = 'gid' elif orderBy == 'pop': df['popInd'] = df['pop'].astype('category') - df['popInd'].cat.set_categories(sim.net.pops.keys(), inplace=True) + df['popInd'] = df['popInd'].cat.set_categories(sim.net.pops.keys()) orderBy = 'popInd' elif isinstance(orderBy, basestring) and not isinstance(cells[0]['tags'][orderBy], Number): orderBy = 'gid' @@ -78,7 +78,7 @@ def prepareSpikeData( if isinstance(orderBy, list): if 'pop' in orderBy: df['popInd'] = df['pop'].astype('category') - df['popInd'].cat.set_categories(sim.net.pops.keys(), inplace=True) + df['popInd'] = df['popInd'].cat.set_categories(sim.net.pops.keys()) orderBy[orderBy.index('pop')] = 'popInd' keep = keep + list(set(orderBy) - set(keep)) elif orderBy not in keep: diff --git a/netpyne/network/conn.py b/netpyne/network/conn.py index 4c78d2f3f..6e006765e 100644 --- a/netpyne/network/conn.py +++ b/netpyne/network/conn.py @@ -11,7 +11,7 @@ import numpy as np from array import array as arrayFast from numbers import Number - +from tqdm import tqdm # ----------------------------------------------------------------------------- # Connect Cells @@ -406,6 +406,9 @@ def fullConn(self, preCellsTags, postCellsTags, connParam): if sim.cfg.verbose: print('Generating set of all-to-all connections (rule: %s) ...' % (connParam['label'])) + if sim.rank == 0 and not sim.cfg.verbose: pbar = tqdm(total=len(postCellsTags.items()), ascii=True, + desc=' ' + connParam['label'], position=0, leave=True, + bar_format= '{l_bar}{bar}| Creating synaptic connections for {n_fmt}/{total_fmt} postsynaptic cells on node %i (all-to-all connectivity)' % sim.rank) # get list of params that have a lambda function paramsStrFunc = [param for param in [p + 'Func' for p in self.connStringFuncParams] if param in connParam] @@ -424,9 +427,11 @@ def fullConn(self, preCellsTags, postCellsTags, connParam): } for postCellGid in postCellsTags: # for each postsyn cell + if sim.rank == 0 and not sim.cfg.verbose: pbar.update(1) if postCellGid in self.gid2lid: # check if postsyn is in this node's list of gids for preCellGid, preCellTags in preCellsTags.items(): # for each presyn cell self._addCellConn(connParam, preCellGid, postCellGid, preCellsTags) # add connection + if sim.rank == 0 and not sim.cfg.verbose: pbar.close() # ----------------------------------------------------------------------------- @@ -505,6 +510,9 @@ def probConn(self, preCellsTags, postCellsTags, connParam): if sim.cfg.verbose: print('Generating set of probabilistic connections (rule: %s) ...' % (connParam['label'])) + if sim.rank == 0 and not sim.cfg.verbose: pbar = tqdm(total=len(postCellsTags.items()), ascii=True, + desc=' ' + connParam['label'], position=0, leave=True, + bar_format= '{l_bar}{bar}| Creating synaptic connections for {n_fmt}/{total_fmt} postsynaptic cells on node %i (probabilistic connectivity)' % sim.rank) allRands = self.generateRandsPrePost(preCellsTags, postCellsTags) @@ -538,13 +546,14 @@ def probConn(self, preCellsTags, postCellsTags, connParam): probMatrix, allRands, connParam['disynapticBias'], prePreGids, postPreGids ) for preCellGid, postCellGid in connGids: + if sim.rank == 0 and not sim.cfg.verbose: pbar.update(1) for paramStrFunc in paramsStrFunc: # call lambda functions to get weight func args connParam[paramStrFunc + 'Args'] = { k: v if isinstance(v, Number) else v(preCellsTags[preCellGid], postCellsTags[postCellGid]) for k, v in connParam[paramStrFunc + 'Vars'].items() } self._addCellConn(connParam, preCellGid, postCellGid, preCellsTags) # add connection - + if sim.rank == 0 and not sim.cfg.verbose: pbar.close() # standard probabilistic conenctions else: # print('rank %d'%(sim.rank)) @@ -552,6 +561,7 @@ def probConn(self, preCellsTags, postCellsTags, connParam): # calculate the conn preGids of the each pre and post cell # for postCellGid,postCellTags in sorted(postCellsTags.items()): # for each postsyn cell for postCellGid, postCellTags in postCellsTags.items(): # for each postsyn cell # for each postsyn cell + if sim.rank==0: pbar.update(1) if postCellGid in self.gid2lid: # check if postsyn is in this node for preCellGid, preCellTags in preCellsTags.items(): # for each presyn cell probability = ( @@ -568,7 +578,7 @@ def probConn(self, preCellsTags, postCellsTags, connParam): ) # connParam[paramStrFunc+'Args'] = {k:v if isinstance(v, Number) else v(preCellTags,postCellTags) for k,v in connParam[paramStrFunc+'Vars'].items()} self._addCellConn(connParam, preCellGid, postCellGid, preCellsTags) # add connection - + if sim.rank == 0 and not sim.cfg.verbose: pbar.close() # ----------------------------------------------------------------------------- # Generate random unique integers @@ -641,6 +651,9 @@ def convConn(self, preCellsTags, postCellsTags, connParam): if sim.cfg.verbose: print('Generating set of convergent connections (rule: %s) ...' % (connParam['label'])) + if sim.rank == 0 and not sim.cfg.verbose: pbar = tqdm(total=len(postCellsTags.items()), ascii=True, + desc=' ' + connParam['label'], position=0, leave=True, + bar_format= '{l_bar}{bar}| Creating synaptic connections for {n_fmt}/{total_fmt} postsynaptic cells on node %i (convergent connectivity)' % sim.rank) # get list of params that have a lambda function paramsStrFunc = [param for param in [p + 'Func' for p in self.connStringFuncParams] if param in connParam] @@ -660,6 +673,7 @@ def convConn(self, preCellsTags, postCellsTags, connParam): hashPreCells = sim.hashList(preCellsTagsKeys) for postCellGid, postCellTags in postCellsTags.items(): # for each postsyn cell + if sim.rank == 0 and not sim.cfg.verbose: pbar.update(1) if postCellGid in self.gid2lid: # check if postsyn is in this node convergence = ( connParam['convergenceFunc'][postCellGid] @@ -692,6 +706,7 @@ def convConn(self, preCellsTags, postCellsTags, connParam): if preCellGid != postCellGid: # if not self-connection self._addCellConn(connParam, preCellGid, postCellGid, preCellsTags) # add connection + if sim.rank == 0 and not sim.cfg.verbose: pbar.close() # ----------------------------------------------------------------------------- @@ -724,6 +739,9 @@ def divConn(self, preCellsTags, postCellsTags, connParam): if sim.cfg.verbose: print('Generating set of divergent connections (rule: %s) ...' % (connParam['label'])) + if sim.rank == 0 and not sim.cfg.verbose: pbar = tqdm(total=len(preCellsTags.items()), ascii=True, + desc=' ' + connParam['label'], position=0, leave=True, + bar_format= '{l_bar}{bar}| Creating synaptic connections for {n_fmt}/{total_fmt} presynaptic cells on node %i (divergent connectivity)' % sim.rank) # get list of params that have a lambda function paramsStrFunc = [param for param in [p + 'Func' for p in self.connStringFuncParams] if param in connParam] @@ -743,6 +761,7 @@ def divConn(self, preCellsTags, postCellsTags, connParam): hashPostCells = sim.hashList(postCellsTagsKeys) for preCellGid, preCellTags in preCellsTags.items(): # for each presyn cell + if sim.rank == 0 and not sim.cfg.verbose: pbar.update(1) divergence = ( connParam['divergenceFunc'][preCellGid] if 'divergenceFunc' in connParam else connParam['divergence'] ) # num of presyn conns / postsyn cell @@ -769,6 +788,7 @@ def divConn(self, preCellsTags, postCellsTags, connParam): if preCellGid != postCellGid: # if not self-connection self._addCellConn(connParam, preCellGid, postCellGid, preCellsTags) # add connection + if sim.rank == 0 and not sim.cfg.verbose: pbar.close() # ----------------------------------------------------------------------------- @@ -801,6 +821,9 @@ def fromListConn(self, preCellsTags, postCellsTags, connParam): if sim.cfg.verbose: print('Generating set of connections from list (rule: %s) ...' % (connParam['label'])) + if sim.rank == 0 and not sim.cfg.verbose: pbar = tqdm(total=len(connParam['connList']), ascii=True, + desc=' ' + connParam['label'], position=0, leave=True, + bar_format= '{l_bar}{bar}| Creating synaptic connections for {n_fmt}/{total_fmt} pairs of neurons on node %i (from list)' % sim.rank) orderedPreGids = sorted(preCellsTags) orderedPostGids = sorted(postCellsTags) @@ -841,6 +864,7 @@ def fromListConn(self, preCellsTags, postCellsTags, connParam): connParam['preSecFromList'] = list(connParam['preSec']) for iconn, (relativePreId, relativePostId) in enumerate(connParam['connList']): # for each postsyn cell + if sim.rank == 0 and not sim.cfg.verbose: pbar.update(1) preCellGid = orderedPreGids[relativePreId] postCellGid = orderedPostGids[relativePostId] if postCellGid in self.gid2lid: # check if postsyn is in this node's list of gids @@ -861,7 +885,8 @@ def fromListConn(self, preCellsTags, postCellsTags, connParam): # TODO: consider cfg.allowSelfConns? if preCellGid != postCellGid: # if not self-connection self._addCellConn(connParam, preCellGid, postCellGid, preCellsTags) # add connection - + if sim.rank == 0 and not sim.cfg.verbose: pbar.close() + # ----------------------------------------------------------------------------- # Set parameters and create connection diff --git a/netpyne/network/network.py b/netpyne/network/network.py index 9a87e579b..dc2b0a434 100644 --- a/netpyne/network/network.py +++ b/netpyne/network/network.py @@ -5,7 +5,7 @@ from ..specs import ODict from neuron import h # import NEURON - +from tqdm import tqdm class Network(object): """ @@ -89,18 +89,22 @@ def createCells(self): sim.pc.barrier() sim.timing('start', 'createTime') - if sim.rank == 0: + if sim.rank == 0 and sim.cfg.verbose: print(("\nCreating network of %i cell populations on %i hosts..." % (len(self.pops), sim.nhosts))) self._setDiversityRanges() # update fractions for rules - + if sim.rank == 0 and not sim.cfg.verbose: pbar = tqdm(total=len(self.pops.values()), ascii=True, + desc="\nCreating network of %i cell populations on %i hosts..." % (len(self.pops), sim.nhosts), + position=-1, leave=True, + bar_format='{l_bar}{bar}|') #{n_fmt}/{total_fmt} populations created on node %i' % sim.rank) for ipop in list(self.pops.values()): # For each pop instantiate the network cells (objects of class 'Cell') + if sim.rank == 0 and not sim.cfg.verbose: pbar.update(1) 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 sim.rank == 0 and not sim.cfg.verbose: pbar.close() if self.params.defineCellShapes: self.defineCellShapes()