From 507a905a688a099a0ae1e1dc66c67f952b1b2295 Mon Sep 17 00:00:00 2001 From: Ionesio Junior Date: Fri, 12 Jan 2024 10:49:10 -0300 Subject: [PATCH 01/10] Fix job.wait() api to allow it to wait for subjobs --- packages/syft/src/syft/service/job/job_stash.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/syft/src/syft/service/job/job_stash.py b/packages/syft/src/syft/service/job/job_stash.py index 982b9f502ad..72e185ef796 100644 --- a/packages/syft/src/syft/service/job/job_stash.py +++ b/packages/syft/src/syft/service/job/job_stash.py @@ -375,7 +375,7 @@ def _repr_markdown_(self) -> str: """ return as_markdown_code(md) - def wait(self): + def wait(self, subjobs=False): # stdlib from time import sleep @@ -388,8 +388,12 @@ def wait(self): if self.resolved: return self.resolve + if subjobs: + self.result.wait() + return self.resolve + print_warning = True - while True: + while not subjobs and True: self.fetch() if print_warning: result_obj = api.services.action.get( From 47a7cc2106944691d3dd08dc830a73d897075af3 Mon Sep 17 00:00:00 2001 From: Ionesio Junior Date: Fri, 12 Jan 2024 15:18:07 -0300 Subject: [PATCH 02/10] Rename job.wait() block flag / Remove unused conditional --- packages/syft/src/syft/service/job/job_stash.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/syft/src/syft/service/job/job_stash.py b/packages/syft/src/syft/service/job/job_stash.py index 72e185ef796..7223adc48b2 100644 --- a/packages/syft/src/syft/service/job/job_stash.py +++ b/packages/syft/src/syft/service/job/job_stash.py @@ -375,7 +375,7 @@ def _repr_markdown_(self) -> str: """ return as_markdown_code(md) - def wait(self, subjobs=False): + def wait(self, block=False): # stdlib from time import sleep @@ -388,12 +388,12 @@ def wait(self, subjobs=False): if self.resolved: return self.resolve - if subjobs: + if block: self.result.wait() return self.resolve print_warning = True - while not subjobs and True: + while True: self.fetch() if print_warning: result_obj = api.services.action.get( @@ -403,7 +403,7 @@ def wait(self, subjobs=False): print( "You're trying to wait on a job that has a link as a result." "This means that the job may be ready but the linked result may not." - "Use job.result.wait() instead to wait for the linked result." + "Use job.wait(subjobs=True) instead to wait for the linked result." ) print_warning = False sleep(2) From e851761e3eccf9557f7e963018e274e9b140ddfb Mon Sep 17 00:00:00 2001 From: Ionesio Junior Date: Fri, 12 Jan 2024 15:22:58 -0300 Subject: [PATCH 03/10] Fix warning message --- packages/syft/src/syft/service/job/job_stash.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/syft/src/syft/service/job/job_stash.py b/packages/syft/src/syft/service/job/job_stash.py index 7223adc48b2..318d750180e 100644 --- a/packages/syft/src/syft/service/job/job_stash.py +++ b/packages/syft/src/syft/service/job/job_stash.py @@ -403,7 +403,7 @@ def wait(self, block=False): print( "You're trying to wait on a job that has a link as a result." "This means that the job may be ready but the linked result may not." - "Use job.wait(subjobs=True) instead to wait for the linked result." + "Use job.wait(block=True) instead to wait for the linked result." ) print_warning = False sleep(2) From b1c144704ae45c3c73f298fdd8634248a889b0b0 Mon Sep 17 00:00:00 2001 From: Ionesio Junior Date: Fri, 12 Jan 2024 15:24:54 -0300 Subject: [PATCH 04/10] Update tests --- packages/syft/tests/syft/syft_functions/syft_function_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/syft/tests/syft/syft_functions/syft_function_test.py b/packages/syft/tests/syft/syft_functions/syft_function_test.py index 2016b68d990..125523dbc96 100644 --- a/packages/syft/tests/syft/syft_functions/syft_function_test.py +++ b/packages/syft/tests/syft/syft_functions/syft_function_test.py @@ -93,4 +93,4 @@ def process_all(domain, x): sub_results = [j.wait().get() for j in job.subjobs] assert set(sub_results) == {2, 3, 5} - assert job.result.wait().get() == 5 + assert job.wait(block=True).get() == 5 From 2749fb7d59d6497034f17e1c8c3602b2ed165f7d Mon Sep 17 00:00:00 2001 From: Ionesio Junior Date: Sat, 20 Jan 2024 17:29:47 -0300 Subject: [PATCH 05/10] ADD block optiona flag in actionObject.get() --- packages/syft/src/syft/service/action/action_object.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/syft/src/syft/service/action/action_object.py b/packages/syft/src/syft/service/action/action_object.py index 3b1e7286f38..93f19bf8428 100644 --- a/packages/syft/src/syft/service/action/action_object.py +++ b/packages/syft/src/syft/service/action/action_object.py @@ -1089,11 +1089,14 @@ def get_from(self, client: SyftClient) -> Any: else: return res.syft_action_data - def get(self) -> Any: + def get(self, block: bool = False) -> Any: """Get the object from a Syft Client""" # relative from ...client.api import APIRegistry + if block: + self.wait() + api = APIRegistry.api_for( node_uid=self.syft_node_location, user_verify_key=self.syft_client_verify_key, From 28150cd9f3117563b07926a2f9dbf6fcd0a74585 Mon Sep 17 00:00:00 2001 From: Ionesio Junior Date: Sat, 20 Jan 2024 17:30:12 -0300 Subject: [PATCH 06/10] Remove block option from job.wait() --- packages/syft/src/syft/service/job/job_stash.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/syft/src/syft/service/job/job_stash.py b/packages/syft/src/syft/service/job/job_stash.py index de9a4803d0a..5d1588d3207 100644 --- a/packages/syft/src/syft/service/job/job_stash.py +++ b/packages/syft/src/syft/service/job/job_stash.py @@ -431,7 +431,7 @@ def _repr_markdown_(self) -> str: """ return as_markdown_code(md) - def wait(self, block=False): + def wait(self): # stdlib from time import sleep @@ -444,10 +444,6 @@ def wait(self, block=False): if self.resolved: return self.resolve - if block: - self.result.wait() - return self.resolve - print_warning = True while True: self.fetch() From d1f7ce726e152e8530614d265480a8e8e6ce6333 Mon Sep 17 00:00:00 2001 From: Ionesio Junior Date: Sat, 20 Jan 2024 17:30:51 -0300 Subject: [PATCH 07/10] Update syft function tests to reflect the last changes --- .../syft/tests/syft/syft_functions/syft_function_test.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/syft/tests/syft/syft_functions/syft_function_test.py b/packages/syft/tests/syft/syft_functions/syft_function_test.py index 97f38e3a585..c89742cd177 100644 --- a/packages/syft/tests/syft/syft_functions/syft_function_test.py +++ b/packages/syft/tests/syft/syft_functions/syft_function_test.py @@ -93,10 +93,11 @@ def process_all(domain, x): assert len(job.subjobs) == 3 # stdlib - + + assert job.result.get(block=True) == 5 sub_results = [j.wait().get() for j in job.subjobs] assert set(sub_results) == {2, 3, 5} - assert job.wait(block=True).get() == 5 + job = client.jobs[-1] - assert job.job_worker_id is not None \ No newline at end of file + assert job.job_worker_id is not None From 8f0237094828cfa8e802d466efc17cb21b9c06d6 Mon Sep 17 00:00:00 2001 From: Ionesio Junior Date: Sat, 20 Jan 2024 18:30:01 -0300 Subject: [PATCH 08/10] Fix linting --- packages/syft/tests/syft/syft_functions/syft_function_test.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/syft/tests/syft/syft_functions/syft_function_test.py b/packages/syft/tests/syft/syft_functions/syft_function_test.py index c89742cd177..b1d32f7a160 100644 --- a/packages/syft/tests/syft/syft_functions/syft_function_test.py +++ b/packages/syft/tests/syft/syft_functions/syft_function_test.py @@ -93,11 +93,10 @@ def process_all(domain, x): assert len(job.subjobs) == 3 # stdlib - + assert job.result.get(block=True) == 5 sub_results = [j.wait().get() for j in job.subjobs] assert set(sub_results) == {2, 3, 5} - job = client.jobs[-1] assert job.job_worker_id is not None From 411f3e49577cf59f1b2acd49daf8a22c16a94799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=C3=A9sio=20Junior?= Date: Mon, 22 Jan 2024 08:11:20 -0300 Subject: [PATCH 09/10] Update job_stash.py Change the warning message for the job.wait --- packages/syft/src/syft/service/job/job_stash.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/syft/src/syft/service/job/job_stash.py b/packages/syft/src/syft/service/job/job_stash.py index 5d1588d3207..47a5a1f2604 100644 --- a/packages/syft/src/syft/service/job/job_stash.py +++ b/packages/syft/src/syft/service/job/job_stash.py @@ -455,7 +455,7 @@ def wait(self): print( "You're trying to wait on a job that has a link as a result." "This means that the job may be ready but the linked result may not." - "Use job.wait(block=True) instead to wait for the linked result." + "Use job.wait().get(block=True) instead to wait for the linked result." ) print_warning = False sleep(2) From d07666987e07238005dd6d2423bb1cf679ef6bbe Mon Sep 17 00:00:00 2001 From: Koen van der Veen Date: Wed, 24 Jan 2024 13:39:55 +0100 Subject: [PATCH 10/10] add job_only arg --- packages/syft/src/syft/service/job/job_stash.py | 9 ++++++--- .../syft/tests/syft/syft_functions/syft_function_test.py | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/syft/src/syft/service/job/job_stash.py b/packages/syft/src/syft/service/job/job_stash.py index 43f8de55955..efa03deac94 100644 --- a/packages/syft/src/syft/service/job/job_stash.py +++ b/packages/syft/src/syft/service/job/job_stash.py @@ -409,7 +409,7 @@ def _repr_markdown_(self) -> str: """ return as_markdown_code(md) - def wait(self): + def wait(self, job_only=False): # stdlib from time import sleep @@ -422,6 +422,9 @@ def wait(self): if self.resolved: return self.resolve + if not job_only: + self.result.wait() + print_warning = True while True: self.fetch() @@ -429,11 +432,11 @@ def wait(self): result_obj = api.services.action.get( self.result.id, resolve_nested=False ) - if isinstance(result_obj.syft_action_data, ActionDataLink): + if isinstance(result_obj.syft_action_data, ActionDataLink) and job_only: print( "You're trying to wait on a job that has a link as a result." "This means that the job may be ready but the linked result may not." - "Use job.wait().get(block=True) instead to wait for the linked result." + "Use job.wait().get() instead to wait for the linked result." ) print_warning = False sleep(2) diff --git a/packages/syft/tests/syft/syft_functions/syft_function_test.py b/packages/syft/tests/syft/syft_functions/syft_function_test.py index b1d32f7a160..c5819fe245a 100644 --- a/packages/syft/tests/syft/syft_functions/syft_function_test.py +++ b/packages/syft/tests/syft/syft_functions/syft_function_test.py @@ -94,7 +94,7 @@ def process_all(domain, x): assert len(job.subjobs) == 3 # stdlib - assert job.result.get(block=True) == 5 + assert job.wait().get() == 5 sub_results = [j.wait().get() for j in job.subjobs] assert set(sub_results) == {2, 3, 5}