OpenMined / PySyft

Perform data science on data that remains in someone else's server
https://www.openmined.org/
Apache License 2.0
9.53k stars 1.99k forks source link

ConnectionRefusedError: [Errno 111] Connection refused #3014

Closed fermat97 closed 4 years ago

fermat97 commented 4 years ago

Hi, I am using PyTorch 1.4.0, and syft version 0.2.3.a1. I am trying to run grid tutorial on federated learning. Once I do compute_nodes.append( NodeClient(hook, node) ), I get the following error:

ConnectionRefusedError: [Errno 111] Connection refused

This is the full stack of the error:

File "./train.py", line 26, in compute_nodes.append( NodeClient(hook, node) ) File "/miniconda3/envs/pysyft/lib/python3.8/site-packages/syft/workers/node_client.py", line 56, in init super().init( File "/miniconda3/envs/pysyft/lib/python3.8/site-packages/syft/workers/websocket_client.py", line 57, in init self.connect() File "/miniconda3/envs/pysyft/lib/python3.8/site-packages/syft/workers/websocket_client.py", line 69, in connect self.ws = websocket.create_connection(args) File "/miniconda3/envs/pysyft/lib/python3.8/site-packages/websocket/_core.py", line 515, in create_connection websock.connect(url, options) File "/miniconda3/envs/pysyft/lib/python3.8/site-packages/websocket/_core.py", line 222, in connect self.sock, addrs = connect(url, self.sock_opt, proxy_info(**options), File "/miniconda3/envs/pysyft/lib/python3.8/site-packages/websocket/_http.py", line 121, in connect sock = _open_socket(addrinfo_list, options.sockopt, options.timeout) File "/miniconda3/envs/pysyft/lib/python3.8/site-packages/websocket/_http.py", line 201, in _open_socket raise err File "/miniconda3/envs/pysyft/lib/python3.8/site-packages/websocket/_http.py", line 176, in _open_socket sock.connect(address) ConnectionRefusedError: [Errno 111] Connection refused

joaolcaas commented 4 years ago

Did you initiate each node/grid?

fermat97 commented 4 years ago

This is the code snippet I used:

import syft as sy 
from syft.workers.node_client import NodeClient
from syft.grid.public_grid import PublicGridNetwork
import torch

hook = sy.TorchHook(torch)
nodes = ["ws://localhost:3000/","ws://localhost:3001/"]
compute_nodes = []
for node in nodes:
    compute_nodes.append( NodeClient(hook, node) )
joaolcaas commented 4 years ago

But if you just did it without support of docker/command line, that's not supposed to work. You have to initiate the gateway and both node using docker from grid documentation or using the following commands:

Gateway (at grid/gateway): python gateway.py --port=5000 --start_local_db

Each node (at grid/app/websocket): python websocket_app.py --id=bob --port=3001 --gateway_url=http://localhost:5000 python websocket_app.py --id=alice --port=3001 --gateway_url=http://localhost:5000

fermat97 commented 4 years ago

thank you so much. It works when I run them as you said, in the background.