Skip to content

Commit 40d6dc9

Browse files
Simplifying the Agent reset logic (#3242)
* Simplifying the Agent reset logic - Agents will reset in ResetIfDone immediately after being marked Done - Agents will always request a decision right after reset - This change implies that additional messages might be sent to Python * Fixing the Unit Tests * Added a note in the Migrating.md document
1 parent 0b16a7e commit 40d6dc9

File tree

3 files changed

+5
-27
lines changed

3 files changed

+5
-27
lines changed

UnitySDK/Assets/ML-Agents/Editor/Tests/MLAgentsEditModeTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ public void TestAgent()
436436
// Request an action without decision regularly
437437
agent2.RequestAction();
438438
}
439-
if (agent1.IsDone() && (((acaStepsSinceReset) % agent1.agentParameters.numberOfActionsBetweenDecisions == 0)))
439+
if (agent1.IsDone())
440440
{
441441
numberAgent1Reset += 1;
442442
}

UnitySDK/Assets/ML-Agents/Scripts/Agent.cs

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,6 @@ public AgentInfo Info
193193
/// their own experience.
194194
int m_StepCount;
195195

196-
/// Flag to signify that an agent has been reset but the fact that it is
197-
/// done has not been communicated (required for On Demand Decisions).
198-
bool m_HasAlreadyReset;
199-
200196
/// Unique identifier each agent receives at initialization. It is used
201197
/// to separate between different agents in the environment.
202198
int m_Id;
@@ -757,7 +753,6 @@ public virtual void AgentReset()
757753
/// </summary>
758754
void ForceReset()
759755
{
760-
m_HasAlreadyReset = false;
761756
_AgentReset();
762757
}
763758

@@ -826,26 +821,9 @@ void SetStatus(int academyStepCounter)
826821
/// Signals the agent that it must reset if its done flag is set to true.
827822
void ResetIfDone()
828823
{
829-
// If an agent is done, then it will also
830-
// request for a decision and an action
831824
if (IsDone())
832825
{
833-
if (agentParameters.onDemandDecision)
834-
{
835-
if (!m_HasAlreadyReset)
836-
{
837-
// If event based, the agent can reset as soon
838-
// as it is done
839-
_AgentReset();
840-
m_HasAlreadyReset = true;
841-
}
842-
}
843-
else if (m_RequestDecision)
844-
{
845-
// If not event based, the agent must wait to request a
846-
// decision before resetting to keep multiple agents in sync.
847-
_AgentReset();
848-
}
826+
_AgentReset();
849827
}
850828
}
851829

@@ -854,15 +832,14 @@ void ResetIfDone()
854832
/// </summary>
855833
void SendInfo()
856834
{
857-
if (m_RequestDecision)
835+
// If the Agent is done, it has just reset and thus requires a new decision
836+
if (m_RequestDecision || IsDone())
858837
{
859838
SendInfoToBrain();
860839
ResetReward();
861840
m_Done = false;
862841
m_MaxStepReached = false;
863842
m_RequestDecision = false;
864-
865-
m_HasAlreadyReset = false;
866843
}
867844
}
868845

docs/Migrating.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The versions can be found in
1616
* Curriculum config files are now YAML formatted and all curricula for a training run are combined into a single file.
1717
* The `--num-runs` command-line option has been removed.
1818
* The "Reset on Done" setting in AgentParameters was removed; this is now effectively always true. `AgentOnDone` virtual method on the Agent has been removed.
19+
* Agents will always request a decision after being marked as `Done()` and will no longer wait for the next call to `RequestDecision()`.
1920

2021
### Steps to Migrate
2122
* If you have a class that inherits from Academy:

0 commit comments

Comments
 (0)