Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing Obsolete methods from the package #5024

Merged
merged 7 commits into from
Mar 8, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ public class BasicActuatorComponent : ActuatorComponent
/// Creates a BasicActuator.
/// </summary>
/// <returns></returns>
#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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ namespace Unity.MLAgentsExamples
public class Match3ExampleActuatorComponent : Match3ActuatorComponent
{
/// <inheritdoc/>
#pragma warning disable 672
public override IActuator CreateActuator()
#pragma warning restore 672
public override IActuator[] CreateActuators()
{
var board = GetComponent<Match3Board>();
var agent = GetComponentInParent<Agent>();
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) };
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ public class Match3ActuatorComponent : ActuatorComponent
public bool ForceHeuristic;

/// <inheritdoc/>
#pragma warning disable 672
public override IActuator CreateActuator()
#pragma warning restore 672
public override IActuator[] CreateActuators()
{
var board = GetComponent<AbstractBoard>();
var agent = GetComponentInParent<Agent>();
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) };
}

/// <inheritdoc/>
Expand Down
11 changes: 1 addition & 10 deletions com.unity.ml-agents/Runtime/Actuators/ActuatorComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,14 @@ namespace Unity.MLAgents.Actuators
/// </summary>
public abstract class ActuatorComponent : MonoBehaviour
{
/// <summary>
/// Create the IActuator. This is called by the Agent when it is initialized.
/// </summary>
/// <returns>Created IActuator object.</returns>
[Obsolete("Use CreateActuators instead.")]
public abstract IActuator CreateActuator();

/// <summary>
/// Create a collection of <see cref="IActuator"/>s. This is called by the <see cref="Agent"/> during
/// initialization.
/// </summary>
/// <returns>A collection of <see cref="IActuator"/>s</returns>
public virtual IActuator[] CreateActuators()
{
#pragma warning disable 618
return new[] { CreateActuator() };
#pragma warning restore 618
return new IActuator[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be abstract (with no implementation).

}

/// <summary>
Expand Down
41 changes: 0 additions & 41 deletions com.unity.ml-agents/Runtime/Actuators/IActionReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,47 +148,6 @@ public override int GetHashCode()
return (ContinuousActions.GetHashCode() * 397) ^ DiscreteActions.GetHashCode();
}
}

/// <summary>
/// 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
/// <see cref="ContinuousActions"/> and <see cref="DiscreteActions"/>.
/// </summary>
/// <param name="destination">A float array to pack actions into whose length is greater than or
/// equal to the addition of the Lengths of this objects <see cref="ContinuousActions"/> and
/// <see cref="DiscreteActions"/> segments.</param>
[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);
}
}
}

/// <summary>
Expand Down
57 changes: 0 additions & 57 deletions com.unity.ml-agents/Runtime/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,6 @@ internal struct AgentParameters
/// </summary>
IActuator m_VectorActuator;

/// <summary>
/// This is used to avoid allocation of a float array every frame if users are still using the old
/// OnActionReceived method.
/// </summary>
float[] m_LegacyActionCache;

/// <summary>
/// This is used to avoid allocation of a float array during legacy calls to Heuristic.
/// </summary>
float[] m_LegacyHeuristicCache;

/// Currect MultiAgentGroup ID. Default to 0 (meaning no group)
int m_GroupId;

Expand Down Expand Up @@ -952,29 +941,7 @@ public virtual void Initialize() { }
/// <seealso cref="IActionReceiver.OnActionReceived"/>
public virtual void Heuristic(in ActionBuffers actionsOut)
{
// Disable deprecation warnings so we can call the legacy overload.
chriselion marked this conversation as resolved.
Show resolved Hide resolved
#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
}

/// <summary>
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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.
chriselion marked this conversation as resolved.
Show resolved Hide resolved
#pragma warning disable CS0618
CollectDiscreteActionMasks(m_ActionMasker);
#pragma warning restore CS0618
}

/// <summary>
Expand Down Expand Up @@ -1310,24 +1271,6 @@ public virtual void OnActionReceived(ActionBuffers actions)
// Nothing implemented.
return;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OnActionReceived should be empty now (no reason to look at the actionSpec)

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
}

/// <summary>
Expand Down
63 changes: 0 additions & 63 deletions com.unity.ml-agents/Runtime/Agent.deprecated.cs

This file was deleted.

3 changes: 0 additions & 3 deletions com.unity.ml-agents/Runtime/Agent.deprecated.cs.meta

This file was deleted.

28 changes: 0 additions & 28 deletions com.unity.ml-agents/Runtime/Sensors/ObservationWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,34 +117,6 @@ public float this[int index]
}
}

/// <summary>
/// Write the range of floats
/// </summary>
/// <param name="data"></param>
/// <param name="writeOffset">Optional write offset.</param>
[Obsolete("Use AddList() for better performance")]
public void AddRange(IEnumerable<float> 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++;
}
}
}

/// <summary>
/// Write the list of floats.
/// </summary>
Expand Down
21 changes: 0 additions & 21 deletions com.unity.ml-agents/Runtime/Sensors/SensorComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,5 @@ public abstract class SensorComponent : MonoBehaviour
/// <returns>Shape of the sensor observation.</returns>
public abstract int[] GetObservationShape();

/// <summary>
/// Whether the observation is visual or not.
/// </summary>
/// <returns>True if the observation is visual, false otherwise.</returns>
[Obsolete("IsVisual is deprecated, please use GetObservationShape() instead.")]
public virtual bool IsVisual()
{
var shape = GetObservationShape();
return shape.Length == 3;
}

/// <summary>
/// Whether the observation is vector or not.
/// </summary>
/// <returns>True if the observation is vector, false otherwise.</returns>
[Obsolete("IsVisual is deprecated, please use GetObservationShape() instead.")]
public virtual bool IsVector()
{
var shape = GetObservationShape();
return shape.Length == 1;
}
}
}
13 changes: 0 additions & 13 deletions com.unity.ml-agents/Runtime/Sensors/VectorSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,6 @@ public void AddObservation(Vector2 observation)
AddFloatObs(observation.y);
}

/// <summary>
/// Adds a collection of float observations to the vector observations of the agent.
/// </summary>
/// <param name="observation">Observation.</param>
[Obsolete("Use AddObservation(IList<float>) for better performance.")]
public void AddObservation(IEnumerable<float> observation)
{
foreach (var f in observation)
{
AddFloatObs(f);
}
}

/// <summary>
/// Adds a list or array of float observations to the vector observations of the agent.
/// </summary>
Expand Down
25 changes: 0 additions & 25 deletions com.unity.ml-agents/Runtime/SideChannels/SideChannelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,29 +241,4 @@ internal static void ProcessSideChannelData(Dictionary<Guid, SideChannel> sideCh
}
}
}

/// <summary>
/// Deprecated, use <see cref="SideChannelManager"/> instead.
/// </summary>
[Obsolete("Use SideChannelManager instead.")]
public static class SideChannelsManager
{
/// <summary>
/// Deprecated, use <see cref="SideChannelManager.RegisterSideChannel"/> instead.
/// </summary>
/// <param name="sideChannel"></param>
public static void RegisterSideChannel(SideChannel sideChannel)
{
SideChannelManager.RegisterSideChannel(sideChannel);
}

/// <summary>
/// Deprecated, use <see cref="SideChannelManager.UnregisterSideChannel"/> instead.
/// </summary>
/// <param name="sideChannel"></param>
public static void UnregisterSideChannel(SideChannel sideChannel)
{
SideChannelManager.UnregisterSideChannel(sideChannel);
}
}
}
Loading