-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Make BehaviorParameters public again, update editor #3595
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
com.unity.ml-agents/Runtime/Agent.cs
Outdated
@@ -362,36 +364,49 @@ void NotifyAgentDone(DoneReason doneReason) | |||
/// Updates the Model for the agent. Any model currently assigned to the | |||
/// agent will be replaced with the provided one. If the arguments are | |||
/// identical to the current parameters of the agent, the model will | |||
/// remain unchanged. | |||
/// remain unchanged, unless the force parameter 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 "If the arguments are identical..." comment was wrong before :)
com.unity.ml-agents/Runtime/Agent.cs
Outdated
{ | ||
if (m_PolicyFactory.m_BehaviorType == behaviorType) | ||
if (m_PolicyFactory.behaviorType == behaviorType && !force) |
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.
Same idea here behind force
.
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.
Would exposing an internal "Reload Policy" do the trick ?
internal void ReloadPolicy()
{
m_Brain?.Dispose();
m_Brain = m_PolicyFactory.GeneratePolicy(Heuristic);
}
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.
Ah yes, that would be a lot cleaner! Then BehaviorParametersEditor can just call that.
public bool useChildSensors | ||
{ | ||
get { return m_UseChildSensors; } | ||
internal set { m_UseChildSensors = value; } // TODO make public, don't allow changes at runtime |
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.
Currently internal since it affects the sensor shapes.
@@ -105,7 +133,7 @@ public string fullyQualifiedBehaviorName | |||
get { return m_BehaviorName + "?team=" + TeamId; } | |||
} | |||
|
|||
public IPolicy GeneratePolicy(Func<float[]> heuristic) | |||
internal IPolicy GeneratePolicy(Func<float[]> heuristic) |
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.
Had to make this internal since IPolicy is internal.
@@ -38,7 +38,7 @@ internal void SetPolicy(IPolicy policy) | |||
|
|||
internal IPolicy GetPolicy() | |||
{ | |||
return (IPolicy) typeof(Agent).GetField("m_Brain", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this); | |||
return (IPolicy)typeof(Agent).GetField("m_Brain", 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.
This got auto-formatted.
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.
It looks good to me, but I am not thrilled with making BrainParameters public.
com.unity.ml-agents/Runtime/Agent.cs
Outdated
{ | ||
if (m_PolicyFactory.m_BehaviorType == behaviorType) | ||
if (m_PolicyFactory.behaviorType == behaviorType && !force) |
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.
Would exposing an internal "Reload Policy" do the trick ?
internal void ReloadPolicy()
{
m_Brain?.Dispose();
m_Brain = m_PolicyFactory.GeneratePolicy(Heuristic);
}
Proposed change(s)
Make BehaviorParameters and BrainParameters public again.
Update the BehaviorParametersEditor to push changes (e.g. model, behavior type) to the Agent at runtime.
Some property setters are still
internal
; this currently indicates the property is not safe to change during training/inference. I will do a pass on these in a subsequent PR to make the public and make sure they have effect at runtime.Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)
Will (mostly) resolve #3580
https://jira.unity3d.com/browse/MLA-741
Types of change(s)
Checklist
Other comments