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.21k stars 4.16k forks source link

Unity build crashes/freezes when i interrupt or close build window #5910

Closed alhasacademy96 closed 1 year ago

alhasacademy96 commented 1 year ago

Describe the bug I am using ML-Agents for my project where we develop AI agents for research purposes. I am using yaml files for python communication with Unity. When i build my unity editor (application and use the yaml file it runs perfectly. However, when i try to close the build window it freezes and gives the error correctly :

UnityCommunicatorStoppedException: Communicator has exited.

To Reproduce Steps to reproduce the behavior:

  1. Any yaml file you have
  2. Click on the x button on the build window
  3. See that the window freezes/crashes.

Console logs / stack traces ''' UnityCommunicatorStoppedException Traceback (most recent call last)

Cell In[4], line 8 5 random.seed(2022) #set seed for random configs 6 print("initializing AAI environment") ----> 8 environment = AnimalAIEnvironment( 9 file_name=env_path, 10 11 base_port=port, 12 arenas_configurations=file, 13 play=True, 14 useCamera=True 15
16 ) 17 #print(environment.get_obs_dict()) 18 #behavior = list(environment.behavior_specs.keys())[0] # by default should be AnimalAI?team=0 19 #print(behaviour) 20 21 22 #make way of making unique folder names for log folders

File c:\users...\desktop\animal-ai\animalai\animalai\envs\environment.py:98, in AnimalAIEnvironment.init(self, additional_args, log_folder, file_name, worker_id, base_port, seed, play, arenas_configurations, inference, useCamera, resolution, grayscale, useRayCasts, raysPerSide, rayMaxDegrees, decisionPeriod, side_channels, no_graphics, use_YAML) 85 self.configure_side_channels(self.side_channels) 87 super().init( 88 file_name=file_name, ... --> 322 raise UnityCommunicatorStoppedException("Communicator has exited.") 323 self._update_behavior_specs(outputs) 324 rl_output = outputs.rl_output '''

Screenshots

Screenshot 2023-04-19 210250

In other words, how can i make sure that when i close the connection between unity and python (via yaml config files) that the connection will terminate then close without freezing/crashing by pressing the X button on the window GUI or any other keyboard key?

I apologise if this is badly written but it's hard for me to produce the problem in 2nd view as this is a bespoke project i am working on.

alhasacademy96 commented 1 year ago

I should also add that there is an established communication between unity and python/yaml config files and that communication needs to be deactivated or terminated and maybe the window will not freeze/crash when clicked on the X (close) button or pressed on Q button on keyboard which will terminate the connection first then close the build window. Any help would be appreciated.

miguelalonsojr commented 1 year ago

Is this with a custom Unity environment or one of our example environments?

alhasacademy96 commented 1 year ago

It’s a custom environment but I am assuming the same thing would happen with your environments as the problem probably lies with the connection interruption between python and unity via yaml files. On 22 Apr 2023 at 12:20 +0100, Miguel Alonso Jr. @.***>, wrote:

Is this with a custom Unity environment or one of our example environments? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

miguelalonsojr commented 1 year ago

It would be great if you can reproduce this with one of our environments and update the bug report accordingly. Thanks!

alhasacademy96 commented 1 year ago

I do not have access to your environments. If you search AnimalAI on GitHub you will see the environment On 22 Apr 2023 at 12:24 +0100, Miguel Alonso Jr. @.***>, wrote:

It would be great if you can reproduce this with one of our environments and update the bug report accordingly. Thanks! — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

miguelalonsojr commented 1 year ago

Our environments are part of this repository. If you open the Project folder in Unity, you'll see all of our examples.

alhasacademy96 commented 1 year ago

I just tried it and it’s the same error regardless of the environment. On 22 Apr 2023 at 15:26 +0100, Miguel Alonso Jr. @.***>, wrote:

Our environments are part of this repository. If you open the Project folder in Unity, you'll see all of our examples. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

miguelalonsojr commented 1 year ago

Thank you for confirming. Are you making a build of Unity and then pressing play in the editor and then closing the editor/build window? If so, that's not the way to use builds or the editor. Builds are stand alone executables and don't need the editor to be used for training. When you make a build, it can run outside the editor. You don't even need the editor running to use a build for training. If you are training in the editor, it runs within the editor, not in a build, and you cannot close the editor during training. These are two different methods of training.

miguelalonsojr commented 1 year ago

Here are the details of how to use executables (builds) for training: https://unity-technologies.github.io/ml-agents/Learning-Environment-Executable/

alhasacademy96 commented 1 year ago

I’m using yaml files for configurations of the training and objects to spawn in the environment. Please read my original issue again. There seems to be a connection when using yaml and unity build and when this connection is interrupted the build freezes/crashes On 22 Apr 2023 at 16:09 +0100, Miguel Alonso Jr. @.***>, wrote:

Here are the details of how to use executables (builds) for training: https://unity-technologies.github.io/ml-agents/Learning-Environment-Executable/ — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>