Skip to content

Commit a2d6d79

Browse files
Removing Obsolete methods from the package (#5024)
* Removing Obsolete methods from the package * Missing depecration and modified changelog * Readding the obsolete BrainParameter methods, will need a larger discussion on these * Removing Action Masker, readding the warining when using a non-implemented Heuristic, Removing NumAction from Brain Parameters * removing documentation and some calls to deprecated methods in the extensions package * Editing the Changelog to put the unreleased on top
1 parent 68def9a commit a2d6d79

20 files changed

+29
-386
lines changed

Project/Assets/ML-Agents/Examples/Basic/Scripts/BasicActuatorComponent.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ public class BasicActuatorComponent : ActuatorComponent
1717
/// Creates a BasicActuator.
1818
/// </summary>
1919
/// <returns></returns>
20-
#pragma warning disable 672
21-
public override IActuator CreateActuator()
22-
#pragma warning restore 672
20+
public override IActuator[] CreateActuators()
2321
{
24-
return new BasicActuator(basicController);
22+
return new IActuator[] { new BasicActuator(basicController) };
2523
}
2624

2725
public override ActionSpec ActionSpec

Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuatorComponent.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ namespace Unity.MLAgentsExamples
77
public class Match3ExampleActuatorComponent : Match3ActuatorComponent
88
{
99
/// <inheritdoc/>
10-
#pragma warning disable 672
11-
public override IActuator CreateActuator()
12-
#pragma warning restore 672
10+
public override IActuator[] CreateActuators()
1311
{
1412
var board = GetComponent<Match3Board>();
1513
var agent = GetComponentInParent<Agent>();
1614
var seed = RandomSeed == -1 ? gameObject.GetInstanceID() : RandomSeed + 1;
17-
return new Match3ExampleActuator(board, ForceHeuristic, agent, ActuatorName, seed);
15+
return new IActuator[] { new Match3ExampleActuator(board, ForceHeuristic, agent, ActuatorName, seed) };
1816
}
1917
}
2018
}

com.unity.ml-agents.extensions/Runtime/Input/InputActuatorComponent.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,6 @@ internal static InputControlScheme CreateControlScheme(InputControl device,
241241
return inputControlScheme;
242242
}
243243

244-
#pragma warning disable 672
245-
/// <inheritdoc cref="ActuatorComponent.CreateActuator"/>
246-
public override IActuator CreateActuator() { return null; }
247-
#pragma warning restore 672
248-
249244
/// <summary>
250245
///
251246
/// </summary>

com.unity.ml-agents.extensions/Runtime/Match3/Match3ActuatorComponent.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@ public class Match3ActuatorComponent : ActuatorComponent
2929
public bool ForceHeuristic;
3030

3131
/// <inheritdoc/>
32-
#pragma warning disable 672
33-
public override IActuator CreateActuator()
34-
#pragma warning restore 672
32+
public override IActuator[] CreateActuators()
3533
{
3634
var board = GetComponent<AbstractBoard>();
3735
var agent = GetComponentInParent<Agent>();
3836
var seed = RandomSeed == -1 ? gameObject.GetInstanceID() : RandomSeed + 1;
39-
return new Match3Actuator(board, ForceHeuristic, seed, agent, ActuatorName);
37+
return new IActuator[] { new Match3Actuator(board, ForceHeuristic, seed, agent, ActuatorName) };
4038
}
4139

4240
/// <inheritdoc/>

