The following issues were found
gym/envs/unittest/cube_crash.py
13 issues
Line: 131
Column: 9
dist = np.abs(self.cube_x - self.hole_x)
if self.potential is not None and self.use_shaped_reward:
reward = (self.potential - dist) * 0.01
self.potential = dist
if self.cube_x - 1 < 0 or self.cube_x + 1 >= FIELD_W:
done = True
reward = -1
elif self.cube_y + 1 >= FIELD_H - 5:
Reported by Pylint.
Line: 143
Column: 9
elif self.cube_y == FIELD_H:
done = True
reward = +1
self.last_obs = obs
return obs, reward, done, {}
def render(self, mode="human"):
if mode == "rgb_array":
return self.last_obs
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import gym
from gym import spaces
from gym.utils import seeding
# Unit test environment for CNNs and CNN+RNN algorithms.
# Looks like this (RGB observations):
#
# ---------------------------
Reported by Pylint.
Line: 42
Column: 1
color_green = np.array((0, 255, 0)).astype("float32")
class CubeCrash(gym.Env):
metadata = {
"render.modes": ["human", "rgb_array"],
"video.frames_per_second": 60,
"video.res_w": FIELD_W,
"video.res_h": FIELD_H,
Reported by Pylint.
Line: 42
Column: 1
color_green = np.array((0, 255, 0)).astype("float32")
class CubeCrash(gym.Env):
metadata = {
"render.modes": ["human", "rgb_array"],
"video.frames_per_second": 60,
"video.res_w": FIELD_W,
"video.res_h": FIELD_H,
Reported by Pylint.
Line: 69
Column: 5
self.np_random, seed = seeding.np_random(seed)
return [seed]
def random_color(self):
return np.array(
[
self.np_random.randint(low=0, high=255),
self.np_random.randint(low=0, high=255),
self.np_random.randint(low=0, high=255),
Reported by Pylint.
Line: 108
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
elif action == 2:
self.cube_x += 1
else:
assert 0, "Action %i is out of range" % action
self.cube_y += 1
self.step_n += 1
obs = np.zeros((FIELD_H, FIELD_W, 3), dtype=np.uint8)
obs[:, :, :] = self.bg_color
Reported by Bandit.
Line: 146
Column: 5
self.last_obs = obs
return obs, reward, done, {}
def render(self, mode="human"):
if mode == "rgb_array":
return self.last_obs
elif mode == "human":
from gym.envs.classic_control import rendering
Reported by Pylint.
Line: 147
Column: 9
return obs, reward, done, {}
def render(self, mode="human"):
if mode == "rgb_array":
return self.last_obs
elif mode == "human":
from gym.envs.classic_control import rendering
Reported by Pylint.
Line: 151
Column: 13
return self.last_obs
elif mode == "human":
from gym.envs.classic_control import rendering
if self.viewer is None:
self.viewer = rendering.SimpleImageViewer()
self.viewer.imshow(self.last_obs)
return self.viewer.isopen
Reported by Pylint.
gym/vector/tests/utils.py
13 issues
Line: 49
Column: 1
HEIGHT, WIDTH = 64, 64
class UnittestSlowEnv(gym.Env):
def __init__(self, slow_reset=0.3):
super(UnittestSlowEnv, self).__init__()
self.slow_reset = slow_reset
self.observation_space = Box(
low=0, high=255, shape=(HEIGHT, WIDTH, 3), dtype=np.uint8
Reported by Pylint.
Line: 70
Column: 1
return observation, reward, done, {}
class CustomSpace(gym.Space):
"""Minimal custom observation space."""
def __eq__(self, other):
return isinstance(other, CustomSpace)
Reported by Pylint.
Line: 70
Column: 1
return observation, reward, done, {}
class CustomSpace(gym.Space):
"""Minimal custom observation space."""
def __eq__(self, other):
return isinstance(other, CustomSpace)
Reported by Pylint.
Line: 83
Column: 1
]
class CustomSpaceEnv(gym.Env):
def __init__(self):
super(CustomSpaceEnv, self).__init__()
self.observation_space = CustomSpace()
self.action_space = CustomSpace()
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import gym
import time
from gym.spaces import Box, Discrete, MultiDiscrete, MultiBinary, Tuple, Dict
spaces = [
Box(low=np.array(-1.0), high=np.array(1.0), dtype=np.float64),
Box(low=np.array([0.0]), high=np.array([10.0]), dtype=np.float32),
Reported by Pylint.
Line: 3
Column: 1
import numpy as np
import gym
import time
from gym.spaces import Box, Discrete, MultiDiscrete, MultiBinary, Tuple, Dict
spaces = [
Box(low=np.array(-1.0), high=np.array(1.0), dtype=np.float64),
Box(low=np.array([0.0]), high=np.array([10.0]), dtype=np.float32),
Reported by Pylint.
Line: 49
Column: 1
HEIGHT, WIDTH = 64, 64
class UnittestSlowEnv(gym.Env):
def __init__(self, slow_reset=0.3):
super(UnittestSlowEnv, self).__init__()
self.slow_reset = slow_reset
self.observation_space = Box(
low=0, high=255, shape=(HEIGHT, WIDTH, 3), dtype=np.uint8
Reported by Pylint.
Line: 51
Column: 9
class UnittestSlowEnv(gym.Env):
def __init__(self, slow_reset=0.3):
super(UnittestSlowEnv, self).__init__()
self.slow_reset = slow_reset
self.observation_space = Box(
low=0, high=255, shape=(HEIGHT, WIDTH, 3), dtype=np.uint8
)
self.action_space = Box(low=0.0, high=1.0, shape=(), dtype=np.float32)
Reported by Pylint.
Line: 83
Column: 1
]
class CustomSpaceEnv(gym.Env):
def __init__(self):
super(CustomSpaceEnv, self).__init__()
self.observation_space = CustomSpace()
self.action_space = CustomSpace()
Reported by Pylint.
Line: 85
Column: 9
class CustomSpaceEnv(gym.Env):
def __init__(self):
super(CustomSpaceEnv, self).__init__()
self.observation_space = CustomSpace()
self.action_space = CustomSpace()
def reset(self):
return "reset"
Reported by Pylint.
gym/wrappers/test_record_video.py
13 issues
Line: 1
Column: 1
import pytest
import os
import shutil
import gym
from gym.wrappers import RecordEpisodeStatistics, RecordVideo
def test_record_video():
Reported by Pylint.
Line: 1
Column: 1
import pytest
import os
import shutil
import gym
from gym.wrappers import RecordEpisodeStatistics, RecordVideo
def test_record_video():
Reported by Pylint.
Line: 6
Column: 1
import os
import shutil
import gym
from gym.wrappers import RecordEpisodeStatistics, RecordVideo
def test_record_video():
env = gym.make("CartPole-v1")
env = gym.wrappers.RecordVideo(
Reported by Pylint.
Line: 6
Column: 1
import os
import shutil
import gym
from gym.wrappers import RecordEpisodeStatistics, RecordVideo
def test_record_video():
env = gym.make("CartPole-v1")
env = gym.wrappers.RecordVideo(
Reported by Pylint.
Line: 43
Column: 9
envs = gym.vector.SyncVectorEnv([make_env("CartPole-v1", 1 + i) for i in range(2)])
envs = gym.wrappers.RecordEpisodeStatistics(envs)
envs.reset()
for i in range(100):
_, _, _, infos = envs.step(envs.action_space.sample())
for info in infos:
if "episode" in info.keys():
print(f"i, episode_reward={info['episode']['r']}")
break
Reported by Pylint.
Line: 1
Column: 1
import pytest
import os
import shutil
import gym
from gym.wrappers import RecordEpisodeStatistics, RecordVideo
def test_record_video():
Reported by Pylint.
Line: 3
Column: 1
import pytest
import os
import shutil
import gym
from gym.wrappers import RecordEpisodeStatistics, RecordVideo
def test_record_video():
Reported by Pylint.
Line: 4
Column: 1
import pytest
import os
import shutil
import gym
from gym.wrappers import RecordEpisodeStatistics, RecordVideo
def test_record_video():
Reported by Pylint.
Line: 9
Column: 1
from gym.wrappers import RecordEpisodeStatistics, RecordVideo
def test_record_video():
env = gym.make("CartPole-v1")
env = gym.wrappers.RecordVideo(
env, "videos", record_video_trigger=lambda x: x % 100 == 0
)
env.reset()
Reported by Pylint.
Line: 21
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
if done:
env.close()
break
assert os.path.isdir("videos")
shutil.rmtree("videos")
def make_env(gym_id, seed):
def thunk():
Reported by Bandit.
gym/utils/tests/test_atexit.py
13 issues
Line: 1
Column: 1
from gym.utils.closer import Closer
class Closeable(object):
close_called = False
def close(self):
self.close_called = True
Reported by Pylint.
Line: 1
Column: 1
from gym.utils.closer import Closer
class Closeable(object):
close_called = False
def close(self):
self.close_called = True
Reported by Pylint.
Line: 4
Column: 1
from gym.utils.closer import Closer
class Closeable(object):
close_called = False
def close(self):
self.close_called = True
Reported by Pylint.
Line: 4
Column: 1
from gym.utils.closer import Closer
class Closeable(object):
close_called = False
def close(self):
self.close_called = True
Reported by Pylint.
Line: 4
Column: 1
from gym.utils.closer import Closer
class Closeable(object):
close_called = False
def close(self):
self.close_called = True
Reported by Pylint.
Line: 7
Column: 5
class Closeable(object):
close_called = False
def close(self):
self.close_called = True
def test_register_unregister():
registry = Closer(atexit_register=False)
Reported by Pylint.
Line: 11
Column: 1
self.close_called = True
def test_register_unregister():
registry = Closer(atexit_register=False)
c1 = Closeable()
c2 = Closeable()
assert not c1.close_called
Reported by Pylint.
Line: 13
Column: 5
def test_register_unregister():
registry = Closer(atexit_register=False)
c1 = Closeable()
c2 = Closeable()
assert not c1.close_called
assert not c2.close_called
registry.register(c1)
Reported by Pylint.
Line: 14
Column: 5
def test_register_unregister():
registry = Closer(atexit_register=False)
c1 = Closeable()
c2 = Closeable()
assert not c1.close_called
assert not c2.close_called
registry.register(c1)
id2 = registry.register(c2)
Reported by Pylint.
Line: 16
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
c1 = Closeable()
c2 = Closeable()
assert not c1.close_called
assert not c2.close_called
registry.register(c1)
id2 = registry.register(c2)
registry.unregister(id2)
Reported by Bandit.
gym/spaces/multi_binary.py
13 issues
Line: 2
Column: 1
import numpy as np
from .space import Space
class MultiBinary(Space):
"""
An n-shape binary space.
The argument to MultiBinary defines n, which could be a number or a `list` of numbers.
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
from .space import Space
class MultiBinary(Space):
"""
An n-shape binary space.
The argument to MultiBinary defines n, which could be a number or a `list` of numbers.
Reported by Pylint.
Line: 29
Column: 5
"""
def __init__(self, n):
self.n = n
if type(n) in [tuple, list, np.ndarray]:
input_n = n
else:
input_n = (n,)
Reported by Pylint.
Line: 30
Column: 9
"""
def __init__(self, n):
self.n = n
if type(n) in [tuple, list, np.ndarray]:
input_n = n
else:
input_n = (n,)
super(MultiBinary, self).__init__(input_n, np.int8)
Reported by Pylint.
Line: 35
Column: 9
input_n = n
else:
input_n = (n,)
super(MultiBinary, self).__init__(input_n, np.int8)
def sample(self):
return self.np_random.randint(low=0, high=2, size=self.n, dtype=self.dtype)
def contains(self, x):
Reported by Pylint.
Line: 37
Column: 5
input_n = (n,)
super(MultiBinary, self).__init__(input_n, np.int8)
def sample(self):
return self.np_random.randint(low=0, high=2, size=self.n, dtype=self.dtype)
def contains(self, x):
if isinstance(x, list) or isinstance(x, tuple):
x = np.array(x) # Promote list to array for contains check
Reported by Pylint.
Line: 40
Column: 5
def sample(self):
return self.np_random.randint(low=0, high=2, size=self.n, dtype=self.dtype)
def contains(self, x):
if isinstance(x, list) or isinstance(x, tuple):
x = np.array(x) # Promote list to array for contains check
if self.shape != x.shape:
return False
return ((x == 0) | (x == 1)).all()
Reported by Pylint.
Line: 40
Column: 5
def sample(self):
return self.np_random.randint(low=0, high=2, size=self.n, dtype=self.dtype)
def contains(self, x):
if isinstance(x, list) or isinstance(x, tuple):
x = np.array(x) # Promote list to array for contains check
if self.shape != x.shape:
return False
return ((x == 0) | (x == 1)).all()
Reported by Pylint.
Line: 41
Column: 12
return self.np_random.randint(low=0, high=2, size=self.n, dtype=self.dtype)
def contains(self, x):
if isinstance(x, list) or isinstance(x, tuple):
x = np.array(x) # Promote list to array for contains check
if self.shape != x.shape:
return False
return ((x == 0) | (x == 1)).all()
Reported by Pylint.
Line: 47
Column: 5
return False
return ((x == 0) | (x == 1)).all()
def to_jsonable(self, sample_n):
return np.array(sample_n).tolist()
def from_jsonable(self, sample_n):
return [np.asarray(sample) for sample in sample_n]
Reported by Pylint.
gym/vector/utils/spaces.py
13 issues
Line: 1
Column: 1
import numpy as np
from collections import OrderedDict
from gym.spaces import Space, Box, Discrete, MultiDiscrete, MultiBinary, Tuple, Dict
_BaseGymSpaces = (Box, Discrete, MultiDiscrete, MultiBinary)
__all__ = ["_BaseGymSpaces", "batch_space"]
Reported by Pylint.
Line: 2
Column: 1
import numpy as np
from collections import OrderedDict
from gym.spaces import Space, Box, Discrete, MultiDiscrete, MultiBinary, Tuple, Dict
_BaseGymSpaces = (Box, Discrete, MultiDiscrete, MultiBinary)
__all__ = ["_BaseGymSpaces", "batch_space"]
Reported by Pylint.
Line: 10
Column: 1
__all__ = ["_BaseGymSpaces", "batch_space"]
def batch_space(space, n=1):
"""Create a (batched) space, containing multiple copies of a single space.
Parameters
----------
space : `gym.spaces.Space` instance
Reported by Pylint.
Line: 37
Column: 5
>>> batch_space(space, n=5)
Dict(position:Box(5, 3), velocity:Box(5, 2))
"""
if isinstance(space, _BaseGymSpaces):
return batch_space_base(space, n=n)
elif isinstance(space, Tuple):
return batch_space_tuple(space, n=n)
elif isinstance(space, Dict):
return batch_space_dict(space, n=n)
Reported by Pylint.
Line: 52
Column: 1
)
def batch_space_base(space, n=1):
if isinstance(space, Box):
repeats = tuple([n] + [1] * space.low.ndim)
low, high = np.tile(space.low, repeats), np.tile(space.high, repeats)
return Box(low=low, high=high, dtype=space.dtype)
Reported by Pylint.
Line: 52
Column: 1
)
def batch_space_base(space, n=1):
if isinstance(space, Box):
repeats = tuple([n] + [1] * space.low.ndim)
low, high = np.tile(space.low, repeats), np.tile(space.high, repeats)
return Box(low=low, high=high, dtype=space.dtype)
Reported by Pylint.
Line: 53
Column: 5
def batch_space_base(space, n=1):
if isinstance(space, Box):
repeats = tuple([n] + [1] * space.low.ndim)
low, high = np.tile(space.low, repeats), np.tile(space.high, repeats)
return Box(low=low, high=high, dtype=space.dtype)
elif isinstance(space, Discrete):
Reported by Pylint.
Line: 73
Column: 1
raise ValueError("Space type `{0}` is not supported.".format(type(space)))
def batch_space_tuple(space, n=1):
return Tuple(tuple(batch_space(subspace, n=n) for subspace in space.spaces))
def batch_space_dict(space, n=1):
return Dict(
Reported by Pylint.
Line: 73
Column: 1
raise ValueError("Space type `{0}` is not supported.".format(type(space)))
def batch_space_tuple(space, n=1):
return Tuple(tuple(batch_space(subspace, n=n) for subspace in space.spaces))
def batch_space_dict(space, n=1):
return Dict(
Reported by Pylint.
Line: 77
Column: 1
return Tuple(tuple(batch_space(subspace, n=n) for subspace in space.spaces))
def batch_space_dict(space, n=1):
return Dict(
OrderedDict(
[
(key, batch_space(subspace, n=n))
for (key, subspace) in space.spaces.items()
Reported by Pylint.
gym/envs/toy_text/blackjack.py
13 issues
Line: 44
Column: 1
return sorted(hand) == [1, 10]
class BlackjackEnv(gym.Env):
"""Simple blackjack environment
Blackjack is a card game where the goal is to obtain cards that sum to as
near as possible to 21 without going over. They're playing against a fixed
dealer.
Reported by Pylint.
Line: 1
Column: 1
import gym
from gym import spaces
from gym.utils import seeding
def cmp(a, b):
return float(a > b) - float(a < b)
Reported by Pylint.
Line: 6
Column: 1
from gym.utils import seeding
def cmp(a, b):
return float(a > b) - float(a < b)
# 1 = Ace, 2-10 = Number cards, Jack/Queen/King = 10
deck = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
Reported by Pylint.
Line: 6
Column: 1
from gym.utils import seeding
def cmp(a, b):
return float(a > b) - float(a < b)
# 1 = Ace, 2-10 = Number cards, Jack/Queen/King = 10
deck = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
Reported by Pylint.
Line: 6
Column: 1
from gym.utils import seeding
def cmp(a, b):
return float(a > b) - float(a < b)
# 1 = Ace, 2-10 = Number cards, Jack/Queen/King = 10
deck = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
Reported by Pylint.
Line: 14
Column: 1
deck = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
def draw_card(np_random):
return int(np_random.choice(deck))
def draw_hand(np_random):
return [draw_card(np_random), draw_card(np_random)]
Reported by Pylint.
Line: 18
Column: 1
return int(np_random.choice(deck))
def draw_hand(np_random):
return [draw_card(np_random), draw_card(np_random)]
def usable_ace(hand): # Does this hand have a usable ace?
return 1 in hand and sum(hand) + 10 <= 21
Reported by Pylint.
Line: 22
Column: 1
return [draw_card(np_random), draw_card(np_random)]
def usable_ace(hand): # Does this hand have a usable ace?
return 1 in hand and sum(hand) + 10 <= 21
def sum_hand(hand): # Return current hand total
if usable_ace(hand):
Reported by Pylint.
Line: 26
Column: 1
return 1 in hand and sum(hand) + 10 <= 21
def sum_hand(hand): # Return current hand total
if usable_ace(hand):
return sum(hand) + 10
return sum(hand)
Reported by Pylint.
Line: 32
Column: 1
return sum(hand)
def is_bust(hand): # Is this hand a bust?
return sum_hand(hand) > 21
def score(hand): # What is the score of this hand (0 if bust)
return 0 if is_bust(hand) else sum_hand(hand)
Reported by Pylint.
gym/envs/tests/test_envs_semantics.py
13 issues
Line: 11
Column: 1
import hashlib
import os
import pytest
from gym import spaces, logger
from gym.envs.tests.spec_list import spec_list
DATA_DIR = os.path.dirname(__file__)
ROLLOUT_STEPS = 100
Reported by Pylint.
Line: 34
Column: 5
def generate_rollout_hash(spec):
spaces.seed(0)
env = spec.make()
env.seed(0)
observation_list = []
action_list = []
Reported by Pylint.
Line: 44
Column: 9
done_list = []
total_steps = 0
for episode in range(episodes):
if total_steps >= ROLLOUT_STEPS:
break
observation = env.reset()
for step in range(steps):
Reported by Pylint.
Line: 49
Column: 13
break
observation = env.reset()
for step in range(steps):
action = env.action_space.sample()
observation, reward, done, _ = env.step(action)
action_list.append(action)
observation_list.append(observation)
Reported by Pylint.
Line: 78
Column: 5
def test_env_semantics(spec):
logger.warn("Skipping this test. Existing hashes were generated in a bad way")
return
with open(ROLLOUT_FILE) as data_file:
rollout_dict = json.load(data_file)
if spec.id not in rollout_dict:
if not spec.nondeterministic:
logger.warn(
Reported by Pylint.
Line: 17
Column: 1
DATA_DIR = os.path.dirname(__file__)
ROLLOUT_STEPS = 100
episodes = ROLLOUT_STEPS
steps = ROLLOUT_STEPS
ROLLOUT_FILE = os.path.join(DATA_DIR, "rollout.json")
if not os.path.isfile(ROLLOUT_FILE):
Reported by Pylint.
Line: 18
Column: 1
DATA_DIR = os.path.dirname(__file__)
ROLLOUT_STEPS = 100
episodes = ROLLOUT_STEPS
steps = ROLLOUT_STEPS
ROLLOUT_FILE = os.path.join(DATA_DIR, "rollout.json")
if not os.path.isfile(ROLLOUT_FILE):
with open(ROLLOUT_FILE, "w") as outfile:
Reported by Pylint.
Line: 27
Column: 1
json.dump({}, outfile, indent=2)
def hash_object(unhashed):
return hashlib.sha256(
str(unhashed).encode("utf-16")
).hexdigest() # This is really bad, str could be same while values change
Reported by Pylint.
Line: 33
Column: 1
).hexdigest() # This is really bad, str could be same while values change
def generate_rollout_hash(spec):
spaces.seed(0)
env = spec.make()
env.seed(0)
observation_list = []
Reported by Pylint.
Line: 33
Column: 1
).hexdigest() # This is really bad, str could be same while values change
def generate_rollout_hash(spec):
spaces.seed(0)
env = spec.make()
env.seed(0)
observation_list = []
Reported by Pylint.
gym/envs/unittest/memorize_digits.py
12 issues
Line: 115
Column: 9
if self.digit == action:
reward = +1
done = self.step_n > 20 and 0 == self.np_random.randint(low=0, high=5)
self.digit = self.np_random.randint(low=0, high=10)
obs = np.zeros((FIELD_H, FIELD_W, 3), dtype=np.uint8)
obs[:, :, :] = self.color_bg
digit_img = np.zeros((6, 6, 3), dtype=np.uint8)
digit_img[:] = self.color_bg
xxx = self.bogus_mnist[self.digit] == 42
Reported by Pylint.
Line: 125
Column: 9
obs[
self.digit_y - 3 : self.digit_y + 3, self.digit_x - 3 : self.digit_x + 3
] = digit_img
self.last_obs = obs
return obs, reward, done, {}
def render(self, mode="human"):
if mode == "rgb_array":
return self.last_obs
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import gym
from gym import spaces
from gym.utils import seeding
# Unit test environment for CNNs.
# Looks like this (RGB observations):
#
# ---------------------------
Reported by Pylint.
Line: 52
Column: 1
color_white = np.array((255, 255, 255)).astype("float32")
class MemorizeDigits(gym.Env):
metadata = {
"render.modes": ["human", "rgb_array"],
"video.frames_per_second": 60,
"video.res_w": FIELD_W,
"video.res_h": FIELD_H,
Reported by Pylint.
Line: 52
Column: 1
color_white = np.array((255, 255, 255)).astype("float32")
class MemorizeDigits(gym.Env):
metadata = {
"render.modes": ["human", "rgb_array"],
"video.frames_per_second": 60,
"video.res_w": FIELD_W,
"video.res_h": FIELD_H,
Reported by Pylint.
Line: 71
Column: 17
self.action_space = spaces.Discrete(10)
self.bogus_mnist = np.zeros((10, 6, 6), dtype=np.uint8)
for digit in range(10):
for y in range(6):
self.bogus_mnist[digit, y, :] = [
ord(char) for char in bogus_mnist[digit][y]
]
self.reset()
Reported by Pylint.
Line: 81
Column: 5
self.np_random, seed = seeding.np_random(seed)
return [seed]
def random_color(self):
return np.array(
[
self.np_random.randint(low=0, high=255),
self.np_random.randint(low=0, high=255),
self.np_random.randint(low=0, high=255),
Reported by Pylint.
Line: 114
Column: 41
else:
if self.digit == action:
reward = +1
done = self.step_n > 20 and 0 == self.np_random.randint(low=0, high=5)
self.digit = self.np_random.randint(low=0, high=10)
obs = np.zeros((FIELD_H, FIELD_W, 3), dtype=np.uint8)
obs[:, :, :] = self.color_bg
digit_img = np.zeros((6, 6, 3), dtype=np.uint8)
digit_img[:] = self.color_bg
Reported by Pylint.
Line: 128
Column: 5
self.last_obs = obs
return obs, reward, done, {}
def render(self, mode="human"):
if mode == "rgb_array":
return self.last_obs
elif mode == "human":
from gym.envs.classic_control import rendering
Reported by Pylint.
Line: 129
Column: 9
return obs, reward, done, {}
def render(self, mode="human"):
if mode == "rgb_array":
return self.last_obs
elif mode == "human":
from gym.envs.classic_control import rendering
Reported by Pylint.
gym/envs/toy_text/discrete.py
12 issues
Line: 17
Column: 1
return (csprob_n > np_random.rand()).argmax()
class DiscreteEnv(Env):
"""
Has the following members
- nS: number of states
- nA: number of actions
Reported by Pylint.
Line: 55
Column: 5
self.lastaction = None
return int(self.s)
def step(self, a):
transitions = self.P[self.s][a]
i = categorical_sample([t[0] for t in transitions], self.np_random)
p, s, r, d = transitions[i]
self.s = s
self.lastaction = a
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
from gym import Env, spaces
from gym.utils import seeding
def categorical_sample(prob_n, np_random):
"""
Sample from categorical distribution
Reported by Pylint.
Line: 17
Column: 1
return (csprob_n > np_random.rand()).argmax()
class DiscreteEnv(Env):
"""
Has the following members
- nS: number of states
- nA: number of actions
Reported by Pylint.
Line: 34
Column: 9
"""
def __init__(self, nS, nA, P, isd):
self.P = P
self.isd = isd
self.lastaction = None # for rendering
self.nS = nS
self.nA = nA
Reported by Pylint.
Line: 37
Column: 9
self.P = P
self.isd = isd
self.lastaction = None # for rendering
self.nS = nS
self.nA = nA
self.action_space = spaces.Discrete(self.nA)
self.observation_space = spaces.Discrete(self.nS)
Reported by Pylint.
Line: 38
Column: 9
self.isd = isd
self.lastaction = None # for rendering
self.nS = nS
self.nA = nA
self.action_space = spaces.Discrete(self.nA)
self.observation_space = spaces.Discrete(self.nS)
self.seed()
Reported by Pylint.
Line: 44
Column: 9
self.observation_space = spaces.Discrete(self.nS)
self.seed()
self.s = categorical_sample(self.isd, self.np_random)
def seed(self, seed=None):
self.np_random, seed = seeding.np_random(seed)
return [seed]
Reported by Pylint.
Line: 58
Column: 18
def step(self, a):
transitions = self.P[self.s][a]
i = categorical_sample([t[0] for t in transitions], self.np_random)
p, s, r, d = transitions[i]
self.s = s
self.lastaction = a
return (int(s), r, d, {"prob": p})
Reported by Pylint.
Line: 58
Column: 15
def step(self, a):
transitions = self.P[self.s][a]
i = categorical_sample([t[0] for t in transitions], self.np_random)
p, s, r, d = transitions[i]
self.s = s
self.lastaction = a
return (int(s), r, d, {"prob": p})
Reported by Pylint.