Skip to content

Conversation

@vincentpierre
Copy link
Contributor

No description provided.

@vincentpierre vincentpierre self-assigned this Feb 12, 2020
Co-Authored-By: Chris Elion <chris.elion@unity3d.com>
if info.n_agents() == self._n_agents:
return info
n_extra_agents = info.n_agents() - self._n_agents
if self._n_agents is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like either this is never true, or the math on the line above is bad (can't do int - None)

Copy link
Contributor

@ervteng ervteng Feb 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should never be true as self.n_agents will be assigned by the check_agents call, which is done before this method - prob should remove this if

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got mypy freeking out

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a look

Copy link
Contributor

@ervteng ervteng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably more comments and better exceptions but the logic seems OK

n_extra_agents = info.n_agents() - self._n_agents
if self._n_agents is None:
self._n_agents = 1
if n_extra_agents < 0 or n_extra_agents > 2 * self._n_agents:
Copy link
Contributor

@chriselion chriselion Feb 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about Agents that don't make a decision every step? Wouldn't that lead to info.n_agents() < self._n_agents?

What about an Agent that calls Done() multiple times in the same step? Wouldn't that lead to info.n_agents() > 2 * self._n_agents ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but you should not call Done multiple times per step : )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we should assert that on the C# side.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And/or provide a more descriptive error message here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Done is sent multiple times, the gym will ignore it if it is sent between decision steps (this is what the while loop is for)

while info.n_agents() < self._n_agents:
if not info.done.all():
raise UnityGymException(
"The environment does not have the expected amount of agents."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a more detailed exception here - something like "Agents didn't make decisions at the same time"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to the error

else:
self._env.step()
info = self._env.get_step_result(self.brain_name)
while info.n_agents() < self._n_agents:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on the scary-looking while loop maybe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know what you think

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add to the documentation that the gym can only be used with environments in which the agents request decisions at the same time and not to use the offset feature?

Co-Authored-By: Chris Elion <chris.elion@unity3d.com>
vincentpierre and others added 4 commits February 11, 2020 17:07
Co-Authored-By: Chris Elion <chris.elion@unity3d.com>
Co-Authored-By: Chris Elion <chris.elion@unity3d.com>
Co-Authored-By: Chris Elion <chris.elion@unity3d.com>
@vincentpierre vincentpierre changed the title """""Fixing"""""" Fixing Gym for single and multi-agent following reset changes on C# Feb 12, 2020
* rename and comments

* enumerate
@vincentpierre vincentpierre merged commit a4acb65 into release-0.14.0 Feb 12, 2020
@delete-merged-branch delete-merged-branch bot deleted the release-fix-gym-multiagent branch February 12, 2020 22:54
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants