def run(self, use_gpu, learners, params_grid, dataset, result_file,
            out_dir):
        # dataset = get_dataset(self.name, dataset_dir)

        device_type = 'GPU' if use_gpu else 'CPU'

        for LearnerType in learners:
            learner = LearnerType(dataset, self.task, self.metric, use_gpu)

            algorithm_name = learner.name() + '-' + device_type
            print('Started to train ' + algorithm_name)

            for params in ParameterGrid(params_grid):
                params_str = params_to_str(params)
                log_file = os.path.join(out_dir, self.name, algorithm_name,
                                        params_str + '.log')

                print(f"\n===== {params_str} ...... ")

                hash_id = Track.hash(self.name, algorithm_name, self.task,
                                     params_str)
                if check_exists(hash_id, result_file):
                    print('Skipped: already evaluated')
                    continue

                #try:
                elapsed = learner.run(params, log_file)
                print('===== Timing: ' + str(elapsed) + ' sec')

                track = parse_log(algorithm_name, self.name, self.task,
                                  params_str, log_file, params['iterations'])
                update_result_file(track, result_file)
예제 #2
0
def json_from_logs(dir_name):
    results = {}
    for experiment_name in os.listdir(dir_name):
        if experiment_name not in EXPERIMENT_TYPE.keys():
            continue

        experiment_dir_name = os.path.join(dir_name, experiment_name)
        task_type = EXPERIMENT_TYPE[experiment_name][0]
        print(experiment_name + ' ' + task_type)
        results[experiment_name] = {}
        for algorithm_name in os.listdir(experiment_dir_name):
            print(algorithm_name)
            if algorithm_name not in ALGORITHMS:
                continue

            results[experiment_name][algorithm_name] = []
            cur_dir = os.path.join(experiment_dir_name, algorithm_name)
            for log_name in os.listdir(cur_dir):
                path = os.path.join(cur_dir, log_name)
                iterations_str = re.findall(r'iterations\[(\d+)\]', log_name)
                if not os.path.isfile(path) or len(iterations_str) != 1:
                    continue
                params_str = log_name.rstrip('.log')
                iterations = int(iterations_str[0])
                try:
                    track = parse_log(algorithm_name, experiment_name,
                                      task_type, params_str, path, iterations)
                except Exception as e:
                    print('Log for ' + path + ' is broken: ' + repr(e))
                    continue
                results[experiment_name][algorithm_name].append(track)
    return results
예제 #3
0
 def locate_cars(self):
     result = []
     for car_id in range(self.car_num):
         log_entries = log_parser.parse_log(f'logs/client{car_id}.log')
         log_entry = next(log_entry for log_entry in reversed(log_entries)
                          if isinstance(log_entry, log_parser.ArriveEntry)
                          or isinstance(log_entry, log_parser.MoveEntry))
         if isinstance(log_entry, log_parser.ArriveEntry):
             result.append([log_entry.pos])
         else:
             result.append([log_entry.from_pos, log_entry.to_pos])
     return result
예제 #4
0
import json
import log_parser


def calc_average_latency(logs):
    latencies = [
        log_entry.latency for log in logs for log_entry in log
        if isinstance(log_entry, log_parser.LatencyEntry)
    ]
    return sum(latencies) / len(latencies)


if __name__ == '__main__':
    config = json.load(open('config.json', 'r'))
    car_num = len(config['car_tasks'])

    logs = [
        log_parser.parse_log(f'logs/client{car_id}.log')
        for car_id in range(car_num)
    ]

    print(f'Average latency: {calc_average_latency(logs):.2f}ms')
예제 #5
0
import log_parser
import matplotlib.pyplot as plt
import matplotlib.animation as ani


if __name__ == '__main__':
    config = json.load(open('config.json', 'r'))
    row_num = config['row_num']
    col_num = config['col_num']
    car_tasks = config['car_tasks']
    car_num = len(car_tasks)

    frames = [
        (car_id, log_entry)
        for car_id in range(car_num)
        for log_entry in log_parser.parse_log(f'logs/client{car_id}.log')
    ]
    frames.sort(key=lambda frame: frame[1].dt)

    fig, ax = plt.subplots()
    ax.axis([-1, col_num, -1, row_num])
    
    for row_idx in range(row_num):
        ax.plot([0, col_num - 1], [row_idx, row_idx], color='black')
    for col_idx in range(col_num):
        ax.plot([col_idx, col_idx], [0, row_num - 1], color='black')
    
    annoations = [
        ax.annotate(
            str(car_id),
            car_task['src_pos'][::-1],