def simulateNetPyNEModelInGeppetto(self, args): try: with redirect_stdout(sys.__stdout__): # TODO mpi is not finding libmpi.dylib.. set LD_LIBRARY_PATH to openmpi bin folder, but nothing if args['parallelSimulation']: logging.debug('Running parallel simulation') if not 'usePrevInst' in args or not args['usePrevInst']: self.netParams.save("netParams.json") self.simConfig.saveJson = True self.simConfig.save("simParams.json") template = os.path.join(os.path.dirname(__file__), 'template.py') else: sim.cfg.saveJson = True oldName = sim.cfg.filename sim.cfg.filename = 'model_output' sim.saveData() sim.cfg.filename = oldName template = os.path.join(os.path.dirname(__file__), 'template2.py') copyfile(template, './init.py') cp = subprocess.run([ "mpiexec", "-n", args['cores'], "nrniv", "-mpi", "-python", "init.py" ], capture_output=True) print(cp.stdout.decode() + cp.stderr.decode()) if cp.returncode != 0: return utils.getJSONError( "Error while simulating the NetPyNE model", cp.stderr.decode()) sim.load('model_output.json') self.geppetto_model = self.model_interpreter.getGeppettoModel( sim) netpyne_model = sim else: logging.info("Starting simulation") if not args.get('usePrevInst', False): logging.debug('Instantiating single thread simulation') netpyne_model = self.instantiateNetPyNEModel() self.geppetto_model = self.model_interpreter.getGeppettoModel( netpyne_model) logging.debug('Running single thread simulation') netpyne_model = self.simulateNetPyNEModel() return json.loads( GeppettoModelSerializer.serialize(self.geppetto_model)) except: return utils.getJSONError( "Error while simulating the NetPyNE model", sys.exc_info())
def simulate_single_model(self, experiment: model.Experiment = None, use_prev_inst: bool = False): if experiment: working_directory = self._prepare_simulation_files( experiment, use_prev_inst) simulations.run( parallel=self.run_config.parallel, cores=self.run_config.cores, asynchronous=self.run_config.asynchronous, method=simulations.MPI_BULLETIN, working_directory=working_directory, ) if self.run_config.asynchronous: message = "Experiment is pending! " \ f"Results will be stored in your workspace at ./{os.path.join(constants.EXPERIMENTS_FOLDER, experiment.name)}" return utils.getJSONError(message, "") else: sim.load(f'{constants.MODEL_OUTPUT_FILENAME}.json') self.geppetto_model = self.model_interpreter.getGeppettoModel( sim) response = json.loads( GeppettoModelSerializer.serialize(self.geppetto_model)) return response else: # Run in same process if not use_prev_inst: logging.debug('Instantiating single thread simulation') netpyne_model = self.instantiateNetPyNEModel() self.geppetto_model = self.model_interpreter.getGeppettoModel( netpyne_model) simulations.run() if self.geppetto_model: response = json.loads( GeppettoModelSerializer.serialize(self.geppetto_model)) return response
def plotBatchConn(batchPath='batch_data', batchLabel='v01_batch48', feature='all'): batchPath = os.path.join(batchPath, batchLabel) batchPathFiles = os.listdir(batchPath) simFiles = [file for file in batchPathFiles if file.endswith('.json')] simFiles = [file for file in simFiles if not file.endswith('cfg.json')] simFiles = [file for file in simFiles if not file.endswith('batch.json')] simFiles.sort() includePre = ['PT5_1', 'PT5_2', 'PT5_3', 'PT5_4', 'PV5'] includePost = ['PT5_1', 'PT5_2', 'PT5_3', 'PT5_4', 'PV5'] features = [ 'numConns', 'divergence', 'convergence', 'weight', 'probability', 'strength' ] groupBy = 'pop' orderBy = 'gid' EEmean = {} EImean = {} IEmean = {} IImean = {} EEstd = {} EIstd = {} IEstd = {} IIstd = {} if feature == 'all': for feature in features: EEmean[feature] = [] EImean[feature] = [] IEmean[feature] = [] IImean[feature] = [] EEstd[feature] = [] EIstd[feature] = [] IEstd[feature] = [] IIstd[feature] = [] for simFile in simFiles: simPath = os.path.join('batch_data', batchLabel, simFile) sim.load(simPath, createNEURONObj=False) for feature in features: (fig, output) = sim.analysis.plotConn(includePre=includePre, includePost=includePost, feature=feature, groupBy=groupBy, orderBy=orderBy, showFig=False) connMatrix = output['connMatrix'] EEmean[feature].append(np.mean(connMatrix[0:4, 0:4])) EImean[feature].append(np.mean(connMatrix[0:4, 4:5])) IEmean[feature].append(np.mean(connMatrix[4:5, 0:4])) IImean[feature].append(np.mean(connMatrix[4:5, 4:5])) EEstd[feature].append(np.std(connMatrix[0:4, 0:4])) EIstd[feature].append(np.std(connMatrix[0:4, 4:5])) IEstd[feature].append(np.std(connMatrix[4:5, 0:4])) IIstd[feature].append(np.std(connMatrix[4:5, 4:5])) for feature in features: labels = ['10', '100', '500', '1000', '5000'] x = np.arange(len(labels)) # the label locations width = 0.2 # the width of the bars fig, ax = plt.subplots() rects1 = ax.bar(x - width * (3 / 2), EEmean[feature], yerr=EEstd[feature], width=width, label='E->E') rects2 = ax.bar(x - width / (2), EImean[feature], yerr=EIstd[feature], width=width, label='E->I') rects3 = ax.bar(x + width / (2), IEmean[feature], yerr=IEstd[feature], width=width, label='I->E') rects4 = ax.bar(x + width * (3 / 2), IImean[feature], yerr=IIstd[feature], width=width, label='I->I') # Add some text for labels, title and custom x-axis tick labels, etc. ax.set_ylabel('Connectivity ' + feature) ax.set_title('Connectivity ' + feature) ax.set_xticks(x) ax.set_xticklabels(labels) ax.set_xlabel('Number of Cells') ax.legend() fig.tight_layout() return
def plotSimSync(simPath='data', simLabel='eee_net_25', showFigs=False, batchLabel=None): if not batchLabel: simPath = os.path.join(simPath, simLabel, simLabel + '.json') sim.load(simPath, createNEURONObj=False) else: simPath = os.path.join(simPath, batchLabel, simLabel + '.json') sim.load(simPath, createNEURONObj=False) #sim.analysis.plotTraces() rasterFig, rasterData = sim.analysis.plotRaster( include=['PT5_1', 'PT5_2', 'PT5_3', 'PT5_4', 'PV5'], orderInverse=False) syncFigPre, syncDataPre = sim.analysis.plotSpikeStats( include=['PT5_1', 'PT5_2', 'PT5_3', 'PT5_4', 'PV5'], timeRange=[200, 400], graphType='boxplot', stats=['sync'], figSize=(6, 8), saveData=None, saveFig=None, showFig=showFigs) syncFigPlat, syncDataPlat = sim.analysis.plotSpikeStats( include=['PT5_1', 'PT5_2', 'PT5_3', 'PT5_4', 'PV5'], timeRange=[800, 1000], graphType='boxplot', stats=['sync'], figSize=(6, 8), saveData=None, saveFig=None, showFig=showFigs) syncFigInput, syncDataInput = sim.analysis.plotSpikeStats( include=['PT5_1', 'PT5_2', 'PT5_3', 'PT5_4', 'PV5'], timeRange=[1400, 1600], graphType='boxplot', stats=['sync'], figSize=(6, 8), saveData=None, saveFig=None, showFig=showFigs) syncFigPlatInput, syncDataPlatInput = sim.analysis.plotSpikeStats( include=['PT5_1', 'PT5_2', 'PT5_3', 'PT5_4', 'PV5'], timeRange=[2000, 2200], graphType='boxplot', stats=['sync'], figSize=(6, 8), saveData=None, saveFig=None, showFig=showFigs) # Bar plot of synchrony labels = ['Control', 'Plats', 'Inputs', 'Plats+Inputs'] PT51_sync = [] PT51_sync.append(syncDataPre['statData'][0][0]) PT51_sync.append(syncDataPlat['statData'][0][0]) PT51_sync.append(syncDataInput['statData'][0][0]) PT51_sync.append(syncDataPlatInput['statData'][0][0]) PT52_sync = [] PT52_sync.append(syncDataPre['statData'][1][0]) PT52_sync.append(syncDataPlat['statData'][1][0]) PT52_sync.append(syncDataInput['statData'][1][0]) PT52_sync.append(syncDataPlatInput['statData'][1][0]) PT53_sync = [] PT53_sync.append(syncDataPre['statData'][2][0]) PT53_sync.append(syncDataPlat['statData'][2][0]) PT53_sync.append(syncDataInput['statData'][2][0]) PT53_sync.append(syncDataPlatInput['statData'][2][0]) PT54_sync = [] PT54_sync.append(syncDataPre['statData'][3][0]) PT54_sync.append(syncDataPlat['statData'][3][0]) PT54_sync.append(syncDataInput['statData'][3][0]) PT54_sync.append(syncDataPlatInput['statData'][3][0]) x = np.arange(len(labels)) # the label locations width = 0.2 # the width of the bars fig, ax = plt.subplots() rects1 = ax.bar(x - width * (3 / 2), PT51_sync, width, label='PT5_1 (+P+I)') rects2 = ax.bar(x - width / (2), PT52_sync, width, label='PT5_2 (+P-I)') rects3 = ax.bar(x + width / (2), PT53_sync, width, label='PT5_3 (-P+I)') rects4 = ax.bar(x + width * (3 / 2), PT54_sync, width, label='PT5_4 (-P-I)') # Add some text for labels, title and custom x-axis tick labels, etc. ax.set_ylabel('Synchrony') ax.set_title('Synchrony by population and condition') ax.set_xticks(x) ax.set_xticklabels(labels) ax.legend() fig.tight_layout() outputData = [PT51_sync, PT52_sync, PT53_sync, PT54_sync] return outputData
import neuron from netpyne import sim # Folder that contains x86_64 folder NETPYNE_WORKDIR_PATH = '../../../' neuron.load_mechanisms(NETPYNE_WORKDIR_PATH) sim.load("./model_output.json") sim.createSimulate() sim.saveData()