Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Halt training process issue when enable / disable ml agents.

Discussion in 'ML-Agents' started by piedpipe, Sep 14, 2020.

  1. piedpipe

    piedpipe

    Joined:
    May 14, 2020
    Posts:
    2
    I have a problem using ml agent.

    Issue is that disabling and enabling agents on Unity causes error.

    When that happens training stops with below errors. I need to switch the agent from disabled to enabled. for example when the agent dies from receiving attacks then respawns after a while, and between that death and respawn time the agent becomes disabled. Meaning the gameobject of the agent becomes SetActive(false). Mlagents-learn halts with below error message

    Traceback (most recent call last):
    File "C:\Program Files\Python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
    File "C:\Program Files\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
    File "D:\UnityProjects\zGame\python-env\release6\Scripts\mlagents-learn.exe\__main__.py", line 7, in <module>
    File "d:\unityprojects\zgame\python-env\release6\lib\site-packages\mlagents\trainers\learn.py", line 276, in main
    run_cli(parse_command_line())
    File "d:\unityprojects\zgame\python-env\release6\lib\site-packages\mlagents\trainers\learn.py", line 272, in run_cli
    run_training(run_seed, options)
    File "d:\unityprojects\zgame\python-env\release6\lib\site-packages\mlagents\trainers\learn.py", line 149, in run_training
    tc.start_learning(env_manager)
    File "d:\unityprojects\zgame\python-env\release6\lib\site-packages\mlagents_envs\timers.py", line 305, in wrapped
    return func(*args, **kwargs)
    File "d:\unityprojects\zgame\python-env\release6\lib\site-packages\mlagents\trainers\trainer_controller.py", line 181, in start_learning
    self.reset_env_if_ready(env_manager)
    File "d:\unityprojects\zgame\python-env\release6\lib\site-packages\mlagents\trainers\trainer_controller.py", line 229, in reset_env_if_ready
    self.end_trainer_episodes()
    File "d:\unityprojects\zgame\python-env\release6\lib\site-packages\mlagents\trainers\trainer_controller.py", line 210, in end_trainer_episodes
    trainer.end_episode()
    File "d:\unityprojects\zgame\python-env\release6\lib\site-packages\mlagents\trainers\ghost\trainer.py", line 298, in end_episode
    self.trainer.end_episode()
    File "d:\unityprojects\zgame\python-env\release6\lib\site-packages\mlagents\trainers\trainer\rl_trainer.py", line 56, in end_episode
    for agent_id in rewards:
    RuntimeError: dictionary changed size during iteration


    Initially I called agent's endEpisode then deactivated the gameobject of the agent. But with the error I tried not calling endEpisode, but both of the cases had the same error but it wasn't consistent at all. Usually occurred between 10M steps to 20M steps. Again, is this a bug and will there be a fix to this?



    Thanks!
     
  2. andrewcoh_unity

    andrewcoh_unity

    Unity Technologies

    Joined:
    Sep 5, 2019
    Posts:
    162
    Hi @piedpipe

    Are you sure that it's due to disable/enabling agents? Do you get an error if you do not disable/enable?
     
  3. piedpipe

    piedpipe

    Joined:
    May 14, 2020
    Posts:
    2
    Sure. I don't get error when does not calling disable/enable agent. ( don't call gameobject SetActive(flase) ).
    that error occurs randomly.
    Same error occured create and destroy agent.
     
  4. andrewcoh_unity

    andrewcoh_unity

    Unity Technologies

    Joined:
    Sep 5, 2019
    Posts:
    162
    Can you try running with threading: false in your config? It seems that the dictionary "reward" is being modified during iteration.