浏览代码

Uncomment obsolete attributes, fix warnings (#4771)

* uncomment obsolete attributes, fix warnings

* Apply suggestions from code review

Co-authored-by: andrewcoh <54679309+andrewcoh@users.noreply.github.com>

Co-authored-by: andrewcoh <54679309+andrewcoh@users.noreply.github.com>
/MLA-1734-demo-provider
GitHub 4 年前
当前提交
c6000214
共有 6 个文件被更改,包括 42 次插入6 次删除
  1. 2
      com.unity.ml-agents/Runtime/Actuators/IActionReceiver.cs
  2. 14
      com.unity.ml-agents/Runtime/Agent.cs
  3. 5
      com.unity.ml-agents/Runtime/Agent.deprecated.cs
  4. 3
      com.unity.ml-agents/Runtime/Communicator/GrpcExtensions.cs
  5. 16
      com.unity.ml-agents/Runtime/Policies/BrainParameters.cs
  6. 8
      com.unity.ml-agents/Tests/Editor/MLAgentsEditModeTest.cs

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


/// <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.")]
[Obsolete("PackActions has been deprecated.")]
public void PackActions(in float[] destination)
{
Debug.Assert(destination.Length >= ContinuousActions.Length + DiscreteActions.Length,

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


/// <seealso cref="IActionReceiver.OnActionReceived"/>
public virtual void Heuristic(in ActionBuffers actionsOut)
{
// For backward compatibility
// 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:

actionsOut.ContinuousActions.Clear();
break;
}
#pragma warning restore CS0618
}
/// <summary>

{
m_ActionMasker = new DiscreteActionMasker(actionMask);
}
// Disable deprecation warnings so we can call the legacy overload.
#pragma warning disable CS0618
#pragma warning restore CS0618
}
/// <summary>

{
m_LegacyActionCache = Array.ConvertAll(actions.DiscreteActions.Array, x => (float)x);
}
// Disable deprecation warnings so we can call the legacy overload.
#pragma warning disable CS0618
#pragma warning restore CS0618
}
/// <summary>

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


/// Deprecated, use <see cref="WriteDiscreteActionMask"/> instead.
/// </summary>
/// <param name="actionMasker"></param>
[Obsolete("CollectDiscreteActionMasks has been deprecated, please use WriteDiscreteActionMask.")]
public virtual void CollectDiscreteActionMasks(DiscreteActionMasker actionMasker)
{
}

/// </summary>
/// <param name="actionsOut"></param>
[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.");

/// Deprecated, use <see cref="OnActionReceived(ActionBuffers)"/> instead.
/// </summary>
/// <param name="vectorAction"></param>
[Obsolete("The float[] version of OnActionReceived has been deprecated, please use the ActionBuffers version instead.")]
public virtual void OnActionReceived(float[] vectorAction) { }
/// <summary>

/// The last action that was decided by the Agent (or null if no decision has been made).
/// </returns>
/// <seealso cref="OnActionReceived(ActionBuffers)"/>
// [Obsolete("GetAction has been deprecated, please use GetStoredActionBuffers, Or GetStoredDiscreteActions.")]
[Obsolete("GetAction has been deprecated, please use GetStoredActionBuffers instead.")]
public float[] GetAction()
{
var storedAction = m_Info.storedVectorActions;

3
com.unity.ml-agents/Runtime/Communicator/GrpcExtensions.cs


/// <param name="isTraining">Whether or not the Brain is training.</param>
public static BrainParametersProto ToProto(this BrainParameters bp, string name, bool isTraining)
{
// Disable deprecation warnings so we can set legacy fields
#pragma warning disable CS0618
var brainParametersProto = new BrainParametersProto
{
VectorActionSpaceTypeDeprecated = (SpaceTypeProto)bp.VectorActionSpaceType,

{
brainParametersProto.VectorActionDescriptionsDeprecated.AddRange(bp.VectorActionDescriptions);
}
#pragma warning restore CS0618
return brainParametersProto;
}

16
com.unity.ml-agents/Runtime/Policies/BrainParameters.cs


/// the action.
/// For the discrete action space: the number of branches in the action space.
/// </value>
/// [Obsolete("VectorActionSize has been deprecated, please use ActionSpec instead.")]
[Obsolete("VectorActionSize has been deprecated, please use ActionSpec instead.")]
[FormerlySerializedAs("vectorActionSize")]
public int[] VectorActionSize = new[] { 1 };

/// <summary>
/// (Deprecated) Defines if the action is discrete or continuous.
/// </summary>
/// [Obsolete("VectorActionSpaceType has been deprecated, please use ActionSpec instead.")]
[Obsolete("VectorActionSpaceType has been deprecated, please use ActionSpec instead.")]
[FormerlySerializedAs("vectorActionSpaceType")]
public SpaceType VectorActionSpaceType = SpaceType.Discrete;

/// <summary>
/// (Deprecated) The number of actions specified by this Brain.
/// </summary>
/// [Obsolete("NumActions has been deprecated, please use ActionSpec instead.")]
[Obsolete("NumActions has been deprecated, please use ActionSpec instead.")]
public int NumActions
{
get

/// <returns> A new BrainParameter object with the same values as the original.</returns>
public BrainParameters Clone()
{
// Disable deprecation warnings so we can read/write the old fields.
#pragma warning disable CS0618
return new BrainParameters
{
VectorObservationSize = VectorObservationSize,

VectorActionSize = (int[])VectorActionSize.Clone(),
VectorActionSpaceType = VectorActionSpaceType,
};
#pragma warning restore CS0618
}
/// <summary>

{
// Disable deprecation warnings so we can read the old fields.
#pragma warning disable CS0618
if (!hasUpgradedBrainParametersWithActionSpec
&& m_ActionSpec.NumContinuousActions == 0
&& m_ActionSpec.BranchSizes == null)

}
}
hasUpgradedBrainParametersWithActionSpec = true;
#pragma warning restore CS0618
}
/// <summary>

{
// Disable deprecation warnings so we can read the old fields.
#pragma warning disable CS0618
if (m_ActionSpec.NumContinuousActions == 0)
{
VectorActionSize = (int[])ActionSpec.BranchSizes.Clone();

{
VectorActionSize = null;
}
#pragma warning restore CS0618
}
/// <summary>

8
com.unity.ml-agents/Tests/Editor/MLAgentsEditModeTest.cs


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
Assert.AreEqual(
agent1.collectObservationsCallsForEpisode,
agent1.GetStoredActionBuffers().ContinuousActions[0]
);
#pragma warning restore CS0618
}
}

正在加载...
取消
保存