PySyft
PySyft copied to clipboard
Reloadable uvicorn app over dev
This adds the ability to create in-memory nodes (python nodes) with a reloadable uvicorn server. Instead of adding a notebook, adding some small code snippets here for local testing.
import syft as sy
CANADA_DOMAIN_PORT = 9081
ITALY_DOMAIN_PORT = 9082
CANADA_ENCLAVE_PORT = 9083
The way to run servers is to use start_reloadable_server as an alternative to sy.orchestra.launch (it returns as NodeHandle)
from syft.node.server_management import start_reloadable_server, stop_all_reloadable_servers
canada_node = start_reloadable_server(name="canada-domain", port=CANADA_DOMAIN_PORT, reset=True)
italy_node = start_reloadable_server(name="italy-domain", port=ITALY_DOMAIN_PORT, reset=True)
canada_enclave = start_reloadable_server(name="canada-enclave", node_type="enclave",
port=CANADA_ENCLAVE_PORT, reset=True)
Right now this only takes a few of the import arguments from sy.orchestra.launch (name: str, node_type: str, node_side_type: str, port: int, processes: int, local_db: bool, reset: bool) but not all.
Test login
do_canada_client = canada_node.login(email="[email protected]", password="changethis")
do_italy_client = italy_node.login(email="[email protected]", password="changethis")
Test enclave login which should give a SyftError preventing admin logging into Enclaves.
enclave_login = canada_enclave.login(email="[email protected]", password="changethis")
enclave_login
Then comes the magic to check the reloading in action. Comment out these lines from user_service.py to allow admin login into Enclaves as well. And just rerun the last cell and it should allow the login!
Additional Notes
- To keep the experience as close to before, you can do
canada_node.land()to shut the server or usestop_all_reloadable_servers()to shutdown/land all servers. - Since the server takes a few seconds to spin up, an intentional sleep has been added to the code so that the uvicorn logs do not show up in future cells when rapidly cruising through jupyter lab cells.
Thanks @itstauq!
@madhavajay This work and you will be able to give this a try locally (and maybe fix the security issues).
Superseded by https://github.com/OpenMined/PySyft/pull/8988