chuangg / tdw-transport-challenge-starter-code

27 stars 2 forks source link

hanging and zmq error from attempt to create environment #4

Closed martinezjulio closed 3 years ago

martinezjulio commented 3 years ago

I am getting a hang after executing the the following line shown in the example under "Not using Docker":

env = gym.make("transport_challenge-v0", train = 0, physics = True, port = 1071)

I am running this on my Mac. After hitting control + c I get the following message:

>>> env = gym.make("transport_challenge-v0", train = 0, physics = True, port = 1071)
connect: 1071
^CTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/anaconda3/envs/tdwEnv/lib/python3.7/site-packages/gym/envs/registration.py", line 145, in make
    return registry.make(id, **kwargs)
  File "/usr/local/anaconda3/envs/tdwEnv/lib/python3.7/site-packages/gym/envs/registration.py", line 90, in make
    env = spec.make(**kwargs)
  File "/usr/local/anaconda3/envs/tdwEnv/lib/python3.7/site-packages/gym/envs/registration.py", line 60, in make
    env = cls(**_kwargs)
  File "/Users/juliomartinez/Documents/tdwProject/tdw-transport-challenge/tdw_transport_challenge/tdw_gym.py", line 44, in __init__
    train = train, exp = exp, fov = 90)
  File "/Users/juliomartinez/Documents/tdwProject/tdw-transport-challenge/tdw_transport_challenge/controller.py", line 32, in __init__
    screen_width=screen_size, screen_height=screen_size, fov = fov)
  File "/Users/juliomartinez/Documents/tdwProject/transport_challenge/transport_challenge/transport_controller.py", line 133, in __init__
    check_pypi_version=False)
  File "/usr/local/anaconda3/envs/tdwEnv/lib/python3.7/site-packages/magnebot/magnebot_controller.py", line 344, in __init__
    super().__init__(port=port, launch_build=launch_build, check_version=check_pypi_version)
  File "/usr/local/anaconda3/envs/tdwEnv/lib/python3.7/site-packages/tdw/controller.py", line 50, in __init__
    self.socket.recv()
  File "zmq/backend/cython/socket.pyx", line 781, in zmq.backend.cython.socket.Socket.recv
  File "zmq/backend/cython/socket.pyx", line 817, in zmq.backend.cython.socket.Socket.recv
  File "zmq/backend/cython/socket.pyx", line 186, in zmq.backend.cython.socket._recv_copy
  File "zmq/backend/cython/checkrc.pxd", line 13, in zmq.backend.cython.checkrc._check_rc
KeyboardInterrupt

I had a similar error with magnebot, but after including launch_build=True in the controller instantiation it worked. Not sure how I could fix that here tho. Any suggestions are appreciated.

abhi1092 commented 3 years ago

Did you run the TDW build separately? It seems from your description that the controller is not able to connect to TDW

martinezjulio commented 3 years ago

I'm not sure how to run it separately on a Mac. If I try to execute/launch tdw separately I run into file damaged error which is why I usually use launch_build=True in the controller itself. Has this worked for you on a Mac?

abhi1092 commented 3 years ago

I have added an option to launch the build. Try re-installing the library.

 env = gym.make("transport_challenge-v0", train = 0, physics = True, port = 1071, launch_build=True)

Let me know if that worked

martinezjulio commented 3 years ago

Ok that is great, that got me past that part and those lines seems to work now so thank you.

I ran into another error after from the following lines:

with open(pkg_resources.resource_filename("tdw_transport_challenge","train_dataset.pkl")) as fp:
    dataset = pickle.load(fp)  

The error output is the following:

Controller connected
Traceback (most recent call last):
  File "test.py", line 14, in <module>
    dataset = pickle.load(fp)  
  File "/usr/local/anaconda3/envs/tdwEnv2/lib/python3.7/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte

The directory tdw_transport_challenge is local and the file "train_dataset.pkl" is in there so I'm not sure if something else I'm doing wrong.

abhi1092 commented 3 years ago

Use binary mode to load the pickle file

with open(pkg_resources.resource_filename("tdw_transport_challenge","train_dataset.pkl"), 'rb') as fp:
    dataset = pickle.load(fp)  
abhi1092 commented 3 years ago

I have also made that change in the Readme

martinezjulio commented 3 years ago

Ok thanks.

Running into another error from inside the while loop, sorry for all the bother.

Controller connected
Traceback (most recent call last):
  File "test.py", line 27, in <module>
    action = agent.act(obs, info)
  File "/Users/juliomartinez/Documents/tdwProject2/tdw-transport-challenge/tdw_transport_challenge/h_agent.py", line 490, in act
    if self.sub_goal != -1:
AttributeError: 'H_agent' object has no attribute 'sub_goal'
abhi1092 commented 3 years ago

Call agent.reset() after creating it. You can refer to the test.py for usage. There are still some bugs in the hard-coded agent (H_agent) so you might run into some other errors while running the test.py script. But you can still use the environment to train your own agent.

martinezjulio commented 3 years ago

Ok great, thanks a ton!