Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove phrase 'Abstract' from abstract class names #135

Merged
merged 6 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion algorithms/a2c/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import torch.nn.functional as F
import wandb

from algorithms.common.abstract.agent import AbstractAgent
from algorithms.common.abstract.agent import Agent as AbstractAgent

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

Expand Down
2 changes: 1 addition & 1 deletion algorithms/bc/ddpg_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import torch.nn.functional as F
import wandb

from algorithms.common.abstract.her import AbstractHER
from algorithms.common.abstract.her import HER as AbstractHER
from algorithms.common.buffer.replay_buffer import ReplayBuffer
import algorithms.common.helper_functions as common_utils
from algorithms.common.noise import OUNoise
Expand Down
2 changes: 1 addition & 1 deletion algorithms/bc/sac_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import torch.nn.functional as F
import wandb

from algorithms.common.abstract.her import AbstractHER
from algorithms.common.abstract.her import HER as AbstractHER
from algorithms.common.buffer.replay_buffer import ReplayBuffer
import algorithms.common.helper_functions as common_utils
from algorithms.sac.agent import Agent as SACAgent
Expand Down
2 changes: 1 addition & 1 deletion algorithms/common/abstract/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import wandb


class AbstractAgent(ABC):
class Agent(ABC):
"""Abstract Agent used for all agents.

Attributes:
Expand Down
6 changes: 3 additions & 3 deletions algorithms/common/abstract/her.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@

import numpy as np

from algorithms.common.abstract.reward_fn import AbstractRewardFn
from algorithms.common.abstract.reward_fn import RewardFn


class AbstractHER(ABC):
class HER(ABC):
"""Abstract class for HER (final strategy).

Attributes:
reward_func (Callable): returns reward from state, action, next_state

"""

def __init__(self, reward_func: AbstractRewardFn):
def __init__(self, reward_func: RewardFn):
"""Initialization.

Args:
Expand Down
2 changes: 1 addition & 1 deletion algorithms/common/abstract/reward_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numpy as np


class AbstractRewardFn(ABC):
class RewardFn(ABC):
"""Abstract class for computing reward.
New compute_reward class should redefine __call__()

Expand Down
2 changes: 1 addition & 1 deletion algorithms/ddpg/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import torch.nn.functional as F
import wandb

from algorithms.common.abstract.agent import AbstractAgent
from algorithms.common.abstract.agent import Agent as AbstractAgent
from algorithms.common.buffer.replay_buffer import ReplayBuffer
import algorithms.common.helper_functions as common_utils
from algorithms.common.noise import OUNoise
Expand Down
2 changes: 1 addition & 1 deletion algorithms/dqn/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from torch.nn.utils import clip_grad_norm_
import wandb

from algorithms.common.abstract.agent import AbstractAgent
from algorithms.common.abstract.agent import Agent as AbstractAgent
from algorithms.common.buffer.priortized_replay_buffer import PrioritizedReplayBuffer
from algorithms.common.buffer.replay_buffer import NStepTransitionBuffer
import algorithms.common.helper_functions as common_utils
Expand Down
2 changes: 1 addition & 1 deletion algorithms/ppo/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import torch.nn as nn
import wandb

from algorithms.common.abstract.agent import AbstractAgent
from algorithms.common.abstract.agent import Agent as AbstractAgent
from algorithms.common.env.multiprocessing_env import SubprocVecEnv
import algorithms.ppo.utils as ppo_utils

Expand Down
2 changes: 1 addition & 1 deletion algorithms/sac/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import torch.optim as optim
import wandb

from algorithms.common.abstract.agent import AbstractAgent
from algorithms.common.abstract.agent import Agent as AbstractAgent
from algorithms.common.buffer.replay_buffer import ReplayBuffer
import algorithms.common.helper_functions as common_utils

Expand Down
2 changes: 1 addition & 1 deletion algorithms/td3/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import torch.nn.functional as F
import wandb

from algorithms.common.abstract.agent import AbstractAgent
from algorithms.common.abstract.agent import Agent as AbstractAgent
from algorithms.common.buffer.replay_buffer import ReplayBuffer
import algorithms.common.helper_functions as common_utils
from algorithms.common.noise import GaussianNoise
Expand Down
8 changes: 4 additions & 4 deletions examples/lunarlander_continuous_v2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import numpy as np

from algorithms.common.abstract.her import AbstractHER
from algorithms.common.abstract.reward_fn import AbstractRewardFn
from algorithms.common.abstract.her import HER as AbstractHER
from algorithms.common.abstract.reward_fn import RewardFn


class L1DistanceRewardFn(AbstractRewardFn):
class L1DistanceRewardFn(RewardFn):
def __call__(self, transition: tuple, goal_state: np.ndarray) -> np.float64:
"""L1 Distance reward function."""
next_state = transition[3]
Expand All @@ -31,7 +31,7 @@ class LunarLanderContinuousHER(AbstractHER):

"""

def __init__(self, reward_func: AbstractRewardFn = L1DistanceRewardFn):
def __init__(self, reward_func: RewardFn = L1DistanceRewardFn):
"""Initialization."""
AbstractHER.__init__(self, reward_func=reward_func)

Expand Down
8 changes: 4 additions & 4 deletions examples/reacher_v2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import numpy as np

from algorithms.common.abstract.her import AbstractHER
from algorithms.common.abstract.reward_fn import AbstractRewardFn
from algorithms.common.abstract.her import HER as AbstractHER
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why HER's class name is declared as AbstractHER, while RewardFn is not AbstractRewardFn?

from algorithms.common.abstract.reward_fn import RewardFn


class ReacherRewardFn(AbstractRewardFn):
class ReacherRewardFn(RewardFn):
def __call__(self, transition: tuple, _) -> np.float64:
"""Reward function for Reacher-v2 environment."""
state, action = transition[0:2]
Expand All @@ -25,7 +25,7 @@ def __call__(self, transition: tuple, _) -> np.float64:
class ReacherHER(AbstractHER):
"""HER for Reacher-v2 environment."""

def __init__(self, reward_func: AbstractRewardFn = ReacherRewardFn):
def __init__(self, reward_func: RewardFn = ReacherRewardFn):
"""Initialization."""
AbstractHER.__init__(self, reward_func=reward_func)

Expand Down