-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Trim some public fields on the Agent #3269
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
Conversation
UnitySDK/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DAgent.cs
Outdated
Show resolved
Hide resolved
|
/// <returns> | ||
/// <c>true</c>, if max step reached was reached, <c>false</c> otherwise. | ||
/// </returns> | ||
public bool IsMaxStepReached() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These seem like they would be useful for users to have access to (although maybe reworking them to properties).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a use case where the user knowing when the Agent is Done or reached max step would be useful. Do you have an example ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not have an example, but I'm sure some users will after we remove it, and it seems like very little overhead to keep.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IsMaxStepReached can be derived from GetStepCount and maxStep, so I that might be OK to remove. But I think keeping it as a method hides the internals better (i.e. you have to know about maxStep <= 0 ==> IsMaxStepReached is never true)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Done(), it's generally really frustrating to be able to set something but not read it's value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a use case where the user knowing when the Agent is Done or reached max step would be useful. Do you have an example?
@vincentpierre I don't think the argument "I can't think of a reason to have it" is sufficient to remove the accessor of a state that is directly modifiable by the user. We use it internally in Agent for a number of reasons. One of the thousands of users that we have may use the IsDone
accessor for reasons we haven't thought of. Whether it's custom UI, an event trigger for something else. I'm not sure how they might use it, but it feels really strange to me to let users modify the state of Agent without being to ask what that state is.
I would argue that, in general, if we are allowing a user to modify a state, we should also allow them to access that state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a concrete of why we should be able to read it is right in our own tests:
public bool IsDone() | |
{ | |
return (bool)typeof(Agent).GetField("m_Done", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we are testing the inner working of the Agent in the tests. I think it is okay, I suppose m_Done can be marked as an internal field on the Agent rather than private.
I think what we need to have access to for testing and for using the tool are very different things.
@andrewcoh @ervteng can you guys look and leave feedback. Arguing for/against this is out of my area of expertise for the removal of |
I'm not in support of removing So you put the |
Agree with @ervteng. |
6f54cac
to
106e5b4
Compare
I reverted my changes to SetReward. |
Seems like it could be a little late but I also agree with @ervteng . The SetReward enables implementation of reward functions that would not be possible otherwise. Should we name it something more explicit like SetFullStepReward so that it's less confusing? |
Some other possibilities:
|
/// <summary> | ||
/// Resets the step reward and possibly the episode reward for the agent. | ||
/// </summary> | ||
public void ResetReward() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The places were this was removed don't account for the case where m_Done
is true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reset logic is really confusing. We have:
ResetIfDone
_AgentReset
AgentReset
ResetData
ForceReset
Just by looking, I have no idea which is done when or why.
This issue may not be in the scope of PR, but it feels like something that should be addressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They do, I reset the Cumulative reward in ResetData
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and ResetReward
I will not rename SetReward in this PR. I think we can do that later |
@ervteng I think there are situations other than termination states where we might want the functionality of SetReward |
On the question of the On the SetReward topic, I think you are very unanimous that it is useful (so I won't fight too long) but I think it introduces a lot of confusion (that I don't think renaming would entirely solve). I personally think adding a reward should be an irrevocable action. |
|
I made the AgentInfo property of the Agent private. So yes I am hiding it. What part of the Public API are we passing it to? |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Don't forget to update the migration guide (but that can be another PR).
Removed the following fields from the Agent :
SetRewards()IsDone()IsMaxStepReached()