1
+ using System . Text . RegularExpressions ;
2
+ using Google . Protobuf ;
3
+ using Google . Protobuf . Collections ;
1
4
using NUnit . Framework ;
2
5
using Unity . MLAgents . Actuators ;
3
6
using Unity . MLAgents . Demonstrations ;
6
9
7
10
using Unity . MLAgents . Analytics ;
8
11
using Unity . MLAgents . CommunicatorObjects ;
12
+ using UnityEditor . VersionControl ;
13
+ using UnityEngine ;
14
+ using UnityEngine . TestTools ;
9
15
10
16
namespace Unity . MLAgents . Tests
11
17
{
12
18
[ TestFixture ]
13
19
public class GrpcExtensionsTests
14
20
{
21
+ [ SetUp ]
22
+ public void SetUp ( )
23
+ {
24
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities ( ) ;
25
+ }
26
+
15
27
[ Test ]
16
28
public void TestDefaultBrainParametersToProto ( )
17
29
{
18
30
// Should be able to convert a default instance to proto.
19
31
var brain = new BrainParameters ( ) ;
20
32
brain . ToProto ( "foo" , false ) ;
33
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities
34
+ {
35
+ BaseRLCapabilities = true ,
36
+ HybridActions = false
37
+ } ;
38
+ brain . ToProto ( "foo" , false ) ;
21
39
}
22
40
23
41
[ Test ]
@@ -26,22 +44,104 @@ public void TestDefaultActionSpecToProto()
26
44
// Should be able to convert a default instance to proto.
27
45
var actionSpec = new ActionSpec ( ) ;
28
46
actionSpec . ToBrainParametersProto ( "foo" , false ) ;
47
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities
48
+ {
49
+ BaseRLCapabilities = true ,
50
+ HybridActions = false
51
+ } ;
52
+ actionSpec . ToBrainParametersProto ( "foo" , false ) ;
29
53
54
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities ( ) ;
30
55
// Continuous
31
56
actionSpec = ActionSpec . MakeContinuous ( 3 ) ;
32
57
actionSpec . ToBrainParametersProto ( "foo" , false ) ;
58
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities
59
+ {
60
+ BaseRLCapabilities = true ,
61
+ HybridActions = false
62
+ } ;
63
+ actionSpec . ToBrainParametersProto ( "foo" , false ) ;
64
+
65
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities ( ) ;
33
66
34
67
// Discrete
35
68
actionSpec = ActionSpec . MakeDiscrete ( 1 , 2 , 3 ) ;
36
69
actionSpec . ToBrainParametersProto ( "foo" , false ) ;
70
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities
71
+ {
72
+ BaseRLCapabilities = true ,
73
+ HybridActions = false
74
+ } ;
75
+ actionSpec . ToBrainParametersProto ( "foo" , false ) ;
76
+ }
77
+
78
+ [ Test ]
79
+ public void ToBrainParameters ( )
80
+ {
81
+ // Should be able to convert a default instance to proto.
82
+ var actionSpec = new ActionSpec ( ) ;
83
+ actionSpec . ToBrainParametersProto ( "foo" , false ) . ToBrainParameters ( ) ;
84
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities
85
+ {
86
+ BaseRLCapabilities = true ,
87
+ HybridActions = false
88
+ } ;
89
+ actionSpec . ToBrainParametersProto ( "foo" , false ) . ToBrainParameters ( ) ;
90
+
91
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities ( ) ;
92
+ // Continuous
93
+ actionSpec = ActionSpec . MakeContinuous ( 3 ) ;
94
+ actionSpec . ToBrainParametersProto ( "foo" , false ) . ToBrainParameters ( ) ;
95
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities
96
+ {
97
+ BaseRLCapabilities = true ,
98
+ HybridActions = false
99
+ } ;
100
+ actionSpec . ToBrainParametersProto ( "foo" , false ) . ToBrainParameters ( ) ;
101
+
102
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities ( ) ;
103
+
104
+ // Discrete
105
+ actionSpec = ActionSpec . MakeDiscrete ( 1 , 2 , 3 ) ;
106
+ actionSpec . ToBrainParametersProto ( "foo" , false ) . ToBrainParameters ( ) ;
107
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities
108
+ {
109
+ BaseRLCapabilities = true ,
110
+ HybridActions = false
111
+ } ;
112
+ actionSpec . ToBrainParametersProto ( "foo" , false ) . ToBrainParameters ( ) ;
37
113
}
38
114
39
115
[ Test ]
40
116
public void TestDefaultAgentInfoToProto ( )
41
117
{
42
118
// Should be able to convert a default instance to proto.
43
119
var agentInfo = new AgentInfo ( ) ;
44
- agentInfo . ToInfoActionPairProto ( ) ;
120
+ var pairProto = agentInfo . ToInfoActionPairProto ( ) ;
121
+ pairProto . AgentInfo . Observations . Add ( new ObservationProto
122
+ {
123
+ CompressedData = ByteString . Empty ,
124
+ CompressionType = CompressionTypeProto . None ,
125
+ FloatData = new ObservationProto . Types . FloatData ( ) ,
126
+ ObservationType = ObservationTypeProto . Default ,
127
+ Name = "Sensor"
128
+ } ) ;
129
+ pairProto . AgentInfo . Observations [ 0 ] . Shape . Add ( 0 ) ;
130
+ pairProto . GetObservationSummaries ( ) ;
131
+ agentInfo . ToAgentInfoProto ( ) ;
132
+ agentInfo . groupId = 1 ;
133
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities
134
+ {
135
+ BaseRLCapabilities = true ,
136
+ MultiAgentGroups = false
137
+ } ;
138
+ agentInfo . ToAgentInfoProto ( ) ;
139
+ LogAssert . Expect ( LogType . Warning , new Regex ( ".+" ) ) ;
140
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities
141
+ {
142
+ BaseRLCapabilities = true ,
143
+ MultiAgentGroups = true
144
+ } ;
45
145
agentInfo . ToAgentInfoProto ( ) ;
46
146
}
47
147
@@ -77,9 +177,9 @@ public byte[] GetCompressedObservation()
77
177
return new byte [ ] { 13 , 37 } ;
78
178
}
79
179
80
- public void Update ( ) { }
180
+ public void Update ( ) { }
81
181
82
- public void Reset ( ) { }
182
+ public void Reset ( ) { }
83
183
84
184
public SensorCompressionType GetCompressionType ( )
85
185
{
@@ -123,7 +223,7 @@ public void TestGetObservationProtoCapabilities()
123
223
( new [ ] { 4 , 4 , 4 } , SensorCompressionType . PNG , true , true ) , // Supported compressed
124
224
} ;
125
225
126
- foreach ( var ( shape , compressionType , supportsMultiPngObs , expectCompressed ) in variants )
226
+ foreach ( var ( shape , compressionType , supportsMultiPngObs , expectCompressed ) in variants )
127
227
{
128
228
var dummySensor = new DummySensor ( ) ;
129
229
var obsWriter = new ObservationWriter ( ) ;
@@ -151,8 +251,6 @@ public void TestGetObservationProtoCapabilities()
151
251
Assert . AreEqual ( obsProto . CompressedData . Length , 0 ) ;
152
252
}
153
253
}
154
-
155
-
156
254
}
157
255
158
256
[ Test ]
@@ -172,6 +270,7 @@ public void TestIsTrivialMapping()
172
270
sparseChannelSensor . Mapping = new [ ] { 0 , 0 , 0 , 1 , 1 , 1 } ;
173
271
Assert . AreEqual ( GrpcExtensions . IsTrivialMapping ( sparseChannelSensor ) , false ) ;
174
272
}
273
+
175
274
[ Test ]
176
275
public void TestDefaultTrainingEvents ( )
177
276
{
0 commit comments