def batchRun(): # Create variable of type ordered dictionary (NetPyNE's customized version) params = specs.ODict() # fill in with parameters to explore and range of values (key has to coincide with a variable in simConfig) #params[''] = [] #params[''] = [] #params['EEconn'] = [0.05, 0.1, 0.2] #params['IEconn'] = [0.1, 0.2, 0.3] #params['numCells'] = [10, 100, 500, 1000, 5000, 10000] #params['ampIClamp2'] = [0.24, 0.25, 0.26] #params['noisePV5'] = [True, False] #params['PT5_noise_amp'] = [0.1, 0.25, 0.5, 0.75, 1.0] #params['PT5_noise_std'] = [0.1, 0.25, 0.5, 0.75, 1.0] #params['ampIClamp1'] = [0.3, 0.4, 0.5, 0.6] #params['ampIClamp2'] = [0.3, 0.3125, 0.325, 0.375] params['GABAAfastWeight'] = [0.01, 0.001, 0.0001, 0.00001] params['noise'] = [False, True] # create Batch object with paramaters to modify, and specifying files to use b = Batch(params=params, cfgFile='cfg.py', netParamsFile='netParams.py') # Set output folder, grid method (all param combinations), and run configuration b.batchLabel = batchLabel b.method = 'grid' if runType == 'hpc_slurm': b.saveFolder = saveFolder + b.batchLabel b.runCfg = { 'type': 'hpc_slurm', 'allocation': allocation, 'walltime': '00:30:00', 'nodes': 4, 'coresPerNode': 48, 'email': '*****@*****.**', 'folder': runFolder, 'script': 'init.py', 'mpiCommand': 'ibrun', 'skip': True, 'custom': '#SBATCH -p skx-normal' } elif runType == 'mpi_bulletin': if not os.path.isdir('data'): os.mkdir('data') b.saveFolder = 'data/' + b.batchLabel b.runCfg = {'type': 'mpi_bulletin', 'script': 'init.py', 'skip': True} else: raise Exception( "Problem in batch file: runType must be either 'hpc_slurm' or 'mpi_bulletin'." ) # Run batch simulations b.run()
def batchRun(): # Create variable of type ordered dictionary (NetPyNE's customized version) params = specs.ODict() # fill in with parameters to explore and range of values (key has to coincide with a variable in simConfig) params['numCells'] = [10, 100, 500, 1000, 5000] #params['EEconv'] = [1.5, 3.0, 6.0] # Default 3.0 #params['IEconv'] = [6.0, 12.0, 24.0] # Default 12.0 #params['ampIClamp1'] = [0.1, 0.5, 1.0] #params['GABAAfastWeight'] = [0.0001, 0.01, 1.0] #params['GABAAslowWeight'] = [0.0001, 0.001, 0.01] # create Batch object with paramaters to modify, and specifying files to use b = Batch(params=params, cfgFile='cfg.py', netParamsFile='netParams.py') # Set output folder, grid method (all param combinations), and run configuration b.batchLabel = batchLabel b.method = 'grid' if runType == 'hpc_slurm': b.saveFolder = '/oasis/scratch/comet/jwgraham/temp_project/EEE_network/eee_net/' + b.batchLabel b.runCfg = { 'type': 'hpc_slurm', 'allocation': 'csd403', 'walltime': '01:00:00', 'nodes': 4, 'coresPerNode': 24, 'email': '*****@*****.**', 'folder': '/home/jwgraham/EEE_network/eee_net/', 'script': 'init.py', 'mpiCommand': 'ibrun', 'skip': True } elif runType == 'mpi_bulletin': if not os.path.isdir('batch_data'): os.mkdir('batch_data') b.saveFolder = 'batch_data/' + b.batchLabel b.runCfg = { 'type': 'mpi_bulletin', 'script': 'init_norun.py', 'skip': True } else: raise Exception( "Problem in batch file: runType must be either 'hpc_slurm' or 'mpi_bulletin'." ) # Run batch simulations b.run()
def batchNMDAMapping(): params = {'tau1NMDA': [10, 15, 20, 25]} initCfg = {'duration': 1100} from cfg import cfg from netParams import netParams b = Batch(params=params, initCfg=initCfg, cfg=cfg, netParams=netParams) runBatch(b, 'batchNMDAMapping', setup='mpi_bulletin')
def batchNa(): params = { 'dendNa': [0.025, 0.03, 0.035, 0.4], ('IClamp1', 'amp'): list(np.arange(-2.0, 8.0, 0.5) / 10.0) } initCfg = {'duration': 1.1, 'tau1NMDA': 15} b = Batch(params=params, initCfg=initCfg) runBatch(b, 'batchNa', setup='mpi_bulletin')
def batchNMDA(): params = { 'tau1NMDA': [10, 15, 20, 25], ('NetStim1', 'weight'): list(np.arange(1.0, 10.0, 1.0) / 1e4) } initCfg = {'duration': 1.1} b = Batch(params=params, initCfg=initCfg) runBatch(b, 'batchNMDA', setup='mpi_bulletin')
def custom(): params = specs.ODict() params[('seeds', 'conn')] = [1] # params[('EEGain')] = [0.5, 1, 2, 4] # params[('IClamp1')] = [0.001] b = Batch(params=params, netParamsFile='netParams.py', cfgFile='cfg.py') return b
def run_batch(experiment): # Map params to netpyne format params = specs.ODict() grouped_params = [] for param in experiment["params"]: params[param["mapsTo"]] = param["values"] if param["inGroup"]: grouped_params.append(param["mapsTo"]) with open("netParams.json", "r") as f: net_params = json.load(f) net_params = specs.NetParams(net_params["net"]["params"]) with open("simConfig.json", "r") as f: sim_config = json.load(f) sim_config = specs.SimConfig(sim_config["simConfig"]) batch = Batch( cfg=sim_config, netParams=net_params, params=params, groupedParams=grouped_params, seed=experiment.get("seed", None), ) # Label will be subfolder of saveFolder batch.batchLabel = experiment.get("name", "batch_template_run") # Have to overwrite the saveFolder, default goes to root folder which is not always allowed by OS batch.saveFolder = os.getcwd() # For now, we only support grid|list batch.method = experiment.get("method", "grid") # for now, we only support mpi_direct or bulletinboard # * mpi_direct can be started by running batch.py # * mpi_bulletin requires to run "mpiexec -n 4 nrniv -mpi batch.py", otherwise runs in single core run_cfg = experiment.get("runCfg", None) cores = run_cfg.get("cores", None) cores = int(cores) if cores else None if run_cfg: batch.runCfg = { "type": run_cfg.get("type", "mpi_bulletin"), "script": run_cfg.get("script", "run.py"), "skip": run_cfg.get("skip", True), "cores": cores, } batch.run() return batch
def custom(): params = specs.ODict() # params[('seeds', 'conn')] = [1] # params[('EEGain')] = [1, 2] params[('wgkbar')] = [0.0001, 0.0002, 0.0004, 0.0008] params[('IClamp1')] = [0.2, 0.4, 0.8, 1.6] b = Batch(params=params, netParamsFile='netParams.py', cfgFile='cfg.py') return b
def EEbalance(): params = specs.ODict() params["EEgain"] = [0.01, 0.1, 0.15, 0.2] params["glutAmp"] = [0.4,0.5,0.6] b = Batch(params=params, netParamsFile='netParams.py', cfgFile='cfg.py') grouped = [] # list of params that are grouped (vary together) for p in b.params: if p['label'] in grouped: p['group'] = True return b
def batchRun(): # Create variable of type ordered dictionary (NetPyNE's customized version) params = specs.ODict() # fill in with parameters to explore and range of values (key has to coincide with a variable in simConfig) #params['stimScale'] = [45.0, 90.0, 180.0] params['noise'] = [True, False] #params['numSynsPyrInh'] = [2, 4, 6, 8] # Default: 2 params['pyrInjectAmp'] = [0.8, 1.0, 1.2, 1.4] # create Batch object with paramaters to modify, and specifying files to use b = Batch(params=params, cfgFile='cfg.py', netParamsFile='netParams.py') # Set output folder, grid method (all param combinations), and run configuration b.batchLabel = batchLabel b.method = 'grid' b.saveFolder = batchSaveFolder if runType == 'hpc_slurm': b.runCfg = { 'type': 'hpc_slurm', 'allocation': allocation, 'walltime': '00:30:00', 'nodes': 4, 'coresPerNode': 48, 'email': '*****@*****.**', 'folder': runFolder, 'script': 'init.py', 'mpiCommand': 'ibrun', 'skip': True, 'custom': '#SBATCH -p skx-normal' } elif runType == 'mpi_bulletin': b.runCfg = {'type': 'mpi_bulletin', 'script': 'init.py', 'skip': True} else: raise Exception( "Problem in batch file: runType must be either 'hpc_slurm' or 'mpi_bulletin'." ) # Run batch simulations b.run()
def run_batch(label, params, cfgFile, netParamsFile, batchdatadir="batch_data", grouped=None): """Runs a batch of simulations.""" b = Batch(cfgFile=cfgFile, netParamsFile=netParamsFile) for k,v in params.iteritems(): b.params.append({'label': k, 'values': v}) if grouped is not None: for p in b.params: if p['label'] in grouped: p['group'] = True b.batchLabel = label b.saveFolder = os.path.join(batchdatadir, b.batchLabel) b.method = 'grid' b.runCfg = {'type': 'mpi', 'script': 'init.py', #'batch_init.py', 'skip': True} b.run()
def multi_params(): params = specs.ODict() #params["EEgain"] = [0.0008, 0.001, 0.0012] params["IEgain"] = [0.035, 0.04, 0.045]#[0.04, 0.05, 0.06] params["EIgain"] = [0.8, 0.9, 1.0, 1.1, 1.2]#[0.15, 0.2, 0.25] #params["IIgain"] = [0.00005, 0.0001, 0.0002]#[0.00008, 0.0001, 0.00012] #params["exc_noise_amp"] = [0.18, 0.2, 0.22] #params["inh_noise_amp"] = [0.18, 0.2, 0.22] b = Batch(params=params, netParamsFile='netParams.py', cfgFile='cfg.py')#, groupedParams=grouped) grouped = [] # list of params that are grouped (vary together) for p in b.params: if p['label'] in grouped: p['group'] = True return b
def stim_batch(): params = specs.ODict() params["glutAmp"] = [1.0, 1.5, 2.0]#, 2.0, 3.0]#, 4.0, 5.0] params["glutAmpExSynScale"] = [1.0, 1.5, 2.0]#, 2.0, 3.0]#, 4.0, 5.0] #params["synLocMiddle"] = [0.2,0.5,0.8] #params["allNaScale"] = [1.0, 1.05, 1.1, 1.15, 1.2] #params["RaScale"] = [0.6, 0.65, 0.7] params['synTime2'] = [200, 250, 300, 350, 400, 500, 600] params['glutAmp2'] = [0.0, 1.0, 3.0, 5.0, 7.0] b = Batch(params=params, netParamsFile='netParams.py', cfgFile='cfg.py')#, groupedParams=grouped) grouped = ["glutAmp","glutAmpExSynScale"] # list of params that are grouped (vary together) for p in b.params: if p['label'] in grouped: p['group'] = True return b
def batchTauWeight(): # Create variable of type ordered dictionary (NetPyNE's customized version) params = specs.ODict() # fill in with parameters to explore and range of values (key has to coincide with a variable in simConfig) params['synMechTau2'] = [3.0, 5.0, 7.0] params['connWeight'] = [0.005, 0.01, 0.15] # create Batch object with paramaters to modify, and specifying files to use b = Batch(params=params, cfgFile='cfg.py', netParamsFile='netParams.py') # Set output folder, grid method (all param combinations), and run configuration b.batchLabel = 'tauWeight' b.saveFolder = 'data' b.method = 'grid' b.runCfg = {'type': 'mpi_bulletin', 'script': 'init.py', 'skip': True} # Run batch simulations b.run()
def batchRxd(): init_list = [0.0, 1.0] gip3r_list = [12040 * 50, 12040 * 150] params = {'ip3_init' : init_list, 'gip3r' : gip3r_list} initCfg = {'duration' : 0.5*1e3} b = Batch(params=params, initCfg=initCfg) b.batchLabel = 'batchRxd' b.saveFolder = 'data/'+b.batchLabel b.method = 'grid' b.runCfg = {'type': 'mpi_bulletin', 'script': 'init.py'} b.run()
def batchTauWeight(): # Create variable of type ordered dictionary (NetPyNE's customized version) params = specs.ODict() # Parameters and values to explore (corresponds to variable in simConfig) params['synMechTau2'] = [3.0, 5.0, 7.0] params['connWeight'] = [0.005, 0.01, 0.15] # create Batch object with paramaters to modify, and model files to use b = Batch(params=params, cfgFile='tut8_cfg.py', netParamsFile='tut8_netParams.py') # Set output folder, optimization method, and run configuration b.batchLabel = 'tauWeight' b.saveFolder = 'tut8_data' b.method = 'grid' b.runCfg = {'type': 'mpi_bulletin', 'script': 'tut8_init.py', 'skip': True} # Run batch simulations b.run()
def batchTest(): # Create variable of type ordered dictionary (NetPyNE's customized version) params = specs.ODict() # fill in with parameters to explore and range of values (key has to coincide with a variable in simConfig) params['glutAmp'] = [0.1, 0.2, 0.3, 0.4, 0.5, 1.0] #params['glutAmp'] = [0.02, 0.2, 2.0] #params['ampIClamp1'] = [0.1, 0.5, 1.0] #params['GABAAfastWeight'] = [0.0001, 0.01, 1.0] #params['GABAAslowWeight'] = [0.0001, 0.001, 0.01] # create Batch object with paramaters to modify, and specifying files to use b = Batch(params=params, cfgFile='cfg.py', netParamsFile='netParams.py') # Set output folder, grid method (all param combinations), and run configuration b.batchLabel = 'batch_test' b.saveFolder = 'batch_data' b.method = 'grid' b.runCfg = {'type': 'mpi_bulletin', 'script': 'init.py', 'skip': True} # Run batch simulations b.run()
def batchRun(): # Create variable of type ordered dictionary (NetPyNE's customized version) params = specs.ODict() # fill in with parameters to explore and range of values (key has to coincide with a variable in simConfig) params['PT5_exc_noise_amp'] = [0.0, 0.5, 1.0, 2.0] # Default 1.0 params['PT5_inh_noise_amp'] = [0.0, 0.5, 1.0, 2.0] # Default 1.0 #params['ampIClamp1'] = [0.1, 0.5, 1.0] #params['GABAAfastWeight'] = [0.0001, 0.01, 1.0] #params['GABAAslowWeight'] = [0.0001, 0.001, 0.01] # create Batch object with paramaters to modify, and specifying files to use b = Batch(params=params, cfgFile='cfg.py', netParamsFile='netParams.py') # Set output folder, grid method (all param combinations), and run configuration b.batchLabel = 'v01_batch04' b.saveFolder = '/oasis/scratch/comet/jwgraham/temp_project/EEE_network/eee_net/' + b.batchLabel b.method = 'grid' b.runCfg = { 'type': 'hpc_slurm', 'allocation': 'shs100', 'walltime': '00:30:00', 'nodes': 1, 'coresPerNode': 24, 'email': '*****@*****.**', 'folder': '/home/jwgraham/EEE_network/eee_net/', 'script': 'init.py', 'mpiCommand': 'ibrun', 'skip': True } #b.runCfg = {'type': 'mpi_bulletin', # 'script': 'init.py', # 'skip': True} # Run batch simulations b.run()
def run_batch(label, params, cfgFile, netParamsFile, script, grouped=None): """Runs a batch of simulations.""" b = Batch(cfgFile=cfgFile, netParamsFile=netParamsFile) for k, v in params.items(): b.params.append({'label': k, 'values': v}) if grouped is not None: for p in b.params: if p['label'] in grouped: p['group'] = True b.batchLabel = label b.saveFolder = os.path.join(b.batchLabel + '_data') b.method = 'grid' b.runCfg = {'type': 'mpi_bulletin', 'script': script, 'skip': True} if not os.path.isdir(b.saveFolder): try: os.makedirs(b.saveFolder) except: pass b.run()
def batchTauWeight(): # Create variable of type ordered dictionary (NetPyNE's customized version) params = specs.ODict() # fill in with parameters to explore and range of values (key has to coincide with a variable in simConfig) params['synMechTau2'] = [3.0, 5.0, 7.0] params['connWeight'] = [0.005, 0.01, 0.15] # create Batch object with paramaters to modify, and specifying files to use b = Batch(params=params, cfgFile='tut8_cfg.py', netParamsFile='tut8_netParams.py') # Set output folder, grid method (all param combinations), and run configuration b.batchLabel = 'tauWeight' b.saveFolder = 'tut8_data' b.method = 'grid' b.runCfg = { 'type': 'hpc_slurm', 'allocation': 'shs100', 'walltime': '0:30:00', 'nodes': 1, 'coresPerNode': 24, 'email': '*****@*****.**', 'folder': '/home/jwgraham/EEE_network/batch_tut', 'script': 'tut8_init.py', 'mpiCommand': 'ibrun', 'skip': True } # b.runCfg = {'type': 'mpi_bulletin', # 'script': 'tut8_init.py', # 'skip': True} # Run batch simulations b.run()
def _create_trials(experiment: model.Experiment) -> List[model.Trial]: """Gerates based on `experiment.params` all possible trial combinations. :param experiment: given experiment. :return: list of generated trials. """ params = copy.deepcopy(experiment.params) params = process_params(params) if len(experiment.params) < 1: # No params defined -> one trial representing base model return [_create_base_model_trial()] params_dict = {} grouped_params = [] for p in params: params_dict[p.mapsTo] = p.values if p.inGroup: grouped_params.append(p.mapsTo) # Initialize Batch so that we can call getParamCombinations() batch = Batch(params=params_dict, groupedParams=grouped_params) batch.method = "grid" batch.saveFolder = "" batch.batchLabel = "" # { indices, values, labels, filenames} combinations = batch.getParamCombinations() if not combinations["labels"]: return [_create_base_model_trial()] trials = [] for combIdx, paramValues in enumerate(combinations["values"]): # index of paramValues := index of labels list # value of paramValues := parameter value params = [{combinations["labels"][idx]: v for idx, v in enumerate(paramValues)}] filename = combinations["filenames"][combIdx][1:] indices = combinations["indices"][combIdx] name = f"Condition {combIdx + 1}" trials.append( model.Trial(name=name, params=params, indices=indices, id=filename) ) return trials
def createBatch(params): b = Batch(netParamsFile='M1_cell.py') for k, v in params.iteritems(): b.params.append({'label': k, 'values': v}) return b
def createBatch(params): # Create Batch object b = Batch() for k,v in params.iteritems(): b.params.append({'label': k, 'values': v}) return b
def batchOptuna(): # parameters space to explore ## simple net params = specs.ODict() params['prob'] = [0.01, 0.5] # can add 3rd value for starting value (0) params['weight'] = [0.001, 0.1] params['delay'] = [1, 20] pops = {} pops['S'] = {'target': 5, 'width': 2, 'min': 2} pops['M'] = {'target': 15, 'width': 2, 'min': 0.2} # fitness function fitnessFuncArgs = {} fitnessFuncArgs['pops'] = pops fitnessFuncArgs['maxFitness'] = 1000 def fitnessFunc(simData, **kwargs): import numpy as np pops = kwargs['pops'] maxFitness = kwargs['maxFitness'] popFitness = [None for i in pops.items()] popFitness = [ min(np.exp(abs(v['target'] - simData['popRates'][k]) / v['width']), maxFitness) if simData["popRates"][k] > v['min'] else maxFitness for k, v in pops.items() ] fitness = np.mean(popFitness) popInfo = '; '.join([ '%s rate=%.1f fit=%1.f' % (p, r, f) for p, r, f in zip(list(simData['popRates'].keys()), list(simData['popRates'].values()), popFitness) ]) print(' ' + popInfo) return fitness # create Batch object with paramaters to modify, and specifying files to use b = Batch(params=params) # Set output folder, grid method (all param combinations), and run configuration b.batchLabel = 'simple' b.saveFolder = './' + b.batchLabel b.method = 'optuna' b.runCfg = { 'type': 'mpi_direct', #'hpc_slurm', 'script': 'init.py', # options required only for mpi_direct or hpc 'mpiCommand': 'mpiexec', 'nodes': 1, 'coresPerNode': 2, # 'allocation': 'default', # 'email': '*****@*****.**', # 'reservation': None, # 'folder': '/home/salvadord/evol' #'custom': 'export LD_LIBRARY_PATH="$HOME/.openmpi/lib"' # only for conda users } b.optimCfg = { 'fitnessFunc': fitnessFunc, # fitness expression (should read simData) 'fitnessFuncArgs': fitnessFuncArgs, 'maxFitness': fitnessFuncArgs['maxFitness'], 'maxiters': 20, # Maximum number of iterations (1 iteration = 1 function evaluation) 'maxtime': 3600, # Maximum time allowed, in seconds 'maxiter_wait': 10, 'time_sleep': 5, 'popsize': 1 # unused - run with mpi } # Run batch simulations b.run()
def batchASD(): # parameters space to explore ## simple net params = specs.ODict() params['prob'] = [0.01, 0.5, [0.4, 0.3]] # can add 3rd value for starting value (0) params['weight'] = [0.001, 0.1, [0.1, 0.2]] params['delay'] = [1, 20, [5, 3]] pops = {} pops['S'] = {'target': 5, 'width': 2, 'min': 2} pops['M'] = {'target': 15, 'width': 2, 'min': 0.2} # fitness function fitnessFuncArgs = {} fitnessFuncArgs['pops'] = pops fitnessFuncArgs['maxFitness'] = 1000 def fitnessFunc(simData, **kwargs): import numpy as np pops = kwargs['pops'] maxFitness = kwargs['maxFitness'] popFitness = [None for i in pops.items()] popFitness = [ min(np.exp(abs(v['target'] - simData['popRates'][k]) / v['width']), maxFitness) if simData["popRates"][k] > v['min'] else maxFitness for k, v in pops.items() ] fitness = np.mean(popFitness) popInfo = '; '.join([ '%s rate=%.1f fit=%1.f' % (p, r, f) for p, r, f in zip(list(simData['popRates'].keys()), list(simData['popRates'].values()), popFitness) ]) print(' ' + popInfo) return fitness # create Batch object with paramaters to modify, and specifying files to use b = Batch(params=params) # Set output folder, grid method (all param combinations), and run configuration b.batchLabel = 'simple' b.saveFolder = './' + b.batchLabel b.method = 'asd' b.runCfg = { 'type': 'mpi_direct', #'hpc_slurm', 'script': 'init.py', # options required only for mpi_direct or hpc 'mpiCommand': 'mpiexec', 'nodes': 1, 'coresPerNode': 2, # 'allocation': 'default', # 'email': '*****@*****.**', # 'reservation': None, # 'folder': '/home/salvadord/evol' #'custom': 'export LD_LIBRARY_PATH="$HOME/.openmpi/lib"' # only for conda users } b.optimCfg = { 'fitnessFunc': fitnessFunc, # fitness expression (should read simData) 'fitnessFuncArgs': fitnessFuncArgs, 'maxFitness': fitnessFuncArgs['maxFitness'], 'stepsize': 0.1, # Initial step size as a fraction of each parameter 'sinc': 2, # Step size learning rate (increase) 'sdec': 2, # Step size learning rate (decrease) 'pinc': 2, # Parameter selection learning rate (increase) 'pdec': 2, # Parameter selection learning rate (decrease) #'pinitial': None, # Set initial parameter selection probabilities #'sinitial': None, # Set initial step sizes; if empty, calculated from stepsize instead 'maxiters': 2, # Maximum number of iterations (1 iteration = 1 function evaluation) 'maxtime': 3600, # Maximum time allowed, in seconds 'abstol': 1e-6, # Minimum absolute change in objective function 'reltol': 1e-3, # Minimum relative change in objective function #'stalliters': 10*len(params)*len(params), # Number of iterations over which to calculate TolFun (n = number of parameters) #'stoppingfunc': None, # External method that can be used to stop the calculation from the outside. #'randseed': None, # The random seed to use 'verbose': 2, # How much information to print during the run #'label': None # A label to use to annotate the output 'maxiter_wait': 10, 'time_sleep': 5, 'popsize': 1 } # Run batch simulations b.run()
def evolCellITS4(): # parameters space to explore params = specs.ODict() params[('tune', 'soma', 'Ra')] = [100. * 0.5, 100 * 1.5] params[('tune', 'soma', 'cm')] = [0.75 * 0.5, 0.75 * 1.5] params[('tune', 'soma', 'kv', 'gbar')] = [1700.0 * 0.5, 1700.0 * 1.5] params[('tune', 'soma', 'naz', 'gmax')] = [72000.0 * 0.5, 72000.0 * 1.5] params[('tune', 'soma', 'pas', 'e')] = [-70 * 1.5, -70.0 * 0.5] params[('tune', 'soma', 'pas', 'g')] = [ 3.3333333333333335e-05 * 0.5, 3.3333333333333335e-05 * 1.5 ] params[('tune', 'dend', 'Ra')] = [0.02974858749381221 * 0.5, 0.02974858749381221 * 1.5] params[('tune', 'dend', 'cm')] = [0.75 * 0.5, 0.75 * 1.5] params[('tune', 'dend', 'Nca', 'gmax')] = [0.3 * 0.5, 0.3 * 1.5] params[('tune', 'dend', 'kca', 'gbar')] = [3.0 * 0.5, 3.0 * 1.5] params[('tune', 'dend', 'km', 'gbar')] = [0.1 * 0.5, 0.1 * 1.5] params[('tune', 'dend', 'naz', 'gmax')] = [15.0 * 0.5, 15.0 * 1.5] params[('tune', 'dend', 'pas', 'e')] = [-70 * 1.5, -70.0 * 0.5] params[('tune', 'dend', 'pas', 'g')] = [ 3.3333333333333335e-05 * 0.5, 3.3333333333333335e-05 * 1.5 ] params[('tune', 'dend1', 'Ra')] = [0.015915494309189534 * 0.5, 0.015915494309189534 * 1.5] params[('tune', 'dend1', 'cm')] = [0.75 * 0.5, 0.75 * 1.5] params[('tune', 'dend1', 'Nca', 'gmax')] = [0.3 * 0.5, 0.3 * 1.5] params[('tune', 'dend1', 'kca', 'gbar')] = [3.0 * 0.5, 3.0 * 1.5] params[('tune', 'dend1', 'km', 'gbar')] = [0.1 * 0.5, 0.1 * 1.5] params[('tune', 'dend1', 'naz', 'gmax')] = [15.0 * 0.5, 15.0 * 1.5] params[('tune', 'dend1', 'pas', 'e')] = [-70 * 1.5, -70.0 * 0.5] params[('tune', 'dend1', 'pas', 'g')] = [ 3.3333333333333335e-05 * 0.5, 3.3333333333333335e-05 * 1.5 ] # current injection params amps = list(np.arange(0.0, 0.65, 0.05)) # amplitudes times = list(np.arange(1000, 2000 * len(amps), 2000)) # start times dur = 500 # ms targetRates = [ 0., 0., 19., 29., 37., 45., 51., 57., 63., 68., 73., 77., 81. ] # initial cfg set up initCfg = {} # specs.ODict() initCfg['duration'] = 2000 * len(amps) initCfg[('hParams', 'celsius')] = 37 initCfg['savePickle'] = True initCfg['saveJson'] = False initCfg['saveDataInclude'] = ['simConfig', 'netParams', 'net', 'simData'] initCfg[('IClamp1', 'pop')] = 'ITS4' initCfg[('IClamp1', 'amp')] = amps initCfg[('IClamp1', 'start')] = times initCfg[('IClamp1', 'dur')] = 1000 initCfg[('analysis', 'plotfI', 'amps')] = amps initCfg[('analysis', 'plotfI', 'times')] = times initCfg[('analysis', 'plotfI', 'dur')] = dur initCfg[('analysis', 'plotfI', 'targetRates')] = targetRates for k, v in params.items(): initCfg[k] = v[0] # initialize params in cfg so they can be modified # fitness function fitnessFuncArgs = {} fitnessFuncArgs['targetRates'] = targetRates def fitnessFunc(simData, **kwargs): targetRates = kwargs['targetRates'] diffRates = [abs(x - t) for x, t in zip(simData['fI'], targetRates)] fitness = np.mean(diffRates) print(' Candidate rates: ', simData['fI']) print(' Target rates: ', targetRates) print(' Difference: ', diffRates) return fitness # create Batch object with paramaters to modify, and specifying files to use b = Batch(params=params, initCfg=initCfg) # Set output folder, grid method (all param combinations), and run configuration b.batchLabel = 'ITS4_evol' b.saveFolder = 'data/' + b.batchLabel b.method = 'evol' b.runCfg = { 'type': 'mpi_bulletin', #'hpc_slurm', 'script': 'init.py', # # options required only for hpc # 'mpiCommand': 'mpirun', # 'nodes': 1, # 'coresPerNode': 2, # 'allocation': 'default', # 'email': '*****@*****.**', # 'reservation': None, # 'folder': '/home/salvadord/evol' # #'custom': 'export LD_LIBRARY_PATH="$HOME/.openmpi/lib"' # only for conda users } b.evolCfg = { 'evolAlgorithm': 'custom', 'fitnessFunc': fitnessFunc, # fitness expression (should read simData) 'fitnessFuncArgs': fitnessFuncArgs, 'pop_size': 40, 'num_elites': 1, # keep this number of parents for next generation if they are fitter than children 'mutation_rate': 0.4, 'crossover': 0.5, 'maximize': False, # maximize fitness function? 'max_generations': 20, 'time_sleep': 5, # wait this time before checking again if sim is completed (for each generation) 'maxiter_wait': 20, # max number of times to check if sim is completed (for each generation) 'defaultFitness': 1000 # set fitness value in case simulation time is over } # Run batch simulations b.run()
def evolCellNGF(): # parameters space to explore params = specs.ODict() params[('tune', 'soma', 'Ra')] = [14., 14.] #*0.5, 14.*1.5] params[('tune', 'soma', 'cm')] = [1.5 * 0.5, 1.5 * 1.5] params[('tune', 'soma', 'ch_CavL', 'gmax')] = [0.056108352 * 0.5, 0.056108352 * 1.5] params[('tune', 'soma', 'ch_CavN', 'gmax')] = [0.00058169587 * 0.5, 0.00058169587 * 1.5] params[('tune', 'soma', 'ch_KCaS', 'gmax')] = [0.006 * 0.5, 0.006 * 1.5] params[('tune', 'soma', 'ch_Kdrfastngf', 'gmax')] = [0.09 * 0.5, 0.09 * 1.5] params[('tune', 'soma', 'ch_KvAngf', 'gmax')] = [0.052 * 0.5, 0.052 * 1.5] params[('tune', 'soma', 'ch_KvAngf', 'gml')] = [1.0 * 0.5, 1.0 * 1.5] params[('tune', 'soma', 'ch_KvAngf', 'gmn')] = [0.6 * 0.5, 0.6 * 1.5] params[('tune', 'soma', 'ch_KvCaB', 'gmax')] = [1.0235317e-06 * 0.5, 1.0235317e-06 * 1.5] params[('tune', 'soma', 'ch_Navngf', 'gmax')] = [0.1 * 0.5, 0.1 * 1.5] params[('tune', 'soma', 'hd', 'ehd')] = [-30 * 1.5, -30 * 0.5] params[('tune', 'soma', 'hd', 'elk')] = [-70 * 1.5, -70 * 0.5] params[('tune', 'soma', 'hd', 'gbar')] = [1e-05 * 0.5, 1e-05 * 1.5] params[('tune', 'soma', 'hd', 'vhalfl')] = [-90 * 1.5, -90 * 0.5] # params[('tune', 'soma', 'iconc_Ca', 'caiinf')] = [5e-06*0.5, 5e-06*1.5] # convergence issues # params[('tune', 'soma', 'iconc_Ca', 'catau')] = [-10*1.5, -10*0.5] params[('tune', 'soma', 'pas', 'e')] = [-85 * 1.5, -85 * 0.5] params[('tune', 'soma', 'pas', 'g')] = [5e-7 * 0.5, 5e-7 * 1.5] params[('tune', 'dend', 'Ra')] = [14 * 0.5, 14 * 1.5] params[('tune', 'dend', 'cm')] = [1.5 * 0.5, 1.5 * 1.5] params[('tune', 'dend', 'ch_Kdrfastngf', 'gmax')] = [0.03 * 0.5, 0.03 * 1.5] params[('tune', 'dend', 'ch_Navngf', 'gmax')] = [3.7860265 * 0.5, 3.7860265 * 1.5] params[('tune', 'dend', 'pas', 'e')] = [-67 * 1.5, -67 * 0.5] params[('tune', 'dend', 'pas', 'g')] = [0.0003 * 0.5, 0.0003 * 1.5] # current injection params interval = 10000 dur = 500 # ms durSteady = 200 # ms amps = list(np.arange(0.04 + 0.075, 0.121 + 0.075, 0.01)) # amplitudes times = list(np.arange(1000, (dur + interval) * len(amps), dur + interval)) # start times targetRatesOnset = [43., 52., 68., 80., 96., 110., 119., 131., 139.] targetRatesSteady = [22., 24., 27., 30., 33., 35., 37., 39., 41.] #targetRates = [(o + s) / 2 for o, s in zip(targetRatesOnset, targetRatesSteady)] # initial cfg set up initCfg = {} # specs.ODict() initCfg['duration'] = (dur + interval) * len(amps) initCfg[('hParams', 'celsius')] = 37 initCfg['savePickle'] = True initCfg['saveJson'] = False initCfg['saveDataInclude'] = ['simConfig', 'netParams', 'net', 'simData'] initCfg[('IClamp1', 'pop')] = 'NGF' initCfg[('IClamp1', 'amp')] = amps initCfg[('IClamp1', 'start')] = times initCfg[('IClamp1', 'dur')] = dur initCfg[('analysis', 'plotTraces', 'timeRange')] = [0, initCfg['duration']] initCfg[('analysis', 'plotfI', 'amps')] = amps initCfg[('analysis', 'plotfI', 'times')] = times initCfg[('analysis', 'plotfI', 'calculateOnset')] = True initCfg[('analysis', 'plotfI', 'dur')] = dur initCfg[('analysis', 'plotfI', 'durSteady')] = durSteady initCfg[('analysis', 'plotfI', 'targetRates')] = [] # initCfg[('analysis', 'plotfI', 'targetRatesOnset')] = targetRatesOnset initCfg[('analysis', 'plotfI', 'targetRatesSteady')] = targetRatesSteady for k, v in params.items(): initCfg[k] = v[0] # initialize params in cfg so they can be modified # fitness function fitnessFuncArgs = {} fitnessFuncArgs['targetRatesOnset'] = targetRatesOnset fitnessFuncArgs['targetRatesSteady'] = targetRatesSteady def fitnessFunc(simData, **kwargs): targetRatesOnset = kwargs['targetRatesOnset'] targetRatesSteady = kwargs['targetRatesSteady'] diffRatesOnset = [ abs(x - t) for x, t in zip(simData['fI_onset'], targetRatesOnset) ] diffRatesSteady = [ abs(x - t) for x, t in zip(simData['fI_steady'], targetRatesSteady) ] fitness = np.mean(diffRatesOnset + diffRatesSteady) print(' Candidate rates: ', simData['fI_onset'] + simData['fI_steady']) print(' Target rates: ', targetRatesOnset + targetRatesSteady) print(' Difference: ', diffRatesOnset + diffRatesSteady) return fitness # create Batch object with paramaters to modify, and specifying files to use b = Batch(params=params, initCfg=initCfg) # Set output folder, grid method (all param combinations), and run configuration b.batchLabel = 'NGF_evol' b.saveFolder = 'data/' + b.batchLabel b.method = 'evol' b.runCfg = { 'type': 'mpi_bulletin', #'hpc_slurm', 'script': 'init.py', # # options required only for hpc # 'mpiCommand': 'mpirun', # 'nodes': 1, # 'coresPerNode': 2, # 'allocation': 'default', # 'email': '*****@*****.**', # 'reservation': None, # 'folder': '/home/salvadord/evol' # #'custom': 'export LD_LIBRARY_PATH="$HOME/.openmpi/lib"' # only for conda users } b.evolCfg = { 'evolAlgorithm': 'custom', 'fitnessFunc': fitnessFunc, # fitness expression (should read simData) 'fitnessFuncArgs': fitnessFuncArgs, 'pop_size': 9, 'num_elites': 1, # keep this number of parents for next generation if they are fitter than children 'mutation_rate': 0.4, 'crossover': 0.5, 'maximize': False, # maximize fitness function? 'max_generations': 10, 'time_sleep': 10, # wait this time before checking again if sim is completed (for each generation) 'maxiter_wait': 20, # max number of times to check if sim is completed (for each generation) 'defaultFitness': 1000 # set fitness value in case simulation time is over } # Run batch simulations b.run()
from netpyne import specs from netpyne.batch import Batch import numpy as np params = specs.ODict() params['freq'] = 1 params['npulses'] = 1 params['duration'] = 50 params['mttxs'] = [x for x in np.linspace(0.5, 1.0, 6)] #params['mn1p8'] = [x for x in np.linspace(0.5, 1.0, 6)] b = Batch(params=params, cfgFile='cfg.py', netParamsFile='netParams.py') b.batchLabel = 'mttxs' b.saveFolder = 'mttxs_batch' b.method = 'grid' b.runCfg = {'type': 'mpi_bulletin', 'script': 'init.py', 'skip': True} b.run()
def batchEvol(networkType): # parameters space to explore if networkType == 'simple': ## simple net params = specs.ODict() params['prob'] = [0.01, 0.5] params['weight'] = [0.001, 0.1] params['delay'] = [1, 20] pops = {} pops['S'] = {'target': 5, 'width': 2, 'min': 2} pops['M'] = {'target': 15, 'width': 2, 'min': 0.2} elif networkType == 'complex': # complex net params = specs.ODict() params['probEall'] = [0.05, 0.2] # 0.1 params['weightEall'] = [0.0025, 0.0075] #5.0 params['probIE'] = [0.2, 0.6] #0.4 params['weightIE'] = [0.0005, 0.002] params['probLengthConst'] = [100,200] params['stimWeight'] = [0.05, 0.2] pops = {} pops['E2'] = {'target': 5, 'width': 2, 'min': 1} pops['I2'] = {'target': 10, 'width': 5, 'min': 2} pops['E4'] = {'target': 30, 'width': 10, 'min': 1} pops['I4'] = {'target': 10, 'width': 3, 'min': 2} pops['E5'] = {'target': 40, 'width': 4, 'min': 1} pops['I5'] = {'target': 25, 'width': 5, 'min': 2} # fitness function fitnessFuncArgs = {} fitnessFuncArgs['pops'] = pops fitnessFuncArgs['maxFitness'] = 1000 def fitnessFunc(simData, **kwargs): import numpy as np pops = kwargs['pops'] maxFitness = kwargs['maxFitness'] popFitness = [None for i in pops.items()] popFitness = [min(np.exp( abs(v['target'] - simData['popRates'][k]) / v['width']), maxFitness) if simData["popRates"][k]>v['min'] else maxFitness for k,v in pops.items()] fitness = np.mean(popFitness) popInfo = '; '.join(['%s rate=%.1f fit=%1.f'%(p,r,f) for p,r,f in zip(list(simData['popRates'].keys()), list(simData['popRates'].values()), popFitness)]) print(' '+popInfo) return fitness # create Batch object with paramaters to modify, and specifying files to use b = Batch(params=params) # Set output folder, grid method (all param combinations), and run configuration b.batchLabel = 'simple' b.saveFolder = './'+b.batchLabel b.method = 'evol' b.runCfg = { 'type': 'mpi_bulletin',#'hpc_slurm', 'script': 'init.py', # options required only for hpc 'mpiCommand': 'mpirun', 'nodes': 1, 'coresPerNode': 2, 'allocation': 'default', 'email': '*****@*****.**', 'reservation': None, 'folder': '/home/salvadord/evol' #'custom': 'export LD_LIBRARY_PATH="$HOME/.openmpi/lib"' # only for conda users } b.evolCfg = { 'evolAlgorithm': 'custom', 'fitnessFunc': fitnessFunc, # fitness expression (should read simData) 'fitnessFuncArgs': fitnessFuncArgs, 'pop_size': 6, 'num_elites': 1, # keep this number of parents for next generation if they are fitter than children 'mutation_rate': 0.4, 'crossover': 0.5, 'maximize': False, # maximize fitness function? 'max_generations': 4, 'time_sleep': 5, # wait this time before checking again if sim is completed (for each generation) 'maxiter_wait': 40, # max number of times to check if sim is completed (for each generation) 'defaultFitness': 1000 # set fitness value in case simulation time is over } # Run batch simulations b.run()
def batchEvol(): # parameters space to explore ## simple net params = specs.ODict() params['na11a'] = [0.001, 0.2] params['na12a'] = [0.001, 0.2] params['na13a'] = [0.001, 0.2] params['na16a'] = [0.001, 0.2] # fitness function fitnessFuncArgs = {} def fitnessFunc(simData, **kwargs): import numpy as np import json with open("./data/original/NaV_0.json", "r") as f: obs_data = json.load(f) targetMemb_ = obs_data["simData"]["V_soma"]["cell_0"] # # calculate MEMBRANE VOLTAGE at interesting point for comparison sum_vol = [] for i in range(len(simData["t"])): diff_vol_ = abs(targetMemb_[i] - simData["V_soma"]["cell_0"][i]) diff_vol = np.array(diff_vol_) sum_vol.append(diff_vol) fitness = sum(sum_vol) / 600 return fitness # create Batch object with paramaters to modify, and specifying files to use b = Batch(params=params, cfgFile='cfg.py', netParamsFile='netParams_SGGA_markov.py') # Set output folder, grid method (all param combinations), and run configuration b.batchLabel = 'na_evol' b.saveFolder = 'data/' + b.batchLabel b.method = 'evol' b.runCfg = { 'type': 'mpi_bulletin', #'hpc_slurm', 'script': 'init_SG.py', ## options required only for hpc # 'mpiCommand': 'mpirun', # 'nodes': 1, # 'coresPerNode': 2, # 'allocation': 'default', # 'email': '*****@*****.**', # 'reservation': None, # 'folder': '/home/salvadord/evol' #'custom': 'export LD_LIBRARY_PATH="$HOME/.openmpi/lib"' # only for conda users } b.evolCfg = { 'evolAlgorithm': 'custom', 'fitnessFunc': fitnessFunc, # fitness expression (should read simData) 'fitnessFuncArgs': fitnessFuncArgs, 'pop_size': 40, 'num_elites': 1, # keep this number of parents for next generation if they are fitter than children 'mutation_rate': 0.4, 'crossover': 0.5, 'maximize': False, # maximize fitness function? 'max_generations': 100, 'time_sleep': 20, # wait this time before checking again if sim is completed (for each generation) 'maxiter_wait': 15, # 40 * 5 sec = 200sec; max number of times to check if sim is completed (for each generation) 'defaultFitness': 10000 # set fitness value in case simulation time is over } # Run batch simulations b.run()