* Add per and modify etc

* Replace pre-commit-config.yaml and add pre-commit hook in .git

* Modify .gitignore

* Modify .gitignore

* Modify buffer and code

* Modify replay buffer and per

* Modify .gitignore
This commit is contained in:
Kyunghwan Kim
2019-02-16 17:30:12 +09:00
committed by GitHub
parent 7f4756a1d4
commit ecb42d30d2
13 changed files with 750 additions and 55 deletions
+14 -9
View File
@@ -20,10 +20,9 @@ class AbstractAgent(ABC):
"""Abstract Agent used for all agents.
Attributes:
env (gym.Env): openAI Gym environment with discrete action space
env (gym.Env): openAI Gym environment
args (argparse.Namespace): arguments including hyperparameters and training settings
state_dim (int): dimension of state space
action_dim (int): dimension of action space
env_name (str) : gym env name for logging
sha (str): sha code of current git commit
"""
@@ -32,7 +31,7 @@ class AbstractAgent(ABC):
"""Initialization.
Args:
env (gym.Env): openAI Gym environment with discrete action space
env (gym.Env): openAI Gym environment
args (argparse.Namespace): arguments including hyperparameters and training settings
"""
@@ -44,6 +43,7 @@ class AbstractAgent(ABC):
self.args.max_episode_steps = env._max_episode_steps
# for logging
self.env_name = str(self.env.env).split("<")[2].replace(">>", "")
self.sha = (
subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])[:-1]
.decode("ascii")
@@ -67,13 +67,13 @@ class AbstractAgent(ABC):
pass
@abstractmethod
def save_params(self, name: str, params: dict, n_episode: int):
def save_params(self, params: dict, n_episode: int):
if not os.path.exists("./save"):
os.mkdir("./save")
path = os.path.join(
"./save/" + name + "_" + self.sha + "_ep_" + str(n_episode) + ".pt"
)
save_name = self.env_name + "_" + self.args.algo + "_" + self.sha
path = os.path.join("./save/" + save_name + "_ep_" + str(n_episode) + ".pt")
torch.save(params, path)
print("[INFO] Saved the model and optimizer to", path)
@@ -92,6 +92,7 @@ class AbstractAgent(ABC):
state = self.env.reset()
done = False
score = 0
step = 0
while not done:
if self.args.render and i_episode >= self.args.render_after:
@@ -102,8 +103,12 @@ class AbstractAgent(ABC):
state = next_state
score += reward
step += 1
print("[INFO] episode %d\ttotal score: %d" % (i_episode, score))
print(
"[INFO] episode %d\tstep: %d\ttotal score: %d"
% (i_episode, step, score)
)
# termination
self.env.close()