-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.py
executable file
·72 lines (59 loc) · 2.59 KB
/
run.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
#!/usr/bin/env python3
"""
You can run RandomAgent locally with following command:
./run.py RandomAgent
You can run FixedActionAgent with visuals with following command:
./run.py FixedActionAgent -v
You can submit FixedActionAgent with visuals with following command:
./run.py FixedActionAgent -s
"""
import argparse
from osim.env import ProstheticsEnv
from osim.http.client import Client
from helper.wrappers import ClientToEnv, DictToListFull, ForceDictObservation, JSONable
from helper.CONFIG import remote_base, crowdai_token
from helper.baselines import *
from agents import *
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Run or submit agent.')
parser.add_argument('agent', help='specify agent\'s class name.')
parser.add_argument('-t', '--train', action='store', dest='nb_steps',
help='train agent locally')
parser.add_argument('-s', '--submit', action='store_true', default=False,
help='submit agent to crowdAI server')
parser.add_argument('-v', '--visualize', action='store_true', default=False,
help='render the environment locally')
args = parser.parse_args()
if args.agent not in globals():
raise ValueError('[run] Agent {} not found.'.format(args.agent))
SpecifiedAgent = globals()[args.agent]
if args.submit and args.nb_steps:
raise ValueError('[run] Cannot train and submit agent at same time.')
if args.submit and args.visualize:
raise ValueError('[run] Cannot visualize agent while submitting.')
if args.submit:
# Submit agent
client = Client(remote_base)
client.env_create(crowdai_token, env_id='ProstheticsEnv')
client_env = ClientToEnv(client)
client_env = DictToListFull(client_env)
client_env = JSONable(client_env)
agent = SpecifiedAgent(client_env.observation_space,
client_env.action_space)
agent.submit(client_env)
elif args.nb_steps:
# Train agent locally
env = ProstheticsEnv(visualize=args.visualize)
env = ForceDictObservation(env)
env = DictToListFull(env)
env = JSONable(env)
agent = SpecifiedAgent(env.observation_space, env.action_space)
agent.train(env, int(args.nb_steps))
else:
# Test agent locally
env = ProstheticsEnv(visualize=args.visualize)
env = ForceDictObservation(env)
env = DictToListFull(env)
env = JSONable(env)
agent = SpecifiedAgent(env.observation_space, env.action_space)
agent.test(env)