Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'])
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'])
# 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
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
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
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']))
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']))
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'])))
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')