Skip to content

[change] Make Agent non-abstract, update Basic scene. #3528

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

Merged
merged 7 commits into from
Mar 2, 2020

Conversation

chriselion
Copy link
Contributor

@chriselion chriselion commented Feb 28, 2020

Proposed change(s)

  • Make Agent non-abstract, and remove exception from default implementation of Heuristic()
  • Change Basic scene to not inherit from Agent
    • Calls Agent.GetAction() and uses a SensorComponent instead of CollectObservations
    • I kept the name BasicAgent - not sure what else to call it?
  • Move SensorBase out of Sensor namespace and into Examples.

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

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

/// Observations are generated by the attached SensorComponent, and the actions
/// are retrieved from the Agent.
/// </summary>
public class BasicAgent : MonoBehaviour
Copy link
Contributor Author

Choose a reason for hiding this comment

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

BasicController? BasicPlayer? BasicAI?

Copy link
Contributor

Choose a reason for hiding this comment

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

BasicController

largeGoal.transform.position = new Vector3(m_LargeGoalPosition - 10f, 0f, 0f);
}

public override 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.

Removed this since I don't want to inherit from Agent. I don't think it was getting us much.

@@ -92,16 +85,21 @@ public void FixedUpdate()

void WaitTimeInference()
{
if (!Academy.Instance.IsCommunicatorOn)
if (Academy.Instance.IsCommunicatorOn)
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 logic got flipped here accidentally at some point. Now training steps quickly and inference takes its time.

Copy link
Contributor

Choose a reason for hiding this comment

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

😨

@@ -1,7 +1,9 @@
namespace MLAgents.Sensors
using MLAgents.Sensors;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: moved out of com.unity.ml-agents

throw new UnityAgentsException(
"The Heuristic method was not implemented for the Agent on the " +
$"{gameObject.name} GameObject.");
return null;
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 we want to keep this usable without inheriting, I think we need to remove this exception. Will to be overruled though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to remove it? If Heuristic is called but not implemented, an error should be raised. Or should be make a Heuristic component?
Other question, is it okay for it to be null? Does that break something down the line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about a log warning instead of an exception?

is it okay for it to be null?

I think that would depend on the AgentAction implementation.

Copy link
Contributor

@surfnerd surfnerd left a comment

Choose a reason for hiding this comment

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

cool!

$"{gameObject.name} GameObject.");
Debug.LogWarning("Heuristic method called but not implemented. Return placeholder actions.");
var param = m_PolicyFactory.brainParameters;
var actionSize = param.vectorActionSpaceType == SpaceType.Continuous ?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Feels like this should be a property on brainParameters since we do it in ResetData() too :

if (param.vectorActionSpaceType == SpaceType.Continuous)
{
m_Action.vectorActions = new float[param.vectorActionSize[0]];
m_Info.storedVectorActions = new float[param.vectorActionSize[0]];
}
else
{
m_Action.vectorActions = new float[param.vectorActionSize.Length];
m_Info.storedVectorActions = new float[param.vectorActionSize.Length];
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

int BrainParameters.ActionAllocationSize()?

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO, vectorActionSize should be an int and in discrete control only there should be an array of ints called discreteActionBrancheSizes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds like a bigger change that's out of scope for this PR. Are you OK leaving this code as is, or do you think a utility method/property would be cleaner?

$"{gameObject.name} GameObject.");
Debug.LogWarning("Heuristic method called but not implemented. Return placeholder actions.");
var param = m_PolicyFactory.brainParameters;
var actionSize = param.vectorActionSpaceType == SpaceType.Continuous ?
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO, vectorActionSize should be an int and in discrete control only there should be an array of ints called discreteActionBrancheSizes.

/// Observations are generated by the attached SensorComponent, and the actions
/// are retrieved from the Agent.
/// </summary>
public class BasicAgent : MonoBehaviour
Copy link
Contributor

Choose a reason for hiding this comment

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

BasicController

@chriselion chriselion merged commit 1073ee6 into master Mar 2, 2020
@delete-merged-branch delete-merged-branch bot deleted the develop-agent-non-abstract branch March 2, 2020 19:21
@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.

3 participants