| @@ 80-128 (lines=49) @@ | ||
| 77 | self._load_data_into_memory(para, score) |
|
| 78 | self.n_dims = len(para.columns) |
|
| 79 | ||
| 80 | def save_memory(self, _main_args_, _opt_args_, _cand_): |
|
| 81 | path = self._get_file_path(_cand_.func_) |
|
| 82 | meta_data = self._collect(_cand_) |
|
| 83 | ||
| 84 | meta_data["run"] = self.datetime |
|
| 85 | self._save_toCSV(meta_data, path) |
|
| 86 | ||
| 87 | obj_func_path = self.func_path + "objective_function.py" |
|
| 88 | if not os.path.exists(obj_func_path): |
|
| 89 | file = open(obj_func_path, "w") |
|
| 90 | file.write(self._get_func_str(_cand_.func_)) |
|
| 91 | file.close() |
|
| 92 | ||
| 93 | search_config_path = self.date_path + "search_config.py" |
|
| 94 | search_config_temp = dict(self._main_args_.search_config) |
|
| 95 | ||
| 96 | for key in search_config_temp.keys(): |
|
| 97 | if isinstance(key, str): |
|
| 98 | continue |
|
| 99 | search_config_temp[key.__name__] = search_config_temp[key] |
|
| 100 | del search_config_temp[key] |
|
| 101 | ||
| 102 | search_config_str = "search_config = " + str(search_config_temp) |
|
| 103 | ||
| 104 | if not os.path.exists(search_config_path): |
|
| 105 | file = open(search_config_path, "w") |
|
| 106 | file.write(search_config_str) |
|
| 107 | file.close() |
|
| 108 | ||
| 109 | """ |
|
| 110 | os.chdir(self.date_path) |
|
| 111 | os.system("black search_config.py") |
|
| 112 | os.getcwd() |
|
| 113 | """ |
|
| 114 | ||
| 115 | run_data = { |
|
| 116 | "random_state": self._main_args_.random_state, |
|
| 117 | "max_time": self._main_args_.random_state, |
|
| 118 | "n_iter": self._main_args_.n_iter, |
|
| 119 | "optimizer": self._main_args_.optimizer, |
|
| 120 | "n_jobs": self._main_args_.n_jobs, |
|
| 121 | "eval_time": np.array(_cand_.eval_time).sum(), |
|
| 122 | "total_time": _cand_.total_time, |
|
| 123 | } |
|
| 124 | ||
| 125 | with open(self.date_path + "run_data.json", "w") as f: |
|
| 126 | json.dump(run_data, f, indent=4) |
|
| 127 | ||
| 128 | """ |
|
| 129 | print("_opt_args_.kwargs_opt", _opt_args_.kwargs_opt) |
|
| 130 | ||
| 131 | opt_para = pd.DataFrame.from_dict(_opt_args_.kwargs_opt, dtype=object) |
|
| @@ 78-126 (lines=49) @@ | ||
| 75 | self._load_data_into_memory(para, score) |
|
| 76 | self.n_dims = len(para.columns) |
|
| 77 | ||
| 78 | def save_memory(self, _main_args_, _opt_args_, _cand_): |
|
| 79 | path = self._get_file_path(_cand_.func_) |
|
| 80 | meta_data = self._collect(_cand_) |
|
| 81 | ||
| 82 | meta_data["run"] = self.datetime |
|
| 83 | self._save_toCSV(meta_data, path) |
|
| 84 | ||
| 85 | obj_func_path = self.func_path + "objective_function.py" |
|
| 86 | if not os.path.exists(obj_func_path): |
|
| 87 | file = open(obj_func_path, "w") |
|
| 88 | file.write(self._get_func_str(_cand_.func_)) |
|
| 89 | file.close() |
|
| 90 | ||
| 91 | search_config_path = self.date_path + "search_config.py" |
|
| 92 | search_config_temp = dict(self._main_args_.search_config) |
|
| 93 | ||
| 94 | for key in search_config_temp.keys(): |
|
| 95 | if isinstance(key, str): |
|
| 96 | continue |
|
| 97 | search_config_temp[key.__name__] = search_config_temp[key] |
|
| 98 | del search_config_temp[key] |
|
| 99 | ||
| 100 | search_config_str = "search_config = " + str(search_config_temp) |
|
| 101 | ||
| 102 | if not os.path.exists(search_config_path): |
|
| 103 | file = open(search_config_path, "w") |
|
| 104 | file.write(search_config_str) |
|
| 105 | file.close() |
|
| 106 | ||
| 107 | """ |
|
| 108 | os.chdir(self.date_path) |
|
| 109 | os.system("black search_config.py") |
|
| 110 | os.getcwd() |
|
| 111 | """ |
|
| 112 | ||
| 113 | run_data = { |
|
| 114 | "random_state": self._main_args_.random_state, |
|
| 115 | "max_time": self._main_args_.random_state, |
|
| 116 | "n_iter": self._main_args_.n_iter, |
|
| 117 | "optimizer": self._main_args_.optimizer, |
|
| 118 | "n_jobs": self._main_args_.n_jobs, |
|
| 119 | "eval_time": np.array(_cand_.eval_time).sum(), |
|
| 120 | "total_time": _cand_.total_time, |
|
| 121 | } |
|
| 122 | ||
| 123 | with open(self.date_path + "run_data.json", "w") as f: |
|
| 124 | json.dump(run_data, f, indent=4) |
|
| 125 | ||
| 126 | """ |
|
| 127 | print("_opt_args_.kwargs_opt", _opt_args_.kwargs_opt) |
|
| 128 | ||
| 129 | opt_para = pd.DataFrame.from_dict(_opt_args_.kwargs_opt, dtype=object) |
|