| @@ -85,9 +85,7 @@ def get_split_errs(algo): | |||||
| split = train_xs.shape[0] - proportion_list[tmp] | split = train_xs.shape[0] - proportion_list[tmp] | ||||
| model.fit( | model.fit( | ||||
| train_xs[ | |||||
| split:, | |||||
| ], | |||||
| train_xs[split:,], | |||||
| train_ys[split:], | train_ys[split:], | ||||
| eval_set=[(val_xs, val_ys)], | eval_set=[(val_xs, val_ys)], | ||||
| early_stopping_rounds=50, | early_stopping_rounds=50, | ||||
| @@ -127,18 +127,16 @@ class LearnwaresContainer: | |||||
| ) | ) | ||||
| for _learnware, _zippath in zip(learnware_list, learnware_zippaths) | for _learnware, _zippath in zip(learnware_list, learnware_zippaths) | ||||
| ] | ] | ||||
| # We should first register the destroy method | # We should first register the destroy method | ||||
| atexit.register(self.cleanup) | atexit.register(self.cleanup) | ||||
| self.init_env() | self.init_env() | ||||
| def init_env(self): | def init_env(self): | ||||
| model_list = [_learnware.get_model() for _learnware in self.learnware_list] | model_list = [_learnware.get_model() for _learnware in self.learnware_list] | ||||
| with ProcessPoolExecutor(max_workers=max(os.cpu_count() // 2, 1)) as executor: | with ProcessPoolExecutor(max_workers=max(os.cpu_count() // 2, 1)) as executor: | ||||
| executor.map(self._initialize_model_container, model_list) | executor.map(self._initialize_model_container, model_list) | ||||
| def cleanup(self): | def cleanup(self): | ||||
| for _learnware in self.learnware_list: | for _learnware in self.learnware_list: | ||||
| self._destroy_model_container(_learnware.get_model()) | self._destroy_model_container(_learnware.get_model()) | ||||
| @@ -148,17 +146,14 @@ class LearnwaresContainer: | |||||
| try: | try: | ||||
| model.init_env_and_metadata() | model.init_env_and_metadata() | ||||
| except Exception as err: | except Exception as err: | ||||
| logger.warning(f"build env {model.conda_env} failed due to {err}") | |||||
| logger.warning(f"build env {model.conda_env} failed due to {err}") | |||||
| @staticmethod | @staticmethod | ||||
| def _destroy_model_container(model: ModelEnvContainer): | def _destroy_model_container(model: ModelEnvContainer): | ||||
| try: | try: | ||||
| model.remove_env() | model.remove_env() | ||||
| except Exception as err: | except Exception as err: | ||||
| logger.warning(f"remove env {model.conda_env} failed due to {err}") | |||||
| logger.warning(f"remove env {model.conda_env} failed due to {err}") | |||||
| def get_learnware_list_with_container(self): | def get_learnware_list_with_container(self): | ||||
| return self.learnware_list | return self.learnware_list | ||||
| @@ -1 +1 @@ | |||||
| from .module import get_semantic_specification | |||||
| from .module import get_semantic_specification | |||||
| @@ -1,5 +1,3 @@ | |||||
| def get_semantic_specification(): | def get_semantic_specification(): | ||||
| semantic_specification = dict() | semantic_specification = dict() | ||||
| semantic_specification["Data"] = {"Type": "Class", "Values": ["Text"]} | semantic_specification["Data"] = {"Type": "Class", "Values": ["Text"]} | ||||
| @@ -8,4 +6,4 @@ def get_semantic_specification(): | |||||
| semantic_specification["Scenario"] = {"Type": "Tag", "Values": "Financial"} | semantic_specification["Scenario"] = {"Type": "Tag", "Values": "Financial"} | ||||
| semantic_specification["Name"] = {"Type": "String", "Values": "test"} | semantic_specification["Name"] = {"Type": "String", "Values": "test"} | ||||
| semantic_specification["Description"] = {"Type": "String", "Values": "test"} | semantic_specification["Description"] = {"Type": "String", "Values": "test"} | ||||
| return semantic_specification | |||||
| return semantic_specification | |||||
| @@ -3,7 +3,7 @@ from learnware.test import get_semantic_specification | |||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||
| semantic_specification = get_semantic_specification() | semantic_specification = get_semantic_specification() | ||||
| zip_path = "test.zip" | zip_path = "test.zip" | ||||
| client = LearnwareClient() | client = LearnwareClient() | ||||
| client.install_environment(zip_path) | client.install_environment(zip_path) | ||||
| @@ -24,7 +24,7 @@ class TestLearnwareLoad(unittest.TestCase): | |||||
| self.zip_paths = [os.path.join(root, x) for x in ["1.zip", "2.zip", "3.zip"]] | self.zip_paths = [os.path.join(root, x) for x in ["1.zip", "2.zip", "3.zip"]] | ||||
| def test_load_single_learnware_by_zippath(self): | def test_load_single_learnware_by_zippath(self): | ||||
| for (learnware_id, zip_path) in zip(self.learnware_ids, self.zip_paths): | |||||
| for learnware_id, zip_path in zip(self.learnware_ids, self.zip_paths): | |||||
| self.client.download_learnware(learnware_id, zip_path) | self.client.download_learnware(learnware_id, zip_path) | ||||
| learnware_list = [ | learnware_list = [ | ||||
| @@ -39,7 +39,7 @@ class TestLearnwareLoad(unittest.TestCase): | |||||
| print(learnware.id, learnware.predict(input_array)) | print(learnware.id, learnware.predict(input_array)) | ||||
| def test_load_multi_learnware_by_zippath(self): | def test_load_multi_learnware_by_zippath(self): | ||||
| for (learnware_id, zip_path) in zip(self.learnware_ids, self.zip_paths): | |||||
| for learnware_id, zip_path in zip(self.learnware_ids, self.zip_paths): | |||||
| self.client.download_learnware(learnware_id, zip_path) | self.client.download_learnware(learnware_id, zip_path) | ||||
| learnware_list = self.client.load_learnware(learnware_path=self.zip_paths, runnable_option="conda_env") | learnware_list = self.client.load_learnware(learnware_path=self.zip_paths, runnable_option="conda_env") | ||||
| @@ -7,7 +7,6 @@ from learnware.learnware.reuse import AveragingReuser | |||||
| from learnware.test.module import get_semantic_specification | from learnware.test.module import get_semantic_specification | ||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||
| semantic_specification = get_semantic_specification() | semantic_specification = get_semantic_specification() | ||||
| zip_paths = [ | zip_paths = [ | ||||
| "/home/bixd/workspace/learnware/Learnware/tests/test_learnware_client/rf_tic.zip", | "/home/bixd/workspace/learnware/Learnware/tests/test_learnware_client/rf_tic.zip", | ||||
| @@ -70,7 +70,7 @@ class TestAllWorkflow(unittest.TestCase): | |||||
| env_file = os.path.join(dir_path, "environment.yaml") | env_file = os.path.join(dir_path, "environment.yaml") | ||||
| copyfile(os.path.join(curr_root, "learnware_example/environment.yaml"), env_file) | copyfile(os.path.join(curr_root, "learnware_example/environment.yaml"), env_file) | ||||
| zip_file = dir_path + ".zip" | zip_file = dir_path + ".zip" | ||||
| # zip -q -r -j zip_file dir_path | # zip -q -r -j zip_file dir_path | ||||
| with zipfile.ZipFile(zip_file, "w") as zip_obj: | with zipfile.ZipFile(zip_file, "w") as zip_obj: | ||||