From 8801fb8f8f5fadf367375e1fc8cecef6752f2c5f Mon Sep 17 00:00:00 2001 From: vincentpierre Date: Wed, 19 Feb 2020 11:34:49 -0800 Subject: [PATCH] Replace Agent.GetStepCount with Agent.StepCount` --- .../ML-Agents/Examples/Hallway/Scripts/HallwayAgent.cs | 2 +- com.unity.ml-agents/CHANGELOG.md | 1 + com.unity.ml-agents/Runtime/Agent.cs | 7 +++---- com.unity.ml-agents/Tests/Editor/MLAgentsEditModeTest.cs | 8 ++++---- docs/Migrating.md | 2 ++ 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Project/Assets/ML-Agents/Examples/Hallway/Scripts/HallwayAgent.cs b/Project/Assets/ML-Agents/Examples/Hallway/Scripts/HallwayAgent.cs index 6340bc0293..9f13889747 100644 --- a/Project/Assets/ML-Agents/Examples/Hallway/Scripts/HallwayAgent.cs +++ b/Project/Assets/ML-Agents/Examples/Hallway/Scripts/HallwayAgent.cs @@ -30,7 +30,7 @@ public override void CollectObservations(VectorSensor sensor) { if (useVectorObs) { - sensor.AddObservation(GetStepCount() / (float)maxStep); + sensor.AddObservation(StepCount / (float)maxStep); } } diff --git a/com.unity.ml-agents/CHANGELOG.md b/com.unity.ml-agents/CHANGELOG.md index 9d4636a8d2..4e4484abb7 100755 --- a/com.unity.ml-agents/CHANGELOG.md +++ b/com.unity.ml-agents/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - The stepping logic for the Agent and the Academy has been simplified (#3448) - Update Barracuda to 0.6.0-preview - The checkpoint file suffix was changed from `.cptk` to `.ckpt` (#3470) + - The method `GetStepCount()` on the Agent class has been replaced with the property getter `StepCount` ### Bugfixes - Fixed an issue which caused self-play training sessions to consume a lot of memory. (#3451) diff --git a/com.unity.ml-agents/Runtime/Agent.cs b/com.unity.ml-agents/Runtime/Agent.cs index 96866c425c..9b857328b9 100644 --- a/com.unity.ml-agents/Runtime/Agent.cs +++ b/com.unity.ml-agents/Runtime/Agent.cs @@ -314,15 +314,14 @@ public void GiveModel( m_Brain = m_PolicyFactory.GeneratePolicy(Heuristic); } - /// /// Returns the current step counter (within the current episode). /// /// - /// Current episode number. + /// Current step count. /// - public int GetStepCount() + public int StepCount { - return m_StepCount; + get { return m_StepCount; } } /// diff --git a/com.unity.ml-agents/Tests/Editor/MLAgentsEditModeTest.cs b/com.unity.ml-agents/Tests/Editor/MLAgentsEditModeTest.cs index bf989371cd..dca9f74f1c 100644 --- a/com.unity.ml-agents/Tests/Editor/MLAgentsEditModeTest.cs +++ b/com.unity.ml-agents/Tests/Editor/MLAgentsEditModeTest.cs @@ -406,7 +406,7 @@ public void TestAgent() Assert.AreEqual(i, aca.TotalStepCount); - Assert.AreEqual(agent2StepSinceReset, agent2.GetStepCount()); + Assert.AreEqual(agent2StepSinceReset, agent2.StepCount); Assert.AreEqual(numberAgent1Reset, agent1.agentResetCalls); Assert.AreEqual(numberAgent2Reset, agent2.agentResetCalls); @@ -536,12 +536,12 @@ public void TestMaxStepsReset() expectedAgentStepCount += 1; // If the next step will put the agent at maxSteps, we expect it to reset - if (agent1.GetStepCount() == maxStep - 1 || (i == 0)) + if (agent1.StepCount == maxStep - 1 || (i == 0)) { expectedResets +=1; } - if (agent1.GetStepCount() == maxStep - 1) + if (agent1.StepCount == maxStep - 1) { expectedAgentActionSinceReset = 0; expectedCollectObsCallsSinceReset = 0; @@ -549,7 +549,7 @@ public void TestMaxStepsReset() } aca.EnvironmentStep(); - Assert.AreEqual(expectedAgentStepCount, agent1.GetStepCount()); + Assert.AreEqual(expectedAgentStepCount, agent1.StepCount); Assert.AreEqual(expectedResets, agent1.agentResetCalls); Assert.AreEqual(expectedAgentAction, agent1.agentActionCalls); Assert.AreEqual(expectedAgentActionSinceReset, agent1.agentActionCallsSinceLastReset); diff --git a/docs/Migrating.md b/docs/Migrating.md index 9a4c5b99ca..09841a689f 100644 --- a/docs/Migrating.md +++ b/docs/Migrating.md @@ -14,11 +14,13 @@ The versions can be found in * The `Monitor` class has been moved to the Examples Project. (It was prone to errors during testing) * The `MLAgents.Sensor` namespace has been removed. All sensors now belong to the `MLAgents` namespace. * The `SetActionMask` method must now be called on the optional `ActionMasker` argument of the `CollectObservations` method. (We now consider an action mask as a type of observation) +* The method `GetStepCount()` on the Agent class has been replaced with the property getter `StepCount` ### Steps to Migrate * Replace your Agent's implementation of `CollectObservations()` with `CollectObservations(VectorSensor sensor)`. In addition, replace all calls to `AddVectorObs()` with `sensor.AddObservation()` or `sensor.AddOneHotObservation()` on the `VectorSensor` passed as argument. * Replace your calls to `SetActionMask` on your Agent to `ActionMasker.SetActionMask` in `CollectObservations` * Re-import all of your `*.NN` files to work with the updated Barracuda package. +* Replace all calls to `Agent.GetStepCount()` with `Agent.StepCount` ## Migrating from 0.13 to 0.14