Skip to content

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

Merged
merged 6 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion UnitySDK/Assets/ML-Agents/Editor/AgentEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public override void OnInspectorGUI()
serializedAgent.Update();

var maxSteps = serializedAgent.FindProperty(
"agentParameters.maxStep");
"maxStep");

EditorGUILayout.PropertyField(
maxSteps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void SetUp()
}
}

static List<Agent> GetFakeAgents()
static List<TestAgent> GetFakeAgents()
{
var goA = new GameObject("goA");
var bpA = goA.AddComponent<BehaviorParameters>();
Expand All @@ -34,7 +34,7 @@ static List<Agent> GetFakeAgents()
bpB.brainParameters.numStackedVectorObservations = 1;
var agentB = goB.AddComponent<TestAgent>();

var agents = new List<Agent> { agentA, agentB };
var agents = new List<TestAgent> { agentA, agentB };
foreach (var agent in agents)
{
var agentEnableMethod = typeof(Agent).GetMethod("OnEnableHelper",
Expand All @@ -56,8 +56,9 @@ static List<Agent> GetFakeAgents()
actionMasks = new[] { true, false, false, false, false },
};

agentA.Info = infoA;
agentB.Info = infoB;

agentA._Info = infoA;
agentB._Info = infoB;
return agents;
}

Expand Down Expand Up @@ -115,8 +116,8 @@ public void GenerateVectorObservation()
var agent1 = agentInfos[1];
var inputs = new List<AgentInfoSensorsPair>
{
new AgentInfoSensorsPair{agentInfo = agent0.Info, sensors = agent0.sensors},
new AgentInfoSensorsPair{agentInfo = agent1.Info, sensors = agent1.sensors},
new AgentInfoSensorsPair{agentInfo = agent0._Info, sensors = agent0.sensors},
new AgentInfoSensorsPair{agentInfo = agent1._Info, sensors = agent1.sensors},
};
generator.Generate(inputTensor, batchSize, inputs);
Assert.IsNotNull(inputTensor.data);
Expand All @@ -143,8 +144,8 @@ public void GeneratePreviousActionInput()
var agent1 = agentInfos[1];
var inputs = new List<AgentInfoSensorsPair>
{
new AgentInfoSensorsPair{agentInfo = agent0.Info, sensors = agent0.sensors},
new AgentInfoSensorsPair{agentInfo = agent1.Info, sensors = agent1.sensors},
new AgentInfoSensorsPair{agentInfo = agent0._Info, sensors = agent0.sensors},
new AgentInfoSensorsPair{agentInfo = agent1._Info, sensors = agent1.sensors},
};
generator.Generate(inputTensor, batchSize, inputs);
Assert.IsNotNull(inputTensor.data);
Expand Down Expand Up @@ -172,8 +173,8 @@ public void GenerateActionMaskInput()
var agent1 = agentInfos[1];
var inputs = new List<AgentInfoSensorsPair>
{
new AgentInfoSensorsPair{agentInfo = agent0.Info, sensors = agent0.sensors},
new AgentInfoSensorsPair{agentInfo = agent1.Info, sensors = agent1.sensors},
new AgentInfoSensorsPair{agentInfo = agent0._Info, sensors = agent0.sensors},
new AgentInfoSensorsPair{agentInfo = agent1._Info, sensors = agent1.sensors},
};

generator.Generate(inputTensor, batchSize, inputs);
Expand Down
25 changes: 18 additions & 7 deletions UnitySDK/Assets/ML-Agents/Editor/Tests/MLAgentsEditModeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ namespace MLAgents.Tests
{
public class TestAgent : Agent
{

public AgentInfo _Info
{
get
{
return (AgentInfo)typeof(Agent).GetField("m_Info", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this);
}
set
{
typeof(Agent).GetField("m_Info", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(this, value);
}
}

public bool IsDone()
{
return (bool)typeof(Agent).GetField("m_Done", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this);
}
public int initializeAgentCalls;
public int collectObservationsCalls;
public int agentActionCalls;
Expand Down Expand Up @@ -264,8 +281,6 @@ public void TestAgent()
var agentEnableMethod = typeof(Agent).GetMethod(
"OnEnableHelper", BindingFlags.Instance | BindingFlags.NonPublic);

agent1.agentParameters = new AgentParameters();
agent2.agentParameters = new AgentParameters();
var decisionRequester = agent1.gameObject.AddComponent<DecisionRequester>();
decisionRequester.DecisionPeriod = 2;
decisionRequester.Awake();
Expand Down Expand Up @@ -371,8 +386,6 @@ public void TestAgent()
var agentEnableMethod = typeof(Agent).GetMethod(
"OnEnableHelper", BindingFlags.Instance | BindingFlags.NonPublic);

agent1.agentParameters = new AgentParameters();
agent2.agentParameters = new AgentParameters();
var decisionRequester = agent1.gameObject.AddComponent<DecisionRequester>();
decisionRequester.DecisionPeriod = 2;

Expand Down Expand Up @@ -473,14 +486,12 @@ public void TestCumulativeReward()

var agentEnableMethod = typeof(Agent).GetMethod(
"OnEnableHelper", BindingFlags.Instance | BindingFlags.NonPublic);
agent1.agentParameters = new AgentParameters();
agent2.agentParameters = new AgentParameters();

var decisionRequester = agent1.gameObject.AddComponent<DecisionRequester>();
decisionRequester.DecisionPeriod = 2;
decisionRequester.Awake();

agent1.agentParameters.maxStep = 20;
agent1.maxStep = 20;

agentEnableMethod?.Invoke(agent2, new object[] { });
agentEnableMethod?.Invoke(agent1, new object[] { });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: aaba48bf82bee4751aa7b89569e57f73, type: 3}
m_Name:
m_EditorClassIdentifier:
agentParameters:
maxStep: 5000
onDemandDecision: 0
numberOfActionsBetweenDecisions: 5
maxStep: 5000
ball: {fileID: 1036225416237908}
--- !u!114 &1306725529891448089
MonoBehaviour:
Expand All @@ -320,6 +317,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
DecisionPeriod: 5
RepeatAction: 1
offsetStep: 0
--- !u!1 &1533320402322554
GameObject:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: edf26e11cf4ed42eaa3ffb7b91bb4676, type: 3}
m_Name:
m_EditorClassIdentifier:
agentParameters:
maxStep: 5000
onDemandDecision: 0
numberOfActionsBetweenDecisions: 5
maxStep: 5000
ball: {fileID: 1142513601053358}
--- !u!114 &8193279139064749781
MonoBehaviour:
Expand All @@ -624,6 +621,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
DecisionPeriod: 5
RepeatAction: 1
offsetStep: 0
--- !u!1 &1978072206102878
GameObject:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1779,10 +1779,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 2f37c30a5e8d04117947188818902ef3, type: 3}
m_Name:
m_EditorClassIdentifier:
agentParameters:
maxStep: 5000
onDemandDecision: 0
numberOfActionsBetweenDecisions: 5
maxStep: 5000
target: {fileID: 4490950947783742}
ground: {fileID: 4684408634944056}
detectTargets: 1
Expand Down Expand Up @@ -1838,6 +1835,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
DecisionPeriod: 5
RepeatAction: 0
offsetStep: 0
--- !u!1 &1520563409393552
GameObject:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1704,10 +1704,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 2f37c30a5e8d04117947188818902ef3, type: 3}
m_Name:
m_EditorClassIdentifier:
agentParameters:
maxStep: 5000
onDemandDecision: 0
numberOfActionsBetweenDecisions: 5
maxStep: 5000
target: {fileID: 4749909135913778}
ground: {fileID: 4856650706546504}
detectTargets: 0
Expand Down Expand Up @@ -1763,6 +1760,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
DecisionPeriod: 5
RepeatAction: 0
offsetStep: 0
--- !u!1 &1492926997393242
GameObject:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void FixedUpdate()
{
foreach (var bodyPart in m_JdController.bodyPartsDict.Values)
{
if (bodyPart.targetContact && !IsDone() && bodyPart.targetContact.touchingTarget)
if (bodyPart.targetContact && bodyPart.targetContact.touchingTarget)
{
TouchedTarget();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2200,10 +2200,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c66e6845309d241c78a6d77ee2567928, type: 3}
m_Name:
m_EditorClassIdentifier:
agentParameters:
maxStep: 5000
onDemandDecision: 0
numberOfActionsBetweenDecisions: 5
maxStep: 5000
area: {fileID: 1819751139121548}
turnSpeed: 300
moveSpeed: 2
Expand Down Expand Up @@ -2260,6 +2257,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
DecisionPeriod: 5
RepeatAction: 1
offsetStep: 0
--- !u!1 &1482701732800114
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2526,10 +2524,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c66e6845309d241c78a6d77ee2567928, type: 3}
m_Name:
m_EditorClassIdentifier:
agentParameters:
maxStep: 5000
onDemandDecision: 0
numberOfActionsBetweenDecisions: 5
maxStep: 0
area: {fileID: 1819751139121548}
turnSpeed: 300
moveSpeed: 2
Expand Down Expand Up @@ -2842,10 +2837,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c66e6845309d241c78a6d77ee2567928, type: 3}
m_Name:
m_EditorClassIdentifier:
agentParameters:
maxStep: 5000
onDemandDecision: 0
numberOfActionsBetweenDecisions: 5
maxStep: 0
area: {fileID: 1819751139121548}
turnSpeed: 300
moveSpeed: 2
Expand Down Expand Up @@ -3421,10 +3413,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c66e6845309d241c78a6d77ee2567928, type: 3}
m_Name:
m_EditorClassIdentifier:
agentParameters:
maxStep: 5000
onDemandDecision: 0
numberOfActionsBetweenDecisions: 5
maxStep: 0
area: {fileID: 1819751139121548}
turnSpeed: 300
moveSpeed: 2
Expand Down Expand Up @@ -3723,10 +3712,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c66e6845309d241c78a6d77ee2567928, type: 3}
m_Name:
m_EditorClassIdentifier:
agentParameters:
maxStep: 5000
onDemandDecision: 0
numberOfActionsBetweenDecisions: 5
maxStep: 0
area: {fileID: 1819751139121548}
turnSpeed: 300
moveSpeed: 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c66e6845309d241c78a6d77ee2567928, type: 3}
m_Name:
m_EditorClassIdentifier:
agentParameters:
maxStep: 5000
onDemandDecision: 0
numberOfActionsBetweenDecisions: 5
maxStep: 0
area: {fileID: 1145096862361766}
turnSpeed: 300
moveSpeed: 2
Expand Down Expand Up @@ -1211,10 +1208,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c66e6845309d241c78a6d77ee2567928, type: 3}
m_Name:
m_EditorClassIdentifier:
agentParameters:
maxStep: 5000
onDemandDecision: 0
numberOfActionsBetweenDecisions: 5
maxStep: 0
area: {fileID: 1145096862361766}
turnSpeed: 300
moveSpeed: 2
Expand Down Expand Up @@ -1591,10 +1585,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c66e6845309d241c78a6d77ee2567928, type: 3}
m_Name:
m_EditorClassIdentifier:
agentParameters:
maxStep: 5000
onDemandDecision: 0
numberOfActionsBetweenDecisions: 5
maxStep: 5000
area: {fileID: 1145096862361766}
turnSpeed: 300
moveSpeed: 2
Expand Down Expand Up @@ -1637,6 +1628,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
DecisionPeriod: 5
RepeatAction: 1
offsetStep: 0
--- !u!1 &1399553220224106
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -3404,10 +3396,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c66e6845309d241c78a6d77ee2567928, type: 3}
m_Name:
m_EditorClassIdentifier:
agentParameters:
maxStep: 5000
onDemandDecision: 0
numberOfActionsBetweenDecisions: 5
maxStep: 0
area: {fileID: 1145096862361766}
turnSpeed: 300
moveSpeed: 2
Expand Down
Loading