def _f_calc(x_list: np.ndarray, extra_data: bool = False) -> float: out_of_range = False for index in range(dimension): if x_list[index] < min_list[index] or x_list[index] > max_list[ index]: print("Warning: {} = {} is out of range [{}, {}].".format( label_list[index], x_list[index], min_list[index], max_list[index], )) out_of_range = True for index in range(dimension): x_list[index] /= unit_list[index] y = float("inf") if not out_of_range: step[0] += 1 set = 1 if extra_data else 0 message = py2dmat.Message(x_list, step[0], set) y = run.submit(message) if not extra_data: callback = step for index in range(dimension): callback.append(x_list[index]) callback.append(y) callback_list.append(callback) return y
def __call__(self, action: np.ndarray) -> float: a = int(action[0]) message = py2dmat.Message(mesh_list[a, 1:], a, 0) fx = runner.submit(message) fx_list.append(fx) param_list.append(mesh_list[a]) return -fx
def submit( self, message: py2dmat.Message, nprocs: int = 1, nthreads: int = 1 ) -> float: x = self.mapping(message.x) message_indeed = py2dmat.Message(x, message.step, message.set) self.solver.prepare(message_indeed) cwd = os.getcwd() os.chdir(self.solver.work_dir) self.solver.run(nprocs, nthreads) os.chdir(cwd) result = self.solver.get_results() self.logger.count(message, result) return result
def _evaluate(self, in_range: np.ndarray = None) -> np.ndarray: """evaluate current "Energy"s ``self.fx`` will be overwritten with the result Parameters ========== run_info: dict Parameter set. Some parameters will be overwritten. """ for iwalker in range(self.nwalkers): x = self.x[iwalker, :] if in_range is None or in_range[iwalker]: message = py2dmat.Message(x, self.istep, iwalker) time_sta = time.perf_counter() self.fx[iwalker] = self.runner.submit(message) time_end = time.perf_counter() self.timer["run"]["submit"] += time_end - time_sta else: self.fx[iwalker] = np.inf return self.fx
def _run(self) -> None: # Make ColorMap label_list = self.label_list dimension = self.dimension run = self.runner print("Make ColorMap") with open("ColorMap.txt", "w") as file_CM: fx_list = [] time_sta = time.perf_counter() file_CM.write("#") for label in label_list: file_CM.write(f"{label} ") file_CM.write("fval\n") time_end = time.perf_counter() self.timer["run"]["file_CM"] = time_end - time_sta self.timer["run"]["submit"] = 0.0 message = py2dmat.Message([], 0, 0) iterations = len(self.mesh_list) for iteration_count, mesh in enumerate(self.mesh_list): print("Iteration : {}/{}".format(iteration_count + 1, iterations)) print("mesh before:", mesh) time_sta = time.perf_counter() for value in mesh[1:]: file_CM.write("{:8f} ".format(value)) time_end = time.perf_counter() self.timer["run"]["file_CM"] += time_end - time_sta # update information message.step = int(mesh[0]) message.x = mesh[1:] time_sta = time.perf_counter() fx = run.submit(message) time_end = time.perf_counter() self.timer["run"]["submit"] += time_end - time_sta fx_list.append(fx) time_sta = time.perf_counter() file_CM.write("{:8f}\n".format(fx)) time_end = time.perf_counter() self.timer["run"]["file_CM"] += time_end - time_sta print("mesh after:", mesh) fx_order = np.argsort(fx_list) minimum_point = [] print("mesh_list[fx_order[0]]:") print(self.mesh_list[fx_order[0]]) for index in range(1, dimension + 1): minimum_point.append(self.mesh_list[fx_order[0]][index]) time_sta = time.perf_counter() file_CM.write("#Minimum point :") for value in minimum_point: file_CM.write(" {:8f}".format(value)) file_CM.write("\n") file_CM.write("#R-factor : {:8f}\n".format(fx_list[fx_order[0]])) file_CM.write("#see Log{}\n".format(round(self.mesh_list[fx_order[0]][0]))) time_end = time.perf_counter() self.timer["run"]["file_CM"] += time_end - time_sta print( "complete main process : rank {:08d}/{:08d}".format( self.mpirank, self.mpisize ) )