예제 #1
0
    def run_sim(self, neural_networks):
        start_t = time.time()
        self.sim.gen_sim()

        if self.initial is True:
            #if the initial sim, run until the offset time reached
            self.initial = False
            self.sim.run_offset(self.offset)
            print(
                str(self.idx) + ' train  waiting at offset ------------- ' +
                str(self.offset) + ' at ' + str(get_time_now()))
            write_to_log(' ACTOR #' + str(self.idx) +
                         ' FINISHED RUNNING OFFSET ' + str(self.offset) +
                         ' to time ' + str(self.sim.t) +
                         ' , WAITING FOR OTHER OFFSETS...')
            self.barrier.wait()
            print(
                str(self.idx) + ' train  broken offset =================== ' +
                str(self.offset) + ' at ' + str(get_time_now()))
            write_to_log(' ACTOR #' + str(self.idx) +
                         '  BROKEN OFFSET BARRIER...')

        self.sim.create_tsc(self.rl_stats, self.exp_replays, self.eps,
                            neural_networks)
        write_to_log('ACTOR #' + str(self.idx) + '  START RUN SIM...')
        self.sim.run()
        print('sim finished in ' + str(time.time() - start_t) + ' on proc ' +
              str(self.idx))
        write_to_log('ACTOR #' + str(self.idx) + '  FINISHED SIM...')
예제 #2
0
 def __init__(self, idx, args, barrier, netdata, agent_ids, rl_stats,
              exp_replay):
     Process.__init__(self)
     self.idx = idx
     self.args = args
     self.barrier = barrier
     self.netdata = netdata
     self.agent_ids = agent_ids
     self.rl_stats = rl_stats
     self.exp_replay = exp_replay
     self.save_t = 0
     self.replay_fp = self.args.save_replay + '/' + self.args.tsc + '/'
     #for saving agent progress
     if self.idx == 0:
         path = 'tmp/'
         check_and_make_dir(path)
         now = get_time_now()
         self.updates_path = path + str(
             self.args.tsc) + '_' + str(now) + '_agent_updates.csv'
         self.replay_path = path + str(
             self.args.tsc) + '_' + str(now) + '_agent_replay.csv'
         self.n_exp_path = path + str(
             self.args.tsc) + '_' + str(now) + '_agent_nexp.csv'
         self.tsc_ids = list(sorted(list(self.netdata['inter'].keys())))
         #write header line with tsc names
         write_line_to_file(self.updates_path, 'a+',
                            ','.join([now] + self.tsc_ids))
         write_line_to_file(self.replay_path, 'a+',
                            ','.join([now] + self.tsc_ids))
         write_line_to_file(self.n_exp_path, 'a+',
                            ','.join([now] + self.tsc_ids))
def main():
    start = time.time()

    args = parse_cl_args()

    #get hyperparams for command line supplied tsc
    tsc_str = args.tsc
    hp_dict = get_hp_dict(tsc_str)
    hp_order = sorted(list(hp_dict.keys()))

    hp_list = [hp_dict[hp] for hp in hp_order]
    #use itertools to produce cartesian product of hyperparams
    hp_set = list(itertools.product(*hp_list))
    print(str(len(hp_set))+' total hyper params')

    #where to find metrics
    hp_travel_times = {}
    metrics_fp = 'metrics/'+tsc_str

    #where to print hp results
    path = 'hyperparams/'+tsc_str+'/'
    check_and_make_dir(path)
    fname = get_time_now()
    hp_fp = path+fname+'.csv'
    write_line_to_file(hp_fp, 'a+', ','.join(hp_order)+',mean,std,mean+std' )

    #run each set of hp from cartesian product
    for hp in hp_set:                                                                                                                                                                                                    
        hp_cmds = create_hp_cmds(args, hp_order, hp)
        #print(hp_cmds)
        for cmd in hp_cmds:
            os.system(cmd)
        #read travel times, store mean and std for determining best hp set
        hp_str = ','.join([str(h) for h in hp])
        travel_times = get_hp_results(metrics_fp+'/traveltime/')
        hp_travel_times[hp_str] = {'mean':int(np.mean(travel_times)), 'std':int(np.std(travel_times))}
        write_temp_hp(hp_str, hp_travel_times[hp_str], hp_fp)
        #generate_returns(tsc_str, 'metrics/', hp_str)
        save_hp_performance(travel_times, 'hp/'+tsc_str+'/', hp_str) 
        #remove all metrics for most recent hp
        shutil.rmtree(metrics_fp)

    #remove temp hp and write ranked final results
    os.remove(hp_fp)
    rank_hp(hp_travel_times, hp_order, tsc_str, hp_fp)
    print('All hyperparamers performance can be viewed at: '+str(hp_fp))

    print('TOTAL HP SEARCH TIME')
    secs = time.time()-start
    print(str(int(secs/60.0))+' minutes ')
예제 #4
0
    def write_sim_tsc_metrics(self):
        #get data dict of all tsc in sim
        #where each tsc has dict of all metrics
        tsc_metrics =  self.sim.get_tsc_metrics()
        #create file name and path for writing metrics data
        #now = datetime.datetime.now()
        #fname = str(self.idx)+'_'+str(now).replace(" ","-")
        fname = get_time_now()
        #write all metrics to correct path
        #path = 'metrics/'+str(self.args.tsc)
        path = 'metrics/'+str(self.args.tsc)
        for tsc in tsc_metrics:
            for m in tsc_metrics[tsc]:
                mpath = path + '/'+str(m)+'/'+str(tsc)+'/'
                check_and_make_dir(mpath)
                save_data(mpath+fname+'_'+str(self.eps)+'_.p', tsc_metrics[tsc][m])

        travel_times = self.sim.get_travel_times()
        path += '/traveltime/'
        check_and_make_dir(path)
        save_data(path+fname+'.p', travel_times)
예제 #5
0
 def write_n_exp_progress(self):
     n_replay = [str(self.rl_stats[i]['n_exp']) for i in self.tsc_ids]
     write_line_to_file( self.n_exp_path, 'a+', ','.join([get_time_now()]+n_replay) )
예제 #6
0
 def write_replay_progress(self):
     n_replay = [str(len(self.exp_replay[i])) for i in self.tsc_ids]
     write_line_to_file( self.replay_path, 'a+', ','.join([get_time_now()]+n_replay) )
예제 #7
0
 def write_training_progress(self):
     updates = [str(self.rl_stats[i]['updates']) for i in self.tsc_ids]
     write_line_to_file( self.updates_path, 'a+', ','.join([get_time_now()]+updates) )