Skip to content

Commit

Permalink
Merge pull request #9001 from OpenMined/rename_unsafe_function
Browse files Browse the repository at this point in the history
Rename 'unsafe_function' to 'run'
  • Loading branch information
IonesioJunior committed Jul 2, 2024
2 parents 0b8e366 + 6cfcc52 commit be0deb9
Show file tree
Hide file tree
Showing 15 changed files with 25 additions and 19 deletions.
4 changes: 2 additions & 2 deletions notebooks/api/0.8/02-review-code-and-approve.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@
"outputs": [],
"source": [
"# Let's grab the actual executable function that was submitted by the user\n",
"users_function = func.unsafe_function"
"users_function = func.run"
]
},
{
Expand Down Expand Up @@ -501,7 +501,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
"version": "3.12.4"
},
"toc": {
"base_numbering": 1,
Expand Down
4 changes: 2 additions & 2 deletions notebooks/api/0.8/05-custom-policy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@
},
"outputs": [],
"source": [
"result = func.unsafe_function(x=x_pointer)\n",
"result = func.run(x=x_pointer)\n",
"result"
]
},
Expand Down Expand Up @@ -626,7 +626,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
"version": "3.12.4"
},
"toc": {
"base_numbering": 1,
Expand Down
2 changes: 1 addition & 1 deletion notebooks/tutorials/hello-syft/01-hello-syft.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@
"metadata": {},
"outputs": [],
"source": [
"get_mean_age_user_function = usercode.unsafe_function"
"get_mean_age_user_function = usercode.run"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion notebooks/tutorials/model-auditing/colab/01-user-log.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@
"metadata": {},
"outputs": [],
"source": [
"real_result = request.code.unsafe_function(data=asset.data)\n",
"real_result = request.code.run(data=asset.data)\n",
"real_result"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
"metadata": {},
"outputs": [],
"source": [
"users_function = user_code.unsafe_function\n",
"users_function = user_code.run\n",
"users_function"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@
},
"outputs": [],
"source": [
"get_col_user_function = func.unsafe_function"
"get_col_user_function = func.run"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@
},
"outputs": [],
"source": [
"get_counts_user_func = func.unsafe_function"
"get_counts_user_func = func.run"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@
},
"outputs": [],
"source": [
"get_counts_user_func = func.unsafe_function"
"get_counts_user_func = func.run"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@
},
"outputs": [],
"source": [
"get_col_user_function = func.unsafe_function"
"get_col_user_function = func.run"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@
},
"outputs": [],
"source": [
"get_col_user_function = func.unsafe_function"
"get_col_user_function = func.run"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@
},
"outputs": [],
"source": [
"get_col_user_function = func.unsafe_function"
"get_col_user_function = func.run"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@
},
"outputs": [],
"source": [
"zip_codes = func.unsafe_function"
"zip_codes = func.run"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@
},
"outputs": [],
"source": [
"find_recently_installed = func.unsafe_function"
"find_recently_installed = func.run"
]
},
{
Expand Down
10 changes: 8 additions & 2 deletions packages/syft/src/syft/service/code/user_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
from ...types.uid import UID
from ...util import options
from ...util.colors import SURFACE
from ...util.decorators import deprecated
from ...util.markdown import CodeMarkdown
from ...util.markdown import as_markdown_code
from ...util.util import prompt_warning_message
Expand Down Expand Up @@ -808,7 +809,7 @@ def get_sync_dependencies(
return dependencies

@property
def unsafe_function(self) -> Callable | None:
def run(self) -> Callable | None:
warning = SyftWarning(
message="This code was submitted by a User and could be UNSAFE."
)
Expand Down Expand Up @@ -850,10 +851,15 @@ def wrapper(*args: Any, **kwargs: Any) -> Callable | SyftError:
# return the results
return result
except Exception as e:
return SyftError(f"Failed to run unsafe_function. Error: {e}")
return SyftError(f"Failed to execute 'run'. Error: {e}")

return wrapper

@property
@deprecated(reason="Use 'run' instead")
def unsafe_function(self) -> Callable | None:
return self.run

def _inner_repr(self, level: int = 0) -> str:
shared_with_line = ""
if len(self.output_readers) > 0 and self.output_reader_names is not None:
Expand Down
4 changes: 2 additions & 2 deletions packages/syft/tests/syft/users/user_code_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_user_code(worker) -> None:
message = root_domain_client.notifications[-1]
request = message.link
user_code = request.changes[0].code
result = user_code.unsafe_function()
result = user_code.run()
request.approve()

result = guest_client.api.services.code.mock_syft_func()
Expand Down Expand Up @@ -355,7 +355,7 @@ def compute_sum():
message = root_domain_client.notifications[-1]
request = message.link
user_code = request.changes[0].code
result = user_code.unsafe_function()
result = user_code.run()
request.approve()

result = ds_client.api.services.code.compute_sum()
Expand Down

0 comments on commit be0deb9

Please sign in to comment.