Search Unity

Unable to connect to 3DBall environment running in Unity [Win64]

Discussion in 'ML-Agents' started by LOSTFREEMAN, Jan 24, 2020.

  1. LOSTFREEMAN

    LOSTFREEMAN

    Joined:
    Jan 24, 2020
    Posts:
    5
    I am trying to get started with ML Agents.

    Here's what I did on my Windows 10 machine in Unity:
    1. installed Unity 2019.2
    2. cloned https://github.com/Unity-Technologies/ml-agents, branch release-0.13.1
    3. opened UnitySDK in Unity and let it run upgrade
    4. let Unity update project
    5. did NOT find "Scripting Runtime Version" in Project Settings, assumed it is now default
    6. went to Assets\ML-Agents\Examples\3DBall\Scenes and double-clicked 3DBall
    In Python:
    1. created new conda environment
    2. in the environment run .\python.exe -m pip install mlagents "tensorflow==1.*" (successfully)
    3. launched Python and run (code from the basic example notebook)
    Code (CSharp):
    1. from mlagents_envs.side_channel.engine_configuration_channel import EngineConfigurationChannel
    2. from mlagents_envs.environment import UnityEnvironment
    3.  
    4. channel = EngineConfigurationChannel()
    5. env = UnityEnvironment(base_port=5006, file_name=None, side_channels=[channel])
    That printed "INFO:mlagents_envs:Listening on port 5006. Start training by pressing the Play button in the Unity Editor."
    So I hit Play button in the editor, and observed for a few minutes how some built-in agent juggled the balls.

    The python, however, never connected. Eventually, I got an error message:

    >>> env = UnityEnvironment(base_port=5006, file_name=None, side_channels=[channel])
    INFO:mlagents_envs:Listening on port 5006. Start training by pressing the Play button in the Unity Editor.
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "C:\Users\lost\.conda\envs\mlagents\lib\site-packages\mlagents_envs\environment.py", line 125, in __init__
    aca_output = self.send_academy_parameters(rl_init_parameters_in)
    File "C:\Users\lost\.conda\envs\mlagents\lib\site-packages\mlagents_envs\environment.py", line 512, in send_academy_parameters
    return self.communicator.initialize(inputs)
    File "C:\Users\lost\.conda\envs\mlagents\lib\site-packages\mlagents_envs\rpc_communicator.py", line 101, in initialize
    self.poll_for_timeout()
    File "C:\Users\lost\.conda\envs\mlagents\lib\site-packages\mlagents_envs\rpc_communicator.py", line 94, in poll_for_timeout
    "The Unity environment took too long to respond. Make sure that :\n"
    mlagents_envs.exception.UnityTimeOutException: The Unity environment took too long to respond. Make sure that :
    The environment does not need user interaction to launch
    The Agents are linked to the appropriate Brains
    The environment and the Python interface have compatible versions.

    So the question is: what have I done wrong? I expected Python to connect to Unity and let me type next command line env.reset()
     
  2. LOSTFREEMAN

    LOSTFREEMAN

    Joined:
    Jan 24, 2020
    Posts:
    5
    BTW, mlagents_envs.__version__ is "0.13.1" as expected.
     
  3. celion_unity

    celion_unity

    Joined:
    Jun 12, 2019
    Posts:
    289
    roddles likes this.
  4. LOSTFREEMAN

    LOSTFREEMAN

    Joined:
    Jan 24, 2020
    Posts:
    5
    Excellent, that solved the problem, and I can now list agent groups!
     
    celion_unity likes this.
  5. roddles

    roddles

    Joined:
    Jan 22, 2014
    Posts:
    3
    Ah-ha! My Jupyter notebook was set to listen on port 5005. To fix, in step 3 add the base_port as such:

    Code (CSharp):
    1. env = UnityEnvironment(base_port = 5004, file_name=env_name, side_channels = [engine_configuration_channel])
     
    createtheimaginable likes this.