-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathrun_gym.py
44 lines (33 loc) · 1.38 KB
/
run_gym.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
'''In this example, a random policy is constructed and its performance is
evaluated on a specified domain.
The syntax for running this example is:
python run_gym.py <domain> <instance> [<episodes>] [<seed>]
where:
<domain> is the name of a domain located in the /Examples directory
<instance> is the instance number
<episodes> is a positive integer for the number of episodes to simulate
(defaults to 1)
<seed> is a positive integer RNG key (defaults to 42)
'''
import sys
import pyRDDLGym
from pyRDDLGym.core.policy import RandomAgent
def main(domain, instance, episodes=1, seed=42):
# create the environment
env = pyRDDLGym.make(domain, instance, enforce_action_constraints=True)
# set up a random policy
agent = RandomAgent(action_space=env.action_space,
num_actions=env.max_allowed_actions,
seed=seed)
agent.evaluate(env, episodes=episodes, verbose=True, render=True, seed=seed)
# important when logging to save all traces
env.close()
if __name__ == "__main__":
args = sys.argv[1:]
if len(args) < 2:
print('python run_gym.py <domain> <instance> [<episodes>] [<seed>]')
exit(1)
kwargs = {'domain': args[0], 'instance': args[1]}
if len(args) >= 3: kwargs['episodes'] = int(args[2])
if len(args) >= 4: kwargs['seed'] = int(args[3])
main(**kwargs)