com.unity.ml-agents/CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ and this project adheres to
99
## [Unreleased]
1010
### Major Changes
1111
#### com.unity.ml-agents (C#)
12+
- Some methods previously marked as `Obsolete` have been removed. If you were using these methods, you need to replace them with their supported counterpart.
13+
#### ml-agents / ml-agents-envs / gym-unity (Python)
14+
15+
### Minor Changes
16+
#### com.unity.ml-agents / com.unity.ml-agents.extensions (C#)
17+
#### ml-agents / ml-agents-envs / gym-unity (Python)
18+
19+
### Bug Fixes
20+
#### com.unity.ml-agents (C#)
21+
#### ml-agents / ml-agents-envs / gym-unity (Python)
22+
23+
24+
## [1.9.0-preview] - 2021-03-17
25+
### Major Changes
26+
#### com.unity.ml-agents (C#)
1227
- The `BufferSensor` and `BufferSensorComponent` have been added. They allow the Agent to observe variable number of entities. (#4909)
1328
#### ml-agents / ml-agents-envs / gym-unity (Python)
1429

com.unity.ml-agents/Runtime/Actuators/ActuatorComponent.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,12 @@ namespace Unity.MLAgents.Actuators
99
/// </summary>
1010
public abstract class ActuatorComponent : MonoBehaviour
1111
{
12-
/// <summary>
13-
/// Create the IActuator. This is called by the Agent when it is initialized.
14-
/// </summary>
15-
/// <returns>Created IActuator object.</returns>
16-
[Obsolete("Use CreateActuators instead.")]
17-
public abstract IActuator CreateActuator();
18-
1912
/// <summary>
2013
/// Create a collection of <see cref="IActuator"/>s. This is called by the <see cref="Agent"/> during
2114
/// initialization.
2215
/// </summary>
2316
/// <returns>A collection of <see cref="IActuator"/>s</returns>
24-
public virtual IActuator[] CreateActuators()
25-
{
26-
#pragma warning disable 618
27-
return new[] { CreateActuator() };
28-
#pragma warning restore 618
29-
}
17+
public abstract IActuator[] CreateActuators();
3018

3119
/// <summary>
3220
/// The specification of the possible actions for this ActuatorComponent.

com.unity.ml-agents/Runtime/Actuators/IActionReceiver.cs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -148,47 +148,6 @@ public override int GetHashCode()
148148
return (ContinuousActions.GetHashCode() * 397) ^ DiscreteActions.GetHashCode();
149149
}
150150
}
151-
152-
/// <summary>
153-
/// Packs the continuous and discrete actions into one float array. The array passed into this method
154-
/// must have a Length that is greater than or equal to the sum of the Lengths of
155-
/// <see cref="ContinuousActions"/> and <see cref="DiscreteActions"/>.
156-
/// </summary>
157-
/// <param name="destination">A float array to pack actions into whose length is greater than or
158-
/// equal to the addition of the Lengths of this objects <see cref="ContinuousActions"/> and
159-
/// <see cref="DiscreteActions"/> segments.</param>
160-
[Obsolete("PackActions has been deprecated.")]
161-
public void PackActions(in float[] destination)
162-
{
163-
Debug.Assert(destination.Length >= ContinuousActions.Length + DiscreteActions.Length,
164-
$"argument '{nameof(destination)}' is not large enough to pack the actions into.\n" +
165-
$"{nameof(destination)}.Length: {destination.Length}\n" +
166-
$"{nameof(ContinuousActions)}.Length + {nameof(DiscreteActions)}.Length: {ContinuousActions.Length + DiscreteActions.Length}");
167-
168-
var start = 0;
169-
if (ContinuousActions.Length > 0)
170-
{
171-
Array.Copy(ContinuousActions.Array,
172-
ContinuousActions.Offset,
173-
destination,
174-
start,
175-
ContinuousActions.Length);
176-
start = ContinuousActions.Length;
177-
}
178-
if (start >= destination.Length)
179-
{
180-
return;
181-
}
182-
183-
if (DiscreteActions.Length > 0)
184-
{
185-
Array.Copy(DiscreteActions.Array,
186-
DiscreteActions.Offset,
187-
destination,
188-
start,
189-
DiscreteActions.Length);
190-
}
191-
}
192151
}
193152

194153
/// <summary>

com.unity.ml-agents/Runtime/Agent.cs

Lines changed: 3 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,6 @@ internal struct AgentParameters
301301
/// Whether or not the Agent has been initialized already
302302
bool m_Initialized;
303303

304-
/// Keeps track of the actions that are masked at each step.
305-
DiscreteActionMasker m_ActionMasker;
306-
307304
/// <summary>
308305
/// Set of DemonstrationWriters that the Agent will write its step information to.
309306
/// If you use a DemonstrationRecorder component, this will automatically register its DemonstrationWriter.
@@ -338,17 +335,6 @@ internal struct AgentParameters
338335
/// </summary>
339336
IActuator m_VectorActuator;
340337

341-
/// <summary>
342-
/// This is used to avoid allocation of a float array every frame if users are still using the old
343-
/// OnActionReceived method.
344-
/// </summary>
345-
float[] m_LegacyActionCache;
346-
347-
/// <summary>
348-
/// This is used to avoid allocation of a float array during legacy calls to Heuristic.
349-
/// </summary>
350-
float[] m_LegacyHeuristicCache;
351-
352338
/// Currect MultiAgentGroup ID. Default to 0 (meaning no group)
353339
int m_GroupId;
354340

