PySyft icon indicating copy to clipboard operation
PySyft copied to clipboard

Reloadable uvicorn app over dev

Open snwagh opened this issue 1 year ago • 1 comments
trafficstars

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 use stop_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!

snwagh avatar Jun 25 '24 15:06 snwagh

@madhavajay This work and you will be able to give this a try locally (and maybe fix the security issues).

snwagh avatar Jun 27 '24 00:06 snwagh

Superseded by https://github.com/OpenMined/PySyft/pull/8988

rasswanth-s avatar Jul 02 '24 11:07 rasswanth-s