-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
49 lines (40 loc) · 1.2 KB
/
test.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
import time
import gymnasium as gym
import mo_gymnasium as mogym
import numpy as np
from methods.sac import SAC, SACStrat
from utils.experiment import get_experiment
from utils.experiment import parse_args
from utils.experiment import setup_run
def test(args):
env = mogym.make(args.gym_id)
if args.stratified:
env = mogym.MORecordEpisodeStatistics(env)
else:
env = mogym.LinearReward(env)
env = gym.wrappers.RecordEpisodeStatistics(env)
if args.stratified:
agent = SACStrat(
args,
env.observation_space,
env.action_space,
)
else:
agent = SAC(args, env.observation_space, env.action_space)
agent.load("models/to_test/")
for _ in range(100):
obs, _ = env.reset()
done = False
while not done:
obs = np.array([obs])
actions = agent.get_action(obs)[0]
next_obs, rewards, termination, truncated, infos = env.step(actions)
done = termination or truncated
obs = next_obs
def main(params):
setup_run(params)
test(params)
if __name__ == "__main__":
args = parse_args()
params = get_experiment(args)
main(params)