@@ -952,29 +938,7 @@ public virtual void Initialize() { }
952938
/// <seealso cref="IActionReceiver.OnActionReceived"/>
953939
public virtual void Heuristic(in ActionBuffers actionsOut)
954940
{
955-
// Disable deprecation warnings so we can call the legacy overload.
956-
#pragma warning disable CS0618
957-
958-
// The default implementation of Heuristic calls the
959-
// obsolete version for backward compatibility
960-
switch (m_PolicyFactory.BrainParameters.VectorActionSpaceType)
961-
{
962-
case SpaceType.Continuous:
963-
Heuristic(m_LegacyHeuristicCache);
964-
Array.Copy(m_LegacyHeuristicCache, actionsOut.ContinuousActions.Array, m_LegacyActionCache.Length);
965-
actionsOut.DiscreteActions.Clear();
966-
break;
967-
case SpaceType.Discrete:
968-
Heuristic(m_LegacyHeuristicCache);
969-
var discreteActionSegment = actionsOut.DiscreteActions;
970-
for (var i = 0; i < actionsOut.DiscreteActions.Length; i++)
971-
{
972-
discreteActionSegment[i] = (int)m_LegacyHeuristicCache[i];
973-
}
974-
actionsOut.ContinuousActions.Clear();
975-
break;
976-
}
977-
#pragma warning restore CS0618
941+
Debug.LogWarning("Heuristic method called but not implemented. Returning placeholder actions.");
978942
}
979943

980944
/// <summary>
@@ -1064,8 +1028,6 @@ void InitializeActuators()
10641028
var param = m_PolicyFactory.BrainParameters;
10651029
m_VectorActuator = new AgentVectorActuator(this, this, param.ActionSpec);
10661030
m_ActuatorManager = new ActuatorManager(attachedActuators.Length + 1);
1067-
m_LegacyActionCache = new float[m_VectorActuator.TotalNumberOfActions()];
1068-
m_LegacyHeuristicCache = new float[m_VectorActuator.TotalNumberOfActions()];
10691031

10701032
m_ActuatorManager.Add(m_VectorActuator);
10711033

@@ -1223,17 +1185,7 @@ public ReadOnlyCollection<float> GetObservations()
12231185
/// [Agents - Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_13_docs/docs/Learning-Environment-Design-Agents.md#actions
12241186
/// </remarks>
12251187
/// <seealso cref="IActionReceiver.OnActionReceived"/>
1226-
public virtual void WriteDiscreteActionMask(IDiscreteActionMask actionMask)
1227-
{
1228-
if (m_ActionMasker == null)
1229-
{
1230-
m_ActionMasker = new DiscreteActionMasker(actionMask);
1231-
}
1232-
// Disable deprecation warnings so we can call the legacy overload.
1233-
#pragma warning disable CS0618
1234-
CollectDiscreteActionMasks(m_ActionMasker);
1235-
#pragma warning restore CS0618
1236-
}
1188+
public virtual void WriteDiscreteActionMask(IDiscreteActionMask actionMask) { }
12371189

12381190
/// <summary>
12391191
/// Implement `OnActionReceived()` to specify agent behavior at every step, based
@@ -1301,34 +1253,7 @@ public virtual void WriteDiscreteActionMask(IDiscreteActionMask actionMask)
13011253
/// <param name="actions">
13021254
/// Struct containing the buffers of actions to be executed at this step.
13031255
/// </param>
1304-
public virtual void OnActionReceived(ActionBuffers actions)
1305-
{
1306-
var actionSpec = m_PolicyFactory.BrainParameters.ActionSpec;
1307-
// For continuous and discrete actions together, we don't need to fall back to the legacy method
1308-
if (actionSpec.NumContinuousActions > 0 && actionSpec.NumDiscreteActions > 0)
1309-
{
1310-
// Nothing implemented.
1311-
return;
1312-
}
1313-
1314-
if (!actions.ContinuousActions.IsEmpty())
1315-
{
1316-
Array.Copy(actions.ContinuousActions.Array,
1317-
m_LegacyActionCache,
1318-
actionSpec.NumContinuousActions);
1319-
}
1320-
else
1321-
{
1322-
for (var i = 0; i < m_LegacyActionCache.Length; i++)
1323-
{
1324-
m_LegacyActionCache[i] = (float)actions.DiscreteActions[i];
1325-
}
1326-
}
1327-
// Disable deprecation warnings so we can call the legacy overload.
1328-
#pragma warning disable CS0618
1329-
OnActionReceived(m_LegacyActionCache);
1330-
#pragma warning restore CS0618
1331-
}
1256+
public virtual void OnActionReceived(ActionBuffers actions) { }
13321257

13331258
/// <summary>
13341259
/// Implement `OnEpisodeBegin()` to set up an Agent instance at the beginning

com.unity.ml-agents/Runtime/Agent.deprecated.cs

Lines changed: 0 additions & 63 deletions
This file was deleted.

com.unity.ml-agents/Runtime/Agent.deprecated.cs.meta

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)