mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-26 16:27:11 +00:00
* Moved pygame imports into render * Formatting * Make pygame optional for box2d, try to make formatting work * fix tests, fix pre-commit. * Update ci linter config. * fix type hints for latest pyright version and backward compatibility with numpy <= 1.21.5 * pre-commit. Co-authored-by: Ariel Kwiatkowski <ariel.j.kwiatkowski@gmail.com> Co-authored-by: Gianluca De Cola <gianluca.decola@ags-it.com>
This commit is contained in:
6
.github/workflows/lint_python.yml
vendored
6
.github/workflows/lint_python.yml
vendored
@@ -8,13 +8,15 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
python-platform: ["Linux"]
|
||||
python-version: ["3.7"]
|
||||
python-version: ["3.7", "3.8", "3.9", "3.10"]
|
||||
fail-fast: false
|
||||
env:
|
||||
PYRIGHT_VERSION: 1.1.204
|
||||
PYRIGHT_VERSION: 1.1.235
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- run: pip install -e .[nomujoco]
|
||||
- uses: jakebailey/pyright-action@v1
|
||||
with:
|
||||
|
@@ -106,7 +106,8 @@ class Env(Generic[ObsType, ActType]):
|
||||
integer seed right after initialization and then never again.
|
||||
|
||||
Args:
|
||||
seed (int or None): The seed that is used to initialize the environment's PRNG. If the environment does not already have a PRNG and ``seed=None`` (the default option) is passed, a seed will be chosen from some source of entropy (e.g. timestamp or /dev/urandom). However, if the environment already has a PRNG and ``seed=None`` is pased, the PRNG will *not* be reset. If you pass an integer, the PRNG will be reset even if it already exists. Usually, you want to pass an integer *right after the environment has been initialized and then never again*. Please refer to the minimal example above to see this paradigm in action.
|
||||
seed (int or None): The seed that is used to initialize the environment's PRNG. If the environment does not already have a PRNG and ``seed=None`` (the default option) is passed, a seed will be chosen from some source of entropy (e.g. timestamp or /dev/urandom). However, if the environment already has a PRNG and ``seed=None`` is passed, the PRNG will *not* be reset.
|
||||
If you pass an integer, the PRNG will be reset even if it already exists. Usually, you want to pass an integer *right after the environment has been initialized and then never again*. Please refer to the minimal example above to see this paradigm in action.
|
||||
return_info (bool): If true, return additional information along with initial observation. This info should be analogous to the info returned in :meth:`step`
|
||||
options (dict or None): Additional information to specify how the environment is reset (optional, depending on the specific environment)
|
||||
|
||||
|
@@ -125,7 +125,7 @@ class Continuous_MountainCarEnv(gym.Env):
|
||||
low=self.low_state, high=self.high_state, dtype=np.float32
|
||||
)
|
||||
|
||||
def step(self, action):
|
||||
def step(self, action: np.ndarray):
|
||||
|
||||
position = self.state[0]
|
||||
velocity = self.state[1]
|
||||
|
@@ -112,7 +112,7 @@ class MountainCarEnv(gym.Env):
|
||||
self.action_space = spaces.Discrete(3)
|
||||
self.observation_space = spaces.Box(self.low, self.high, dtype=np.float32)
|
||||
|
||||
def step(self, action):
|
||||
def step(self, action: int):
|
||||
assert self.action_space.contains(
|
||||
action
|
||||
), f"{action!r} ({type(action)}) invalid"
|
||||
|
@@ -66,9 +66,9 @@ class Box(Space[np.ndarray]):
|
||||
|
||||
# Capture the boundedness information before replacing np.inf with get_inf
|
||||
_low = np.full(shape, low, dtype=float) if np.isscalar(low) else low
|
||||
self.bounded_below = -np.inf < _low
|
||||
self.bounded_below = -np.inf < _low # type: ignore
|
||||
_high = np.full(shape, high, dtype=float) if np.isscalar(high) else high
|
||||
self.bounded_above = np.inf > _high
|
||||
self.bounded_above = np.inf > _high # type: ignore
|
||||
|
||||
low = _broadcast(low, dtype, shape, inf_sign="-") # type: ignore
|
||||
high = _broadcast(high, dtype, shape, inf_sign="+") # type: ignore
|
||||
|
@@ -35,7 +35,8 @@ class MultiBinary(Space[np.ndarray]):
|
||||
self.n = n = int(n)
|
||||
input_n = (n,)
|
||||
|
||||
assert (np.asarray(input_n) > 0).all(), "n (counts) have to be positive"
|
||||
# n (counts) have to be positive
|
||||
assert (np.asarray(input_n) > 0).all() # type: ignore
|
||||
|
||||
super().__init__(input_n, np.int8, seed)
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence
|
||||
from typing import Iterable
|
||||
|
||||
import numpy as np
|
||||
|
||||
@@ -52,7 +53,7 @@ class MultiDiscrete(Space[np.ndarray]):
|
||||
# is within correct bounds for space dtype (even though x does not have to be unsigned)
|
||||
return bool(x.shape == self.shape and (0 <= x).all() and (x < self.nvec).all())
|
||||
|
||||
def to_jsonable(self, sample_n):
|
||||
def to_jsonable(self, sample_n: Iterable[np.ndarray]):
|
||||
return [sample.tolist() for sample in sample_n]
|
||||
|
||||
def from_jsonable(self, sample_n):
|
||||
@@ -66,7 +67,7 @@ class MultiDiscrete(Space[np.ndarray]):
|
||||
if nvec.ndim == 0:
|
||||
subspace = Discrete(nvec)
|
||||
else:
|
||||
subspace = MultiDiscrete(nvec, self.dtype)
|
||||
subspace = MultiDiscrete(nvec, self.dtype) # type: ignore
|
||||
subspace.np_random.bit_generator.state = self.np_random.bit_generator.state
|
||||
return subspace
|
||||
|
||||
|
@@ -72,7 +72,7 @@ class Tuple(Space[tuple], Sequence):
|
||||
def __repr__(self) -> str:
|
||||
return "Tuple(" + ", ".join([str(s) for s in self.spaces]) + ")"
|
||||
|
||||
def to_jsonable(self, sample_n) -> list:
|
||||
def to_jsonable(self, sample_n: Sequence) -> list:
|
||||
# serialize as list-repr of tuple of vectors
|
||||
return [
|
||||
space.to_jsonable([sample[i] for sample in sample_n])
|
||||
|
@@ -134,7 +134,7 @@ def _unflatten_multidiscrete(space: MultiDiscrete, x: np.ndarray) -> np.ndarray:
|
||||
offsets[1:] = np.cumsum(space.nvec.flatten())
|
||||
|
||||
(indices,) = np.nonzero(x)
|
||||
return np.asarray(indices - offsets[:-1], dtype=space.dtype).reshape(space.shape)
|
||||
return np.asarray(indices - offsets[:-1], dtype=space.dtype).reshape(space.shape) # type: ignore
|
||||
|
||||
|
||||
@unflatten.register(Tuple)
|
||||
|
Reference in New Issue
Block a user