From 7b12b8eceaa5f742e3453bd75d8caa3e69b8c703 Mon Sep 17 00:00:00 2001 From: TSikes <50559900+tsikes@users.noreply.github.com> Date: Mon, 8 Nov 2021 11:47:03 -0600 Subject: [PATCH] Working on Bug Fix New bug with RBFopt when using as executable. Working on fixing. (command window is flashing each iteration) --- src/calculate/optimize/optimize_worker.py | 42 +++++++++++++++-------- src/main.py | 2 +- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/calculate/optimize/optimize_worker.py b/src/calculate/optimize/optimize_worker.py index 334d74e..3d9141e 100644 --- a/src/calculate/optimize/optimize_worker.py +++ b/src/calculate/optimize/optimize_worker.py @@ -384,24 +384,36 @@ def rbfopt(self, x0, bnds, options): # noisy, cheap function option. supports d max_time = options['stop_criteria_val']*60 var_type = ['R']*np.size(x0) # specifies that all variables are continious - bb = rbfopt.RbfoptUserBlackBox(np.size(x0), np.array(bnds[0]), np.array(bnds[1]), - np.array(var_type), self.obj_fcn) - settings = rbfopt.RbfoptSettings(max_iterations=max_eval, - max_evaluations=max_eval, - max_cycles=1E30, - max_clock_time=max_time, - minlp_solver_path=path['bonmin'], - nlp_solver_path=path['ipopt']) - algo = rbfopt.RbfoptAlgorithm(settings, bb, init_node_pos=x0) - val, x, itercount, evalcount, fast_evalcount = algo.optimize() + + output = {'success': False, 'message': []} + # Intialize and report any problems to log, not to console window + stdout = io.StringIO() + stderr = io.StringIO() + with contextlib.redirect_stderr(stderr): + with contextlib.redirect_stdout(stdout): + bb = rbfopt.RbfoptUserBlackBox(np.size(x0), np.array(bnds[0]), np.array(bnds[1]), + np.array(var_type), self.obj_fcn) + settings = rbfopt.RbfoptSettings(max_iterations=max_eval, + max_evaluations=max_eval, + max_cycles=1E30, + max_clock_time=max_time, + minlp_solver_path=path['bonmin'], + nlp_solver_path=path['ipopt']) + algo = rbfopt.RbfoptAlgorithm(settings, bb, init_node_pos=x0) + val, x, itercount, evalcount, fast_evalcount = algo.optimize() - obj_fcn, x, shock_output = self.Scaled_Fit_Fun(x, optimizing=False) + obj_fcn, x, shock_output = self.Scaled_Fit_Fun(x, optimizing=False) + + output['message'] = 'Optimization terminated successfully.' + output['success'] = True - msg = 'Optimization terminated successfully.' - success = True - + ct_out = stdout.getvalue() + ct_err = stderr.getvalue() + + print(ct_out) + # opt.last_optimum_value() is the same as optimal obj_fcn res = {'x': x, 'shock': shock_output, 'fval': obj_fcn, 'nfev': evalcount + fast_evalcount, - 'success': success, 'message': msg, 'time': timer() - timer_start} + 'success': output['success'], 'message': output['message'], 'time': timer() - timer_start} return res \ No newline at end of file diff --git a/src/main.py b/src/main.py index 06988dc..b54c9e1 100644 --- a/src/main.py +++ b/src/main.py @@ -5,7 +5,7 @@ # and licensed under BSD-3-Clause. See License.txt in the top-level # directory for license and copyright information. -version = '1.2.10' +version = '1.3.0' import os, sys, platform, multiprocessing, pathlib # os.environ['QT_API'] = 'pyside2' # forces pyside2