From b51f82700901b72d8ba422779626612d624def12 Mon Sep 17 00:00:00 2001 From: vincentpierre Date: Tue, 2 Mar 2021 15:24:52 -0800 Subject: [PATCH 1/6] Removing Obsolete methods from the package --- .../Basic/Scripts/BasicActuatorComponent.cs | 6 +- .../Scripts/Match3ExampleActuatorComponent.cs | 6 +- .../Runtime/Match3/Match3ActuatorComponent.cs | 6 +- .../Runtime/Actuators/ActuatorComponent.cs | 11 +--- .../Runtime/Actuators/IActionReceiver.cs | 41 ------------ com.unity.ml-agents/Runtime/Agent.cs | 57 ----------------- .../Runtime/Agent.deprecated.cs | 63 ------------------- .../Runtime/Agent.deprecated.cs.meta | 3 - .../Runtime/Sensors/ObservationWriter.cs | 28 --------- .../Runtime/Sensors/SensorComponent.cs | 21 ------- .../Runtime/Sensors/VectorSensor.cs | 13 ---- .../SideChannels/SideChannelManager.cs | 25 -------- .../Tests/Editor/MLAgentsEditModeTest.cs | 6 -- 13 files changed, 7 insertions(+), 279 deletions(-) delete mode 100644 com.unity.ml-agents/Runtime/Agent.deprecated.cs delete mode 100644 com.unity.ml-agents/Runtime/Agent.deprecated.cs.meta diff --git a/Project/Assets/ML-Agents/Examples/Basic/Scripts/BasicActuatorComponent.cs b/Project/Assets/ML-Agents/Examples/Basic/Scripts/BasicActuatorComponent.cs index afde4117d8..cd019a1424 100644 --- a/Project/Assets/ML-Agents/Examples/Basic/Scripts/BasicActuatorComponent.cs +++ b/Project/Assets/ML-Agents/Examples/Basic/Scripts/BasicActuatorComponent.cs @@ -17,11 +17,9 @@ public class BasicActuatorComponent : ActuatorComponent /// Creates a BasicActuator. /// /// -#pragma warning disable 672 - public override IActuator CreateActuator() -#pragma warning restore 672 + public override IActuator[] CreateActuators() { - return new BasicActuator(basicController); + return new IActuator[] { new BasicActuator(basicController) }; } public override ActionSpec ActionSpec diff --git a/Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuatorComponent.cs b/Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuatorComponent.cs index 7033b35ff3..6e9a2c5e69 100644 --- a/Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuatorComponent.cs +++ b/Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuatorComponent.cs @@ -7,14 +7,12 @@ namespace Unity.MLAgentsExamples public class Match3ExampleActuatorComponent : Match3ActuatorComponent { /// -#pragma warning disable 672 - public override IActuator CreateActuator() -#pragma warning restore 672 + public override IActuator[] CreateActuators() { var board = GetComponent(); var agent = GetComponentInParent(); var seed = RandomSeed == -1 ? gameObject.GetInstanceID() : RandomSeed + 1; - return new Match3ExampleActuator(board, ForceHeuristic, agent, ActuatorName, seed); + return new IActuator[] { new Match3ExampleActuator(board, ForceHeuristic, agent, ActuatorName, seed) }; } } } diff --git a/com.unity.ml-agents.extensions/Runtime/Match3/Match3ActuatorComponent.cs b/com.unity.ml-agents.extensions/Runtime/Match3/Match3ActuatorComponent.cs index 4f17e2964f..bca7b8f163 100644 --- a/com.unity.ml-agents.extensions/Runtime/Match3/Match3ActuatorComponent.cs +++ b/com.unity.ml-agents.extensions/Runtime/Match3/Match3ActuatorComponent.cs @@ -29,14 +29,12 @@ public class Match3ActuatorComponent : ActuatorComponent public bool ForceHeuristic; /// -#pragma warning disable 672 - public override IActuator CreateActuator() -#pragma warning restore 672 + public override IActuator[] CreateActuators() { var board = GetComponent(); var agent = GetComponentInParent(); var seed = RandomSeed == -1 ? gameObject.GetInstanceID() : RandomSeed + 1; - return new Match3Actuator(board, ForceHeuristic, seed, agent, ActuatorName); + return new IActuator[] { new Match3Actuator(board, ForceHeuristic, seed, agent, ActuatorName) }; } /// diff --git a/com.unity.ml-agents/Runtime/Actuators/ActuatorComponent.cs b/com.unity.ml-agents/Runtime/Actuators/ActuatorComponent.cs index 8e0b1814a3..ae91604b59 100644 --- a/com.unity.ml-agents/Runtime/Actuators/ActuatorComponent.cs +++ b/com.unity.ml-agents/Runtime/Actuators/ActuatorComponent.cs @@ -9,13 +9,6 @@ namespace Unity.MLAgents.Actuators /// public abstract class ActuatorComponent : MonoBehaviour { - /// - /// Create the IActuator. This is called by the Agent when it is initialized. - /// - /// Created IActuator object. - [Obsolete("Use CreateActuators instead.")] - public abstract IActuator CreateActuator(); - /// /// Create a collection of s. This is called by the during /// initialization. @@ -23,9 +16,7 @@ public abstract class ActuatorComponent : MonoBehaviour /// A collection of s public virtual IActuator[] CreateActuators() { -#pragma warning disable 618 - return new[] { CreateActuator() }; -#pragma warning restore 618 + return new IActuator[0]; } /// diff --git a/com.unity.ml-agents/Runtime/Actuators/IActionReceiver.cs b/com.unity.ml-agents/Runtime/Actuators/IActionReceiver.cs index 07af9e8458..c266a7256a 100644 --- a/com.unity.ml-agents/Runtime/Actuators/IActionReceiver.cs +++ b/com.unity.ml-agents/Runtime/Actuators/IActionReceiver.cs @@ -148,47 +148,6 @@ public override int GetHashCode() return (ContinuousActions.GetHashCode() * 397) ^ DiscreteActions.GetHashCode(); } } - - /// - /// Packs the continuous and discrete actions into one float array. The array passed into this method - /// must have a Length that is greater than or equal to the sum of the Lengths of - /// and . - /// - /// A float array to pack actions into whose length is greater than or - /// equal to the addition of the Lengths of this objects and - /// segments. - [Obsolete("PackActions has been deprecated.")] - public void PackActions(in float[] destination) - { - Debug.Assert(destination.Length >= ContinuousActions.Length + DiscreteActions.Length, - $"argument '{nameof(destination)}' is not large enough to pack the actions into.\n" + - $"{nameof(destination)}.Length: {destination.Length}\n" + - $"{nameof(ContinuousActions)}.Length + {nameof(DiscreteActions)}.Length: {ContinuousActions.Length + DiscreteActions.Length}"); - - var start = 0; - if (ContinuousActions.Length > 0) - { - Array.Copy(ContinuousActions.Array, - ContinuousActions.Offset, - destination, - start, - ContinuousActions.Length); - start = ContinuousActions.Length; - } - if (start >= destination.Length) - { - return; - } - - if (DiscreteActions.Length > 0) - { - Array.Copy(DiscreteActions.Array, - DiscreteActions.Offset, - destination, - start, - DiscreteActions.Length); - } - } } /// diff --git a/com.unity.ml-agents/Runtime/Agent.cs b/com.unity.ml-agents/Runtime/Agent.cs index 72c4c20f2c..47252bac0f 100644 --- a/com.unity.ml-agents/Runtime/Agent.cs +++ b/com.unity.ml-agents/Runtime/Agent.cs @@ -338,17 +338,6 @@ internal struct AgentParameters /// IActuator m_VectorActuator; - /// - /// This is used to avoid allocation of a float array every frame if users are still using the old - /// OnActionReceived method. - /// - float[] m_LegacyActionCache; - - /// - /// This is used to avoid allocation of a float array during legacy calls to Heuristic. - /// - float[] m_LegacyHeuristicCache; - /// Currect MultiAgentGroup ID. Default to 0 (meaning no group) int m_GroupId; @@ -952,29 +941,7 @@ public virtual void Initialize() { } /// public virtual void Heuristic(in ActionBuffers actionsOut) { - // Disable deprecation warnings so we can call the legacy overload. -#pragma warning disable CS0618 - // The default implementation of Heuristic calls the - // obsolete version for backward compatibility - switch (m_PolicyFactory.BrainParameters.VectorActionSpaceType) - { - case SpaceType.Continuous: - Heuristic(m_LegacyHeuristicCache); - Array.Copy(m_LegacyHeuristicCache, actionsOut.ContinuousActions.Array, m_LegacyActionCache.Length); - actionsOut.DiscreteActions.Clear(); - break; - case SpaceType.Discrete: - Heuristic(m_LegacyHeuristicCache); - var discreteActionSegment = actionsOut.DiscreteActions; - for (var i = 0; i < actionsOut.DiscreteActions.Length; i++) - { - discreteActionSegment[i] = (int)m_LegacyHeuristicCache[i]; - } - actionsOut.ContinuousActions.Clear(); - break; - } -#pragma warning restore CS0618 } /// @@ -1064,8 +1031,6 @@ void InitializeActuators() var param = m_PolicyFactory.BrainParameters; m_VectorActuator = new AgentVectorActuator(this, this, param.ActionSpec); m_ActuatorManager = new ActuatorManager(attachedActuators.Length + 1); - m_LegacyActionCache = new float[m_VectorActuator.TotalNumberOfActions()]; - m_LegacyHeuristicCache = new float[m_VectorActuator.TotalNumberOfActions()]; m_ActuatorManager.Add(m_VectorActuator); @@ -1229,10 +1194,6 @@ public virtual void WriteDiscreteActionMask(IDiscreteActionMask actionMask) { m_ActionMasker = new DiscreteActionMasker(actionMask); } - // Disable deprecation warnings so we can call the legacy overload. -#pragma warning disable CS0618 - CollectDiscreteActionMasks(m_ActionMasker); -#pragma warning restore CS0618 } /// @@ -1310,24 +1271,6 @@ public virtual void OnActionReceived(ActionBuffers actions) // Nothing implemented. return; } - - if (!actions.ContinuousActions.IsEmpty()) - { - Array.Copy(actions.ContinuousActions.Array, - m_LegacyActionCache, - actionSpec.NumContinuousActions); - } - else - { - for (var i = 0; i < m_LegacyActionCache.Length; i++) - { - m_LegacyActionCache[i] = (float)actions.DiscreteActions[i]; - } - } - // Disable deprecation warnings so we can call the legacy overload. -#pragma warning disable CS0618 - OnActionReceived(m_LegacyActionCache); -#pragma warning restore CS0618 } /// diff --git a/com.unity.ml-agents/Runtime/Agent.deprecated.cs b/com.unity.ml-agents/Runtime/Agent.deprecated.cs deleted file mode 100644 index fd9d6a1a88..0000000000 --- a/com.unity.ml-agents/Runtime/Agent.deprecated.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using UnityEngine; -using UnityEngine.Profiling; - -namespace Unity.MLAgents -{ - public partial class Agent - { - /// - /// Deprecated, use instead. - /// - /// - [Obsolete("CollectDiscreteActionMasks has been deprecated, please use WriteDiscreteActionMask.")] - public virtual void CollectDiscreteActionMasks(DiscreteActionMasker actionMasker) - { - } - - /// - /// Deprecated, use instead. - /// - /// - [Obsolete("The float[] version of Heuristic has been deprecated, please use the ActionBuffers version instead.")] - public virtual void Heuristic(float[] actionsOut) - { - Debug.LogWarning("Heuristic method called but not implemented. Returning placeholder actions."); - Array.Clear(actionsOut, 0, actionsOut.Length); - } - - /// - /// Deprecated, use instead. - /// - /// - [Obsolete("The float[] version of OnActionReceived has been deprecated, please use the ActionBuffers version instead.")] - public virtual void OnActionReceived(float[] vectorAction) { } - - /// - /// Returns the last action that was decided on by the Agent. - /// - /// - /// The last action that was decided by the Agent (or null if no decision has been made). - /// - /// - [Obsolete("GetAction has been deprecated, please use GetStoredActionBuffers instead.")] - public float[] GetAction() - { - Profiler.BeginSample("Agent.GetAction.Deprecated"); - var actionSpec = m_PolicyFactory.BrainParameters.ActionSpec; - // For continuous and discrete actions together, this shouldn't be called because we can only return one. - if (actionSpec.NumContinuousActions > 0 && actionSpec.NumDiscreteActions > 0) - { - Debug.LogWarning("Agent.GetAction() when both continuous and discrete actions are in use. Use Agent.GetStoredActionBuffers() instead."); - } - - var storedAction = m_Info.storedActions; - if (!storedAction.ContinuousActions.IsEmpty()) - { - return storedAction.ContinuousActions.Array; - } - Profiler.EndSample(); - return Array.ConvertAll(storedAction.DiscreteActions.Array, x => (float)x); - } - } -} diff --git a/com.unity.ml-agents/Runtime/Agent.deprecated.cs.meta b/com.unity.ml-agents/Runtime/Agent.deprecated.cs.meta deleted file mode 100644 index 767483f7f7..0000000000 --- a/com.unity.ml-agents/Runtime/Agent.deprecated.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 9650a482703b47db8cd7fb2df8caa1bf -timeCreated: 1595613441 \ No newline at end of file diff --git a/com.unity.ml-agents/Runtime/Sensors/ObservationWriter.cs b/com.unity.ml-agents/Runtime/Sensors/ObservationWriter.cs index 67832c4a1a..e3e958011e 100644 --- a/com.unity.ml-agents/Runtime/Sensors/ObservationWriter.cs +++ b/com.unity.ml-agents/Runtime/Sensors/ObservationWriter.cs @@ -117,34 +117,6 @@ public float this[int index] } } - /// - /// Write the range of floats - /// - /// - /// Optional write offset. - [Obsolete("Use AddList() for better performance")] - public void AddRange(IEnumerable data, int writeOffset = 0) - { - if (m_Data != null) - { - int index = 0; - foreach (var val in data) - { - m_Data[index + m_Offset + writeOffset] = val; - index++; - } - } - else - { - int index = 0; - foreach (var val in data) - { - m_Proxy.data[m_Batch, index + m_Offset + writeOffset] = val; - index++; - } - } - } - /// /// Write the list of floats. /// diff --git a/com.unity.ml-agents/Runtime/Sensors/SensorComponent.cs b/com.unity.ml-agents/Runtime/Sensors/SensorComponent.cs index bd139312e7..a217e5d159 100644 --- a/com.unity.ml-agents/Runtime/Sensors/SensorComponent.cs +++ b/com.unity.ml-agents/Runtime/Sensors/SensorComponent.cs @@ -21,26 +21,5 @@ public abstract class SensorComponent : MonoBehaviour /// Shape of the sensor observation. public abstract int[] GetObservationShape(); - /// - /// Whether the observation is visual or not. - /// - /// True if the observation is visual, false otherwise. - [Obsolete("IsVisual is deprecated, please use GetObservationShape() instead.")] - public virtual bool IsVisual() - { - var shape = GetObservationShape(); - return shape.Length == 3; - } - - /// - /// Whether the observation is vector or not. - /// - /// True if the observation is vector, false otherwise. - [Obsolete("IsVisual is deprecated, please use GetObservationShape() instead.")] - public virtual bool IsVector() - { - var shape = GetObservationShape(); - return shape.Length == 1; - } } } diff --git a/com.unity.ml-agents/Runtime/Sensors/VectorSensor.cs b/com.unity.ml-agents/Runtime/Sensors/VectorSensor.cs index 62276b110a..c1017a0b77 100644 --- a/com.unity.ml-agents/Runtime/Sensors/VectorSensor.cs +++ b/com.unity.ml-agents/Runtime/Sensors/VectorSensor.cs @@ -167,19 +167,6 @@ public void AddObservation(Vector2 observation) AddFloatObs(observation.y); } - /// - /// Adds a collection of float observations to the vector observations of the agent. - /// - /// Observation. - [Obsolete("Use AddObservation(IList) for better performance.")] - public void AddObservation(IEnumerable observation) - { - foreach (var f in observation) - { - AddFloatObs(f); - } - } - /// /// Adds a list or array of float observations to the vector observations of the agent. /// diff --git a/com.unity.ml-agents/Runtime/SideChannels/SideChannelManager.cs b/com.unity.ml-agents/Runtime/SideChannels/SideChannelManager.cs index 93931a170d..bdcc596b85 100644 --- a/com.unity.ml-agents/Runtime/SideChannels/SideChannelManager.cs +++ b/com.unity.ml-agents/Runtime/SideChannels/SideChannelManager.cs @@ -241,29 +241,4 @@ internal static void ProcessSideChannelData(Dictionary sideCh } } } - - /// - /// Deprecated, use instead. - /// - [Obsolete("Use SideChannelManager instead.")] - public static class SideChannelsManager - { - /// - /// Deprecated, use instead. - /// - /// - public static void RegisterSideChannel(SideChannel sideChannel) - { - SideChannelManager.RegisterSideChannel(sideChannel); - } - - /// - /// Deprecated, use instead. - /// - /// - public static void UnregisterSideChannel(SideChannel sideChannel) - { - SideChannelManager.UnregisterSideChannel(sideChannel); - } - } } diff --git a/com.unity.ml-agents/Tests/Editor/MLAgentsEditModeTest.cs b/com.unity.ml-agents/Tests/Editor/MLAgentsEditModeTest.cs index e8be0c36bb..07dd089ceb 100644 --- a/com.unity.ml-agents/Tests/Editor/MLAgentsEditModeTest.cs +++ b/com.unity.ml-agents/Tests/Editor/MLAgentsEditModeTest.cs @@ -711,16 +711,10 @@ public void TestHeuristicPolicyStepsSensors() Assert.AreEqual(numSteps, agent1.sensor1.numWriteCalls); Assert.AreEqual(numSteps, agent1.sensor2.numCompressedCalls); - // Disable deprecation warnings so we can read/write the old fields. -#pragma warning disable CS0618 - - // Make sure the Heuristic method read the observation and set the action - Assert.AreEqual(agent1.collectObservationsCallsForEpisode, agent1.GetAction()[0]); Assert.AreEqual( agent1.collectObservationsCallsForEpisode, agent1.GetStoredActionBuffers().ContinuousActions[0] ); -#pragma warning restore CS0618 } } From 911696e004d21b99ea8a5839492839c9f75a6623 Mon Sep 17 00:00:00 2001 From: vincentpierre Date: Tue, 2 Mar 2021 18:04:31 -0800 Subject: [PATCH 2/6] Missing depecration and modified changelog --- com.unity.ml-agents/CHANGELOG.md | 15 ++++++ .../Runtime/Actuators/ActuatorComponent.cs | 5 +- .../Runtime/Policies/BrainParameters.cs | 49 ------------------- docs/Migrating.md | 3 ++ 4 files changed, 19 insertions(+), 53 deletions(-) diff --git a/com.unity.ml-agents/CHANGELOG.md b/com.unity.ml-agents/CHANGELOG.md index 79d10169cd..e382ac3e5e 100755 --- a/com.unity.ml-agents/CHANGELOG.md +++ b/com.unity.ml-agents/CHANGELOG.md @@ -6,6 +6,21 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [2.0.0-preview] +### Major Changes +#### com.unity.ml-agents (C#) +- Some methods previously marked as `Obsolete` have been removed. If you were using these methods, you need to replace them with their supported counterpart. +#### ml-agents / ml-agents-envs / gym-unity (Python) + +### Minor Changes +#### com.unity.ml-agents / com.unity.ml-agents.extensions (C#) +#### ml-agents / ml-agents-envs / gym-unity (Python) + +### Bug Fixes +#### com.unity.ml-agents (C#) +#### ml-agents / ml-agents-envs / gym-unity (Python) + + ## [Unreleased] ### Major Changes #### com.unity.ml-agents (C#) diff --git a/com.unity.ml-agents/Runtime/Actuators/ActuatorComponent.cs b/com.unity.ml-agents/Runtime/Actuators/ActuatorComponent.cs index ae91604b59..215267992c 100644 --- a/com.unity.ml-agents/Runtime/Actuators/ActuatorComponent.cs +++ b/com.unity.ml-agents/Runtime/Actuators/ActuatorComponent.cs @@ -14,10 +14,7 @@ public abstract class ActuatorComponent : MonoBehaviour /// initialization. /// /// A collection of s - public virtual IActuator[] CreateActuators() - { - return new IActuator[0]; - } + public abstract IActuator[] CreateActuators(); /// /// The specification of the possible actions for this ActuatorComponent. diff --git a/com.unity.ml-agents/Runtime/Policies/BrainParameters.cs b/com.unity.ml-agents/Runtime/Policies/BrainParameters.cs index fde0d04a12..0f31c441b0 100644 --- a/com.unity.ml-agents/Runtime/Policies/BrainParameters.cs +++ b/com.unity.ml-agents/Runtime/Policies/BrainParameters.cs @@ -5,22 +5,6 @@ namespace Unity.MLAgents.Policies { - /// - /// This is deprecated. Agents can now use both continuous and discrete actions together. - /// - [Obsolete("Continuous and discrete actions on the same Agent are now supported; see ActionSpec.")] - public enum SpaceType - { - /// - /// Discrete action space: a fixed number of options are available. - /// - Discrete, - - /// - /// Continuous action space: each action can take on a float value. - /// - Continuous - } /// /// Holds information about the brain. It defines what are the inputs and outputs of the @@ -69,49 +53,16 @@ public ActionSpec ActionSpec } } - /// - /// (Deprecated) The number of possible actions. - /// - /// The size specified is interpreted differently depending on whether - /// the agent uses the continuous or the discrete actions. - /// - /// For the continuous actions: the length of the float vector that represents - /// the action. - /// For the discrete actions: the number of branches. - /// - [Obsolete("VectorActionSize has been deprecated, please use ActionSpec instead.")] - [FormerlySerializedAs("vectorActionSize")] - public int[] VectorActionSize = new[] { 1 }; - /// /// The list of strings describing what the actions correspond to. /// [FormerlySerializedAs("vectorActionDescriptions")] public string[] VectorActionDescriptions; - /// - /// (Deprecated) Defines if the action is discrete or continuous. - /// - [Obsolete("VectorActionSpaceType has been deprecated, please use ActionSpec instead.")] - [FormerlySerializedAs("vectorActionSpaceType")] - public SpaceType VectorActionSpaceType = SpaceType.Discrete; - [SerializeField] [HideInInspector] internal bool hasUpgradedBrainParametersWithActionSpec; - /// - /// (Deprecated) The number of actions specified by this Brain. - /// - [Obsolete("NumActions has been deprecated, please use ActionSpec instead.")] - public int NumActions - { - get - { - return ActionSpec.NumContinuousActions > 0 ? ActionSpec.NumContinuousActions : ActionSpec.NumDiscreteActions; - } - } - /// /// Deep clones the BrainParameter object. /// diff --git a/docs/Migrating.md b/docs/Migrating.md index 0a943a53e0..dd367621e5 100644 --- a/docs/Migrating.md +++ b/docs/Migrating.md @@ -14,6 +14,9 @@ double-check that the versions are in the same. The versions can be found in # Migrating +## Migrating the package to version 2.0 +- If you used any of the APIs that were deprecated before version 2.0, you need to use their replacement. These deprecated APIs have been removed. See the migration steps bellow for specific API replacements. + ## Migrating to Release 13 ### Implementing IHeuristic in your IActuator implementations - If you have any custom actuators, you can now implement the `IHeuristicProvider` interface to have your actuator From 3ace30a66a0d9343d0b1e85e14dc1b389ae4dc6b Mon Sep 17 00:00:00 2001 From: vincentpierre Date: Wed, 3 Mar 2021 10:55:27 -0800 Subject: [PATCH 3/6] Readding the obsolete BrainParameter methods, will need a larger discussion on these --- .../Runtime/Policies/BrainParameters.cs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/com.unity.ml-agents/Runtime/Policies/BrainParameters.cs b/com.unity.ml-agents/Runtime/Policies/BrainParameters.cs index 0f31c441b0..fde0d04a12 100644 --- a/com.unity.ml-agents/Runtime/Policies/BrainParameters.cs +++ b/com.unity.ml-agents/Runtime/Policies/BrainParameters.cs @@ -5,6 +5,22 @@ namespace Unity.MLAgents.Policies { + /// + /// This is deprecated. Agents can now use both continuous and discrete actions together. + /// + [Obsolete("Continuous and discrete actions on the same Agent are now supported; see ActionSpec.")] + public enum SpaceType + { + /// + /// Discrete action space: a fixed number of options are available. + /// + Discrete, + + /// + /// Continuous action space: each action can take on a float value. + /// + Continuous + } /// /// Holds information about the brain. It defines what are the inputs and outputs of the @@ -53,16 +69,49 @@ public ActionSpec ActionSpec } } + /// + /// (Deprecated) The number of possible actions. + /// + /// The size specified is interpreted differently depending on whether + /// the agent uses the continuous or the discrete actions. + /// + /// For the continuous actions: the length of the float vector that represents + /// the action. + /// For the discrete actions: the number of branches. + /// + [Obsolete("VectorActionSize has been deprecated, please use ActionSpec instead.")] + [FormerlySerializedAs("vectorActionSize")] + public int[] VectorActionSize = new[] { 1 }; + /// /// The list of strings describing what the actions correspond to. /// [FormerlySerializedAs("vectorActionDescriptions")] public string[] VectorActionDescriptions; + /// + /// (Deprecated) Defines if the action is discrete or continuous. + /// + [Obsolete("VectorActionSpaceType has been deprecated, please use ActionSpec instead.")] + [FormerlySerializedAs("vectorActionSpaceType")] + public SpaceType VectorActionSpaceType = SpaceType.Discrete; + [SerializeField] [HideInInspector] internal bool hasUpgradedBrainParametersWithActionSpec; + /// + /// (Deprecated) The number of actions specified by this Brain. + /// + [Obsolete("NumActions has been deprecated, please use ActionSpec instead.")] + public int NumActions + { + get + { + return ActionSpec.NumContinuousActions > 0 ? ActionSpec.NumContinuousActions : ActionSpec.NumDiscreteActions; + } + } + /// /// Deep clones the BrainParameter object. /// From 7d9eb6d3c15fa9664063d841209d478abda4ac0f Mon Sep 17 00:00:00 2001 From: vincentpierre Date: Wed, 3 Mar 2021 11:46:47 -0800 Subject: [PATCH 4/6] Removing Action Masker, readding the warining when using a non-implemented Heuristic, Removing NumAction from Brain Parameters --- com.unity.ml-agents/Runtime/Agent.cs | 24 +------ .../Runtime/DiscreteActionMasker.cs | 62 ------------------- .../Runtime/DiscreteActionMasker.cs.meta | 3 - .../Runtime/Policies/BrainParameters.cs | 12 ---- 4 files changed, 3 insertions(+), 98 deletions(-) delete mode 100644 com.unity.ml-agents/Runtime/DiscreteActionMasker.cs delete mode 100644 com.unity.ml-agents/Runtime/DiscreteActionMasker.cs.meta diff --git a/com.unity.ml-agents/Runtime/Agent.cs b/com.unity.ml-agents/Runtime/Agent.cs index 47252bac0f..c558718f9c 100644 --- a/com.unity.ml-agents/Runtime/Agent.cs +++ b/com.unity.ml-agents/Runtime/Agent.cs @@ -301,9 +301,6 @@ internal struct AgentParameters /// Whether or not the Agent has been initialized already bool m_Initialized; - /// Keeps track of the actions that are masked at each step. - DiscreteActionMasker m_ActionMasker; - /// /// Set of DemonstrationWriters that the Agent will write its step information to. /// If you use a DemonstrationRecorder component, this will automatically register its DemonstrationWriter. @@ -941,7 +938,7 @@ public virtual void Initialize() { } /// public virtual void Heuristic(in ActionBuffers actionsOut) { - + Debug.LogWarning("Heuristic method called but not implemented. Returning placeholder actions."); } /// @@ -1188,13 +1185,7 @@ public ReadOnlyCollection GetObservations() /// [Agents - Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_13_docs/docs/Learning-Environment-Design-Agents.md#actions /// /// - public virtual void WriteDiscreteActionMask(IDiscreteActionMask actionMask) - { - if (m_ActionMasker == null) - { - m_ActionMasker = new DiscreteActionMasker(actionMask); - } - } + public virtual void WriteDiscreteActionMask(IDiscreteActionMask actionMask) { } /// /// Implement `OnActionReceived()` to specify agent behavior at every step, based @@ -1262,16 +1253,7 @@ public virtual void WriteDiscreteActionMask(IDiscreteActionMask actionMask) /// /// Struct containing the buffers of actions to be executed at this step. /// - public virtual void OnActionReceived(ActionBuffers actions) - { - var actionSpec = m_PolicyFactory.BrainParameters.ActionSpec; - // For continuous and discrete actions together, we don't need to fall back to the legacy method - if (actionSpec.NumContinuousActions > 0 && actionSpec.NumDiscreteActions > 0) - { - // Nothing implemented. - return; - } - } + public virtual void OnActionReceived(ActionBuffers actions) { } /// /// Implement `OnEpisodeBegin()` to set up an Agent instance at the beginning diff --git a/com.unity.ml-agents/Runtime/DiscreteActionMasker.cs b/com.unity.ml-agents/Runtime/DiscreteActionMasker.cs deleted file mode 100644 index 38a612d10a..0000000000 --- a/com.unity.ml-agents/Runtime/DiscreteActionMasker.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System.Collections.Generic; -using Unity.MLAgents.Actuators; - -namespace Unity.MLAgents -{ - /// - /// The DiscreteActionMasker class represents a set of masked (disallowed) actions and - /// provides utilities for setting and retrieving them. - /// - /// - /// Agents that take discrete actions can explicitly indicate that specific actions - /// are not allowed at a point in time. This enables the agent to indicate that some actions - /// may be illegal. For example, if an agent is adjacent to a wall or other obstacle - /// you could mask any actions that direct the agent to move into the blocked space. - /// - public class DiscreteActionMasker : IDiscreteActionMask - { - IDiscreteActionMask m_Delegate; - - internal DiscreteActionMasker(IDiscreteActionMask actionMask) - { - m_Delegate = actionMask; - } - - /// - /// Modifies an action mask for discrete control agents. - /// - /// - /// When used, the agent will not be able to perform the actions passed as argument - /// at the next decision for the specified action branch. The actionIndices correspond - /// to the action options the agent will be unable to perform. - /// - /// See [Agents - Actions] for more information on masking actions. - /// - /// [Agents - Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_13_docs/docs/Learning-Environment-Design-Agents.md#actions - /// - /// The branch for which the actions will be masked. - /// The indices of the masked actions. - public void SetMask(int branch, IEnumerable actionIndices) - { - m_Delegate.WriteMask(branch, actionIndices); - } - - /// - public void WriteMask(int branch, IEnumerable actionIndices) - { - m_Delegate.WriteMask(branch, actionIndices); - } - - /// - public bool[] GetMask() - { - return m_Delegate.GetMask(); - } - - /// - public void ResetMask() - { - m_Delegate.ResetMask(); - } - } -} diff --git a/com.unity.ml-agents/Runtime/DiscreteActionMasker.cs.meta b/com.unity.ml-agents/Runtime/DiscreteActionMasker.cs.meta deleted file mode 100644 index a7ab396c89..0000000000 --- a/com.unity.ml-agents/Runtime/DiscreteActionMasker.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 8a0ec4ccf4ee450da7766f65228d5460 -timeCreated: 1534530911 \ No newline at end of file diff --git a/com.unity.ml-agents/Runtime/Policies/BrainParameters.cs b/com.unity.ml-agents/Runtime/Policies/BrainParameters.cs index fde0d04a12..0b7c83fa34 100644 --- a/com.unity.ml-agents/Runtime/Policies/BrainParameters.cs +++ b/com.unity.ml-agents/Runtime/Policies/BrainParameters.cs @@ -100,18 +100,6 @@ public ActionSpec ActionSpec [HideInInspector] internal bool hasUpgradedBrainParametersWithActionSpec; - /// - /// (Deprecated) The number of actions specified by this Brain. - /// - [Obsolete("NumActions has been deprecated, please use ActionSpec instead.")] - public int NumActions - { - get - { - return ActionSpec.NumContinuousActions > 0 ? ActionSpec.NumContinuousActions : ActionSpec.NumDiscreteActions; - } - } - /// /// Deep clones the BrainParameter object. /// From b8001c60014631849214c3d145f16126a859980e Mon Sep 17 00:00:00 2001 From: vincentpierre Date: Thu, 4 Mar 2021 15:03:56 -0800 Subject: [PATCH 5/6] removing documentation and some calls to deprecated methods in the extensions package --- .../Runtime/Input/InputActuatorComponent.cs | 5 ----- docs/Learning-Environment-Design-Agents.md | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/com.unity.ml-agents.extensions/Runtime/Input/InputActuatorComponent.cs b/com.unity.ml-agents.extensions/Runtime/Input/InputActuatorComponent.cs index c3fed4974c..ada3c5a804 100644 --- a/com.unity.ml-agents.extensions/Runtime/Input/InputActuatorComponent.cs +++ b/com.unity.ml-agents.extensions/Runtime/Input/InputActuatorComponent.cs @@ -241,11 +241,6 @@ internal static InputControlScheme CreateControlScheme(InputControl device, return inputControlScheme; } -#pragma warning disable 672 - /// - public override IActuator CreateActuator() { return null; } -#pragma warning restore 672 - /// /// /// diff --git a/docs/Learning-Environment-Design-Agents.md b/docs/Learning-Environment-Design-Agents.md index a5660f4319..32d017fa48 100644 --- a/docs/Learning-Environment-Design-Agents.md +++ b/docs/Learning-Environment-Design-Agents.md @@ -707,7 +707,7 @@ Notes: The Actuator API allows users to abstract behavior out of Agents and in to components (similar to the ISensor API). The `IActuator` interface and `Agent` class both implement the `IActionReceiver` interface to allow for backward compatibility -with the current `Agent.OnActionReceived` and `Agent.CollectDiscreteActionMasks` APIs. +with the current `Agent.OnActionReceived`. This means you will not have to change your code until you decide to use the `IActuator` API. Like the `ISensor` interface, the `IActuator` interface is intended for advanced users. From 47c4489f028b8335dcf7c46aa0db716f9c6ab334 Mon Sep 17 00:00:00 2001 From: vincentpierre Date: Fri, 5 Mar 2021 11:17:20 -0800 Subject: [PATCH 6/6] Editing the Changelog to put the unreleased on top --- com.unity.ml-agents/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.unity.ml-agents/CHANGELOG.md b/com.unity.ml-agents/CHANGELOG.md index e382ac3e5e..2e269c7719 100755 --- a/com.unity.ml-agents/CHANGELOG.md +++ b/com.unity.ml-agents/CHANGELOG.md @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [2.0.0-preview] +## [Unreleased] ### Major Changes #### com.unity.ml-agents (C#) - Some methods previously marked as `Obsolete` have been removed. If you were using these methods, you need to replace them with their supported counterpart. @@ -21,7 +21,7 @@ and this project adheres to #### ml-agents / ml-agents-envs / gym-unity (Python) -## [Unreleased] +## [1.9.0-preview] - 2021-03-17 ### Major Changes #### com.unity.ml-agents (C#) - The `BufferSensor` and `BufferSensorComponent` have been added. They allow the Agent to observe variable number of entities. (#4909)