-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimulate.py
65 lines (60 loc) · 1.71 KB
/
simulate.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
import time
from agents import initialize_agent
from envs import get_env
def simulate(env_name,
method_name,
seed,
logger,
rate_limiter,
config={},
wandb=None):
# Load environment
env = get_env(env_name, config, logger, seed)
env.set_seed(seed)
env.reset(config=config, logger=logger)
# Load agent
agent = initialize_agent(method_name, env, config, rate_limiter, wandb,
logger)
# Run experiment
max_episodes = config.run.max_episodes
def loop():
episode = 0
start_time = time.perf_counter()
while episode < max_episodes:
episode += 1
# env.reset()
time.perf_counter()
test_mse = agent.run()
return {
"method_name":
method_name,
"env_name":
env_name,
"episode_elapsed_time":
time.perf_counter() - start_time,
"episode_elapsed_time_per_episode":
(time.perf_counter() - start_time) / episode,
"test_mse":
test_mse,
"trajectories":
config.run.trajectories,
}
ddict = {
"method_name":
method_name,
"env_name":
env_name,
"episode_elapsed_time":
time.perf_counter() - start_time,
"episode_elapsed_time_per_episode":
(time.perf_counter() - start_time) / episode,
"cumulative_reward":
cumulative_reward,
"reward":
cumulative_reward / episode,
}
if not config.setup.multi_process_results:
logger.info(f"[{env_name}\t{method_name}\t][Result] {str(ddict)}")
return ddict
result = loop()
return result