|
|
|
|
|
|
using System; |
|
|
|
using System.Text.RegularExpressions; |
|
|
|
using Google.Protobuf; |
|
|
|
using Google.Protobuf.Collections; |
|
|
|
using NUnit.Framework; |
|
|
|
using Unity.MLAgents.Actuators; |
|
|
|
using Unity.MLAgents.Demonstrations; |
|
|
|
|
|
|
using Unity.MLAgents.Analytics; |
|
|
|
using Unity.MLAgents.CommunicatorObjects; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.TestTools; |
|
|
|
|
|
|
|
namespace Unity.MLAgents.Tests |
|
|
|
{ |
|
|
|
|
|
|
[SetUp] |
|
|
|
public void SetUp() |
|
|
|
{ |
|
|
|
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities(); |
|
|
|
} |
|
|
|
|
|
|
|
[Test] |
|
|
|
public void TestDefaultBrainParametersToProto() |
|
|
|
{ |
|
|
|
|
|
|
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities |
|
|
|
{ |
|
|
|
BaseRLCapabilities = true, |
|
|
|
HybridActions = false |
|
|
|
}; |
|
|
|
brain.ToProto("foo", false); |
|
|
|
} |
|
|
|
|
|
|
|
[Test] |
|
|
|
|
|
|
var actionSpec = new ActionSpec(); |
|
|
|
actionSpec.ToBrainParametersProto("foo", false); |
|
|
|
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities |
|
|
|
{ |
|
|
|
BaseRLCapabilities = true, |
|
|
|
HybridActions = false |
|
|
|
}; |
|
|
|
actionSpec.ToBrainParametersProto("foo", false); |
|
|
|
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities(); |
|
|
|
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities |
|
|
|
{ |
|
|
|
BaseRLCapabilities = true, |
|
|
|
HybridActions = false |
|
|
|
}; |
|
|
|
actionSpec.ToBrainParametersProto("foo", false); |
|
|
|
|
|
|
|
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities(); |
|
|
|
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities |
|
|
|
{ |
|
|
|
BaseRLCapabilities = true, |
|
|
|
HybridActions = false |
|
|
|
}; |
|
|
|
actionSpec.ToBrainParametersProto("foo", false); |
|
|
|
} |
|
|
|
|
|
|
|
[Test] |
|
|
|
public void ToBrainParameters() |
|
|
|
{ |
|
|
|
// Should be able to convert a default instance to proto.
|
|
|
|
var actionSpec = new ActionSpec(); |
|
|
|
actionSpec.ToBrainParametersProto("foo", false).ToBrainParameters(); |
|
|
|
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities |
|
|
|
{ |
|
|
|
BaseRLCapabilities = true, |
|
|
|
HybridActions = false |
|
|
|
}; |
|
|
|
actionSpec.ToBrainParametersProto("foo", false).ToBrainParameters(); |
|
|
|
|
|
|
|
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities(); |
|
|
|
// Continuous
|
|
|
|
actionSpec = ActionSpec.MakeContinuous(3); |
|
|
|
actionSpec.ToBrainParametersProto("foo", false).ToBrainParameters(); |
|
|
|
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities |
|
|
|
{ |
|
|
|
BaseRLCapabilities = true, |
|
|
|
HybridActions = false |
|
|
|
}; |
|
|
|
actionSpec.ToBrainParametersProto("foo", false).ToBrainParameters(); |
|
|
|
|
|
|
|
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities(); |
|
|
|
|
|
|
|
// Discrete
|
|
|
|
actionSpec = ActionSpec.MakeDiscrete(1, 2, 3); |
|
|
|
actionSpec.ToBrainParametersProto("foo", false).ToBrainParameters(); |
|
|
|
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities |
|
|
|
{ |
|
|
|
BaseRLCapabilities = true, |
|
|
|
HybridActions = false |
|
|
|
}; |
|
|
|
actionSpec.ToBrainParametersProto("foo", false).ToBrainParameters(); |
|
|
|
} |
|
|
|
|
|
|
|
[Test] |
|
|
|
|
|
|
var agentInfo = new AgentInfo(); |
|
|
|
agentInfo.ToInfoActionPairProto(); |
|
|
|
var pairProto = agentInfo.ToInfoActionPairProto(); |
|
|
|
pairProto.AgentInfo.Observations.Add(new ObservationProto |
|
|
|
{ |
|
|
|
CompressedData = ByteString.Empty, |
|
|
|
CompressionType = CompressionTypeProto.None, |
|
|
|
FloatData = new ObservationProto.Types.FloatData(), |
|
|
|
ObservationType = ObservationTypeProto.Default, |
|
|
|
Name = "Sensor" |
|
|
|
}); |
|
|
|
pairProto.AgentInfo.Observations[0].Shape.Add(0); |
|
|
|
pairProto.GetObservationSummaries(); |
|
|
|
agentInfo.ToAgentInfoProto(); |
|
|
|
agentInfo.groupId = 1; |
|
|
|
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities |
|
|
|
{ |
|
|
|
BaseRLCapabilities = true, |
|
|
|
MultiAgentGroups = false |
|
|
|
}; |
|
|
|
agentInfo.ToAgentInfoProto(); |
|
|
|
LogAssert.Expect(LogType.Warning, new Regex(".+")); |
|
|
|
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities |
|
|
|
{ |
|
|
|
BaseRLCapabilities = true, |
|
|
|
MultiAgentGroups = true |
|
|
|
}; |
|
|
|
agentInfo.ToAgentInfoProto(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(obsProto.CompressedData.Length, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
[Test] |
|
|
|