Skip to content

Commit

Permalink
Merge pull request #7921 from OpenMined/code_versioning
Browse files Browse the repository at this point in the history
Syft function versioning
  • Loading branch information
teo-milea authored Jul 31, 2023
2 parents a368b9a + 3ad38d9 commit 185c986
Show file tree
Hide file tree
Showing 14 changed files with 896 additions and 97 deletions.
2 changes: 1 addition & 1 deletion notebooks/api/0.8/00-load-data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.9.16"
},
"toc": {
"base_numbering": 1,
Expand Down
2 changes: 1 addition & 1 deletion notebooks/api/0.8/01-submit-code.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
"version": "3.9.16"
},
"toc": {
"base_numbering": 1,
Expand Down
2 changes: 1 addition & 1 deletion notebooks/api/0.8/03-data-scientist-download-result.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.9.16"
},
"toc": {
"base_numbering": 1,
Expand Down
297 changes: 297 additions & 0 deletions notebooks/api/0.8/08-code-version.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,297 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Using the Code History "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Import packages"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"SYFT_VERSION = \">=0.8.2.b0,<0.9\"\n",
"package_string = f'\"syft{SYFT_VERSION}\"'\n",
"%pip install {package_string} -f https://whls.blob.core.windows.net/unstable/index.html -q"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import syft as sy\n",
"sy.requires(SYFT_VERSION)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Launch a Syft Domain Server"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"node = sy.orchestra.launch(name=\"test-domain-1\", port=\"auto\", dev_mode=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# log into the node with default root credentials\n",
"domain_client = node.login(email=\"[email protected]\", password=\"changethis\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Create a new Data Scientist account on the Domain Server\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"domain_client.register(name=\"Jane Doe\", email=\"[email protected]\", password=\"abc123\", institution=\"Caltech\", website=\"https://www.caltech.edu/\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"jane_client = node.login(email=\"[email protected]\", password=\"abc123\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Create a UserCode"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# DS: Create function to submit to DO\n",
"@sy.syft_function(input_policy=sy.ExactMatch(),\n",
" output_policy=sy.SingleExecutionExactOutput())\n",
"def test_func():\n",
" return 1\n",
"test_func()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"jane_client.code.request_code_execution(code=test_func)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"jane_client.code"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Check Personal History"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"jane_client.code_history"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Submit new version"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# DS: Create function to submit to DO\n",
"@sy.syft_function(input_policy=sy.ExactMatch(),\n",
" output_policy=sy.SingleExecutionExactOutput())\n",
"def test_func():\n",
" return 2\n",
"test_func()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"jane_client.code.request_code_execution(code=test_func)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"jane_client.code_history.test_func"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Check History as an Admin"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"admin_client = node.login(email=\"[email protected]\", password=\"changethis\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"admin_client.code_histories"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"admin_client.code_histories['[email protected]']"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"admin_client.code_histories['[email protected]'].test_func[0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"test_func_history = admin_client.code_histories['[email protected]'].test_func"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"admin_client.code_histories['[email protected]'].test_func[-1]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# # Cleanup local domain server\n",
"if node.node_type.value == \"python\":\n",
" node.land()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": true
}
},
"nbformat": 4,
"nbformat_minor": 2
}
18 changes: 16 additions & 2 deletions packages/syft/src/syft/client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from ..service.response import SyftSuccess
from ..service.service import UserLibConfigRegistry
from ..service.service import UserServiceConfigRegistry
from ..service.user.user_roles import ServiceRole
from ..service.warnings import APIEndpointWarning
from ..service.warnings import WarningContext
from ..types.identity import Identity
Expand Down Expand Up @@ -393,6 +394,7 @@ class SyftAPI(SyftObject):
signing_key: Optional[SyftSigningKey] = None
# serde / storage rules
refresh_api_callback: Optional[Callable] = None
__user_role: ServiceRole = ServiceRole.NONE

# def __post_init__(self) -> None:
# pass
Expand Down Expand Up @@ -477,8 +479,13 @@ def for_user(
node_uid=node.id,
endpoints=endpoints,
lib_endpoints=lib_endpoints,
__user_role=role,
)

@property
def user_role(self) -> ServiceRole:
return self.__user_role

def make_call(self, api_call: SyftAPICall) -> Result:
signed_call = api_call.sign(credentials=self.signing_key)
signed_result = self.connection.make_call(signed_call)
Expand Down Expand Up @@ -729,11 +736,18 @@ def validate_callable_args_and_kwargs(args, kwargs, signature: Signature):
try:
if t is not inspect.Parameter.empty:
if isinstance(t, _GenericAlias) and type(None) in t.__args__:
success = False
for v in t.__args__:
if issubclass(v, EmailStr):
v = str
check_type(key, value, v) # raises Exception
break # only need one to match
try:
check_type(key, value, v) # raises Exception
success = True
break # only need one to match
except Exception: # nosec
pass
if not success:
raise TypeError()
else:
check_type(key, value, t) # raises Exception
except TypeError:
Expand Down
Loading

0 comments on commit 185c986

Please sign in to comment.