""" from grid_params import GridRateParams import pylab as pl import numpy as np from grid_functions import map_merge, get_params from grid_const import ModelType import plotlib as pp from grid_batch import GridBatch from simlib import run_from_ipython from grid_inputs import GridInputs from simlib import ensureDir figures_path = '../figures' ensureDir(figures_path) force = False batch_default_map = map_merge(GridRateParams.gau_mix_small_arena_biphasic_neg, { 'dt': 10., 'compute_scores': False, }) p = get_params(batch_default_map) batch_override_map = {'inputs_seed': np.arange(100)} batch = GridBatch(ModelType.MODEL_RATE_AVG, batch_default_map, batch_override_map,
def post_init(self): ############################################################################## ###### CREATE POOL ############################################################################## self.batch_data_folder = batch_data_folder_map[self.model_type] ensureDir(self.batch_data_folder) # create pool self.host = socket.gethostname() if self.host in procs_by_host.keys(): self.num_procs = procs_by_host[self.host] else: self.num_procs = 7 self.pool = Pool(processes=self.num_procs) self.sims = [] self.hashes = [] self.all_par_values = sorted( itertools.product(*self.batch_override_map.values())) self.batch_override_str = ' '.join([ '%s (%s-%s)' % (key, format_val(min(values)), format_val(max(values))) for key, values in self.batch_override_map.items() ]) # loop over all different paramater values for par_values in self.all_par_values: override_param_map = { k: v for (k, v) in zip(self.batch_override_map.keys(), par_values) } parMap = map_merge(self.batch_default_map, override_param_map) if self.model_type == ModelType.MODEL_RATE: self.sim_class = GridRate elif self.model_type == ModelType.MODEL_RATE_AVG: self.sim_class = GridRateAvg elif self.model_type == ModelType.MODEL_SPIKING: self.sim_class = GridSpikes sim = self.sim_class(parMap) #print sim.hash_id+' Run: %s'%sim.do_run if self.force: sim.force_gen_inputs = True sim.force_gen_corr = True sim.do_run = True if sim.do_run is True: self.sims.append(sim) self.hashes.append(sim.hash_id) # generate batch hash self.batch_hash = gen_hash_id('_'.join(self.hashes)) self.batch_data_path = os.path.join(self.batch_data_folder, '%s_data.npz' % self.batch_hash) self.batch_params_path = os.path.join( self.batch_data_folder, '%s_params.txt' % self.batch_hash) self.batch_summary_str=\ "\n\nBATCH HASH: %s\n\nBATCH PARAMS = %s\n\n"%\ (self.batch_hash, self.batch_override_str ) print self.batch_summary_str self.toSaveMap = { 'hashes': self.hashes, 'batch_override_map': self.batch_override_map, 'batch_default_map': self.batch_default_map } if os.path.exists(self.batch_data_path) and not self.force: return False else: print '\n\n*** BATCH DATA NOT PRESENT!! ***\n\n' print self.batch_data_path print '%d/%d simulations to be run' % (len( self.sims), len(self.all_par_values)) return True