浏览代码

Develop passing package validation (#3494)

* Fixed package validation errors in DecisionRequester

* Fixed package validation errors in ActionMasker

* Fix package validation for DemoRecorder

* Fix package validation for DemoStore

* Fix package validation for TimerStack

* Fix package validation for UnityAgentsExceptions

* Fix package validation for BarracudaPolicy

* Fix package validation for BehaviorParameters

* Fix package validation for BrainParameters

* Addressed PR comments

* Made DemoWriter.MetaDataBytes internal as it’s referenced in unit tests
/asymm-envs
GitHub 4 年前
当前提交
45bd2d2c
共有 9 个文件被更改,包括 143 次插入23 次删除
  1. 7
      com.unity.ml-agents/Runtime/ActionMasker.cs
  2. 29
      com.unity.ml-agents/Runtime/DecisionRequester.cs
  3. 20
      com.unity.ml-agents/Runtime/Demonstrations/DemonstrationRecorder.cs
  4. 16
      com.unity.ml-agents/Runtime/Demonstrations/DemonstrationWriter.cs
  5. 12
      com.unity.ml-agents/Runtime/Policy/BarracudaPolicy.cs
  6. 21
      com.unity.ml-agents/Runtime/Policy/BehaviorParameters.cs
  7. 34
      com.unity.ml-agents/Runtime/Policy/BrainParameters.cs
  8. 18
      com.unity.ml-agents/Runtime/Timer.cs
  9. 9
      com.unity.ml-agents/Runtime/UnityAgentsException.cs

7
com.unity.ml-agents/Runtime/ActionMasker.cs


namespace MLAgents
{
/// <summary>
/// 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 (e.g. the King in Chess taking a move to the left if it is already in the
/// left side of the board). This class represents the set of masked actions and provides
/// the utilities for setting and retrieving them.
/// </summary>
public class ActionMasker
{
/// When using discrete control, is the starting indices of the actions

29
com.unity.ml-agents/Runtime/DecisionRequester.cs


using System;
using System.Runtime.CompilerServices;
using UnityEngine;
namespace MLAgents

[AddComponentMenu("ML Agents/Decision Requester", (int)MenuGroup.Default)]
public class DecisionRequester : MonoBehaviour
{
/// <summary>
/// The frequency with which the agent requests a decision. A DecisionPeriod of 5 means
/// that the Agent will request a decision every 5 Academy steps.
/// </summary>
[Tooltip("The agent will automatically request a decision every X Academy steps.")]
[Tooltip("The frequency with which the agent requests a decision. A DecisionPeriod " +
"of 5 means that the Agent will request a decision every 5 Academy steps.")]
[Tooltip("Whether or not AgentAction will be called on Academy steps that decisions aren't requested. Has no effect if DecisionPeriod is 1.")]
/// <summary>
/// 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.
/// </summary>
[Tooltip("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.")]
[Tooltip("Whether or not Agent decisions should start at a random offset.")]
/// <summary>
/// Whether or not the Agent decisions should start at an offset (different for each agent).
/// This does not affect <see cref="DecisionPeriod"/>. Turning this on will distribute
/// the decision-making computations for all the agents across multiple Academy steps.
/// This can be valuable in scenarios where you have many agents in the scene, particularly
/// during the inference phase.
/// </summary>
[Tooltip("Whether or not Agent decisions should start at an offset.")]
public void Awake()
internal void Awake()
{
m_Offset = offsetStep ? gameObject.GetInstanceID() : 0;
m_Agent = gameObject.GetComponent<Agent>();

20
com.unity.ml-agents/Runtime/Demonstrations/DemonstrationRecorder.cs


[AddComponentMenu("ML Agents/Demonstration Recorder", (int)MenuGroup.Default)]
public class DemonstrationRecorder : MonoBehaviour
{
/// <summary>
/// Whether or not to record demonstrations.
/// </summary>
[Tooltip("Base demonstration file name. Will have numbers appended to make unique.")]
/// <summary>
/// Base demonstration file name. If multiple files are saved, the additional filenames
/// will have a sequence of unique numbers appended.
/// </summary>
[Tooltip("Base demonstration file name. If multiple files are saved, the additional " +
"filenames will have a unique number appended.")]
[Tooltip("Base directory to write the demo files. If null, will use {Application.dataPath}/Demonstrations.")]
/// <summary>
/// Directory to save the demo files. Will default to a "Demonstrations/" folder in the
/// Application data path if not specified.
/// </summary>
[Tooltip("Directory to save the demo files. Will default to " +
"{Application.dataPath}/Demonstrations if not specified.")]
public string demonstrationDirectory;
DemonstrationWriter m_DemoWriter;

const string k_DefaultDirectoryName = "Demonstrations";
IFileSystem m_FileSystem;
Agent m_Agent;

}
if (string.IsNullOrEmpty(demonstrationDirectory))
{
demonstrationDirectory = Path.Combine(Application.dataPath, "Demonstrations");
demonstrationDirectory = Path.Combine(Application.dataPath, k_DefaultDirectoryName);
}
demonstrationName = SanitizeName(demonstrationName, MaxNameLength);

16
com.unity.ml-agents/Runtime/Demonstrations/DemonstrationWriter.cs


namespace MLAgents
{
/// <summary>
/// Responsible for writing demonstration data to stream (usually a file stream).
/// Responsible for writing demonstration data to stream (typically a file stream).
public const int MetaDataBytes = 32; // Number of bytes allocated to metadata in demo file.
/// <summary>
/// Number of bytes reserved for the Demonstration metadata at the start of the demo file.
/// </summary>
internal const int MetaDataBytes = 32;
DemonstrationMetaData m_MetaData;
Stream m_Writer;

/// <summary>
/// Writes the initial data to the stream.
/// </summary>
/// <param name="demonstrationName">Base name of the demonstration file(s).</param>
/// <param name="brainName">The name of the Brain the agent is attached to.</param>
/// <param name="brainParameters">The parameters of the Brain the agent is attached to.</param>
public void Initialize(
string demonstrationName, BrainParameters brainParameters, string brainName)
{

/// <summary>
/// Writes brain parameters to file.
/// </summary>
/// <param name="brainName">The name of the Brain the agent is attached to.</param>
/// <param name="brainParameters">The parameters of the Brain the agent is attached to.</param>
void WriteBrainParameters(string brainName, BrainParameters brainParameters)
{
if (m_Writer == null)

/// <summary>
/// Write AgentInfo experience to file.
/// </summary>
/// <param name="info"> <see cref="AgentInfo"/> for the agent being recorded.</param>
/// <param name="sensors">List of sensors to record for the agent.</param>
internal void Record(AgentInfo info, List<ISensor> sensors)
{
if (m_Writer == null)

/// <summary>
/// Performs all clean-up necessary
/// Performs all clean-up necessary.
/// </summary>
public void Close()
{

12
com.unity.ml-agents/Runtime/Policy/BarracudaPolicy.cs


namespace MLAgents
{
/// <summary>
/// Where to perform inference.
/// </summary>
/// <summary>
/// CPU inference
/// </summary>
/// <summary>
/// GPU inference
/// </summary>
/// every step. It uses a ModelRunner that is shared accross all
/// every step. It uses a ModelRunner that is shared across all
/// Barracuda Policies that use the same model and inference devices.
/// </summary>
internal class BarracudaPolicy : IPolicy

21
com.unity.ml-agents/Runtime/Policy/BehaviorParameters.cs


/// <summary>
/// The Factory to generate policies.
/// </summary>
///
[AddComponentMenu("ML Agents/Behavior Parameters", (int)MenuGroup.Default)]
public class BehaviorParameters : MonoBehaviour
{

[HideInInspector]
[SerializeField]
string m_BehaviorName = "My Behavior";
/// <summary>
/// The team ID for this behavior.
/// </summary>
[HideInInspector]
[SerializeField]
public int m_TeamID;

[Tooltip("Use all Sensor components attached to child GameObjects of this Agent.")]
bool m_UseChildSensors = true;
/// <summary>
/// The associated <see cref="BrainParameters"/> for this behavior.
/// </summary>
/// <summary>
/// Whether or not to use all the sensor components attached to child GameObjects of the agent.
/// </summary>
/// <summary>
/// The name of this behavior, which is used as a base name. See
/// <see cref="fullyQualifiedBehaviorName"/> for the full name.
/// </summary>
public string behaviorName
{
get { return m_BehaviorName; }

}
}
/// <summary>
/// Updates the model and related details for this behavior.
/// </summary>
/// <param name="newBehaviorName">New name for the behavior.</param>
/// <param name="model">New neural network model for this behavior.</param>
/// <param name="inferenceDevice">New inference device for this behavior.</param>
public void GiveModel(
string newBehaviorName,
NNModel model,

34
com.unity.ml-agents/Runtime/Policy/BrainParameters.cs


namespace MLAgents
{
/// <summary>
/// Whether the action space is discrete or continuous.
/// </summary>
/// <summary>
/// Discrete action space: a fixed number of options are available.
/// </summary>
/// <summary>
/// Continuous action space: each action can take on a float value.
/// </summary>
Continuous
}

public class BrainParameters
{
/// <summary>
/// If continuous : The length of the float vector that represents
/// the state
/// If discrete : The number of possible values the state can take
/// If continuous : The length of the float vector that represents the state.
/// If discrete : The number of possible values the state can take.
/// <summary>
/// Stacking refers to concatenating the observations across multiple frames. This field
/// indicates the number of frames to concatenate across.
/// </summary>
/// If continuous : The length of the float vector that represents
/// the action
/// If discrete : The number of possible values the action can take*/
/// If continuous : The length of the float vector that represents the action.
/// If discrete : The number of possible values the action can take.
/// <summary></summary>The list of strings describing what the actions correpond to */
/// <summary>
/// The list of strings describing what the actions correspond to.
/// </summary>
/// <summary>Defines if the action is discrete or continuous</summary>
/// <summary>
/// Defines if the action is discrete or continuous.
/// </summary>
/// Deep clones the BrainParameter object
/// Deep clones the BrainParameter object.
/// </summary>
/// <returns> A new BrainParameter object with the same values as the original.</returns>
public BrainParameters Clone()

18
com.unity.ml-agents/Runtime/Timer.cs


static double s_TicksToSeconds = 1e-7; // 100 ns per tick
/// <summary>
/// Full name of the node. This is the node's parents full name concatenated with this node's name
/// Full name of the node. This is the node's parents full name concatenated with this
/// node's name.
/// </summary>
string m_FullName;

Reset();
}
/// <summary>
/// Resets the timer stack and the root node.
/// </summary>
/// <param name="name">Name of the root node.</param>
public void Reset(string name = "root")
{
m_Stack = new Stack<TimerNode>();

/// <summary>
/// The singleton <see cref="TimerStack"/> instance.
/// </summary>
public static TimerStack Instance
{
get { return k_Instance; }

get { return m_RootNode; }
}
/// <summary>
/// Whether or not new timers and gauges can be added.
/// </summary>
public bool Recording
{
get { return m_Recording; }

/// <summary>
/// Updates the referenced gauge in the root node with the provided value.
/// </summary>
/// <param name="name">The name of the Gauge to modify.</param>
/// <param name="value">The value to update the Gauge with.</param>
public void SetGauge(string name, float value)
{
if (!Recording)

9
com.unity.ml-agents/Runtime/UnityAgentsException.cs


namespace MLAgents
{
/// <summary>
/// </summary>
/// <summary>
/// </summary>
/// <param name="message">The exception message</param>
/// <summary>
/// </summary>
/// <param name="info">Data for serializing/de-serializing</param>
/// <param name="context">Describes the source and destination of the serialized stream</param>
protected UnityAgentsException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)

正在加载...
取消
保存