Skip to content

Commit

Permalink
Merge pull request #8 from ropiens/env_register
Browse files Browse the repository at this point in the history
register new envs
  • Loading branch information
nikhilbarhate99 authored Sep 4, 2021
2 parents 1533356 + 5ffc1c2 commit 0383979
Show file tree
Hide file tree
Showing 36 changed files with 29 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
14 changes: 14 additions & 0 deletions asset/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from asset.continuous_mountain_car import Continuous_MountainCarEnv
from asset.pendulum import PendulumEnv

from gym.envs.registration import register

register(
id="MountainCarContinuous-h-v1",
entry_point="asset:Continuous_MountainCarEnv",
)

register(
id="Pendulum-h-v1",
entry_point="asset:PendulumEnv",
)
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def render(self, mode='human'):
carheight=20

if self.viewer is None:
from gym.envs.classic_control import rendering
from asset import rendering
self.viewer = rendering.Viewer(screen_width, screen_height)
xs = np.linspace(self.min_position, self.max_position, 100)
ys = self._height(xs)
Expand Down Expand Up @@ -152,7 +152,7 @@ def render_goal(self, goal, end_goal, mode='human'):
carheight=20

if self.viewer is None:
from gym.envs.classic_control import rendering
from asset import rendering
self.viewer = rendering.Viewer(screen_width, screen_height)
xs = np.linspace(self.min_position, self.max_position, 100)
ys = self._height(xs)
Expand Down Expand Up @@ -235,7 +235,7 @@ def render_goal_2(self, goal1, goal2, end_goal, mode='human'):


if self.viewer is None:
from gym.envs.classic_control import rendering
from asset import rendering
self.viewer = rendering.Viewer(screen_width, screen_height)
xs = np.linspace(self.min_position, self.max_position, 100)
ys = self._height(xs)
Expand Down
6 changes: 3 additions & 3 deletions gym/pendulum.py → asset/pendulum.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _get_obs(self):
def render(self, mode='human'):

if self.viewer is None:
from gym.envs.classic_control import rendering
from asset import rendering
self.viewer = rendering.Viewer(500,500)
self.viewer.set_bounds(-2.2,2.2,-2.2,2.2)
rod = rendering.make_capsule(1, .2)
Expand All @@ -89,7 +89,7 @@ def render(self, mode='human'):
def render_goal(self, goal, end_goal, mode='human'):

if self.viewer is None:
from gym.envs.classic_control import rendering
from asset import rendering
self.viewer = rendering.Viewer(500,500)
self.viewer.set_bounds(-2.2,2.2,-2.2,2.2)

Expand Down Expand Up @@ -138,7 +138,7 @@ def render_goal(self, goal, end_goal, mode='human'):
def render_goal_2(self, goal1, goal2, end_goal, mode='human'):

if self.viewer is None:
from gym.envs.classic_control import rendering
from asset import rendering
self.viewer = rendering.Viewer(500,500)
self.viewer.set_bounds(-2.2,2.2,-2.2,2.2)

Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
gym
torch
pyglet
six
3 changes: 2 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import torch
import gym
import asset
import numpy as np
from HAC import HAC

Expand All @@ -8,7 +9,7 @@
def test():

#################### Hyperparameters ####################
env_name = "MountainCarContinuous-v0"
env_name = "MountainCarContinuous-h-v1"#"MountainCarContinuous-v0"
save_episode = 10 # keep saving every n episodes
max_episodes = 5 # max num of training episodes
random_seed = 0
Expand Down
3 changes: 2 additions & 1 deletion train.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import torch
import gym
import asset
import numpy as np
from HAC import HAC

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

def train():
#################### Hyperparameters ####################
env_name = "MountainCarContinuous-v0"
env_name = "MountainCarContinuous-h-v1"
save_episode = 10 # keep saving every n episodes
max_episodes = 1000 # max num of training episodes
random_seed = 0
Expand Down

0 comments on commit 0383979

Please sign in to comment.