-
Notifications
You must be signed in to change notification settings - Fork 0
/
dqn-minigrid.py
69 lines (45 loc) · 2.56 KB
/
dqn-minigrid.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
"""
The script to run DQN on MiniGrid environments.
"""
import argparse
from RLAlgos.DQN import DQN
from Networks.QNetworks import QNetMiniGrid
from utils.env_makers import minigrid_env_maker
def parse_args():
parser = argparse.ArgumentParser(description="Run DQN on classic control environments.")
parser.add_argument("--exp-name", type=str, default="dqn-minigrid")
parser.add_argument("--env-id", type=str, default="MiniGrid-Empty-8x8-v0")
parser.add_argument("--render", type=bool, default=False)
parser.add_argument("--seed", type=int, default=1)
parser.add_argument("--cuda", type=int, default=0)
parser.add_argument("--gamma", type=float, default=0.99)
parser.add_argument("--learning-rate", type=float, default=2.5e-4)
parser.add_argument("--buffer-size", type=int, default=10000)
parser.add_argument("--rb-optimize-memory", type=bool, default=False)
parser.add_argument("--batch-size", type=int, default=128)
parser.add_argument("--target-network-frequency", type=int, default=500)
parser.add_argument("--tau", type=float, default=1.)
parser.add_argument("--start-e", type=float, default=1.0)
parser.add_argument("--end-e", type=float, default=0.05)
parser.add_argument("--exploration-fraction", type=float, default=0.5)
parser.add_argument("--train-frequency", type=int, default=10)
parser.add_argument("--write-frequency", type=int, default=100)
parser.add_argument("--save-folder", type=str, default="./dqn-minigrid/")
parser.add_argument("--total-timesteps", type=int, default=500000)
parser.add_argument("--learning-starts", type=int, default=10000)
args = parser.parse_args()
return args
def run():
args = parse_args()
env = minigrid_env_maker(env_id=args.env_id, seed=args.seed, render=args.render)
agent = DQN(env=env, q_network_class=QNetMiniGrid, exp_name=args.exp_name, seed=args.seed, cuda=args.cuda,
learning_rate=args.learning_rate, buffer_size=args.buffer_size,
rb_optimize_memory=args.rb_optimize_memory, gamma=args.gamma, tau=args.tau,
target_network_frequency=args.target_network_frequency, batch_size=args.batch_size,
start_e=args.start_e, end_e=args.end_e, exploration_fraction=args.exploration_fraction,
train_frequency=args.train_frequency, write_frequency=args.write_frequency,
save_folder=args.save_folder)
agent.learn(total_timesteps=args.total_timesteps, learning_starts=args.learning_starts)
agent.save(indicator="final")
if __name__ == "__main__":
run()