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

non-IEnumerable interface for action masking #5060

Merged
merged 5 commits into from
Mar 10, 2021

Conversation

chriselion
Copy link
Contributor

@chriselion chriselion commented Mar 9, 2021

Proposed change(s)

This fixes a few things that bugged me about IDiscreteActionMask:

  • Removes the GetMask and ResetMask methods - these were part of the implementation in ActuatorDiscreteActionMask, but they weren't meant for public use (and there was no safe way to use them in an OnActionReceived callback).
  • Adds a method that doesn't require an IEnumerable. The previous approach required creating an object to pass, and also needed to allocate memory to iterate over it.
  • Made what you're doing more explicit, and also undoable - "WriteMask" always felt vague, and I always had to look up whether I was enabling or disabling the actions.

Things I haven't done yet but would like feedback on:

  • Should we remove IDiscreteActionMask.WriteMask()? This would be a larger interface change for anyone using it, but I think it's for the best.
  • Should we stop having this as an interface and use a concrete implementation instead? Making it an interface feels strange, as there's no way for a user to implement their own version and get it passed through the system (although this could change in the future if we want to decouple the implementations.

I'm leaning towards removing WriteMask but keeping the interface, but wanted to discuss it further.

I haven't updated existing tests or documentation yet; wanted to get feedback on the general approach first.

Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)

https://jira.unity3d.com/browse/MLA-1831
https://jira.unity3d.com/browse/MLA-1728

Types of change(s)

  • Code refactor
  • Breaking change
  • Documentation update
  • Other (please describe)

Checklist

  • Added tests that prove my fix is effective or that my feature works
  • Updated the changelog (if applicable)
  • Updated the documentation (if applicable)
  • Updated the migration guide (if applicable)

Other comments

@@ -122,23 +115,33 @@ IEnumerable<int> InvalidMoveIndices()
"an invalid move will be passed to AbstractBoard.MakeMove()."
);
}
// This means the last move won't be returned as an invalid index.
yield break;
actionMask.SetActionEnabled(branch, numMoves - 1, false);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This needs to be true

@chriselion chriselion marked this pull request as ready for review March 10, 2021 03:37
@chriselion chriselion merged commit 7f74c08 into v2-staging Mar 10, 2021
@delete-merged-branch delete-merged-branch bot deleted the MLA-1831-action-mask-interface branch March 10, 2021 18:55
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 10, 2022
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.

3 participants