From 3a9ce6fd6eb2e6bfe0ace6d3e36e5a173dfbdcef Mon Sep 17 00:00:00 2001 From: Sen Chao Date: Wed, 7 Sep 2022 15:28:33 +0800 Subject: [PATCH 1/5] Made stop method for uploading and experiment --- decanter_ai_sdk/client.py | 12 +++++++++++- decanter_ai_sdk/web_api/api.py | 8 ++++++++ decanter_ai_sdk/web_api/decanter_api.py | 23 +++++++++++++++++++++++ examples/iid_example.py | 5 +++-- examples/ts_example.py | 2 +- 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/decanter_ai_sdk/client.py b/decanter_ai_sdk/client.py index ea68f20..803ae60 100644 --- a/decanter_ai_sdk/client.py +++ b/decanter_ai_sdk/client.py @@ -520,6 +520,14 @@ def predict_ts( ) return prediction + def stop_uploading(self, id): + logging.info(self.api.stop_uploading(id)) + return + + def stop_training(self, id): + logging.info(self.api.stop_training(id)) + return + def wait_for_response(self, url, id): pbar = tqdm(total=100, desc=url + " task is now pending") progress = 0 @@ -530,7 +538,9 @@ def wait_for_response(self, url, id): raise RuntimeError(res["progress_message"]) if res["status"] == "running": - pbar.set_description("[" + url + "] " + res["progress_message"]) + pbar.set_description( + "[" + url + "] " + "id: " + id + " " + res["progress_message"] + ) pbar.update(int(float(res["progress"]) * 100) - progress) progress = int(float(res["progress"]) * 100) diff --git a/decanter_ai_sdk/web_api/api.py b/decanter_ai_sdk/web_api/api.py index 9754a05..621c1a8 100644 --- a/decanter_ai_sdk/web_api/api.py +++ b/decanter_ai_sdk/web_api/api.py @@ -42,3 +42,11 @@ def get_table(self, data_id): @abstractmethod def get_model_list(self, experiment_id, query): raise NotImplementedError + + @abstractmethod + def stop_uploading(self, id): + raise NotImplementedError + + @abstractmethod + def stop_training(self, id): + raise NotImplementedError diff --git a/decanter_ai_sdk/web_api/decanter_api.py b/decanter_ai_sdk/web_api/decanter_api.py index 7df1da4..7a82a58 100644 --- a/decanter_ai_sdk/web_api/decanter_api.py +++ b/decanter_ai_sdk/web_api/decanter_api.py @@ -147,3 +147,26 @@ def get_model_list(self, experiment_id, query): # pragma: no cover verify=False, ) return res.json()["model_list"] + + def stop_uploading(self, id): + res = requests.post( + f"{self.url}table/stop", + headers=self.auth_headers, + verify=False, + data={"table_id": id, "project_id": self.project_id}, + ) + if not res.ok: + return "This task has already stopped or doesn't exist." + return res.json()["message"] + + def stop_training(self, id): + res = requests.post( + f"{self.url}experiment/stop", + headers=self.auth_headers, + verify=False, + data={"experiment_id": id, "project_id": self.project_id}, + ) + if not res.ok: + return "This task has already stopped or doesn't exist." + else: + return res.json()["message"] diff --git a/examples/iid_example.py b/examples/iid_example.py index 3c844fe..864c650 100644 --- a/examples/iid_example.py +++ b/examples/iid_example.py @@ -1,3 +1,4 @@ +import sys from decanter_ai_sdk.client import Client import os from decanter_ai_sdk.enums.evaluators import ClassificationMetric @@ -16,11 +17,11 @@ def test_iid(): train_file_path = os.path.join(current_path, "../data/train.csv") train_file = open(train_file_path, "rb") - train_id = client.upload(train_file, "../data/test_file") + train_id = client.upload(train_file, "train_file") test_file_path = os.path.join(current_path, "../data/test.csv") test_file = open(test_file_path, "rb") - test_id = client.upload(test_file, "../data/test_file") + test_id = client.upload(test_file, "test_file") print("This will show top 2 uploaded table names and ids: \n") diff --git a/examples/ts_example.py b/examples/ts_example.py index dd678a1..13d900f 100644 --- a/examples/ts_example.py +++ b/examples/ts_example.py @@ -9,7 +9,7 @@ def test_iid(): auth_key = "" # TODO fill in real authorization key project_id = "" # TODO fill in real project id host = "" # TODO fill in real host - print("---From test iid---") + print("---From test ts---") client = Client(auth_key=auth_key, project_id=project_id, host=host) From 79b2f94457ccb6e7664319b7152c71b4a2c30361 Mon Sep 17 00:00:00 2001 From: Sen Chao Date: Wed, 7 Sep 2022 15:39:48 +0800 Subject: [PATCH 2/5] Made tests for stop methods --- decanter_ai_sdk/web_api/decanter_api.py | 4 ++-- decanter_ai_sdk/web_api/iid_testing_api.py | 6 ++++++ decanter_ai_sdk/web_api/ts_testing_api.py | 6 ++++++ tests/test_mock_iid.py | 4 ++++ tests/test_mock_ts.py | 4 ++++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/decanter_ai_sdk/web_api/decanter_api.py b/decanter_ai_sdk/web_api/decanter_api.py index 7a82a58..3e5682c 100644 --- a/decanter_ai_sdk/web_api/decanter_api.py +++ b/decanter_ai_sdk/web_api/decanter_api.py @@ -148,7 +148,7 @@ def get_model_list(self, experiment_id, query): # pragma: no cover ) return res.json()["model_list"] - def stop_uploading(self, id): + def stop_uploading(self, id): # pragma: no cover res = requests.post( f"{self.url}table/stop", headers=self.auth_headers, @@ -159,7 +159,7 @@ def stop_uploading(self, id): return "This task has already stopped or doesn't exist." return res.json()["message"] - def stop_training(self, id): + def stop_training(self, id): # pragma: no cover res = requests.post( f"{self.url}experiment/stop", headers=self.auth_headers, diff --git a/decanter_ai_sdk/web_api/iid_testing_api.py b/decanter_ai_sdk/web_api/iid_testing_api.py index fc400dd..d5d02d4 100644 --- a/decanter_ai_sdk/web_api/iid_testing_api.py +++ b/decanter_ai_sdk/web_api/iid_testing_api.py @@ -74,3 +74,9 @@ def get_model_list(self, experiment_id, query): f = open(current_path + "/data/model_list.json") model_list_data = json.load(f) return model_list_data + + def stop_uploading(self, id): + return "root:Table stop successful" + + def stop_training(self, id): + return "root:Experiment stop successful" diff --git a/decanter_ai_sdk/web_api/ts_testing_api.py b/decanter_ai_sdk/web_api/ts_testing_api.py index 656be02..d99619c 100644 --- a/decanter_ai_sdk/web_api/ts_testing_api.py +++ b/decanter_ai_sdk/web_api/ts_testing_api.py @@ -74,3 +74,9 @@ def get_model_list(self, experiment_id, query): f = open(current_path + "/data/model_list.json") model_list_data = json.load(f) return model_list_data + + def stop_uploading(self, id): + return "root:Table stop successful" + + def stop_training(self, id): + return "root:Experiment stop successful" diff --git a/tests/test_mock_iid.py b/tests/test_mock_iid.py index 10c8d50..eaf7756 100644 --- a/tests/test_mock_iid.py +++ b/tests/test_mock_iid.py @@ -22,6 +22,8 @@ def test_iid(): train_file = open(train_file_path, "rb") train_id = client.upload(train_file, "train_file") + client.stop_uploading(train_id) + test_file_path = os.path.join(current_path, "../data/test.csv") test_file = open(test_file_path, "rb") test_id = client.upload(test_file, "test_file") @@ -43,6 +45,8 @@ def test_iid(): }, ) + client.stop_training(experiment.id) + best_model = experiment.get_best_model() assert ( experiment.get_best_model_by_metric( diff --git a/tests/test_mock_ts.py b/tests/test_mock_ts.py index 19ed2f3..7856f30 100644 --- a/tests/test_mock_ts.py +++ b/tests/test_mock_ts.py @@ -23,6 +23,8 @@ def test_ts(): train_file_df = pd.read_csv(open(train_file_path, "rb")) train_id = client.upload(train_file_df, "train_file") + client.stop_uploading(train_id) + test_file_path = os.path.join(current_path, "../data/ts_test.csv") test_file = open(test_file_path, "rb") test_id = client.upload(test_file, "test_file") @@ -47,6 +49,8 @@ def test_ts(): custom_feature_types={"Pclass": DataType.numerical}, ) + client.stop_training(experiment.id) + best_model = experiment.get_best_model() for metric in RegressionMetric: From 2e33c5359fe7cc0b33a14284581c2dc498662122 Mon Sep 17 00:00:00 2001 From: Sen Chao Date: Mon, 12 Sep 2022 10:16:21 +0800 Subject: [PATCH 3/5] Revised stopping function and made some test cases --- decanter_ai_sdk/client.py | 14 ++++++++++---- decanter_ai_sdk/web_api/decanter_api.py | 9 ++------- decanter_ai_sdk/web_api/iid_testing_api.py | 8 ++++++-- decanter_ai_sdk/web_api/ts_testing_api.py | 8 ++++++-- tests/test_mock_iid.py | 2 ++ tests/test_mock_ts.py | 2 ++ 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/decanter_ai_sdk/client.py b/decanter_ai_sdk/client.py index 803ae60..93873cc 100644 --- a/decanter_ai_sdk/client.py +++ b/decanter_ai_sdk/client.py @@ -520,12 +520,18 @@ def predict_ts( ) return prediction - def stop_uploading(self, id): - logging.info(self.api.stop_uploading(id)) + def stop_uploading(self, id: str): + if self.api.stop_uploading(id): + logging.info("Uploading stopped successfully.") + else: + logging.info("This task has already stopped or doesn't exist.") return - def stop_training(self, id): - logging.info(self.api.stop_training(id)) + def stop_training(self, id: str): + if self.api.stop_training(id): + logging.info("Experiment stopped successfully.") + else: + logging.info("This task has already stopped or doesn't exist.") return def wait_for_response(self, url, id): diff --git a/decanter_ai_sdk/web_api/decanter_api.py b/decanter_ai_sdk/web_api/decanter_api.py index 3e5682c..55136bb 100644 --- a/decanter_ai_sdk/web_api/decanter_api.py +++ b/decanter_ai_sdk/web_api/decanter_api.py @@ -155,9 +155,7 @@ def stop_uploading(self, id): # pragma: no cover verify=False, data={"table_id": id, "project_id": self.project_id}, ) - if not res.ok: - return "This task has already stopped or doesn't exist." - return res.json()["message"] + return res.ok def stop_training(self, id): # pragma: no cover res = requests.post( @@ -166,7 +164,4 @@ def stop_training(self, id): # pragma: no cover verify=False, data={"experiment_id": id, "project_id": self.project_id}, ) - if not res.ok: - return "This task has already stopped or doesn't exist." - else: - return res.json()["message"] + return res.ok diff --git a/decanter_ai_sdk/web_api/iid_testing_api.py b/decanter_ai_sdk/web_api/iid_testing_api.py index d5d02d4..0e9abfa 100644 --- a/decanter_ai_sdk/web_api/iid_testing_api.py +++ b/decanter_ai_sdk/web_api/iid_testing_api.py @@ -76,7 +76,11 @@ def get_model_list(self, experiment_id, query): return model_list_data def stop_uploading(self, id): - return "root:Table stop successful" + if id == "": + return False + return True def stop_training(self, id): - return "root:Experiment stop successful" + if id == "": + return False + return True diff --git a/decanter_ai_sdk/web_api/ts_testing_api.py b/decanter_ai_sdk/web_api/ts_testing_api.py index d99619c..3d6146b 100644 --- a/decanter_ai_sdk/web_api/ts_testing_api.py +++ b/decanter_ai_sdk/web_api/ts_testing_api.py @@ -76,7 +76,11 @@ def get_model_list(self, experiment_id, query): return model_list_data def stop_uploading(self, id): - return "root:Table stop successful" + if id == "": + return False + return True def stop_training(self, id): - return "root:Experiment stop successful" + if id == "": + return False + return True diff --git a/tests/test_mock_iid.py b/tests/test_mock_iid.py index eaf7756..ac6934c 100644 --- a/tests/test_mock_iid.py +++ b/tests/test_mock_iid.py @@ -23,6 +23,7 @@ def test_iid(): train_id = client.upload(train_file, "train_file") client.stop_uploading(train_id) + client.stop_uploading("") test_file_path = os.path.join(current_path, "../data/test.csv") test_file = open(test_file_path, "rb") @@ -46,6 +47,7 @@ def test_iid(): ) client.stop_training(experiment.id) + client.stop_training("") best_model = experiment.get_best_model() assert ( diff --git a/tests/test_mock_ts.py b/tests/test_mock_ts.py index 7856f30..6fb6c57 100644 --- a/tests/test_mock_ts.py +++ b/tests/test_mock_ts.py @@ -24,6 +24,7 @@ def test_ts(): train_id = client.upload(train_file_df, "train_file") client.stop_uploading(train_id) + client.stop_uploading("") test_file_path = os.path.join(current_path, "../data/ts_test.csv") test_file = open(test_file_path, "rb") @@ -50,6 +51,7 @@ def test_ts(): ) client.stop_training(experiment.id) + client.stop_training("") best_model = experiment.get_best_model() From 0713584bc1b0e4206da1a278cb9a696f6945fe14 Mon Sep 17 00:00:00 2001 From: Sen Chao Date: Wed, 14 Sep 2022 15:34:30 +0800 Subject: [PATCH 4/5] add id infomation after stopping --- decanter_ai_sdk/client.py | 12 ++++++------ examples/iid_example.py | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/decanter_ai_sdk/client.py b/decanter_ai_sdk/client.py index 93873cc..47fea2d 100644 --- a/decanter_ai_sdk/client.py +++ b/decanter_ai_sdk/client.py @@ -520,19 +520,19 @@ def predict_ts( ) return prediction - def stop_uploading(self, id: str): + def stop_uploading(self, id: str) -> None: if self.api.stop_uploading(id): - logging.info("Uploading stopped successfully.") + logging.info("Uploading task: " + id + " stopped successfully.") else: logging.info("This task has already stopped or doesn't exist.") - return + return None - def stop_training(self, id: str): + def stop_training(self, id: str) -> None: if self.api.stop_training(id): - logging.info("Experiment stopped successfully.") + logging.info("Experiment: " + id + " stopped successfully.") else: logging.info("This task has already stopped or doesn't exist.") - return + return None def wait_for_response(self, url, id): pbar = tqdm(total=100, desc=url + " task is now pending") diff --git a/examples/iid_example.py b/examples/iid_example.py index 864c650..e0e3292 100644 --- a/examples/iid_example.py +++ b/examples/iid_example.py @@ -1,4 +1,3 @@ -import sys from decanter_ai_sdk.client import Client import os from decanter_ai_sdk.enums.evaluators import ClassificationMetric From c72ed1eeac5fb303d574d7877cc960b499cdcd87 Mon Sep 17 00:00:00 2001 From: Sen Chao Date: Wed, 21 Sep 2022 16:30:38 +0800 Subject: [PATCH 5/5] Added return type for stopping api methods. --- decanter_ai_sdk/web_api/decanter_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/decanter_ai_sdk/web_api/decanter_api.py b/decanter_ai_sdk/web_api/decanter_api.py index 55136bb..0275ffa 100644 --- a/decanter_ai_sdk/web_api/decanter_api.py +++ b/decanter_ai_sdk/web_api/decanter_api.py @@ -148,7 +148,7 @@ def get_model_list(self, experiment_id, query): # pragma: no cover ) return res.json()["model_list"] - def stop_uploading(self, id): # pragma: no cover + def stop_uploading(self, id) -> bool: # pragma: no cover res = requests.post( f"{self.url}table/stop", headers=self.auth_headers, @@ -157,7 +157,7 @@ def stop_uploading(self, id): # pragma: no cover ) return res.ok - def stop_training(self, id): # pragma: no cover + def stop_training(self, id) -> bool: # pragma: no cover res = requests.post( f"{self.url}experiment/stop", headers=self.auth_headers,