Skip to content

Conversation

chriselion
Copy link
Contributor

@chriselion chriselion commented Mar 9, 2020

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)

  • Bug fix
  • New feature
  • 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

@@ -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.
Copy link
Contributor Author

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 :)

{
if (m_PolicyFactory.m_BehaviorType == behaviorType)
if (m_PolicyFactory.behaviorType == behaviorType && !force)
Copy link
Contributor Author

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.

Copy link
Contributor

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);
}

Copy link
Contributor Author

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
Copy link
Contributor Author

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)
Copy link
Contributor Author

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);
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 got auto-formatted.

Copy link
Contributor

@vincentpierre vincentpierre left a 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.

{
if (m_PolicyFactory.m_BehaviorType == behaviorType)
if (m_PolicyFactory.behaviorType == behaviorType && !force)
Copy link
Contributor

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);
}

@chriselion chriselion merged commit dceb5c4 into master Mar 10, 2020
@delete-merged-branch delete-merged-branch bot deleted the develop-BehaviorParams-public branch March 10, 2020 04:36
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 15, 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.

BehaviorParameters being Internal breaks code and makes automation impossible
3 participants