Skip to content

Commit 9c1204a

Browse files
author
Chris Elion
authored
[MLA-1009] observable performance tests (#4031)
* WIP perf tests * WIP perf test * add marker tests too * move to devproject * yamato first pass * chmod * fix trigger, fix meta files * fix utr command * fix artifact paths * Update com.unity.ml-agents-performance.yml * test properties, reduce some noise * timer around RequestDecision * actually set ObservableAttributeHandling * undo asmdef changes
1 parent d4c4b3a commit 9c1204a

File tree

11 files changed

+314
-1
lines changed

11 files changed

+314
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
test_editors:
2+
- version: 2019.3
3+
- version: 2020.1
4+
---
5+
{% for editor in test_editors %}
6+
Run_Mac_Perfomance_Tests{{ editor.version }}:
7+
name: Run Mac Performance Tests {{ editor.version }}
8+
agent:
9+
type: Unity::VM::osx
10+
image: package-ci/mac:stable
11+
flavor: b1.small
12+
variables:
13+
UNITY_VERSION: {{ editor.version }}
14+
commands:
15+
- python -m pip install unity-downloader-cli --extra-index-url https://artifactory.eu-cph-1.unityops.net/api/pypi/common-python/simple
16+
- unity-downloader-cli -u {{ editor.version }} -c editor --wait --fast
17+
- curl -s https://artifactory.internal.unity3d.com/core-automation/tools/utr-standalone/utr --output utr
18+
- chmod +x ./utr
19+
- ./utr --suite=editor --platform=StandaloneOSX --editor-location=.Editor --testproject=DevProject --artifacts_path=build/test-results --report-performance-data --performance-project-id=com.unity.ml-agents --zero-tests-are-ok=1
20+
triggers:
21+
cancel_old_ci: true
22+
expression: |
23+
(pull_request.target eq "master" OR
24+
pull_request.target match "release.+") AND
25+
NOT pull_request.draft AND
26+
(pull_request.changes.any match "com.unity.ml-agents/**" OR
27+
pull_request.changes.any match "DevProject/**" OR
28+
pull_request.changes.any match "ml-agents/**" OR
29+
pull_request.changes.any match "ml-agents-envs/**" OR
30+
pull_request.changes.any match ".yamato/com.unity.ml-agents-performance.yml") AND
31+
NOT pull_request.changes.all match "**/*.md"
32+
artifacts:
33+
logs:
34+
paths:
35+
- "build/test-results/**"
36+
- "*.log"
37+
{% endfor %}

DevProject/Assets/ML-Agents.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DevProject/Assets/ML-Agents/Scripts.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DevProject/Assets/ML-Agents/Scripts/Tests.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DevProject/Assets/ML-Agents/Scripts/Tests/Performance.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
using NUnit.Framework;
2+
using Unity.MLAgents;
3+
using Unity.MLAgents.Policies;
4+
using Unity.MLAgents.Sensors;
5+
using Unity.MLAgents.Sensors.Reflection;
6+
using Unity.PerformanceTesting;
7+
using UnityEngine;
8+
9+
namespace MLAgentsExamples.Tests.Performance
10+
{
11+
[TestFixture]
12+
public class SensorPerformanceTests
13+
{
14+
string[] s_Markers =
15+
{
16+
"root.InitializeSensors",
17+
"root.AgentSendState.CollectObservations",
18+
"root.AgentSendState.RequestDecision"
19+
};
20+
const int k_NumAgentSteps = 10;
21+
const int k_MeasurementCount = 25;
22+
const int k_MarkerTestSteps = 10;
23+
24+
[SetUp]
25+
public void SetUp()
26+
{
27+
// Step a dummy agent here, so that we don't time the Academy initialization connection attempt and
28+
// any other static setup costs.
29+
RunAgent<DummyAgent>(1, 0, ObservableAttributeOptions.ExamineAll);
30+
}
31+
32+
/// <summary>
33+
/// Simple Agent just used for "burning in" the Academy for testing.
34+
/// </summary>
35+
class DummyAgent : Agent
36+
{
37+
public override void CollectObservations(VectorSensor sensor)
38+
{
39+
}
40+
41+
public override void Heuristic(float[] actionsOut)
42+
{
43+
}
44+
}
45+
46+
/// <summary>
47+
/// Agent used for performance testing that uses the CollectObservations interface.
48+
/// </summary>
49+
class CollectObservationsAgent : Agent
50+
{
51+
public override void CollectObservations(VectorSensor sensor)
52+
{
53+
sensor.AddObservation(new Vector3(1, 2, 3));
54+
sensor.AddObservation(new Quaternion(1, 2, 3, 4));
55+
}
56+
57+
public override void Heuristic(float[] actionsOut)
58+
{
59+
}
60+
}
61+
62+
/// <summary>
63+
/// Agent used for performance testing that uses the ObservableAttributes on fields.
64+
/// </summary>
65+
class ObservableFieldAgent : Agent
66+
{
67+
[Observable]
68+
public Vector3 Vector3Field = new Vector3(1, 2, 3);
69+
70+
[Observable]
71+
public Quaternion QuaternionField = new Quaternion(1, 2, 3, 4);
72+
73+
public override void Heuristic(float[] actionsOut)
74+
{
75+
}
76+
}
77+
78+
/// <summary>
79+
/// Agent used for performance testing that uses the ObservableAttributes on properties.
80+
/// </summary>
81+
class ObservablePropertyAgent : Agent
82+
{
83+
Vector3 m_Vector3Field = new Vector3(1, 2, 3);
84+
85+
[Observable]
86+
Vector3 Vector3Property
87+
{
88+
get { return m_Vector3Field; }
89+
}
90+
91+
Quaternion m_QuaternionField = new Quaternion(1, 2, 3, 4);
92+
93+
[Observable]
94+
Quaternion QuaternionProperty
95+
{
96+
get { return m_QuaternionField; }
97+
}
98+
99+
public override void Heuristic(float[] actionsOut)
100+
{
101+
}
102+
}
103+
104+
void RunAgent<T>(int numSteps, int obsSize, ObservableAttributeOptions obsOptions) where T : Agent
105+
{
106+
var agentGameObj = new GameObject();
107+
var agent = agentGameObj.AddComponent<T>();
108+
109+
var behaviorParams = agent.GetComponent<BehaviorParameters>();
110+
behaviorParams.BrainParameters.VectorObservationSize = obsSize;
111+
behaviorParams.ObservableAttributeHandling = obsOptions;
112+
113+
agent.LazyInitialize();
114+
for (var i = 0; i < numSteps; i++)
115+
{
116+
agent.RequestDecision();
117+
Academy.Instance.EnvironmentStep();
118+
}
119+
Object.DestroyImmediate(agentGameObj);
120+
}
121+
122+
[Test, Performance]
123+
public void TestCollectObservationsAgent()
124+
{
125+
Measure.Method(() =>
126+
{
127+
RunAgent<CollectObservationsAgent>(k_NumAgentSteps, 7, ObservableAttributeOptions.Ignore);
128+
})
129+
.MeasurementCount(k_MeasurementCount)
130+
.GC()
131+
.Run();
132+
}
133+
134+
[Test, Performance]
135+
public void TestObservableFieldAgent()
136+
{
137+
Measure.Method(() =>
138+
{
139+
RunAgent<ObservableFieldAgent>(k_NumAgentSteps, 0, ObservableAttributeOptions.ExcludeInherited);
140+
})
141+
.MeasurementCount(k_MeasurementCount)
142+
.GC()
143+
.Run();
144+
}
145+
146+
[Test, Performance]
147+
public void TestObservablePropertyAgent()
148+
{
149+
Measure.Method(() =>
150+
{
151+
RunAgent<ObservablePropertyAgent>(k_NumAgentSteps, 0, ObservableAttributeOptions.ExcludeInherited);
152+
})
153+
.MeasurementCount(k_MeasurementCount)
154+
.GC()
155+
.Run();
156+
}
157+
158+
[Test, Performance]
159+
public void TestCollectObservationsAgentMarkers()
160+
{
161+
using (Measure.ProfilerMarkers(s_Markers))
162+
{
163+
for(var i=0; i<k_MarkerTestSteps; i++)
164+
{
165+
RunAgent<CollectObservationsAgent>(k_NumAgentSteps, 7, ObservableAttributeOptions.Ignore);
166+
}
167+
}
168+
}
169+
170+
[Test, Performance]
171+
public void TestObservableFieldAgentMarkers()
172+
{
173+
using (Measure.ProfilerMarkers(s_Markers))
174+
{
175+
for (var i = 0; i < k_MarkerTestSteps; i++)
176+
{
177+
RunAgent<ObservableFieldAgent>(k_NumAgentSteps, 0, ObservableAttributeOptions.ExcludeInherited);
178+
}
179+
}
180+
}
181+
182+
[Test, Performance]
183+
public void TestObservablePropertyAgentMarkers()
184+
{
185+
using (Measure.ProfilerMarkers(s_Markers))
186+
{
187+
for (var i = 0; i < k_MarkerTestSteps; i++)
188+
{
189+
RunAgent<ObservableFieldAgent>(k_NumAgentSteps, 0, ObservableAttributeOptions.ExcludeInherited);
190+
}
191+
}
192+
}
193+
}
194+
}

DevProject/Assets/ML-Agents/Scripts/Tests/Performance/SensorPerformanceTests.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "Unity.ML-Agents.Performance.Tests",
3+
"references": [
4+
"Unity.ML-Agents.Editor",
5+
"Unity.ML-Agents",
6+
"Unity.Barracuda",
7+
"Unity.ML-Agents.CommunicatorObjects",
8+
"Unity.PerformanceTesting"
9+
],
10+
"optionalUnityReferences": [
11+
"TestAssemblies"
12+
],
13+
"includePlatforms": [
14+
"Editor"
15+
],
16+
"excludePlatforms": [],
17+
"allowUnsafeCode": false,
18+
"overrideReferences": true,
19+
"precompiledReferences": [
20+
"System.IO.Abstractions.dll",
21+
"System.IO.Abstractions.TestingHelpers.dll",
22+
"Google.Protobuf.dll"
23+
],
24+
"autoReferenced": false,
25+
"defineConstraints": [
26+
"UNITY_INCLUDE_TESTS"
27+
]
28+
}

DevProject/Assets/ML-Agents/Scripts/Tests/Tests.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DevProject/Packages/manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"com.unity.package-validation-suite": "0.11.0-preview",
1616
"com.unity.purchasing": "2.0.6",
1717
"com.unity.test-framework": "1.1.13",
18+
"com.unity.test-framework.performance": "2.2.0-preview",
1819
"com.unity.testtools.codecoverage": "0.2.2-preview",
1920
"com.unity.textmeshpro": "2.0.1",
2021
"com.unity.timeline": "1.2.12",

0 commit comments

Comments
 (0)