Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
juliagsy committed Jun 15, 2023
1 parent 459bbc9 commit 9d5a04c
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ and use this to set the ivy backend framework.

.. code-block:: python
import ivy
import ivy
fw = ivy.choose_random_backend()
ivy.set_backend(fw)
Expand Down
18 changes: 9 additions & 9 deletions ivy_gym/cartpole.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Cart-pole task adapted from:
https://github.com/openai/gym/blob/master/gym/envs/classic_control/cartpole.py"""
"""
Cart-pole task adapted from:
https://github.com/openai/gym/blob/master/gym/envs/classic_control/cartpole.py
"""

# global
import ivy
Expand All @@ -9,8 +11,6 @@

# noinspection PyAttributeOutsideInit
class CartPole(gym.Env):
""" """

metadata = {"render.modes": ["human", "rgb_array"], "video.frames_per_second": 30}

def __init__(self): # noqa
Expand Down Expand Up @@ -166,7 +166,7 @@ def render(self, mode="human"):
# noinspection PyBroadException
try:
from gym.envs.classic_control import rendering
except:
except Exception:
if not self._logged_headless_message:
print(
"Unable to connect to display. Running the Ivy environment "
Expand All @@ -183,22 +183,22 @@ def render(self, mode="human"):
self.viewer.add_geom(track)

# Cart.
l = -cart_width / 2
ll = -cart_width / 2
r = cart_width / 2
t = cart_height / 2
b = -cart_height / 2
cart_geom = rendering.FilledPolygon([(l, b), (l, t), (r, t), (r, b)])
cart_geom = rendering.FilledPolygon([(ll, b), (ll, t), (r, t), (r, b)])
self.cart_tr = rendering.Transform()
cart_geom.add_attr(self.cart_tr)
cart_geom.set_color(0.0, 0.0, 0.0)
self.viewer.add_geom(cart_geom)

# Pole.
l = -pole_width / 2
ll = -pole_width / 2
r = pole_width / 2
t = pole_len - pole_width / 2
b = -pole_width / 2
self.pole_geom = rendering.FilledPolygon([(l, b), (l, t), (r, t), (r, b)])
self.pole_geom = rendering.FilledPolygon([(ll, b), (ll, t), (r, t), (r, b)])
self.pole_tr = rendering.Transform(translation=(0, 0))
self.pole_geom.add_attr(self.pole_tr)
self.pole_geom.add_attr(self.cart_tr)
Expand Down
11 changes: 5 additions & 6 deletions ivy_gym/mountain_car.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Mountain-car task adapted from:
https://github.com/openai/gym/blob/master/gym/envs/classic_control/mountain_car.py"""
"""
Mountain-car task adapted from:
https://github.com/openai/gym/blob/master/gym/envs/classic_control/mountain_car.py
"""

# global
import ivy
Expand All @@ -9,8 +11,6 @@

# noinspection PyAttributeOutsideInit
class MountainCar(gym.Env):
""" """

metadata = {"render.modes": ["human", "rgb_array"], "video.frames_per_second": 30}

def __init__(self): # noqa
Expand Down Expand Up @@ -79,7 +79,6 @@ def set_state(self, state):
return self.get_observation()

def reset(self):
""" """
self.x = ivy.random_uniform(low=-0.9, high=-0.2, shape=(1,))
self.x_vel = ivy.zeros((1,))
return self.get_observation()
Expand Down Expand Up @@ -147,7 +146,7 @@ def render(self, mode="human"):
# noinspection PyBroadException
try:
from gym.envs.classic_control import rendering
except:
except Exception:
if not self._logged_headless_message:
print(
"Unable to connect to display. Running the Ivy environment "
Expand Down
18 changes: 8 additions & 10 deletions ivy_gym/pendulum.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Pendulum task adapted from:
https://github.com/openai/gym/blob/master/gym/envs/classic_control/pendulum.py"""
"""
Pendulum task adapted from:
https://github.com/openai/gym/blob/master/gym/envs/classic_control/pendulum.py
"""

# global
import ivy
Expand All @@ -9,8 +11,6 @@

# noinspection PyAttributeOutsideInit
class Pendulum(gym.Env):
""" """

metadata = {"render.modes": ["human", "rgb_array"], "video.frames_per_second": 30}

def __init__(self): # noqa
Expand All @@ -21,7 +21,7 @@ def __init__(self): # noqa
self.g = 9.8
self.dt = 0.05
self.m = 1.0
self.l = 1.0
self.ll = 1.0
self.action_space = gym.spaces.Box(low=-1, high=1, shape=[1], dtype=np.float32)
high = np.array([1.0, 1.0, np.inf], dtype=np.float32)
self.observation_space = gym.spaces.Box(low=-high, high=high, dtype=np.float32)
Expand Down Expand Up @@ -83,14 +83,12 @@ def set_state(self, state):
return self.get_observation()

def reset(self):
""" """
self.angle = ivy.random_uniform(low=-np.pi, high=np.pi, shape=(1,))
self.angle_vel = ivy.random_uniform(low=-1.0, high=1.0, shape=(1,))
return self.get_observation()

def step(self, action):
"""
Parameters
----------
action
Expand All @@ -99,8 +97,8 @@ def step(self, action):
action = action * self.torque_scale

angle_acc = (
-3 * self.g / (2 * self.l) * ivy.sin(self.angle + np.pi)
+ 3.0 / (self.m * self.l**2) * action
-3 * self.g / (2 * self.ll) * ivy.sin(self.angle + np.pi)
+ 3.0 / (self.m * self.ll**2) * action
)

self.angle_vel = self.angle_vel + self.dt * angle_acc
Expand Down Expand Up @@ -138,7 +136,7 @@ def render(self, mode="human"):
# noinspection PyBroadException
try:
from gym.envs.classic_control import rendering
except:
except Exception:
if not self._logged_headless_message:
print(
"Unable to connect to display. Running the Ivy environment "
Expand Down
5 changes: 1 addition & 4 deletions ivy_gym/reacher.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

# noinspection PyAttributeOutsideInit
class Reacher(gym.Env):
""" """

metadata = {"render.modes": ["human", "rgb_array"], "video.frames_per_second": 30}

def __init__(self, num_joints=2): # noqa
Expand Down Expand Up @@ -99,7 +97,6 @@ def set_state(self, state):
return self.get_observation()

def reset(self):
""" """
self.angles = ivy.random_uniform(
low=-np.pi, high=np.pi, shape=(self.num_joints,)
)
Expand Down Expand Up @@ -152,7 +149,7 @@ def render(self, mode="human"):
# noinspection PyBroadException
try:
from gym.envs.classic_control import rendering
except:
except Exception:
if not self._logged_headless_message:
print(
"Unable to connect to display. Running the Ivy environment "
Expand Down
17 changes: 5 additions & 12 deletions ivy_gym/swimmer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Path finding task.
A fish needs to reach a goal location while avoiding urchins."""
"""
Path finding task.
A fish needs to reach a goal location while avoiding urchins.
"""

import ivy
import gym
Expand All @@ -12,8 +14,6 @@

# noinspection PyAttributeOutsideInit
class Swimmer(gym.Env):
""" """

metadata = {"render.modes": ["human", "rgb_array"], "video.frames_per_second": 30}

def __init__(self, num_urchins=5): # noqa
Expand Down Expand Up @@ -99,7 +99,6 @@ def set_state(self, state):
return self.get_observation()

def reset(self):
""" """
self.urchin_xys = ivy.random_uniform(
low=-1, high=1, shape=(self.num_urchins, 2)
)
Expand Down Expand Up @@ -150,7 +149,7 @@ def render(self, mode="human"):
# noinspection PyBroadException
try:
from gym.envs.classic_control import rendering
except:
except Exception:
if not self._logged_headless_message:
print(
"Unable to connect to display. Running the Ivy environment "
Expand All @@ -161,16 +160,13 @@ def render(self, mode="human"):
from pyglet import gl

class _StarGeom(rendering.Geom):
""" """

def __init__(self, r1, r2, n):
super().__init__()
self.r1 = r1
self.r2 = r2
self.n = n

def render1(self):
""" """
n = self.n * 2
for i in range(0, n, 2):
gl.glBegin(gl.GL_TRIANGLES)
Expand All @@ -188,14 +184,11 @@ def render1(self):
gl.glEnd()

class _FishGeom(rendering.Geom):
""" """

def __init__(self):
super().__init__()
self.color = 0.0, 0.0, 0.0

def render1(self):
""" """
points = [
[0.08910714285714288, -0.009017857142857133],
[0.13910714285714287, -0.04026785714285712],
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ per-file-ignores =

[autoflake]
in-place = true
remove-all-unused-imports = true
ignore-init-module-imports = true
remove-all-unused-import s = true
ignore-init-module-import s = true
remove-duplicate-keys = true
remove-unused-variables = true
quiet = true
Expand Down

0 comments on commit 9d5a04c

Please sign in to comment.