-
Notifications
You must be signed in to change notification settings - Fork 23
/
__init__.py
35 lines (26 loc) · 1.04 KB
/
__init__.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
from argparse import ArgumentParser
from common.util import load_hyperparams, merge_dict
import gym
import os
from pickle import loads
from rl.mcts_planning.util import plan_mcts, Root, train
from rl.util import WithSnapshots
# disable warnings
gym.logger.set_level(40)
def run(constant_overwrites):
config_path = os.path.join(os.path.dirname(__file__), 'hyperparams.yml')
constants = merge_dict(load_hyperparams(config_path), constant_overwrites)
env = WithSnapshots(gym.make('CartPole-v0'))
root_observation = env.reset()
root_snapshot = env.get_snapshot()
n_actions = env.action_space.n
root = Root(env, n_actions, root_snapshot, root_observation)
plan_mcts(root, n_iters=constants['n_iters'])
test_env = loads(root_snapshot)
train(root, test_env, show=False)
if __name__ == '__main__':
# read args
parser = ArgumentParser(description='Run CartPole MCTS model')
parser.add_argument('--iters', dest='n_iters', type=int, help='number iterations')
args = parser.parse_args()
run(vars(args))