Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Would love a little help getting Jupyter Notebook working with Unity.

Discussion in 'ML-Agents' started by janimator, Apr 18, 2020.

  1. janimator

    janimator

    Joined:
    Apr 5, 2013
    Posts:
    52
    When you go to the
    ml-agent/notebooks/directory
    there are two notebook files.

    getting-started-gym.ipynb

    and
    getting-started.ipynb
    .

    I can get the gym environment to run correctly, where it asks you to hit play on unity and runs, but not the other one. What is the difference between the two? Any guesses why the non-gym environment wont run? Can I only control Unity using python gym environment?

    The problem starts when running the Start Environment section of
    getting-started.ipynb
    I do not receive any notification to hit Play in Unity. Once that block of code times out i get.

    Code (CSharp):
    1.  
    2. UnityTimeOutException: The Unity environment took too long to respond. Make sure that :
    3.     The environment does not need user interaction to launch
    4.     The Agents are linked to the appropriate Brains
    5.     The environment and the Python interface have compatible versions.
    6.  
    I did set
    env_name = None
    which seems to work for the OpenAiGym notebook, but not this one.
     
  2. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,843
    I'll flag this for the team to check out.
     
  3. vincentpierre

    vincentpierre

    Joined:
    May 5, 2017
    Posts:
    160
    What version of ml-agents are you using? We deprecated the notebooks in our most recent release. It is possible that the message prompting you to press play in the editor did not go through, but Python is still waiting for it. Maybe press play in the editor regardless and see if it works. Alternatively, you can use an executable to start the training, this way you will not need to interact with the editor.
     
  4. janimator

    janimator

    Joined:
    Apr 5, 2013
    Posts:
    52
    Using MLAgent Version 0.15.1
    I'm not sure if maybe I'm doing something wrong but the code I'm trying to run is.
    Code (CSharp):
    1. engine_configuration_channel = EngineConfigurationChannel()
    2. env = UnityEnvironment(file_name=env_name, side_channels = [engine_configuration_channel])
    3. #env = UnityEnv(env_name, worker_id=0, use_visual=True, multiagent=True)
    4. #Reset the environment
    5. env.reset()
    6.  
    7. # Set the default brain to work with
    8. group_name = env.get_agent_groups()[0]
    9. group_spec = env.get_agent_group_spec(group_name)
    10.  
    11. # Set the time scale of the engine
    12. engine_configuration_channel.set_configuration_parameters(time_scale = 3.0)
    After running that, the code block stalls for a bit before giving me the following error.

    Code (CSharp):
    1. UnityTimeOutException: The Unity environment took too long to respond. Make sure that :
    2.      The environment does not need user interaction to launch
    3.      The Agents are linked to the appropriate Brains
    4.      The environment and the Python interface have compatible versions.
    .
    I did try to just run Unity anyways, but with no luck. I'm new to working with MLAgent and python so I may be missing something simpe. I did set the env_name to None.

    When you say "We deprecated the notebooks in our most recent release", do you mean you Jupyter Notebook will not be supported?
     
  5. vincentpierre

    vincentpierre

    Joined:
    May 5, 2017
    Posts:
    160
    I miss-spoke, the notebooks will be deprecated in the next release but we will still support the use of UnityEnvironment. (We did not manage to integrate the notebooks in our testing framework)
    Your error is rather strange (even stranger that it works with the gym wrapper) When passing an executable path, there should not be any missed timing since Python launches the environment.
    - Have you tried our sample environments? Are you seeing this issue with the examples or a custom environment?
    It is possible that the executable you are has a problem (no agent requested a decision in it before Python timed out).
    - Are you sure you have the same version of the communication? You can check by comparing the numbers here https://github.com/Unity-Technologi....1/com.unity.ml-agents/Runtime/Academy.cs#L61 and here https://github.com/Unity-Technologi...-agents-envs/mlagents_envs/environment.py#L63
    - Are you able to use the mlagents-learn command? If you are, this might be due to an issue in the jupyter notebook.
    - What path to the environment are you using? Are you sure it is the intended one? Does the environment launch properly? (when building the environment you can check DevelopementBuild to see potential error messages when launching the executable)
     
  6. vincentpierre

    vincentpierre

    Joined:
    May 5, 2017
    Posts:
    160