From 558edac2f23e6e393b25c5651b5097a5e0966df7 Mon Sep 17 00:00:00 2001 From: mitsunami Date: Tue, 20 Jun 2023 14:19:53 +0100 Subject: [PATCH 1/2] Added DecisionStep parameter to the decision requester * Updated com.unity.ml-agents/Runtime/DecisionRequester.cs --- com.unity.ml-agents/Runtime/DecisionRequester.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/com.unity.ml-agents/Runtime/DecisionRequester.cs b/com.unity.ml-agents/Runtime/DecisionRequester.cs index 49590c7be4..bee232f574 100644 --- a/com.unity.ml-agents/Runtime/DecisionRequester.cs +++ b/com.unity.ml-agents/Runtime/DecisionRequester.cs @@ -30,6 +30,17 @@ public class DecisionRequester : MonoBehaviour "of 5 means that the Agent will request a decision every 5 Academy steps.")] public int DecisionPeriod = 5; + /// + /// Indicates when to requests a decision. By changing this value, the timing of decision + /// can be shifted even among agents with the same decision period. The value can be + /// from 0 to DecisionPeriod - 1. + /// + [Range(0, 19)] + [Tooltip("Indicates when to requests a decision. By changing this value, the timing " + + "of decision can be shifted even among agents with the same decision period. " + + "The value can be from 0 to DecisionPeriod - 1.")] + public int DecisionStep = 0; + /// /// Indicates whether or not the agent will take an action during the Academy steps where /// it does not request a decision. Has no effect when DecisionPeriod is set to 1. @@ -53,6 +64,7 @@ public Agent Agent internal void Awake() { + Debug.Assert(DecisionStep < DecisionPeriod, "DecisionStep must be between 0 than DecisionPeriod - 1."); m_Agent = gameObject.GetComponent(); Debug.Assert(m_Agent != null, "Agent component was not found on this gameObject and is required."); Academy.Instance.AgentPreStep += MakeRequests; @@ -107,7 +119,7 @@ void MakeRequests(int academyStepCount) /// protected virtual bool ShouldRequestDecision(DecisionRequestContext context) { - return context.AcademyStepCount % DecisionPeriod == 0; + return context.AcademyStepCount % DecisionPeriod == DecisionStep; } /// From 104d99a809512e2960d553a0508ed46508bf3879 Mon Sep 17 00:00:00 2001 From: mitsunami Date: Tue, 20 Jun 2023 14:50:47 +0100 Subject: [PATCH 2/2] Added DecisionStep parameter to the decision requester - Updated the changelog --- com.unity.ml-agents/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/com.unity.ml-agents/CHANGELOG.md b/com.unity.ml-agents/CHANGELOG.md index 7f7eff3a95..db3b194051 100755 --- a/com.unity.ml-agents/CHANGELOG.md +++ b/com.unity.ml-agents/CHANGELOG.md @@ -14,6 +14,8 @@ and this project adheres to ### Minor Changes #### com.unity.ml-agents / com.unity.ml-agents.extensions (C#) +- Added DecisionStep parameter to DecisionRequester (#) + - This will allow the staggering of execution timing when using multi-agents, leading to more stable performance. #### ml-agents / ml-agents-envs - Added training config feature to evenly distribute checkpoints throughout training. (#5842)