Skip to content

Commit

Permalink
Update mech_optimize.py
Browse files Browse the repository at this point in the history
Automatically set minimum time between plots when optimizing
  • Loading branch information
tsikes committed Mar 11, 2021
1 parent c177ed6 commit 4a6efa5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/optimize/mech_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ def __init__(self, parent):
# parent.threadpool.setMaxThreadCount(2) # Sets thread count to 1 (1 for gui - this is implicit, 1 for calc)
# log_txt = 'Multithreading with maximum {:d} threads\n'.format(parent.threadpool.maxThreadCount())
# parent.log.append(log_txt, alert=False)

self.time_between_plots = 0.01 # maximum update rate

# Set Distribution
self.dist = stats.gennorm
Expand All @@ -44,6 +42,7 @@ def start_threads(self):
parent.path_set.optimized_mech()

self.last_plot_timer = 0.0
self.time_between_plots = 0.0 # maximum update rate, updated based on time to plot

## Check fit_coeffs
#from optimize.fit_coeffs import debug
Expand Down Expand Up @@ -439,13 +438,19 @@ def update(self, result, writeLog=True):
self.parent.tree.update_coef_rate_from_opt(result['coef_opt'], result['x'])

if timer() - self.last_plot_timer > self.time_between_plots:
plot_start_time = timer()
# if displayed shock isn't in shocks being optimized, calculate the new plot
if result['ind_var'] is None and result['observable'] is None:
self.parent.run_single()
else: # if displayed shock in list being optimized, show result
self.parent.plot.signal.update_sim(result['ind_var'][:,0], result['observable'][:,0])
self.parent.plot.opt.update(result['stat_plot'])

# this keeps gui responsive, minimum time between plots = max time to plot*0.1
current_time_to_plot = timer() - plot_start_time
if current_time_to_plot*0.1 > self.time_between_plots:
self.time_between_plots = current_time_to_plot*0.1

self.last_plot_timer = timer()

def on_worker_progress(self, perc_completed, time_left):
Expand Down

0 comments on commit 4a6efa5

Please sign in to comment.