diff --git a/notebooks/tutorials/enclaves/Enclave-single-notebook-DO-DS.ipynb b/notebooks/tutorials/enclaves/Enclave-single-notebook-DO-DS.ipynb index 1346d11086d..3b6a34e3cb7 100644 --- a/notebooks/tutorials/enclaves/Enclave-single-notebook-DO-DS.ipynb +++ b/notebooks/tutorials/enclaves/Enclave-single-notebook-DO-DS.ipynb @@ -35,12 +35,14 @@ "metadata": {}, "outputs": [], "source": [ - "#Local Python Mode\n", - "enclave_node = sy.orchestra.launch(name=\"Enclave\",\n", - " node_type=sy.NodeType.ENCLAVE,\n", - " local_db=True,\n", - " dev_mode=True,\n", - " reset=True)" + "# Local Python Node\n", + "enclave_node = sy.orchestra.launch(\n", + " name=\"Enclave\",\n", + " node_type=sy.NodeType.ENCLAVE,\n", + " local_db=True,\n", + " dev_mode=True,\n", + " reset=True\n", + ")" ] }, { @@ -69,14 +71,18 @@ "metadata": {}, "outputs": [], "source": [ - "ca_node = sy.orchestra.launch(name=\"Canada\",\n", - " local_db=True,\n", - " reset=True,\n", - " dev_mode=True)\n", - "it_node = sy.orchestra.launch(name=\"Italy\",\n", - " local_db=True,\n", - " reset=True,\n", - " dev_mode=True) " + "ca_node = sy.orchestra.launch(\n", + " name=\"Canada\",\n", + " local_db=True,\n", + " reset=True,\n", + " dev_mode=True\n", + ")\n", + "it_node = sy.orchestra.launch(\n", + " name=\"Italy\",\n", + " local_db=True,\n", + " reset=True,\n", + " dev_mode=True\n", + ") " ] }, { @@ -105,11 +111,13 @@ "metadata": {}, "outputs": [], "source": [ - "gateway_node = sy.orchestra.launch(name=\"gateway\",\n", - " node_type = sy.NodeType.GATEWAY,\n", - " local_db=True,\n", - " reset=True,\n", - " dev_mode=True)" + "gateway_node = sy.orchestra.launch(\n", + " name=\"gateway\",\n", + " node_type = sy.NodeType.GATEWAY,\n", + " local_db=True,\n", + " reset=True,\n", + " dev_mode=True\n", + ")" ] }, { @@ -334,7 +342,7 @@ "metadata": {}, "outputs": [], "source": [ - "#Explore the domains and enclaves connected to the gateway\n", + "# Explore the domains and enclaves connected to the gateway\n", "ds_gateway_client.domains" ] }, @@ -345,9 +353,9 @@ "metadata": {}, "outputs": [], "source": [ - "#logs into canada as proxy_client\n", + "# Log into canada as proxy_client\n", "ds_ca_proxy_client = ds_gateway_client.domains[0]\n", - "ds_ca_proxy_client.login(email=\"sheldon@caltech.edu\" , password=\"changethis\")\n", + "ds_ca_proxy_client = ds_ca_proxy_client.login(email=\"sheldon@caltech.edu\", password=\"changethis\")\n", "assert ds_ca_proxy_client.name == \"Canada\"\n", "assert ds_ca_proxy_client.connection.proxy_target_uid == do_ca_client.id\n", "assert isinstance(ds_ca_proxy_client, DomainClient)" @@ -360,9 +368,9 @@ "metadata": {}, "outputs": [], "source": [ - "#logs into italy as proxy_client\n", + "# Log into italy as proxy_client\n", "ds_it_proxy_client = ds_gateway_client.domains[1]\n", - "ds_it_proxy_client.login(email=\"sheldon@caltech.edu\" , password=\"changethis\")\n", + "ds_it_proxy_client = ds_it_proxy_client.login(email=\"sheldon@caltech.edu\", password=\"changethis\")\n", "assert ds_it_proxy_client.name == \"Italy\"\n", "assert ds_it_proxy_client.connection.proxy_target_uid == do_it_client.id\n", "assert isinstance(ds_it_proxy_client, DomainClient)" @@ -375,9 +383,11 @@ "metadata": {}, "outputs": [], "source": [ - "# Creates and account and logs into enclave as proxy client\n", + "# Create an account and log into enclave as proxy client\n", "ds_enclave_proxy_client = ds_gateway_client.enclaves[0]\n", - "ds_enclave_proxy_client.login(email=\"sheldon@caltech.edu\" , password=\"changethis\",name=\"Sheldon\", register=True)\n", + "ds_enclave_proxy_client = ds_enclave_proxy_client.login(\n", + " email=\"sheldon@caltech.edu\" , password=\"changethis\", name=\"Sheldon\", register=True\n", + ")\n", "assert ds_enclave_proxy_client.name == \"Enclave\"\n", "assert ds_enclave_proxy_client.connection.proxy_target_uid == enclave_guest_client.id\n", "assert isinstance(ds_enclave_proxy_client, EnclaveClient)" @@ -453,11 +463,11 @@ "metadata": {}, "outputs": [], "source": [ - "#Checking result of mock data execution\n", + "# Check result of mock data execution\n", "mock_result = compute_census_matches(\n", - " canada_census_data=canada_census_data.mock,\n", - " italy_census_data=italy_census_data.mock\n", - " )\n", + " canada_census_data=canada_census_data.mock,\n", + " italy_census_data=italy_census_data.mock,\n", + ")\n", "mock_result" ] }, @@ -659,14 +669,6 @@ "source": [ "assert result_ptr.syft_action_data == 813" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "1beca4ac", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/notebooks/tutorials/pandas-cookbook/01-reading-from-a-csv.ipynb b/notebooks/tutorials/pandas-cookbook/01-reading-from-a-csv.ipynb index ce844ee7f47..4a8e63dd094 100644 --- a/notebooks/tutorials/pandas-cookbook/01-reading-from-a-csv.ipynb +++ b/notebooks/tutorials/pandas-cookbook/01-reading-from-a-csv.ipynb @@ -510,7 +510,7 @@ "new_project = sy.Project(\n", " name=\"My pandas project 1\",\n", " description=\"Hi, I would like to plot the Berri 1 column.\",\n", - " members=[guest_domain_client],\n", + " members=[guest_client],\n", ")\n", "new_project" ] @@ -538,7 +538,7 @@ }, "outputs": [], "source": [ - "project.create_code_request(get_column, guest_domain_client)" + "project.create_code_request(get_column, guest_client)" ] }, { @@ -550,7 +550,7 @@ }, "outputs": [], "source": [ - "assert len(guest_domain_client.code.get_all())==1" + "assert len(guest_client.code.get_all())==1" ] }, { @@ -821,14 +821,6 @@ "source": [ "node.land()" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "32ab7e8e", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -847,7 +839,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8" + "version": "3.11.5" }, "toc": { "base_numbering": 1, diff --git a/notebooks/tutorials/pandas-cookbook/02-selecting-data-finding-common-complain.ipynb b/notebooks/tutorials/pandas-cookbook/02-selecting-data-finding-common-complain.ipynb index 2b75c070ea3..ecb945878a1 100644 --- a/notebooks/tutorials/pandas-cookbook/02-selecting-data-finding-common-complain.ipynb +++ b/notebooks/tutorials/pandas-cookbook/02-selecting-data-finding-common-complain.ipynb @@ -209,9 +209,9 @@ " \"X Coordinate (State Plane)\": lambda x: randint(1,1000000),\n", " \"Y Coordinate (State Plane)\": lambda x: randint(1,1000000),\n", " \"Complaint Type\": lambda x: random.choice([\"Illegal Parking\", \"Noise - Street/Sidewalk\", \"'Animal in a Park'\"]),\n", - " \"Descriptor\": lambda x: random.choice([ 'Branch or Limb Has Fallen Down','Branches Damaged','Broken Fence', 'Broken Glass']),\n", - " \"School Number\": lambda x: random.choice([ 'B073', 'B077', 'B079', 'B080-01', 'B087', 'B099', 'B100', 'B102', 'B109', 'B111']),\n", - " \"Bridge Highway Segment\": lambda x: random.choice([ 'Grand Central Pkwy (Exit 1 E-W)',\n", + " \"Descriptor\": lambda x: random.choice(['Branch or Limb Has Fallen Down','Branches Damaged','Broken Fence', 'Broken Glass']),\n", + " \"School Number\": lambda x: random.choice(['B073', 'B077', 'B079', 'B080-01', 'B087', 'B099', 'B100', 'B102', 'B109', 'B111']),\n", + " \"Bridge Highway Segment\": lambda x: random.choice(['Grand Central Pkwy (Exit 1 E-W)',\n", " 'Grand Central Pkwy (Exit 10) - 69th Rd-Jewel Ave (Exit 11)',\n", " 'GrandCentral Pkwy/VanWyck Expwy/College Point Blvd (Exit 22 A-E)',\n", " 'Hamilton Ave (Exit 2A) - Gowanus Expwy (I-278) (Exit 1)',\n", @@ -698,7 +698,7 @@ "new_project = sy.Project(\n", " name=\"Pandas chapter 2\",\n", " description=\"Hi, I would like to plot the histogram of the complaint types.\",\n", - " members=[guest_domain_client],\n", + " members=[guest_client],\n", ")\n", "new_project" ] @@ -726,7 +726,7 @@ }, "outputs": [], "source": [ - "project.create_code_request(get_counts, guest_domain_client)" + "project.create_code_request(get_counts, guest_client)" ] }, { @@ -738,7 +738,7 @@ }, "outputs": [], "source": [ - "assert len(guest_domain_client.code.get_all())==1" + "assert len(guest_client.code.get_all()) == 1" ] }, { @@ -974,14 +974,6 @@ "source": [ "node.land()" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "247f8f48-7281-4dd5-a6fe-702ed46891cb", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/notebooks/tutorials/pandas-cookbook/03-which-borough-has-the-most-noise-complaints.ipynb b/notebooks/tutorials/pandas-cookbook/03-which-borough-has-the-most-noise-complaints.ipynb index 2f3e20955be..a0ff4c3f34d 100644 --- a/notebooks/tutorials/pandas-cookbook/03-which-borough-has-the-most-noise-complaints.ipynb +++ b/notebooks/tutorials/pandas-cookbook/03-which-borough-has-the-most-noise-complaints.ipynb @@ -95,9 +95,9 @@ "# Make the graphs a bit prettier, and bigger\n", "plt.style.use('ggplot')\n", "\n", - "# This is necessary to show lots of columns in pandas 0.12. \n", + "# This is necessary to show lots of columns in pandas 0.12.\n", "# Not necessary in pandas 0.13.\n", - "pd.set_option('display.width', 5000) \n", + "pd.set_option('display.width', 5000)\n", "pd.set_option('display.max_columns', 60)\n", "\n", "plt.rcParams['figure.figsize'] = (15, 5)" @@ -222,9 +222,9 @@ " \"X Coordinate (State Plane)\": lambda x: randint(1,1000000),\n", " \"Y Coordinate (State Plane)\": lambda x: randint(1,1000000),\n", " \"Complaint Type\": lambda x: random.choice([\"Illegal Parking\", \"Noise - Street/Sidewalk\", \"'Animal in a Park'\"]),\n", - " \"Descriptor\": lambda x: random.choice([ 'Branch or Limb Has Fallen Down','Branches Damaged','Broken Fence', 'Broken Glass']),\n", - " \"School Number\": lambda x: random.choice([ 'B073', 'B077', 'B079', 'B080-01', 'B087', 'B099', 'B100', 'B102', 'B109', 'B111']),\n", - " \"Bridge Highway Segment\": lambda x: random.choice([ 'Grand Central Pkwy (Exit 1 E-W)',\n", + " \"Descriptor\": lambda x: random.choice(['Branch or Limb Has Fallen Down','Branches Damaged','Broken Fence', 'Broken Glass']),\n", + " \"School Number\": lambda x: random.choice(['B073', 'B077', 'B079', 'B080-01', 'B087', 'B099', 'B100', 'B102', 'B109', 'B111']),\n", + " \"Bridge Highway Segment\": lambda x: random.choice(['Grand Central Pkwy (Exit 1 E-W)',\n", " 'Grand Central Pkwy (Exit 10) - 69th Rd-Jewel Ave (Exit 11)',\n", " 'GrandCentral Pkwy/VanWyck Expwy/College Point Blvd (Exit 22 A-E)',\n", " 'Hamilton Ave (Exit 2A) - Gowanus Expwy (I-278) (Exit 1)',\n", @@ -265,7 +265,7 @@ "mock_data = dict()\n", "for col in complaints.columns:\n", " col_vals = complaints[col]\n", - " \n", + "\n", " if col in fake_functions:\n", " mock_func = fake_functions[col]\n", " elif len(set(complaints[col])) < 100:\n", @@ -810,7 +810,7 @@ "new_project = sy.Project(\n", " name=\"Pandas chapter 3\",\n", " description=\"Hi, I would like to plot the histogram of the noise complaint counts per area.\",\n", - " members=[guest_domain_client],\n", + " members=[guest_client],\n", ")\n", "new_project" ] @@ -838,7 +838,7 @@ }, "outputs": [], "source": [ - "project.create_code_request(get_counts, guest_domain_client)" + "project.create_code_request(get_counts, guest_client)" ] }, { @@ -850,7 +850,7 @@ }, "outputs": [], "source": [ - "assert len(guest_domain_client.code.get_all())==1" + "assert len(guest_client.code.get_all())==1" ] }, { @@ -1086,14 +1086,6 @@ "source": [ "node.land()" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "4374c6ed-b64f-4819-aca4-5570676d6c68", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -1112,7 +1104,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8" + "version": "3.11.5" }, "toc": { "base_numbering": 1, diff --git a/notebooks/tutorials/pandas-cookbook/04-weekday-bike-most-groupby-aggregate.ipynb b/notebooks/tutorials/pandas-cookbook/04-weekday-bike-most-groupby-aggregate.ipynb index ed59b274c64..2f5c7182e68 100644 --- a/notebooks/tutorials/pandas-cookbook/04-weekday-bike-most-groupby-aggregate.ipynb +++ b/notebooks/tutorials/pandas-cookbook/04-weekday-bike-most-groupby-aggregate.ipynb @@ -588,7 +588,7 @@ "new_project = sy.Project(\n", " name=\"Pandas Chapter 4\",\n", " description=\"Hi, I would like to plot histogram of bikers per weekday\",\n", - " members=[guest_domain_client],\n", + " members=[guest_client],\n", ")\n", "new_project" ] @@ -616,7 +616,7 @@ }, "outputs": [], "source": [ - "project.create_code_request(get_bike_hist, guest_domain_client)" + "project.create_code_request(get_bike_hist, guest_client)" ] }, { @@ -628,7 +628,7 @@ }, "outputs": [], "source": [ - "assert len(guest_domain_client.code.get_all())==1" + "assert len(guest_client.code.get_all()) == 1" ] }, { @@ -876,14 +876,6 @@ "source": [ "node.land()" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "cbcd55e5", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -902,7 +894,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8" + "version": "3.11.5" }, "toc": { "base_numbering": 1, diff --git a/notebooks/tutorials/pandas-cookbook/05-combining-dataframes-scraping-weather-data.ipynb b/notebooks/tutorials/pandas-cookbook/05-combining-dataframes-scraping-weather-data.ipynb index 1fc3212aaa2..519e749a82b 100644 --- a/notebooks/tutorials/pandas-cookbook/05-combining-dataframes-scraping-weather-data.ipynb +++ b/notebooks/tutorials/pandas-cookbook/05-combining-dataframes-scraping-weather-data.ipynb @@ -258,11 +258,13 @@ "for month in range(1, 13):\n", " url = url_template.format(month=month, year=2012)\n", " weather = pd.read_csv(url, parse_dates=True, index_col='Date/Time (LST)')\n", - " mock = pd.DataFrame(index=[Timestamp(get_mock_date(i)) for i in range(len(weather))],\n", - " data=[get_mock_row(i) for i in range(len(weather))],\n", - " columns=weather.columns)\n", + " mock = pd.DataFrame(\n", + " index=[Timestamp(get_mock_date(i)) for i in range(len(weather))],\n", + " data=[get_mock_row(i) for i in range(len(weather))],\n", + " columns=weather.columns\n", + " )\n", " \n", - " assets += [sy.Asset(name=f\"weather{month}\", data=weather, mock=mock, mock_is_real=False)]" + " assets.append(sy.Asset(name=f\"weather{month}\", data=weather, mock=mock, mock_is_real=False))" ] }, { @@ -793,7 +795,7 @@ "new_project = sy.Project(\n", " name=\"Pandas Chapter 5\",\n", " description=\"Hi, get all weather data for 2012\",\n", - " members=[guest_domain_client],\n", + " members=[guest_client],\n", ")\n", "new_project" ] @@ -821,7 +823,7 @@ }, "outputs": [], "source": [ - "project.create_code_request(get_2012_weather, guest_domain_client)" + "project.create_code_request(get_2012_weather, guest_client)" ] }, { @@ -833,7 +835,7 @@ }, "outputs": [], "source": [ - "assert len(guest_domain_client.code.get_all())==1" + "assert len(guest_client.code.get_all())==1" ] }, { @@ -1175,7 +1177,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8" + "version": "3.11.5" }, "toc": { "base_numbering": 1, diff --git a/notebooks/tutorials/pandas-cookbook/06-string-operations-which-month-was-the-snowiest.ipynb b/notebooks/tutorials/pandas-cookbook/06-string-operations-which-month-was-the-snowiest.ipynb index 0a639bcb2b2..7c4769191ac 100644 --- a/notebooks/tutorials/pandas-cookbook/06-string-operations-which-month-was-the-snowiest.ipynb +++ b/notebooks/tutorials/pandas-cookbook/06-string-operations-which-month-was-the-snowiest.ipynb @@ -211,8 +211,7 @@ " res = dict()\n", " for k, function in mock_functions.items():\n", " res[k] = function()\n", - " return res\n", - " " + " return res\n" ] }, { @@ -247,7 +246,7 @@ "mock = pd.DataFrame(index=[Timestamp(get_mock_date(i)) for i in range(len(weather_2012_final))],\n", " data=[get_mock_row(i) for i in range(len(weather_2012_final))],\n", " columns=weather_2012_final.columns)\n", - " \n" + "\n" ] }, { @@ -657,10 +656,10 @@ " weather_2012 = df\n", " weather_description = weather_2012['Weather']\n", " is_snowing = weather_description.str.contains('Snow')\n", - " \n", + "\n", " median_temperature = weather_2012['Temp (C)'].resample('M').apply(np.median)\n", " snow_frequency = is_snowing.astype(float).resample('M').apply(np.mean)\n", - " \n", + "\n", " temperature = weather_2012['Temp (C)'].resample('M').apply(np.median)\n", " is_snowing = weather_2012['Weather'].str.contains('Snow')\n", " snowiness = is_snowing.astype(float).resample('M').apply(np.mean)\n", @@ -670,7 +669,7 @@ " snowiness.name = \"Snowiness\"\n", " stats = pd.concat([temperature, snowiness], axis=1)\n", " stats.columns = [\"temperature\", \"snowiness\"]\n", - " \n", + "\n", " return is_snowing.astype(float), median_temperature, snow_frequency, stats" ] }, @@ -694,7 +693,7 @@ "new_project = sy.Project(\n", " name=\"Pandas Chapter 6\",\n", " description=\"Hi, I would like to get some insights about snow and temperature for 2012\",\n", - " members=[guest_domain_client],\n", + " members=[guest_client],\n", ")\n", "new_project" ] @@ -722,7 +721,7 @@ }, "outputs": [], "source": [ - "project.create_code_request(snow_and_temperature, guest_domain_client)" + "project.create_code_request(snow_and_temperature, guest_client)" ] }, { @@ -734,7 +733,7 @@ }, "outputs": [], "source": [ - "assert len(guest_domain_client.code.get_all())==1" + "assert len(guest_client.code.get_all()) == 1" ] }, { diff --git a/notebooks/tutorials/pandas-cookbook/07-cleaning-up-messy-data.ipynb b/notebooks/tutorials/pandas-cookbook/07-cleaning-up-messy-data.ipynb index 92490b2ba40..89917c1f4a7 100644 --- a/notebooks/tutorials/pandas-cookbook/07-cleaning-up-messy-data.ipynb +++ b/notebooks/tutorials/pandas-cookbook/07-cleaning-up-messy-data.ipynb @@ -360,7 +360,7 @@ }, "outputs": [], "source": [ - "ds = guest_domain_client.datasets[0]" + "ds = guest_client.datasets[0]" ] }, { @@ -740,7 +740,7 @@ "new_project = sy.Project(\n", " name=\"Pandas Chapter 7\",\n", " description=\"Hi, I would like to get some insights about the zip codes of the complaints\",\n", - " members=[guest_domain_client],\n", + " members=[guest_client],\n", ")\n", "new_project" ] @@ -768,7 +768,7 @@ }, "outputs": [], "source": [ - "project.create_code_request(zip_codes, guest_domain_client)" + "project.create_code_request(zip_codes, guest_client)" ] }, { @@ -780,7 +780,7 @@ }, "outputs": [], "source": [ - "assert len(guest_domain_client.code.get_all())==1" + "assert len(guest_client.code.get_all()) == 1" ] }, { @@ -1064,14 +1064,6 @@ "source": [ "node.land()" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "cb11ce89", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -1090,7 +1082,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8" + "version": "3.11.5" }, "toc": { "base_numbering": 1, diff --git a/notebooks/tutorials/pandas-cookbook/08-how-to-deal-with-timestamps.ipynb b/notebooks/tutorials/pandas-cookbook/08-how-to-deal-with-timestamps.ipynb index 60387e53d39..a9945663fef 100644 --- a/notebooks/tutorials/pandas-cookbook/08-how-to-deal-with-timestamps.ipynb +++ b/notebooks/tutorials/pandas-cookbook/08-how-to-deal-with-timestamps.ipynb @@ -677,7 +677,7 @@ "new_project = sy.Project(\n", " name=\"Pandas Chapter 8\",\n", " description=\"Hi, I would like to get some insights about the installed programs\",\n", - " members=[guest_domain_client],\n", + " members=[guest_client],\n", ")\n", "new_project" ] @@ -705,7 +705,7 @@ }, "outputs": [], "source": [ - "project.create_code_request(find_recently_installed, guest_domain_client)" + "project.create_code_request(find_recently_installed, guest_client)" ] }, { @@ -717,7 +717,7 @@ }, "outputs": [], "source": [ - "assert len(guest_domain_client.code.get_all())==1" + "assert len(guest_client.code.get_all()) == 1" ] }, { @@ -979,14 +979,6 @@ "source": [ "node.land()" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "0b4dc278-0a7f-4d01-b660-82aed6419fcc", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -1005,7 +997,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8" + "version": "3.11.5" }, "toc": { "base_numbering": 1, diff --git a/packages/hagrid/hagrid/orchestra.py b/packages/hagrid/hagrid/orchestra.py index 2fee2c09ae6..542739b304d 100644 --- a/packages/hagrid/hagrid/orchestra.py +++ b/packages/hagrid/hagrid/orchestra.py @@ -166,7 +166,7 @@ def __init__( def client(self) -> Any: if self.port: sy = get_syft_client() - return sy.login(url=self.url, port=self.port) # type: ignore + return sy.login_as_guest(url=self.url, port=self.port) # type: ignore elif self.deployment_type == DeploymentType.PYTHON: return self.python_node.get_guest_client(verbose=False) # type: ignore else: diff --git a/packages/syft/src/syft/client/client.py b/packages/syft/src/syft/client/client.py index c6371f487a0..3492dd4423a 100644 --- a/packages/syft/src/syft/client/client.py +++ b/packages/syft/src/syft/client/client.py @@ -653,38 +653,45 @@ def login_as_guest(self) -> Self: return _guest_client def login( - self, email: str, password: str, cache: bool = True, register=False, **kwargs + self, + email: Optional[str] = None, + password: Optional[str] = None, + cache: bool = True, + register: bool = False, + **kwargs: Any, ) -> Self: + if email is None: + email = input("Email: ") + if password is None: + password = getpass("Password: ") + if register: - if not email: - email = input("Email: ") - if not password: - password = getpass("Password: ") self.register( email=email, password=password, password_verify=password, **kwargs ) - if password is None: - password = getpass("Password: ") + user_private_key = self.connection.login(email=email, password=password) if isinstance(user_private_key, SyftError): return user_private_key - signing_key = None - if user_private_key is not None: - signing_key = user_private_key.signing_key - self.__user_role = user_private_key.role - if signing_key is not None: - self.credentials = signing_key - self.__logged_in_user = email - # Get current logged in user name - self.__logged_in_username = self.users.get_current_user().name + signing_key = None if user_private_key is None else user_private_key.signing_key - # TODO: How to get the role of the user? - # self.__user_role = - self._fetch_api(self.credentials) + client = self.__class__( + connection=self.connection, + metadata=self.metadata, + credentials=signing_key, + ) + + client.__logged_in_user = email + + if user_private_key is not None: + client.__user_role = user_private_key.role + client.__logged_in_username = client.users.get_current_user().name + + if signing_key is not None: print( - f"Logged into <{self.name}: {self.metadata.node_side_type.capitalize()} side " - f"{self.metadata.node_type.capitalize()}> as <{email}>" + f"Logged into <{client.name}: {client.metadata.node_side_type.capitalize()} side " + f"{client.metadata.node_type.capitalize()}> as <{email}>" ) # relative from ..node.node import get_default_root_password @@ -700,8 +707,8 @@ def login( SyftClientSessionCache.add_client( email=email, password=password, - connection=self.connection, - syft_client=self, + connection=client.connection, + syft_client=client, ) # Adding another cache storage # as this would be useful in retrieving unique clients @@ -712,16 +719,16 @@ def login( # combining both email, password and verify key and uid SyftClientSessionCache.add_client_by_uid_and_verify_key( verify_key=signing_key.verify_key, - node_uid=self.id, - syft_client=self, + node_uid=client.id, + syft_client=client, ) # relative from ..node.node import CODE_RELOADER - CODE_RELOADER[thread_ident()] = self._reload_user_code + CODE_RELOADER[thread_ident()] = client._reload_user_code - return self + return client def _reload_user_code(self): # relative @@ -756,7 +763,9 @@ def register( password_verify=password_verify, institution=institution, website=website, - created_by=self.credentials, + created_by=( + None if self.__user_role == ServiceRole.GUEST else self.credentials + ), ) except Exception as e: return SyftError(message=str(e)) @@ -890,10 +899,10 @@ def login_as_guest( @instrument def login( + email: str, url: Union[str, GridURL] = DEFAULT_PYGRID_ADDRESS, node: Optional[AbstractNode] = None, port: Optional[int] = None, - email: Optional[str] = None, password: Optional[str] = None, cache: bool = True, ) -> SyftClient: @@ -906,10 +915,9 @@ def login( login_credentials = None - if email: - if not password: - password = getpass("Password: ") - login_credentials = UserLoginCredentials(email=email, password=password) + if not password: + password = getpass("Password: ") + login_credentials = UserLoginCredentials(email=email, password=password) if cache and login_credentials: _client_cache = SyftClientSessionCache.get_client( @@ -924,13 +932,11 @@ def login( _client = _client_cache if not _client.authed and login_credentials: - _client.login( + _client = _client.login( email=login_credentials.email, password=login_credentials.password, cache=cache, ) - if not _client.authed: - return SyftError(message=f"Failed to login as {login_credentials.email}") return _client diff --git a/packages/syft/src/syft/client/domain_client.py b/packages/syft/src/syft/client/domain_client.py index c687ee0f3e2..55f46c8de4a 100644 --- a/packages/syft/src/syft/client/domain_client.py +++ b/packages/syft/src/syft/client/domain_client.py @@ -29,6 +29,7 @@ from .api import APIModule from .client import SyftClient from .client import login +from .client import login_as_guest if TYPE_CHECKING: # relative @@ -121,14 +122,19 @@ def connect_to_gateway( url: Optional[str] = None, port: Optional[int] = None, handle: Optional[NodeHandle] = None, # noqa: F821 - **kwargs, + email: Optional[str] = None, + password: Optional[str] = None, ) -> None: if via_client is not None: client = via_client elif handle is not None: client = handle.client else: - client = login(url=url, port=port, **kwargs) + client = ( + login_as_guest(url=url, port=port) + if email is None + else login(url=url, port=port, email=email, password=password) + ) if isinstance(client, SyftError): return client diff --git a/packages/syft/src/syft/client/enclave_client.py b/packages/syft/src/syft/client/enclave_client.py index 84ece593460..e0a09167805 100644 --- a/packages/syft/src/syft/client/enclave_client.py +++ b/packages/syft/src/syft/client/enclave_client.py @@ -20,6 +20,7 @@ from .api import APIModule from .client import SyftClient from .client import login +from .client import login_as_guest if TYPE_CHECKING: # relative @@ -65,14 +66,19 @@ def connect_to_gateway( url: Optional[str] = None, port: Optional[int] = None, handle: Optional[NodeHandle] = None, # noqa: F821 - **kwargs, + email: Optional[str] = None, + password: Optional[str] = None, ) -> None: if via_client is not None: client = via_client elif handle is not None: client = handle.client else: - client = login(url=url, port=port, **kwargs) + client = ( + login_as_guest(url=url, port=port) + if email is None + else login(url=url, port=port, email=email, password=password) + ) if isinstance(client, SyftError): return client diff --git a/packages/syft/src/syft/client/gateway_client.py b/packages/syft/src/syft/client/gateway_client.py index 03900821d7a..2a569cabd22 100644 --- a/packages/syft/src/syft/client/gateway_client.py +++ b/packages/syft/src/syft/client/gateway_client.py @@ -62,7 +62,7 @@ def proxy_client_for( return SyftError(message=f"No domain with name {name}") res = self.proxy_to(peer) if email and password: - res.login(email=email, password=password, **kwargs) + res = res.login(email=email, password=password, **kwargs) return res @property diff --git a/packages/syft/src/syft/external/oblv/deployment_client.py b/packages/syft/src/syft/external/oblv/deployment_client.py index a0c3b932fc9..8a170a5d0ac 100644 --- a/packages/syft/src/syft/external/oblv/deployment_client.py +++ b/packages/syft/src/syft/external/oblv/deployment_client.py @@ -24,6 +24,7 @@ from ...client.api import SyftAPI from ...client.client import SyftClient from ...client.client import login +from ...client.client import login_as_guest from ...enclave.metadata import EnclaveMetadata from ...serde.serializable import serializable from ...types.uid import UID @@ -246,7 +247,7 @@ def register( website: Optional[str] = None, ): self.check_connection_string() - guest_client = login(url=self.__conn_string) + guest_client = login_as_guest(url=self.__conn_string) return guest_client.register( name=name, email=email, diff --git a/packages/syft/src/syft/service/project/project.py b/packages/syft/src/syft/service/project/project.py index 6a2679694b2..b343f170f20 100644 --- a/packages/syft/src/syft/service/project/project.py +++ b/packages/syft/src/syft/service/project/project.py @@ -1216,7 +1216,7 @@ def verify_members(cls, val: Union[List[SyftClient], List[NodeIdentity]]): if len(clients) > 0: emails = {client.logged_in_user for client in clients} if len(emails) > 1: - raise SyftException( + raise ValueError( f"All clients must be logged in from the same account. Found multiple: {emails}" ) return val diff --git a/packages/syft/tests/syft/api_test.py b/packages/syft/tests/syft/api_test.py index 42b98584f69..66ba36fafe6 100644 --- a/packages/syft/tests/syft/api_test.py +++ b/packages/syft/tests/syft/api_test.py @@ -49,7 +49,7 @@ def test_api_cache_invalidation_login(root_verify_key, worker): assert guest_client.register( name="q", email="a@b.org", password="aaa", password_verify="aaa" ) - guest_client.login(email="a@b.org", password="aaa") + guest_client = guest_client.login(email="a@b.org", password="aaa") user_id = worker.document_store.partitions["User"].all(root_verify_key).value[-1].id def get_role(verify_key): @@ -75,6 +75,6 @@ def get_role(verify_key): assert get_role(guest_client.credentials.verify_key) == ServiceRole.DATA_OWNER - guest_client.login(email="a@b.org", password="aaa") + guest_client = guest_client.login(email="a@b.org", password="aaa") assert guest_client.upload_dataset(dataset) diff --git a/packages/syft/tests/syft/client_test.py b/packages/syft/tests/syft/client_test.py index 89e5374c850..b1d7f475948 100644 --- a/packages/syft/tests/syft/client_test.py +++ b/packages/syft/tests/syft/client_test.py @@ -2,16 +2,16 @@ def test_client_logged_in_user(worker): guest_client = worker.guest_client assert guest_client.logged_in_user == "" - guest_client.login(email="info@openmined.org", password="changethis") - assert guest_client.logged_in_user == "info@openmined.org" + client = guest_client.login(email="info@openmined.org", password="changethis") + assert client.logged_in_user == "info@openmined.org" - guest_client.register( + client.register( name="sheldon", email="sheldon@caltech.edu", password="bazinga", password_verify="bazinga", ) - guest_client.login(email="sheldon@caltech.edu", password="bazinga") + client = client.login(email="sheldon@caltech.edu", password="bazinga") - assert guest_client.logged_in_user == "sheldon@caltech.edu" + assert client.logged_in_user == "sheldon@caltech.edu" diff --git a/packages/syft/tests/syft/gateways/gateway_test.py b/packages/syft/tests/syft/gateways/gateway_test.py index 1bc1f04146f..ca379ec61b1 100644 --- a/packages/syft/tests/syft/gateways/gateway_test.py +++ b/packages/syft/tests/syft/gateways/gateway_test.py @@ -76,8 +76,12 @@ def test_domain_connect_to_gateway(faker: Faker): assert proxy_domain_client.metadata == domain_client.metadata assert proxy_domain_client.user_role == ServiceRole.NONE - domain_client.login(email="info@openmined.org", password="changethis") - proxy_domain_client.login(email="info@openmined.org", password="changethis") + domain_client = domain_client.login( + email="info@openmined.org", password="changethis" + ) + proxy_domain_client = proxy_domain_client.login( + email="info@openmined.org", password="changethis" + ) assert proxy_domain_client.logged_in_user == "info@openmined.org" assert proxy_domain_client.user_role == ServiceRole.ADMIN @@ -129,8 +133,10 @@ def test_enclave_connect_to_gateway(faker: Faker): password_verify=password, ) - enclave_client.login(email=user_email, password=password) - proxy_enclave_client.login(email=user_email, password=password) + enclave_client = enclave_client.login(email=user_email, password=password) + proxy_enclave_client = proxy_enclave_client.login( + email=user_email, password=password + ) assert proxy_enclave_client.logged_in_user == user_email assert proxy_enclave_client.user_role == enclave_client.user_role diff --git a/packages/syft/tests/syft/project/project_test.py b/packages/syft/tests/syft/project/project_test.py index 9524e608caf..9b2c8ce92f3 100644 --- a/packages/syft/tests/syft/project/project_test.py +++ b/packages/syft/tests/syft/project/project_test.py @@ -72,9 +72,7 @@ def test_exception_different_email(worker): ds_sheldon = sy.login(node=worker, email="sheldon@caltech.edu", password="bazinga") - ds_leonard = sy.login( - node=worker, email="leonard@princeton.edu", password="starwars" - ) + ds_leonard = sy.login(node=worker, email="leonard@princeton.edu", password="penny") with pytest.raises(ValidationError): sy.Project( diff --git a/packages/syft/tests/syft/settings/settings_service_test.py b/packages/syft/tests/syft/settings/settings_service_test.py index a8ba4d0da68..596e5cec17b 100644 --- a/packages/syft/tests/syft/settings/settings_service_test.py +++ b/packages/syft/tests/syft/settings/settings_service_test.py @@ -305,8 +305,9 @@ def get_mock_client(faker, root_client, role): assert not isinstance(result, SyftError) guest_client = root_client.guest() - guest_client.login(email=user_create.email, password=user_create.password) - return guest_client + return guest_client.login( + email=user_create.email, password=user_create.password + ) verify_key = SyftSigningKey.generate().verify_key mock_node_metadata = NodeMetadata( diff --git a/packages/syft/tests/syft/users/user_code_test.py b/packages/syft/tests/syft/users/user_code_test.py index f24dc8f3c59..9fe191e25ea 100644 --- a/packages/syft/tests/syft/users/user_code_test.py +++ b/packages/syft/tests/syft/users/user_code_test.py @@ -64,7 +64,7 @@ def test_scientist_can_list_code_assets(worker: sy.Worker, faker: Faker) -> None guest_client = root_client.guest() credentials.pop("name") - guest_client.login(**credentials) + guest_client = guest_client.login(**credentials) root_client.upload_dataset(dataset=dataset) diff --git a/packages/syft/tests/syft/users/user_test.py b/packages/syft/tests/syft/users/user_test.py index 63d581926b2..3b56ca54a9e 100644 --- a/packages/syft/tests/syft/users/user_test.py +++ b/packages/syft/tests/syft/users/user_test.py @@ -46,7 +46,7 @@ def get_mock_client(root_client, role) -> DomainClient: assert worker.root_client.api.services.user.update( user_id, UserUpdate(user_id=user_id, role=role) ) - client.login(email=mail, password=password) + client = client.login(email=mail, password=password) client._fetch_api(client.credentials) # hacky, but useful for testing: patch user id and role on client client.user_id = user_id diff --git a/tests/integration/network/gateway_test.py b/tests/integration/network/gateway_test.py index b58b9cc12fb..e5c1e4e6adf 100644 --- a/tests/integration/network/gateway_test.py +++ b/tests/integration/network/gateway_test.py @@ -39,8 +39,12 @@ def test_domain_connect_to_gateway(domain_1_port, gateway_port): assert proxy_domain_client.metadata == domain_client.metadata assert proxy_domain_client.user_role == ServiceRole.NONE - domain_client.login(email="info@openmined.org", password="changethis") - proxy_domain_client.login(email="info@openmined.org", password="changethis") + domain_client = domain_client.login( + email="info@openmined.org", password="changethis" + ) + proxy_domain_client = proxy_domain_client.login( + email="info@openmined.org", password="changethis" + ) assert proxy_domain_client.logged_in_user == "info@openmined.org" assert proxy_domain_client.user_role == ServiceRole.ADMIN