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 UnityEngine ;
14
+ using UnityEngine . TestTools ;
10
15
11
16
namespace Unity . MLAgents . Tests
12
17
{
13
18
[ TestFixture ]
14
19
public class GrpcExtensionsTests
15
20
{
21
+ [ SetUp ]
22
+ public void SetUp ( )
23
+ {
24
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities ( ) ;
25
+ }
26
+
16
27
[ Test ]
17
28
public void TestDefaultBrainParametersToProto ( )
18
29
{
19
30
// Should be able to convert a default instance to proto.
20
31
var brain = new BrainParameters ( ) ;
21
32
brain . ToProto ( "foo" , false ) ;
33
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities
34
+ {
35
+ BaseRLCapabilities = true ,
36
+ HybridActions = false
37
+ } ;
38
+ brain . ToProto ( "foo" , false ) ;
22
39
}
23
40
24
41
[ Test ]
@@ -27,22 +44,104 @@ public void TestDefaultActionSpecToProto()
27
44
// Should be able to convert a default instance to proto.
28
45
var actionSpec = new ActionSpec ( ) ;
29
46
actionSpec . ToBrainParametersProto ( "foo" , false ) ;
47
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities
48
+ {
49
+ BaseRLCapabilities = true ,
50
+ HybridActions = false
51
+ } ;
52
+ actionSpec . ToBrainParametersProto ( "foo" , false ) ;
30
53
54
+ Academy . Instance . TrainerCapabilities = new UnityRLCapabilities ( ) ;
31
55
// Continuous
32
56
actionSpec = ActionSpec . MakeContinuous ( 3 ) ;
33
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 ( ) ;
34
66
35
67
// Discrete
36
68
actionSpec = ActionSpec . MakeDiscrete ( 1 , 2 , 3 ) ;
37
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 ( ) ;
38
113
}
39
114
40
115
[ Test ]
41
116
public void TestDefaultAgentInfoToProto ( )
42
117
{
43
118
// Should be able to convert a default instance to proto.
44
119
var agentInfo = new AgentInfo ( ) ;
45
- 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
+ } ;
46
145
agentInfo . ToAgentInfoProto ( ) ;
47
146
}
48
147
@@ -151,8 +250,6 @@ public void TestGetObservationProtoCapabilities()
151
250
Assert . AreEqual ( obsProto . CompressedData . Length , 0 ) ;
152
251
}
153
252
}
154
-
155
-
156
253
}
157
254
158
255
[ Test ]
0 commit comments