This repository has been archived by the owner on Feb 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
test_moab_perf.py
executable file
·125 lines (94 loc) · 2.86 KB
/
test_moab_perf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
"""
Unit tests for Moab physics model
"""
__copyright__ = "Copyright 2020, Microsoft Corp."
# pyright: strict
import time
import os
from bonsai_common import Schema
from microsoft_bonsai_api.simulator.client import BonsaiClientConfig
from moab_model import MoabModel
from moab_sim import MoabSim
def run_model_for_count(count: int):
""" Runs the model without actions for a duration """
# sync the plate position with commanded position
model = MoabModel()
model.reset()
model.update_plate(True)
model.plate_noise = 0
model.ball_noise = 0
model.jitter = 0
# run for count
iterations = 0
while iterations < count:
model.step()
iterations += 1
def run_sim_for_count(config: Schema, action: Schema, count: int) -> MoabSim:
"""
This uses a passed in config to init the sim and then runs
it for a fixed duration with no actions.
We do not connect to the platform and drive the loop ourselves.
"""
service_config = BonsaiClientConfig(workspace="moab", access_key="utah")
sim = MoabSim(service_config)
# run with no actions for N seconds.
sim.episode_start(config)
# disable noise
sim.model.plate_noise = 0
sim.model.ball_noise = 0
sim.model.jitter = 0
iterations = 0
while iterations < count:
sim.episode_step(action)
iterations += 1
# return the results
return sim
"""
Speed tests.
Run the simulation for N runs, M times each.
Average FPS count and assert if it drops below threshold.
This tests for:
- regressions in simulator performance
"""
# constants for speed tests
MAX_RUNS = 10
MAX_ITER = 250
# use FPS fail limit from env if it is available
ENV_FPS_FAIL_LIMIT = os.environ.get("MOAB_PERF_TEST_THRESHOLD")
FPS_FAIL_LIMIT = int(ENV_FPS_FAIL_LIMIT) if ENV_FPS_FAIL_LIMIT else 500
def test_model_perf():
avg_fps = 0
for _ in range(0, MAX_RUNS):
start = time.time()
run_model_for_count(MAX_ITER)
end = time.time()
fps = MAX_ITER / (end - start)
avg_fps = avg_fps + fps
avg_fps /= MAX_RUNS
print("model average avg fps: ", avg_fps)
assert (
avg_fps > FPS_FAIL_LIMIT
), "Iteration speed for Model dropped below {} fps.".format(FPS_FAIL_LIMIT)
def test_sim_perf():
avg_fps = 0
for _ in range(0, MAX_RUNS):
start = time.time()
run_sim_for_count(
{},
{
"input_pitch": 0.0,
"input_roll": 0.0,
},
MAX_ITER,
)
end = time.time()
fps = MAX_ITER / (end - start)
avg_fps = avg_fps + fps
avg_fps /= MAX_RUNS
print("simulator average avg fps: ", avg_fps)
assert (
avg_fps > FPS_FAIL_LIMIT
), "Iteration speed for Simulator dropped below {} fps.".format(FPS_FAIL_LIMIT)
if __name__ == "__main__":
test_model_perf()
test_sim_perf()