Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiagent Bug in Gym-Unity 14.1 #3531

Closed
sahandrez opened this issue Feb 28, 2020 · 10 comments
Closed

Multiagent Bug in Gym-Unity 14.1 #3531

sahandrez opened this issue Feb 28, 2020 · 10 comments
Labels
bug Issue describes a potential bug in ml-agents.

Comments

@sahandrez
Copy link

Hello,

There seems to be a bug with multiagent environments in gym-unity release 14.1.
Some of the example environments work fine (e.g. 3D ball) while some of them (e.g. WallJump) fail with this error:

"The environment does not have the expected amount of agents. "
gym_unity.envs.UnityGymException: The environment does not have the expected amount of agents. Some agents did not request decisions at the same time.

It is possible that the issue is originated in the Unity environment side, but I can't seem to find the reason behind it. Single Agent environments work fine.

I'm using the provided notebooks here.

Thanks,
Sahand

@sahandrez sahandrez added the bug Issue describes a potential bug in ml-agents. label Feb 28, 2020
@ervteng
Copy link
Contributor

ervteng commented Feb 28, 2020

Hi @sahandrez, the multi-agent gym currently doesn't support environments with multiple types of behaviors (WallJump has two), or on-demand decisions (e.g. Bouncer). This is due to how gym expects all data per step to be from the same observation/action space.

@sahandrez
Copy link
Author

sahandrez commented Feb 28, 2020

Hi @ervteng,
I see. Thanks. I'm having another problem after fixing what you mentioned. Now in our custom environment, we are getting this error as soon as an agent is done in the environment:

File "\workspace\ml-agents\gym-unity\gym_unity\envs\__init__.py", line 531, in mark_agent_done
    gym_index = self._agent_id_to_gym_index.pop(agent_id)
KeyError: 7

Any idea what might have caused it? Thanks.

@ervteng
Copy link
Contributor

ervteng commented Mar 2, 2020

Hi @sahandrez, are the agents done at different times/do they use on demand decisions?

Could you post the Inspector for your agents? Would be really helpful for us to debug. Thanks!

@sahandrez
Copy link
Author

Hi @ervteng,
Thanks. We solved our problem. There was a bug in our environment which was not flagged in V0.13 but with the new multiagent system in V0.14 we figured it out.

@batu
Copy link

batu commented Mar 8, 2020

Hello @sahandrez ,
Can you tell me how you fixed the problem? I am facing the same KeyError issue in mark_agent_done

@sahandrez
Copy link
Author

Hi @batu,
Sorry I no longer have access to the code. You can ask @ReinforcedMan for more info.

@RealZST
Copy link

RealZST commented Mar 23, 2020

Hi @batu ,
Did you fix it? I got the same error when I use gym-unity-0.15.0. Looking forward to your reply. Thank you.

@batu
Copy link

batu commented Mar 24, 2020

Unfortunately no. But I have something that is good enough.

In my case, I believe it happened when my agent got out of bounds and didn't reset properly. It was going out of bound because my implementation was acting weird when I push the simulation speed very high.

Currently, it happens only every 10-100 episodes, so when it does I just catch it and... pass.

@chriselion
Copy link
Contributor

For this error:

File "\workspace\ml-agents\gym-unity\gym_unity\envs\__init__.py", line 531, in mark_agent_done
    gym_index = self._agent_id_to_gym_index.pop(agent_id)
KeyError: 7

We found a bug in the gym wrapper which would appear if an Agent called EndEpisode multiple times in the same step. The fix for this is in #3700, and we'll be doing a patch release next week that contains this fix (and a few others).

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue describes a potential bug in ml-agents.
Projects
None yet
Development

No branches or pull requests

5 participants