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
from math import pi
import yaml
import time
import matplotlib.pyplot as plt
import decmcts
import greedy
......@@ -18,7 +19,8 @@ def batch_run(
output_stats_file,
plan_save_dir,
nth_layer,
mcts_nodes_per_layer):
mcts_nodes_per_layer,
retries=3):
"""
runs various planning algos on multiple gcode files
"""
......@@ -42,75 +44,85 @@ def batch_run(
tracker = tu.get_tracker(model)
stats[model] = {}
stats[model]['every_nth_layer'] = nth_layer
notes.write("Running Dec-MCTS planner\n")
try:
s_time = time.time()
plan = decmcts.decmcts(
env,
tracker,
nth_layer=nth_layer,
nodes_per_layer=mcts_nodes_per_layer
)
e_time = time.time()
notes.write("Dec-MCTS plan successfully created, saving plan and stats\n")
plan.save(plan_save_dir + "/" + model + "_decmcts.plan")
stats[model]['decmcts'] = \
{'total_time': str(plan.len()),
'print_time': str(plan.extrusion_time()),
'planning_time': e_time - s_time,
'status': 'SUCCESS'}
except:
stats[model]['decmcts'] = {'status': 'FAILED'}
notes.write("FAILED TO COMPLETE DEC_MCTS ON MODEL {}\n".format(model))
notes.write("Running Dec-MCTS planner\n")
r = retries
while r:
try:
s_time = time.time()
plan = decmcts.decmcts(
env,
tracker,
nth_layer=nth_layer,
nodes_per_layer=mcts_nodes_per_layer
)
e_time = time.time()
notes.write("Dec-MCTS plan successfully created, saving plan and stats\n")
plan.save(plan_save_dir + "/" + model + "_decmcts.plan")
stats[model]['decmcts'] = \
{'total_time': str(plan.len()),
'print_time': str(plan.extrusion_time()),
'planning_time': e_time - s_time,
'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")
try:
s_time = time.time()
plan = greedy.greedy(
env,
tracker,
nth_layer=nth_layer
)
e_time = time.time()
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()),
'print_time': str(plan.extrusion_time()),
'planning_time': e_time - s_time,
'status': 'SUCCESS'}
except:
stats[model]['greedy'] = {'status': 'FAILED'}
notes.write("FAILED TO COMPLETE GREEDY ON MODEL {}\n".format(model))
r = retries
while r:
try:
s_time = time.time()
plan = greedy.greedy(
env,
tracker,
nth_layer=nth_layer
)
e_time = time.time()
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()),
'print_time': str(plan.extrusion_time()),
'planning_time': e_time - s_time,
'status': 'SUCCESS'}
r = False
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")
try:
s_time = time.time()
plan = zoneblocking.zoneblocking(
env,
tracker,
nth_layer=nth_layer
)
e_time = time.time()
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()),
'print_time': str(plan.extrusion_time()),
'planning_time': e_time - s_time,
'status': 'SUCCESS'}
except:
stats[model]['zoneblocking'] = {'status': 'FAILED'}
notes.write("FAILED TO COMPLETE ZONE BLOCKING ON MODEL {}\n".format(model))
r = retries
while r:
try:
s_time = time.time()
plan = zoneblocking.zoneblocking(
env,
tracker,
nth_layer=nth_layer
)
e_time = time.time()
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()),
'print_time': str(plan.extrusion_time()),
'planning_time': e_time - s_time,
'status': 'SUCCESS'}
r = False
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))
notes.close()
......@@ -118,6 +130,49 @@ def batch_run(
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__':
# get model names to process
......@@ -126,11 +181,11 @@ if __name__ == '__main__':
for i in range(len(models)):
models[i] = models[i][:-1]
batch_run(
models,
'bulk.log',
'bulk.stats',
'plans',
50,
2000)
# batch_run(
# models,
# 'bulk.log',
# 'bulk.stats',
# 'plans',
# 50,
# 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