-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrun_experiments.py
122 lines (98 loc) · 4.41 KB
/
run_experiments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import multiprocessing
import sys
import os
# relative file paths
sim_folder = "DataSim"
experiments_folder = sim_folder + "/configs/experiments"
bt_pipeline_folder = "BehaviorTreeDev"
result_analysis_folder = "ResultAnalysis"
# local imports, uses hacky path additions
# sim imports
sys.path.append(os.path.join(os.path.dirname(__file__), '.', sim_folder))
# pipeline imports
sys.path.append(os.path.join(os.path.dirname(
__file__), '.', bt_pipeline_folder))
# result analysis imports
sys.path.append(os.path.join(os.path.dirname(
__file__), '.', result_analysis_folder))
# For Paths
from joblib import Parallel, delayed
import multiprocessing as mp
import glob
from multiprocessing import process
import argparse
import bt_sim
import run_pipeline
import json_manager
from json_manager import JsonManager
import run_results
json_file_path = "config.json"
output_file_path = "output.log"
should_recolor = run_multiprocess = run_original_bt_espresso = False
# global imports
def parse_args():
ap = argparse.ArgumentParser()
ap.add_argument("-c", "--config", required=False,
help="Name of experiment config json, without this flag it will recurse though all experiments")
ap.add_argument("-r", "--recolor", required=False,
action='store_true', help="Run recoloring of all trees")
ap.add_argument("-m", "--multiprocess", required=False,
action='store_true', help="Run experiments in ||")
ap.add_argument("-k", "--kevin", required=False,
action='store_true', help="Run w original BT-Espresso also")
args = vars(ap.parse_args())
json_file_path = None
if "config" in args and args["config"] != None:
json_file_path = args["config"]
should_recolor = "recolor" in args and args["recolor"] != None and args['recolor']
run_multiprocess = "multiprocess" in args and args["multiprocess"] != None and args['multiprocess']
run_original_bt_espresso = "kevin" in args and args["kevin"] != None and args['kevin']
return json_file_path, should_recolor, run_multiprocess, run_original_bt_espresso
# this should not be moved
base_pipeline_config = "DataSim/configs/base_pipeline_config.json"
should_recolor = False
run_original_bt_espresso = False
def main():
"""Runs the simulator and full pipeline end to end
'-c, --config' - [optional] Path to json config
"""
print("Start Experiments")
global experiments_folder, should_recolor, run_original_bt_espresso
single_experiment_filename, should_recolor, run_multiprocess, run_original_bt_espresso = parse_args()
if single_experiment_filename:
run_experiment(experiments_folder + "/" + single_experiment_filename)
else:
run_all_experiments(base_pipeline_config)
def run_all_experiments(run_multiprocess):
if run_multiprocess:
pool = multiprocessing.Pool()
for config_file in glob.glob(experiments_folder + "/*.json"):
pool.apply_async(run_experiment, [config_file])
pool.close()
pool.join()
else:
for config_file in glob.glob(experiments_folder + "/*.json"):
run_experiment(config_file)
print("Finished all experiments")
def run_experiment(experiment_file):
global base_pipeline_config, should_recolor, run_original_bt_espresso
sim_data_output_path, sim_tree_name = bt_sim.run_sim(experiment_file)
pipeline_config_path = write_pipeline_config(
base_pipeline_config, sim_data_output_path, sim_data_output_path + "output")
bt_tree_filepath_list = run_pipeline.run_pipeline(
pipeline_config_path, should_recolor, sim_data_output_path + "fmt.log", run_original_bt_espresso)
simulated_tree_file = sim_data_output_path + sim_tree_name + ".dot"
bt_tree_filepath_list.insert(0, simulated_tree_file)
run_results.run_result_list(bt_tree_filepath_list[:-1], run_original_bt_espresso) # removes the tree with nothing in it / final prune
def write_pipeline_config(base_pipeline_config, sim_data_output_path, output_folder):
jm = JsonManager(base_pipeline_config)
jm.set_csv_path(sim_data_output_path)
jm.set_output_path(output_folder)
jm.set_normalized_path(output_folder)
jm.set_upsampled_path(output_folder)
jm.set_hot_encoded_path(output_folder)
pipeline_config_path = sim_data_output_path + "pipeline_config.json"
jm.write_out_json_to_file(pipeline_config_path)
return pipeline_config_path
if __name__ == '__main__':
main()