Skip to content

Commit

Permalink
Merge pull request #7955 from OpenMined/propagate-results-enclaves
Browse files Browse the repository at this point in the history
propagate outputs to shareholders on enclaves
  • Loading branch information
koenvanderveen authored Jul 20, 2023
2 parents c2b73d7 + 3e5e606 commit 6e9b90b
Show file tree
Hide file tree
Showing 11 changed files with 313 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.2"
"version": "3.9.16"
},
"toc": {
"base_numbering": 1,
Expand Down
66 changes: 62 additions & 4 deletions notebooks/tutorials/enclaves/Enclave-single-notebook-DO-DS.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@
"metadata": {},
"outputs": [],
"source": [
"@sy.syft_function_single_use(canada_census_data=canada_census_data, italy_census_data=italy_census_data)\n",
"@sy.syft_function_single_use(canada_census_data=canada_census_data, italy_census_data=italy_census_data, share_results_with_owners=True)\n",
"def compute_census_matches(canada_census_data, italy_census_data):\n",
" import recordlinkage\n",
" \n",
Expand Down Expand Up @@ -543,10 +543,20 @@
"metadata": {},
"outputs": [],
"source": [
"for st in status.base_dict.values():\n",
"for st in status.status_dict.values():\n",
" assert st == sy.service.request.request.UserCodeStatus.EXECUTE"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "43538640",
"metadata": {},
"outputs": [],
"source": [
"ds_enclave_proxy_client.code[-1].output_policy"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -601,10 +611,58 @@
"assert real_result == 813"
]
},
{
"cell_type": "markdown",
"id": "0c186d96",
"metadata": {},
"source": [
"# DO"
]
},
{
"cell_type": "markdown",
"id": "92a07f21",
"metadata": {},
"source": [
"## Can also get the result"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0a0cc302",
"metadata": {},
"outputs": [],
"source": [
"request = do_ca_client.requests[0]\n",
"request"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bc567390",
"metadata": {},
"outputs": [],
"source": [
"result_ptr = request.get_results()\n",
"result_ptr"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c3715aa1",
"metadata": {},
"outputs": [],
"source": [
"assert result_ptr.syft_action_data == 813"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c7e8c775-400a-46ce-ba3c-58ca0563621e",
"id": "1beca4ac",
"metadata": {},
"outputs": [],
"source": []
Expand All @@ -626,7 +684,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.9.16"
},
"toc": {
"base_numbering": 1,
Expand Down
2 changes: 2 additions & 0 deletions packages/syft/src/syft/client/domain_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ def data_subject_registry(self) -> Optional[APIModule]:

@property
def code(self) -> Optional[APIModule]:
# if self.api.refresh_api_callback is not None:
# self.api.refresh_api_callback()
if self.api.has_service("code"):
return self.api.services.code
return None
Expand Down
4 changes: 3 additions & 1 deletion packages/syft/src/syft/client/enclave_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ def request_code_execution(self, code: SubmitUserCode):
apis += [api]

for api in apis:
api.services.code.request_code_execution(code=code)
res = api.services.code.request_code_execution(code=code)
if isinstance(res, SyftError):
return res

# we are using the real method here, see the .code property getter
_ = self.code
Expand Down
12 changes: 12 additions & 0 deletions packages/syft/src/syft/service/action/action_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
from .action_object import ActionType
from .action_object import AnyActionObject
from .action_object import TwinMode
from .action_permissions import ActionObjectPermission
from .action_permissions import ActionObjectREAD
from .action_permissions import ActionPermission
from .action_store import ActionStore
from .action_types import action_type_for_type
from .numpy import NumpyArrayObject
Expand Down Expand Up @@ -211,8 +213,18 @@ def _user_code_execute(
syft_object=result_action_object,
has_result_read_permission=True,
)

if set_result.is_err():
return set_result.err()

if len(code_item.output_policy.output_readers) > 0:
self.store.add_permissions(
[
ActionObjectPermission(result_id, ActionPermission.READ, x)
for x in code_item.output_policy.output_readers
]
)

return Ok(result_action_object)

def execute_plan(
Expand Down
Loading

0 comments on commit 6e9b90b

Please sign in to comment.