Unity-Technologies / ml-agents

The Unity Machine Learning Agents Toolkit (ML-Agents) is an open-source project that enables games and simulations to serve as environments for training intelligent agents using deep reinforcement learning and imitation learning.
https://unity.com/products/machine-learning-agents
Other
17.04k stars 4.15k forks source link

UnityTimeOutException: The Unity environment took too long to respond. #258

Closed NinaMaz closed 6 years ago

NinaMaz commented 6 years ago

Hello!

I am having the exact same problem as @TheChrizZly here #172 .

I have double checked the whole instructions on Building Unity Environment for 3DBall. I launch the Basics.ipynb. When the environment is instantiated, the binary launches. I see the balls falling down and then after some time get this error:

---------------------------------------------------------------------------
timeout                                   Traceback (most recent call last)
~\Desktop\RL_Nina\ml-agents\python\unityagents\environment.py in __init__(self, file_name, worker_id, base_port, curriculum)
    102                 self._socket.listen(1)
--> 103                 self._conn, _ = self._socket.accept()
    104                 self._conn.settimeout(30)

c:\users\nina.mazyavkina\appdata\local\continuum\anaconda3\envs\tensorflow-gpu\lib\socket.py in accept(self)
    194         """
--> 195         fd, addr = self._accept()
    196         # If our type has the SOCK_NONBLOCK flag, we shouldn't pass it onto the

timeout: timed out

During handling of the above exception, another exception occurred:

UnityTimeOutException                     Traceback (most recent call last)
<ipython-input-17-19bd9c6b2f7f> in <module>()
----> 1 env = UnityEnvironment(file_name=env_name)
      2 
      3 # Examine environment parameters
      4 print(str(env))
      5 

~\Desktop\RL_Nina\ml-agents\python\unityagents\environment.py in __init__(self, file_name, worker_id, base_port, curriculum)
    109                     "The Unity environment took too long to respond. Make sure {} does not need user interaction to "
    110                     "launch and that the Academy and the external Brain(s) are attached to objects in the Scene."
--> 111                     .format(str(file_name)))
    112 
    113             if "apiNumber" not in p:

UnityTimeOutException: The Unity environment took too long to respond. Make sure Ball_test does not need user interaction to launch and that the Academy and the external Brain(s) are attached to objects in the Scene.

After this I am unable to do any env.reset commands and get this mistake:

---------------------------------------------------------------------------
ConnectionResetError                      Traceback (most recent call last)
<ipython-input-12-b40f416a1ca7> in <module>()
      1 # Reset the environment
----> 2 env_info = env.reset(train_mode=train_mode)[default_brain]
      3 
      4 # Examine the state space for the default brain
      5 print("Agent state looks like: \n{}".format(env_info.states[0]))

~\Desktop\RL_Nina\ml-agents\python\unityagents\environment.py in reset(self, train_mode, config, progress)
    258 
    259         if self._loaded:
--> 260             self._conn.send(b"RESET")
    261             try:
    262                 self._conn.recv(self._buffer_size)

ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

As @awjuliani suggested as an answer to #172, I have taken the same steps with the Development build and this is what appeared in the output_log:


SocketException: No connection could be made because the target machine actively refused it.

  at System.Net.Sockets.Socket.Connect (System.Net.IPAddress[] addresses, System.Int32 port) [0x000c3] in <2d96311935af40c7b35c6ff5c955d7e7>:0 
  at System.Net.Sockets.Socket.Connect (System.String host, System.Int32 port) [0x00007] in <2d96311935af40c7b35c6ff5c955d7e7>:0 
  at ExternalCommunicator.InitializeCommunicator () [0x000a6] in C:\Users\nina.mazyavkina\Desktop\RL_Nina\ml-agents\unity-environment\Assets\ML-Agents\Scripts\ExternalCommunicator.cs:121 
  at Academy.Awake () [0x000e0] in C:\Users\nina.mazyavkina\Desktop\RL_Nina\ml-agents\unity-environment\Assets\ML-Agents\Scripts\Academy.cs:128 

What can be the issue causing this? Once again I have the type of the Ball3DBrain as External, but it doesn't seem to do the trick.

wouterhardeman commented 6 years ago

Maybe the solution in #254 might help?

NinaMaz commented 6 years ago

Unfortunately, no. I have closely followed the instructions on Building New Environment, but for some reason this doesn't help.

buntyke commented 6 years ago

Hi @NinaMaz, I was trying to run a unity executable on an AWS instance and was getting the same error. I was able to resolve the error by increasing the socket.settimeout parameter from 30 to 300 here and it started to work. Hope this might help you šŸ˜ƒ

bli0219 commented 6 years ago

I found the reply by @Maomao110 helpful at here https://github.com/Unity-Technologies/ml-agents/issues/71

Basically you just shutdown the ipynb in Jupyter and restart it.

TheChrizZly commented 6 years ago

Hi @NinaMaz I could resolve this issue by random trying. Here is what helped me: 1) Change brain to external. 2) save the scene and the project. 3) exit unity. and open the project again. 4) check if the brain is still on external (if not repeat 1-4) (I guess it have some issues with saving it properly) 5) delete (or move it away) all the 3d ball data folder and the exe from your previous builds. 6) build the project 7) check if its working (if not repeat 5-7 (if brain isnt on external repeat from 1)).

For some strange reason it worked for me at the 4th build without changing anything (just by deleting it and rebuilding it).

I hope you could resolve your issue.

NinaMaz commented 6 years ago

Thanks so much! Indeed just restarting notebook might help. For some reason if you haven't closed the environment and try to repeatedly launch some of the cells, you will receive the same error as me.

JunaidRana commented 5 years ago

Hi @NinaMaz, I was trying to run a unity executable on an AWS instance and was getting the same error. I was able to resolve the error by increasing the socket.settimeout parameter from 30 to 300 here and it started to work. Hope this might help you šŸ˜ƒ

can you please tell me where i can change this statement...i'm having same error

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.