forked from openai/neural-mmo
-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathtest_performance.py
More file actions
186 lines (142 loc) · 5.92 KB
/
test_performance.py
File metadata and controls
186 lines (142 loc) · 5.92 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# pylint: disable=no-member
# import time
import cProfile
import io
import pstats
from tqdm import tqdm
import nmmo
from nmmo.core.config import (NPC, AllGameSystems, Combat, Communication,
Equipment, Exchange, Item, Medium, Profession,
Progression, Resource, Small, Terrain)
from nmmo.task.task_api import nmmo_default_task, make_same_task
from nmmo.task.base_predicates import CountEvent, FullyArmed
from nmmo.systems.skill import Melee
from tests.testhelpers import profile_env_step
from scripted import baselines
# Test utils
def create_and_reset(conf):
env = nmmo.Env(conf())
env.reset(map_id=1)
def create_config(base, *systems):
systems = (base, *systems)
name = '_'.join(cls.__name__ for cls in systems)
conf = type(name, systems, {})()
conf.set("TERRAIN_TRAIN_MAPS", 1)
conf.set("TERRAIN_EVAL_MAPS", 1)
conf.set("IMMORTAL", True)
return conf
def benchmark_config(benchmark, base, nent, *systems):
conf = create_config(base, *systems)
conf.set("PLAYER_N", nent)
conf.set("PLAYERS", [baselines.Random])
env = nmmo.Env(conf)
env.reset()
benchmark(env.step, actions={})
# Small map tests -- fast with greater coverage for individual game systems
def test_small_env_creation(benchmark):
benchmark(lambda: nmmo.Env(Small()))
def test_small_env_reset(benchmark):
config = Small()
config.set("PLAYERS", [baselines.Random])
env = nmmo.Env(config)
benchmark(lambda: env.reset(map_id=1))
def test_fps_base_small_1_pop(benchmark):
benchmark_config(benchmark, Small, 1)
def test_fps_minimal_small_1_pop(benchmark):
benchmark_config(benchmark, Small, 1, Terrain, Resource, Combat, Progression)
def test_fps_npc_small_1_pop(benchmark):
benchmark_config(benchmark, Small, 1, Terrain, Resource, Combat, Progression, NPC)
def test_fps_test_small_1_pop(benchmark):
benchmark_config(benchmark, Small, 1, Terrain, Resource, Combat, Progression, Item, Exchange)
def test_fps_no_npc_small_1_pop(benchmark):
benchmark_config(benchmark, Small, 1, Terrain, Resource,
Combat, Progression, Item, Equipment, Profession, Exchange, Communication)
def test_fps_all_small_1_pop(benchmark):
benchmark_config(benchmark, Small, 1, AllGameSystems)
def test_fps_base_med_1_pop(benchmark):
benchmark_config(benchmark, Medium, 1)
def test_fps_minimal_med_1_pop(benchmark):
benchmark_config(benchmark, Medium, 1, Terrain, Resource, Combat)
def test_fps_npc_med_1_pop(benchmark):
benchmark_config(benchmark, Medium, 1, Terrain, Resource, Combat, NPC)
def test_fps_test_med_1_pop(benchmark):
benchmark_config(benchmark, Medium, 1, Terrain, Resource, Combat, Progression, Item, Exchange)
def test_fps_no_npc_med_1_pop(benchmark):
benchmark_config(benchmark, Medium, 1, Terrain, Resource,
Combat, Progression, Item, Equipment, Profession, Exchange, Communication)
def test_fps_all_med_1_pop(benchmark):
benchmark_config(benchmark, Medium, 1, AllGameSystems)
def test_fps_base_med_100_pop(benchmark):
benchmark_config(benchmark, Medium, 100)
def test_fps_minimal_med_100_pop(benchmark):
benchmark_config(benchmark, Medium, 100, Terrain, Resource, Combat)
def test_fps_npc_med_100_pop(benchmark):
benchmark_config(benchmark, Medium, 100, Terrain, Resource, Combat, NPC)
def test_fps_test_med_100_pop(benchmark):
benchmark_config(benchmark, Medium, 100, Terrain, Resource, Combat, Progression, Item, Exchange)
def test_fps_no_npc_med_100_pop(benchmark):
benchmark_config(benchmark, Medium, 100, Terrain, Resource, Combat,
Progression, Item, Equipment, Profession, Exchange, Communication)
def test_fps_all_med_100_pop(benchmark):
benchmark_config(benchmark, Medium, 100, AllGameSystems)
def set_seed_test():
random_seed = 5000
# conf = create_config(Medium, Terrain, Resource, Combat, NPC, Communication)
# conf.set("PLAYER_N", 7)
# conf.set("PLAYERS", [baselines.Random])
conf = nmmo.config.Default()
conf.set("TERRAIN_TRAIN_MAPS", 1)
conf.set("TERRAIN_EVAL_MAPS", 1)
conf.set("IMMORTAL", True)
conf.set("NPC_N", 128)
conf.set("USE_CYTHON", True)
conf.set("PROVIDE_DEATH_FOG_OBS", True)
env = nmmo.Env(conf)
env.reset(seed=random_seed)
for _ in tqdm(range(1024)):
env.step({})
def set_seed_test_complex():
tasks = nmmo_default_task(range(1, 129))
tasks += make_same_task(CountEvent, range(128),
pred_kwargs={'event': 'EAT_FOOD', 'N': 10})
tasks += make_same_task(FullyArmed, range(128),
pred_kwargs={'combat_style': Melee, 'level': 3, 'num_agent': 1})
profile_env_step(tasks=tasks)
if __name__ == '__main__':
pr = cProfile.Profile()
pr.enable()
#set_seed_test_complex()
set_seed_test()
pr.disable()
with open('profile.run','a', encoding="utf-8") as f:
s = io.StringIO()
ps = pstats.Stats(pr,stream=s).sort_stats('tottime')
ps.print_stats(100)
f.write(s.getvalue())
'''
def benchmark_env(benchmark, env, nent):
env.config.PLAYER_N = nent
env.config.PLAYERS = [nmmo.agent.Random]
env.reset()
benchmark(env.step, actions={})
# Reuse large maps since we aren't benchmarking the reset function
def test_large_env_creation(benchmark):
benchmark(lambda: nmmo.Env(Large()))
def test_large_env_reset(benchmark):
env = nmmo.Env(Large())
benchmark(lambda: env.reset(idx=1))
LargeMapsRCP = nmmo.Env(create_config(Large, Resource, Terrain, Combat, Progression))
LargeMapsAll = nmmo.Env(create_config(Large, AllGameSystems))
def test_fps_large_rcp_1_pop(benchmark):
benchmark_env(benchmark, LargeMapsRCP, 1)
def test_fps_large_rcp_100_pop(benchmark):
benchmark_env(benchmark, LargeMapsRCP, 100)
def test_fps_large_rcp_1000_pop(benchmark):
benchmark_env(benchmark, LargeMapsRCP, 1000)
def test_fps_large_all_1_pop(benchmark):
benchmark_env(benchmark, LargeMapsAll, 1)
def test_fps_large_all_100_pop(benchmark):
benchmark_env(benchmark, LargeMapsAll, 100)
def test_fps_large_all_1000_pop(benchmark):
benchmark_env(benchmark, LargeMapsAll, 1000)
'''