Skip to content

Commit

Permalink
Clearing of optimization plots at the start of each opt run
Browse files Browse the repository at this point in the history
  • Loading branch information
mlauer154 committed Sep 8, 2023
1 parent bd96d02 commit ee98f4c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
49 changes: 27 additions & 22 deletions pymead/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1309,8 +1309,30 @@ def progress_update(self, status: str, data: object):
background_color=bcolor)
callback.exec_callback()

def clear_opt_plots(self):
def clear_handles(h_list: list):
for h in h_list:
if isinstance(h, list):
for h_ in h:
h_.clear()
else:
h.clear()
h_list.clear()

for handle_list in [self.opt_airfoil_plot_handles, self.parallel_coords_plot_handles,
self.Cp_graph_plot_handles]:
clear_handles(handle_list)

if self.drag_graph is not None:
for Cd_val in ["Cd", "Cdp", "Cdv", "Cdw", "Cdf"]:
if hasattr(self.drag_graph, f"pg_plot_handle_{Cd_val}"):
handle = getattr(self.drag_graph, f"pg_plot_handle_{Cd_val}")
handle.clear()

def run_shape_optimization(self, param_dict: dict, opt_settings: dict, mea: dict, objectives, constraints):

self.clear_opt_plots()

def run_cpu_bound_process():
shape_opt_process = CPUBoundProcess(
shape_optimization_static,
Expand All @@ -1321,37 +1343,20 @@ def run_cpu_bound_process():
shape_opt_process.start()
self.shape_opt_process = shape_opt_process

# Start running the CPU-bound process from a worker thread (separate from the main GUI thread)
thread = Thread(target=run_cpu_bound_process)
self.opt_thread = thread
self.opt_thread.start()

# TODO: make sure thread.join() is run following premature optimization termination.
# TODO: follow this same code architecture for XFOIL and MSES one-off analysis

def stop_optimization(self):
# if self.pool is not None:
# self.pool.terminate()
# if self.closer is not None:
# self.output_area_text(self.closer)
# self.output_area_text("\n")
# self.closer = None
# self.output_area_text("Optimization terminated. ")
# self.output_area_text(self.generate_output_folder_link_text(self.current_opt_folder), mode="html")
# self.pool = None
# self.current_opt_folder = None
# print(f"Terminating! {self.shape_opt_process = }, {self.shape_opt_process.term_event = }")

# Close the Pipe, which triggers either an immediate termination of the worker process or a termination of the
# Pool after the next CFD evaluation completes, depending on the progress of the optimization.
self.shape_opt_process.parent_conn.close()
self.shape_opt_process.child_conn.close()
# if self.shape_opt_process is not None:
# try:
# # self.shape_opt_process.progress_emitter.signals.progress.emit("terminate", None)
# # self.shape_opt_process.progress_emitter.conn.send(("terminate", None))
# # self.shape_opt_process.term_event.set()
# # print(f"{self.shape_opt_process.term_event.is_set()}")
# self.shape_opt_process.terminate()
# except BrokenPipeError: # This probably does not actually do anything since the BrokenPipe is in another
# # thread
# pass

if self.opt_thread is not None:
self.opt_thread.join()

Expand Down
2 changes: 0 additions & 2 deletions pymead/optimization/opt_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ def exec_callback(self):
self.parent.output_area_text(f"{self.generate_closer(len(t))}")
self.parent.output_area_text("\n")

# TODO: fix plotting of MSES or XFOIL optimization results after a previous optimization was completed (need to clear the plots)


class PlotAirfoilCallback(OptCallback):
def __init__(self, parent, coords: list, background_color: str = 'w'):
Expand Down
1 change: 0 additions & 1 deletion pymead/optimization/shape_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ def send_over_pipe(data: object):
best_in_previous_generation = True

if best_in_previous_generation:
# TODO: need to make new forces_dict and overwrite for each generation because this can lead to a KeyError
for k, v in forces_dict.items():
if k not in forces_dict.keys():
forces_dict[k] = []
Expand Down

0 comments on commit ee98f4c

Please sign in to comment.