Skip to content

Commit

Permalink
Merge pull request #813 from RomanB22/development
Browse files Browse the repository at this point in the history
Pandas deprecated parameter fix + Loading Bar
  • Loading branch information
vvbragin authored May 1, 2024
2 parents ca53c5b + a629a10 commit e97ed5c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
4 changes: 2 additions & 2 deletions netpyne/analysis/spikes.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ 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'

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:
Expand Down
33 changes: 29 additions & 4 deletions netpyne/network/conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import numpy as np
from array import array as arrayFast
from numbers import Number

from tqdm import tqdm

# -----------------------------------------------------------------------------
# Connect Cells
Expand Down Expand Up @@ -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]
Expand All @@ -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()


# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -538,20 +546,22 @@ 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))
# print(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 = (
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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()


# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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()


# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 8 additions & 4 deletions netpyne/network/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from ..specs import ODict
from neuron import h # import NEURON

from tqdm import tqdm

class Network(object):
"""
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit e97ed5c

Please sign in to comment.