Skip to content

Commit

Permalink
Merge pull request #7734 from OpenMined/small_ux_addons
Browse files Browse the repository at this point in the history
Some Small changes
  • Loading branch information
koenvanderveen authored Jun 15, 2023
2 parents 520419f + c9384b9 commit 27a2560
Show file tree
Hide file tree
Showing 11 changed files with 215 additions and 45 deletions.
3 changes: 1 addition & 2 deletions notebooks/api/0.8/01-submit-code.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@
},
"outputs": [],
"source": [
"@sy.syft_function(input_policy=sy.ExactMatch(trade_data=asset),\n",
" output_policy=sy.SingleExecutionExactOutput())\n",
"@sy.syft_function_single_use(trade_data=asset)\n",
"def sum_trade_value_mil(trade_data):\n",
" import pandas as pd\n",
" from opendp.mod import enable_features\n",
Expand Down
42 changes: 21 additions & 21 deletions packages/hagrid/hagrid/manifest_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ files:
grid:
path: packages/grid/
common:
- rabbitmq/rabbitmq.conf
- redis/redis.conf
- seaweedfs/filer.toml
- seaweedfs/s3config.json
- vpn/config.yaml
- rabbitmq/rabbitmq.conf
- redis/redis.conf
- seaweedfs/filer.toml
- seaweedfs/s3config.json
- vpn/config.yaml
docker:
- default.env
- docker-compose.build.yml
- docker-compose.dev.yml
- docker-compose.pull.yml
- docker-compose.test.yml
- docker-compose.tls.yml
- docker-compose.yml
- traefik/docker/dynamic-tls.yml
- traefik/docker/dynamic.yml
- traefik/docker/traefik-tls.template.yml
- traefik/docker/traefik.yml
- vpn/headscale.dockerfile
- vpn/tailscale.dockerfile
- default.env
- docker-compose.build.yml
- docker-compose.dev.yml
- docker-compose.pull.yml
- docker-compose.test.yml
- docker-compose.tls.yml
- docker-compose.yml
- traefik/docker/dynamic-tls.yml
- traefik/docker/dynamic.yml
- traefik/docker/traefik-tls.template.yml
- traefik/docker/traefik.yml
- vpn/headscale.dockerfile
- vpn/tailscale.dockerfile
k8s:
- devspace.yaml
- traefik/k8s/dynamic.yml
- traefik/k8s/traefik.yml
- devspace.yaml
- traefik/k8s/dynamic.yml
- traefik/k8s/traefik.yml
5 changes: 3 additions & 2 deletions packages/syft/src/syft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
from .service.action.action_object import ActionObject # noqa: F401
from .service.action.plan import Plan # noqa: F401
from .service.action.plan import planify # noqa: F401
from .service.code.user_code import UserCodeStatus # noqa: F401
from .service.code.user_code import syft_function # noqa: F401
from .service.code.user_code import UserCodeStatus # noqa: F401; noqa: F401
from .service.code.user_code import syft_function # noqa: F401; noqa: F401
from .service.code.user_code import syft_function_single_use # noqa: F401; noqa: F401
from .service.data_subject import DataSubjectCreate as DataSubject # noqa: F401
from .service.dataset.dataset import Contributor # noqa: F401
from .service.dataset.dataset import CreateAsset as Asset # noqa: F401
Expand Down
26 changes: 26 additions & 0 deletions packages/syft/src/syft/service/code/user_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from ..metadata.node_metadata import EnclaveMetadata
from ..policy.policy import CustomInputPolicy
from ..policy.policy import CustomOutputPolicy
from ..policy.policy import ExactMatch
from ..policy.policy import InputPolicy
from ..policy.policy import OutputPolicy
from ..policy.policy import Policy
Expand Down Expand Up @@ -106,6 +107,12 @@ def __init__(self, base_dict: Dict):
def __repr__(self):
return str(self.base_dict)

def __repr_syft_nested__(self):
string = ""
for node_view, status in self.base_dict.items():
string += f"{node_view.node_name}: {status}<br>"
return string

@property
def approved(self) -> bool:
# approved for this node only
Expand Down Expand Up @@ -347,6 +354,16 @@ def wrapper(*args: Any, **kwargs: Any) -> Callable:
def code(self) -> str:
return self.raw_code

def show_code_cell(self):
warning_message = """# WARNING: \n# Before you submit
# change the name of the function \n# for no duplicates\n\n"""

# third party
from IPython import get_ipython

ip = get_ipython()
ip.set_next_input(warning_message + self.raw_code)


@serializable(without=["local_function"])
class SubmitUserCode(SyftObject):
Expand All @@ -366,6 +383,8 @@ class SubmitUserCode(SyftObject):
input_kwargs: List[str]
enclave_metadata: Optional[EnclaveMetadata] = None

__attr_repr_cols__ = ["func_name", "code"]

@property
def kwargs(self) -> List[str]:
return self.input_policy_init_kwargs
Expand Down Expand Up @@ -394,6 +413,13 @@ def debox_asset(arg: Any) -> Any:
return deboxed_arg


def syft_function_single_use(*args: Any, **kwargs: Any):
return syft_function(
input_policy=ExactMatch(*args, **kwargs),
output_policy=SingleExecutionExactOutput(),
)


def syft_function(
input_policy: Union[InputPolicy, UID],
output_policy: Optional[Union[OutputPolicy, UID]] = None,
Expand Down
19 changes: 15 additions & 4 deletions packages/syft/src/syft/service/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@
from ...serde.serializable import serializable
from ...store.document_store import PartitionKey
from ...types.datetime import DateTime
from ...types.syft_object import SURFACE_DARK_BRIGHT
from ...types.syft_object import SYFT_OBJECT_VERSION_1
from ...types.syft_object import SyftObject
from ...types.syft_object import itables_css
from ...types.transforms import TransformContext
from ...types.transforms import generate_id
from ...types.transforms import transform
from ...types.transforms import validate_url
from ...types.uid import UID
from ...util import options
from ...util.colors import ON_SURFACE_HIGHEST
from ...util.colors import SURFACE
from ...util.colors import SURFACE_SURFACE
from ...util.fonts import ITABLES_CSS
from ...util.fonts import fonts_css
from ...util.markdown import as_markdown_python_code
Expand Down Expand Up @@ -88,6 +90,15 @@ class Asset(SyftObject):
__attr_repr_cols__ = ["name", "shape"]

def _repr_html_(self) -> Any:
itables_css = f"""
.itables table {{
margin: 0 auto;
float: left;
color: {ON_SURFACE_HIGHEST[options.color_theme]};
}}
.itables table th {{color: {SURFACE_SURFACE[options.color_theme]};}}
"""

# relative
from ...service.action.action_object import ActionObject

Expand All @@ -106,7 +117,7 @@ def _repr_html_(self) -> Any:
f"""
<style>
{fonts_css}
.syft-asset {{color: {SURFACE_DARK_BRIGHT};}}
.syft-asset {{color: {SURFACE[options.color_theme]};}}
.syft-asset h3,
.syft-asset p
{{font-family: 'Open Sans'}}
Expand Down Expand Up @@ -338,7 +349,7 @@ def _repr_html_(self) -> Any:
f"""
<style>
{fonts_css}
.syft-dataset {{color: {SURFACE_DARK_BRIGHT};}}
.syft-dataset {{color: {SURFACE[options.color_theme]};}}
.syft-dataset h3,
.syft-dataset p
{{font-family: 'Open Sans';}}
Expand Down
39 changes: 39 additions & 0 deletions packages/syft/src/syft/service/project/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@
from ...types.datetime import DateTime
from ...types.syft_object import SYFT_OBJECT_VERSION_1
from ...types.syft_object import SyftObject
from ...types.syft_object import short_qual_name
from ...types.transforms import TransformContext
from ...types.transforms import keep
from ...types.transforms import transform
from ...types.uid import UID
from ...util import options
from ...util.colors import SURFACE
from ...util.markdown import markdown_as_class_with_fields
from ...util.util import full_name_with_qualname
from ..code.user_code import SubmitUserCode
from ..network.network_service import NodePeer
from ..network.routes import NodeRoute
Expand Down Expand Up @@ -116,6 +120,12 @@ class ProjectEvent(SyftObject):
creator_verify_key: Optional[SyftVerifyKey]
signature: Optional[bytes] # dont use in signing

def __repr_syft_nested__(self):
return (
short_qual_name(full_name_with_qualname(self)),
f"{str(self.id)[:4]}...{str(self.id)[-3:]}",
)

@pydantic.root_validator(pre=True)
def make_timestamp(cls, values: Dict[str, Any]) -> Dict[str, Any]:
if "timestamp" not in values or values["timestamp"] is None:
Expand Down Expand Up @@ -704,6 +714,21 @@ class Project(SyftObject):
# store: Dict[UID, Dict[UID, SyftObject]] = {}
# permissions: Dict[UID, Dict[UID, Set[str]]] = {}

def _repr_html_(self) -> Any:
return (
f"""
<style>
.syft-project {{color: {SURFACE[options.color_theme]};}}
</style>
"""
+ "<div class='syft-project'>"
+ f"<h3>{self.name}</h3>"
+ f"<p>{self.description}</p>"
+ f"<p><strong>Created by: </strong>{self.created_by}</p>"
+ self.requests._repr_html_()
+ "</div>"
)

def _broadcast_event(
self, project_event: ProjectEvent
) -> Union[SyftSuccess, SyftError]:
Expand Down Expand Up @@ -1165,6 +1190,20 @@ def __init__(self, *args, **kwargs):
# Convert SyftClients to NodeIdentities
self.members = list(map(self.to_node_identity, self.members))

def _repr_html_(self) -> Any:
return (
f"""
<style>
.syft-project-create {{color: {SURFACE[options.color_theme]};}}
</style>
"""
+ "<div class='syft-project-create'>"
+ f"<h3>{self.name}</h3>"
+ f"<p>{self.description}</p>"
+ f"<p><strong>Created by: </strong>{self.created_by}</p>"
+ "</div>"
)

@validator("members", pre=True)
def verify_members(cls, val: Union[List[SyftClient], List[NodeIdentity]]):
# SyftClients must be logged in by the same emails
Expand Down
56 changes: 56 additions & 0 deletions packages/syft/src/syft/service/request/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
from ...types.transforms import transform
from ...types.uid import LineageID
from ...types.uid import UID
from ...util import options
from ...util.colors import SURFACE
from ...util.markdown import markdown_as_class_with_fields
from ..action.action_object import ActionObject
from ..action.action_service import ActionService
Expand Down Expand Up @@ -140,6 +142,7 @@ class Request(SyftObject):
__version__ = SYFT_OBJECT_VERSION_1

requesting_user_verify_key: SyftVerifyKey
requesting_user_name: str
approving_user_verify_key: Optional[SyftVerifyKey]
request_time: DateTime
updated_at: Optional[DateTime]
Expand All @@ -161,6 +164,44 @@ class Request(SyftObject):
"requesting_user_verify_key",
]

def _repr_html_(self) -> Any:
# add changes
updated_at_line = ""
if self.updated_at is not None:
updated_at_line += f"<p><strong>Created by: </strong>{self.created_by}</p>"
str_changes = []
for change in self.changes:
str_change = ""
if isinstance(change, UserCodeStatusChange):
str_change += f"User <b>{self.requesting_user_name}</b> requests to change\
<b>{change.link.service_func_name}</b> to permission <b>RequestStatus.APPROVED</b>"
else:
str_change += f"{type(change)}"
str_changes.append(str_change)
str_changes = str(str_changes)
return f"""
<style>
.syft-request {{color: {SURFACE[options.color_theme]};}}
</style>
<div class='syft-request'>
<h3>Request</h3>
<p><strong>Id: </strong>{self.id}</p>
<p><strong>Request time: </strong>{self.request_time}</p>
{updated_at_line}
<p><strong> Changes: </strong> {str_changes}</p>
<p><strong>Status: </strong>{self.status}</p>
</div>
"""

@property
def code(self) -> Any:
if len(self.changes) == 1:
if isinstance(self.changes[0], UserCodeStatusChange):
return self.changes[0].link
return SyftError(
msg="This type of request does not have code associated with it."
)

@property
def current_change_state(self) -> Dict[UID, bool]:
change_applied_map = {}
Expand Down Expand Up @@ -402,13 +443,25 @@ def check_requesting_user_verify_key(context: TransformContext) -> TransformCont
return context


def add_requesting_user_name(context: TransformContext) -> TransformContext:
try:
user_key = context.output["requesting_user_verify_key"]
user_service = context.node.get_service("UserService")
user = user_service.get_by_verify_key(user_key)
context.output["requesting_user_name"] = user.name
except Exception:
context.output["requesting_user_name"] = "guest_user"
return context


@transform(SubmitRequest, Request)
def submit_request_to_request() -> List[Callable]:
return [
generate_id,
add_node_uid_for_key("node_uid"),
add_request_time,
check_requesting_user_verify_key,
add_requesting_user_name,
hash_changes,
]

Expand Down Expand Up @@ -561,6 +614,9 @@ class UserCodeStatusChange(Change):
"link.status.approved",
]

def __repr_syft_nested__(self):
return f"Request to change <b>{self.link.service_func_name}</b> to permission <b>RequestStatus.APPROVED</b>"

def _repr_markdown_(self) -> str:
link = self.link
input_policy_type = (
Expand Down
Loading

0 comments on commit 27a2560

Please sign in to comment.