1
1
using System ;
2
+ using System . Text . RegularExpressions ;
3
+ using Google . Protobuf ;
4
+ using Google . Protobuf . Collections ;
2
5
using NUnit . Framework ;
3
6
using Unity . MLAgents . Actuators ;
4
7
using Unity . MLAgents . Demonstrations ;
7
10
8
11
using Unity . MLAgents . Analytics ;
9
12
using Unity . MLAgents . CommunicatorObjects ;
13
+ using UnityEditor . VersionControl ;
14
+ using UnityEngine ;
15
+ using UnityEngine . TestTools ;
10
16
11
17
namespace Unity . MLAgents . Tests
12
18
{
13
19
[ TestFixture ]
14
20
public class GrpcExtensionsTests
15
21
{
22
+ [ SetUp ]
23
+ public void SetUp ( )
24
+ {
25
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities ( ) ;
26
+ }
27
+
16
28
[ Test ]
17
29
public void TestDefaultBrainParametersToProto ( )
18
30
{
19
31
// Should be able to convert a default instance to proto.
20
32
var brain = new BrainParameters ( ) ;
21
33
brain . ToProto ( "foo" , false ) ;
34
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities
35
+ {
36
+ BaseRLCapabilities = true ,
37
+ HybridActions = false
38
+ } ;
39
+ brain . ToProto ( "foo" , false ) ;
22
40
}
23
41
24
42
[ Test ]
@@ -27,22 +45,104 @@ public void TestDefaultActionSpecToProto()
27
45
// Should be able to convert a default instance to proto.
28
46
var actionSpec = new ActionSpec ( ) ;
29
47
actionSpec . ToBrainParametersProto ( "foo" , false ) ;
48
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities
49
+ {
50
+ BaseRLCapabilities = true ,
51
+ HybridActions = false
52
+ } ;
53
+ actionSpec . ToBrainParametersProto ( "foo" , false ) ;
30
54
55
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities ( ) ;
31
56
// Continuous
32
57
actionSpec = ActionSpec . MakeContinuous ( 3 ) ;
33
58
actionSpec . ToBrainParametersProto ( "foo" , false ) ;
59
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities
60
+ {
61
+ BaseRLCapabilities = true ,
62
+ HybridActions = false
63
+ } ;
64
+ actionSpec . ToBrainParametersProto ( "foo" , false ) ;
65
+
66
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities ( ) ;
34
67
35
68
// Discrete
36
69
actionSpec = ActionSpec . MakeDiscrete ( 1 , 2 , 3 ) ;
37
70
actionSpec . ToBrainParametersProto ( "foo" , false ) ;
71
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities
72
+ {
73
+ BaseRLCapabilities = true ,
74
+ HybridActions = false
75
+ } ;
76
+ actionSpec . ToBrainParametersProto ( "foo" , false ) ;
77
+ }
78
+
79
+ [ Test ]
80
+ public void ToBrainParameters ( )
81
+ {
82
+ // Should be able to convert a default instance to proto.
83
+ var actionSpec = new ActionSpec ( ) ;
84
+ actionSpec . ToBrainParametersProto ( "foo" , false ) . ToBrainParameters ( ) ;
85
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities
86
+ {
87
+ BaseRLCapabilities = true ,
88
+ HybridActions = false
89
+ } ;
90
+ actionSpec . ToBrainParametersProto ( "foo" , false ) . ToBrainParameters ( ) ;
91
+
92
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities ( ) ;
93
+ // Continuous
94
+ actionSpec = ActionSpec . MakeContinuous ( 3 ) ;
95
+ actionSpec . ToBrainParametersProto ( "foo" , false ) . ToBrainParameters ( ) ;
96
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities
97
+ {
98
+ BaseRLCapabilities = true ,
99
+ HybridActions = false
100
+ } ;
101
+ actionSpec . ToBrainParametersProto ( "foo" , false ) . ToBrainParameters ( ) ;
102
+
103
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities ( ) ;
104
+
105
+ // Discrete
106
+ actionSpec = ActionSpec . MakeDiscrete ( 1 , 2 , 3 ) ;
107
+ actionSpec . ToBrainParametersProto ( "foo" , false ) . ToBrainParameters ( ) ;
108
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities
109
+ {
110
+ BaseRLCapabilities = true ,
111
+ HybridActions = false
112
+ } ;
113
+ actionSpec . ToBrainParametersProto ( "foo" , false ) . ToBrainParameters ( ) ;
38
114
}
39
115
40
116
[ Test ]
41
117
public void TestDefaultAgentInfoToProto ( )
42
118
{
43
119
// Should be able to convert a default instance to proto.
44
120
var agentInfo = new AgentInfo ( ) ;
45
- agentInfo . ToInfoActionPairProto ( ) ;
121
+ var pairProto = agentInfo . ToInfoActionPairProto ( ) ;
122
+ pairProto . AgentInfo . Observations . Add ( new ObservationProto
123
+ {
124
+ CompressedData = ByteString . Empty ,
125
+ CompressionType = CompressionTypeProto . None ,
126
+ FloatData = new ObservationProto . Types . FloatData ( ) ,
127
+ ObservationType = ObservationTypeProto . Default ,
128
+ Name = "Sensor"
129
+ } ) ;
130
+ pairProto . AgentInfo . Observations [ 0 ] . Shape . Add ( 0 ) ;
131
+ pairProto . GetObservationSummaries ( ) ;
132
+ agentInfo . ToAgentInfoProto ( ) ;
133
+ agentInfo . groupId = 1 ;
134
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities
135
+ {
136
+ BaseRLCapabilities = true ,
137
+ MultiAgentGroups = false
138
+ } ;
139
+ agentInfo . ToAgentInfoProto ( ) ;
140
+ LogAssert . Expect ( LogType . Warning , new Regex ( ".+" ) ) ;
141
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities
142
+ {
143
+ BaseRLCapabilities = true ,
144
+ MultiAgentGroups = true
145
+ } ;
46
146
agentInfo . ToAgentInfoProto ( ) ;
47
147
}
48
148
@@ -164,8 +264,6 @@ public void TestGetObservationProtoCapabilities()
164
264
Assert . AreEqual ( obsProto . CompressedData . Length , 0 ) ;
165
265
}
166
266
}
167
-
168
-
169
267
}
170
268
171
269
[ Test ]
@@ -185,6 +283,7 @@ public void TestIsTrivialMapping()
185
283
sparseChannelSensor . Mapping = new [ ] { 0 , 0 , 0 , 1 , 1 , 1 } ;
186
284
Assert . AreEqual ( GrpcExtensions . IsTrivialMapping ( sparseChannelSensor ) , false ) ;
187
285
}
286
+
188
287
[ Test ]
189
288
public void TestDefaultTrainingEvents ( )
190
289
{
0 commit comments