Commit 3dc49d8c authored by Jayant Khatkar's avatar Jayant Khatkar
Browse files

add retries and plotting (#64)

parent 4914ee93
...@@ -4,6 +4,7 @@ import os ...@@ -4,6 +4,7 @@ import os
from math import pi from math import pi
import yaml import yaml
import time import time
import matplotlib.pyplot as plt
import decmcts import decmcts
import greedy import greedy
...@@ -18,7 +19,8 @@ def batch_run( ...@@ -18,7 +19,8 @@ def batch_run(
output_stats_file, output_stats_file,
plan_save_dir, plan_save_dir,
nth_layer, nth_layer,
mcts_nodes_per_layer): mcts_nodes_per_layer,
retries=3):
""" """
runs various planning algos on multiple gcode files runs various planning algos on multiple gcode files
""" """
...@@ -42,75 +44,85 @@ def batch_run( ...@@ -42,75 +44,85 @@ def batch_run(
tracker = tu.get_tracker(model) tracker = tu.get_tracker(model)
stats[model] = {} stats[model] = {}
stats[model]['every_nth_layer'] = nth_layer stats[model]['every_nth_layer'] = nth_layer
notes.write("Running Dec-MCTS planner\n")
try: notes.write("Running Dec-MCTS planner\n")
s_time = time.time() r = retries
plan = decmcts.decmcts( while r:
env, try:
tracker, s_time = time.time()
nth_layer=nth_layer, plan = decmcts.decmcts(
nodes_per_layer=mcts_nodes_per_layer env,
) tracker,
e_time = time.time() nth_layer=nth_layer,
nodes_per_layer=mcts_nodes_per_layer
notes.write("Dec-MCTS plan successfully created, saving plan and stats\n") )
plan.save(plan_save_dir + "/" + model + "_decmcts.plan") e_time = time.time()
stats[model]['decmcts'] = \ notes.write("Dec-MCTS plan successfully created, saving plan and stats\n")
{'total_time': str(plan.len()), plan.save(plan_save_dir + "/" + model + "_decmcts.plan")
'print_time': str(plan.extrusion_time()),
'planning_time': e_time - s_time, stats[model]['decmcts'] = \
'status': 'SUCCESS'} {'total_time': str(plan.len()),
except: 'print_time': str(plan.extrusion_time()),
stats[model]['decmcts'] = {'status': 'FAILED'} 'planning_time': e_time - s_time,
notes.write("FAILED TO COMPLETE DEC_MCTS ON MODEL {}\n".format(model)) 'status': 'SUCCESS'}
r = False
except:
stats[model]['decmcts'] = {'status': 'FAILED'}
notes.write("FAILED TO COMPLETE DEC_MCTS ON MODEL {}\n".format(model))
r-=1
notes.write("Running Greedy planner\n") notes.write("Running Greedy planner\n")
r = retries
try: while r:
s_time = time.time() try:
plan = greedy.greedy( s_time = time.time()
env, plan = greedy.greedy(
tracker, env,
nth_layer=nth_layer tracker,
) nth_layer=nth_layer
e_time = time.time() )
e_time = time.time()
notes.write("Greedy plan successfully created, saving plan and stats\n")
plan.save(plan_save_dir + "/" + model + "_greedy.plan") notes.write("Greedy plan successfully created, saving plan and stats\n")
plan.save(plan_save_dir + "/" + model + "_greedy.plan")
stats[model]['greedy'] = \
{'total_time': str(plan.len()), stats[model]['greedy'] = \
'print_time': str(plan.extrusion_time()), {'total_time': str(plan.len()),
'planning_time': e_time - s_time, 'print_time': str(plan.extrusion_time()),
'status': 'SUCCESS'} 'planning_time': e_time - s_time,
except: 'status': 'SUCCESS'}
stats[model]['greedy'] = {'status': 'FAILED'} r = False
notes.write("FAILED TO COMPLETE GREEDY ON MODEL {}\n".format(model)) except:
stats[model]['greedy'] = {'status': 'FAILED'}
notes.write("FAILED TO COMPLETE GREEDY ON MODEL {}\n".format(model))
r-=1
notes.write("Running Zone Blocking planner\n") notes.write("Running Zone Blocking planner\n")
r = retries
try: while r:
s_time = time.time() try:
plan = zoneblocking.zoneblocking( s_time = time.time()
env, plan = zoneblocking.zoneblocking(
tracker, env,
nth_layer=nth_layer tracker,
) nth_layer=nth_layer
e_time = time.time() )
e_time = time.time()
notes.write("Zone blocking plan successfully created, saving plan and stats\n")
plan.save(plan_save_dir + "/" + model + "_zoneblocking.plan") notes.write("Zone blocking plan successfully created, saving plan and stats\n")
plan.save(plan_save_dir + "/" + model + "_zoneblocking.plan")
stats[model]['zoneblocking'] = \
{'total_time': str(plan.len()), stats[model]['zoneblocking'] = \
'print_time': str(plan.extrusion_time()), {'total_time': str(plan.len()),
'planning_time': e_time - s_time, 'print_time': str(plan.extrusion_time()),
'status': 'SUCCESS'} 'planning_time': e_time - s_time,
except: 'status': 'SUCCESS'}
stats[model]['zoneblocking'] = {'status': 'FAILED'} r = False
notes.write("FAILED TO COMPLETE ZONE BLOCKING ON MODEL {}\n".format(model)) except:
stats[model]['zoneblocking'] = {'status': 'FAILED'}
notes.write("FAILED TO COMPLETE ZONE BLOCKING ON MODEL {}\n".format(model))
r-=1
stat_file.write(yaml.dump(stats)) stat_file.write(yaml.dump(stats))
notes.close() notes.close()
...@@ -118,6 +130,49 @@ def batch_run( ...@@ -118,6 +130,49 @@ def batch_run(
return return
def plot_comparison(stats_file, algo1='greedy', algo2='decmcts'):
"""
Read the stats file of a bulk run and plot it's results
"""
# read data
with open(stats_file, 'r') as f:
stats = yaml.load(f)
# unroll data into x,y
x = [] # algo1
y = [] # algo2
label = []
for model in stats:
if algo1 in stats[model] and algo2 in stats[model]:
label.append(model)
x.append(float(stats[model][algo1]['print_time'])/float(stats[model][algo1]['total_time']))
y.append(float(stats[model][algo2]['print_time'])/float(stats[model][algo2]['total_time']))
# plot
print(x)
print(y)
plt.scatter(x,y)
plt.plot([0,2],[0,2], color='r')
plt.ylabel(algo2)
plt.xlabel(algo1)
# plt.axis('equal')
plt.xlim(0,2)
plt.ylim(0,2)
plt.gca().set_aspect('equal', adjustable='box')
i = 0
for xi,yi in zip(x,y):
plt.annotate(label[i],
(xi,yi),
textcoords="offset points",
xytext=(0,2),
ha='left',
fontsize=7)
i+=1
plt.show()
if __name__ == '__main__': if __name__ == '__main__':
# get model names to process # get model names to process
...@@ -126,11 +181,11 @@ if __name__ == '__main__': ...@@ -126,11 +181,11 @@ if __name__ == '__main__':
for i in range(len(models)): for i in range(len(models)):
models[i] = models[i][:-1] models[i] = models[i][:-1]
# batch_run(
batch_run( # models,
models, # 'bulk.log',
'bulk.log', # 'bulk.stats',
'bulk.stats', # 'plans',
'plans', # 50,
50, # 2000)
2000) plot_comparison("bulk.stats")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment