Commit Graph

21 Commits

Author SHA1 Message Date
Mark Towers
134de4a713 Updates the environment checker (#2864)
* Updated testing requirements based off extra["testing"]

* Updated setup to check the version is valid, added testing and all dependency groups and collects the requirements from requirements.txt to keep everything standardized.

* Updated requirements.txt based on the current minimum gym requirements.txt to work

* Updated requirements.txt based on the current minimum gym requirements.txt to work

* Updated test_requirements.txt based on the current gym full testing requirements

* Pre-commit updates

* Add integer check for the `n` parameter

* The type of self.spaces is an Iterable which is absorbed by the tuple.

* Simplifies the environment checker to two files, env_checker.py and passive_env_checker.py with a new wrapper env_checker.py

* Adds the passive environment checker on `gym.make`

* Ignore the `check_env` warn parameter

* Ignore the `check_env` warn parameter

* Use the `data_equivalence` function

* Revert rewrite setup.py changes

* Remove smart formatting for 3.6 support

* Fixed `check_action_space` and `check_observation_space`

* Added disable_env_checker to vector.make such that env_checker would only run on the first environment created.

* Removing check that different seeds would produce different initialising states

* Use the unwrapped environment np_random

* Fixed vector environment creator
2022-06-06 11:21:45 -04:00
Mark Towers
0263deb5ab Add support for python 3.6 (#2836)
* Add support for python 3.6

* Add support for python 3.6

* Added check for python 3.6 to not install mujoco as no version exists

* Fixed the install groups for python 3.6

* Re-added python 3.6 support for gym

* black

* Added support for dataclasses through dataclasses module in setup that backports the module

* Fixed install requirements

* Re-added dummy env spec with dataclasses

* Changed type for compatability for python 3.6

* Added a python 3.6 warning

* Fixed python 3.6 typing issue

* Removed __future__ import annotation for python 3.6 support

* Fixed python 3.6 typing
2022-05-25 10:28:19 -04:00
Mark Towers
273e3f22ce Updated docstrings using darglint (#2827)
* Updated docstrings using darglint, ignoring 402 and 202 plus shortened lines into multiple where they were overflowing

* Remove abstract method decorators, for a future PR

* Add __future__ import annotation for python 3.7+ notion

* Added missing bracket

* Fix minor docstring tables
2022-05-25 09:46:41 -04:00
Mark Towers
4487008ea9 Mujoco and Website Docstring fixes (#2834)
* Fixed minor docstring issues found on the website

* Updated the top docstrings with mujoco environments that fixed the observation and action tables. Added v4 gym.make code
2022-05-24 18:09:05 -04:00
Mark Towers
e2266025e6 Pydocstyle utils vector docstring (#2788)
* Added pydocstyle to pre-commit

* Added docstrings for tests and updated the tests for autoreset

* Add pydocstyle exclude folder to allow slowly adding new docstrings

* Add docstrings for setup.py and gym/__init__.py, core.py, error.py and logger.py

* Check that all unwrapped environment are of a particular wrapper type

* Reverted back to import gym.spaces.Space to gym.spaces

* Fixed the __init__.py docstring

* Fixed autoreset autoreset test

* Updated gym __init__.py top docstring

* Fix examples in docstrings

* Add docstrings and type hints where known to all functions and classes in gym/utils and gym/vector

* Remove unnecessary import

* Removed "unused error" and make APIerror deprecated at gym 1.0

* Add pydocstyle description to CONTRIBUTING.md

* Added docstrings section to CONTRIBUTING.md

* Added :meth: and :attr: keywords to docstrings

* Added :meth: and :attr: keywords to docstrings

* Imported annotations from __future__ to fix python 3.7

* Add __future__ import annotations for python 3.7

* isort

* Remove utils and vectors for this PR and spaces for previous PR

* Update gym/envs/classic_control/acrobot.py

Co-authored-by: Markus Krimmel <montcyril@gmail.com>

* Update gym/envs/classic_control/acrobot.py

Co-authored-by: Markus Krimmel <montcyril@gmail.com>

* Update gym/envs/classic_control/acrobot.py

Co-authored-by: Markus Krimmel <montcyril@gmail.com>

* Update gym/spaces/dict.py

Co-authored-by: Markus Krimmel <montcyril@gmail.com>

* Update gym/utils/env_checker.py

Co-authored-by: Markus Krimmel <montcyril@gmail.com>

* Update gym/utils/env_checker.py

Co-authored-by: Markus Krimmel <montcyril@gmail.com>

* Update gym/utils/env_checker.py

Co-authored-by: Markus Krimmel <montcyril@gmail.com>

* Update gym/utils/env_checker.py

Co-authored-by: Markus Krimmel <montcyril@gmail.com>

* Update gym/utils/env_checker.py

Co-authored-by: Markus Krimmel <montcyril@gmail.com>

* Update gym/utils/ezpickle.py

Co-authored-by: Markus Krimmel <montcyril@gmail.com>

* Update gym/utils/ezpickle.py

Co-authored-by: Markus Krimmel <montcyril@gmail.com>

* Update gym/utils/play.py

Co-authored-by: Markus Krimmel <montcyril@gmail.com>

* Pre-commit

* Updated docstrings with :meth:

* Updated docstrings with :meth:

* Update gym/utils/play.py

* Update gym/utils/play.py

* Update gym/utils/play.py

* Apply suggestions from code review

Co-authored-by: Markus Krimmel <montcyril@gmail.com>

* pre-commit

* Update gym/utils/play.py

Co-authored-by: Markus Krimmel <montcyril@gmail.com>

* Updated fps and zoom parameter docstring

* Update play docstring

* Apply suggestions from code review

Added suggested corrections from @markus28

Co-authored-by: Markus Krimmel <montcyril@gmail.com>

* Pre-commit magic

* Update the `gym.make` docstring with a warning for `env_checker`

* Updated and fixed vector docstrings

* Update test names for reflect the project filename style

Co-authored-by: Markus Krimmel <montcyril@gmail.com>
2022-05-20 09:49:30 -04:00
Markus Krimmel
745e7059e7 Pydocstyle spaces docstring (#2798)
* Added docstrings for spaces, WIP

* Formatting changes

* Use raw docstring for Box.sample

* Formatting fix

* Formatting fix

* Use :class:, :meth:, formatting fixes, resolve TODO, use Optional
2022-05-10 11:18:06 -04:00
Mark Towers
3354451300 Fixed batch spaces where the original space's seed was ignored. Issue 2680 (#2727)
* Add a case for the Box shape where the low and high values are both scalars

* Add seeding.RandomNumberGenerator parameter to Dict seed. Modify __repr__ for the dictionary space string looks similar to an actual dictionary

* Add seeding.RandomNumberGenerator parameter to Multi Binary seed

* Add seeding.RandomNumberGenerator parameter to Multi Binary seed. Modify nvec typing to include np.ndarray

* Space seed typing can be a seeding.RandomNumberGenerator. If a seeding.RNG is provided then it is assigned to _np_random and .seed is not run

* Fixed the tuple seeding type as List[int] is not a valid Space seed type

* Added typing to batch_space. The batch_space seed is equal to the space's seeding

* Fixed the seeding type

* Add test for batch space seeds are identical to the original space's seeding

* Add equivalence function for RandomNumberGenerator comparing the bit_generator.state

* The batch_space functions uses a copy of the seed for the original space

* Set the action space seed for sync_vector_env seed testing

* Add test for the seeding of the sync vector environment

* Update the test_batch_space_seed to check the resulting sampling are equivalent for testing

* Revert representation back to the original version

* Remove additional Box shape initialisation

* Remove additional typing of MultiDiscrete

* Fixed bug of Space batch space where the original space's np_random is not a complete copy of the original space

* Add CustomSpace to the batched space seed test

* Modify the CustomSpace sample to produce a random number not a static value

* Fix CustomSpace to reflect the sample function

* Copy the space.np_random for the batched_space seed to ensure that the original space doesn't sampling doesn't effect the batched_space

* Parameterized the batch_space_seed, added testing for rng_different_at_each_index and test_deterministic

* Black and isort pre-commit changes

* Pre-commit fix

* MacOS, test_read_from_shared_memory throws an error that the inner _process_write function was unpicklable. Making the function a top-level function solves this error

* Fixed typing of seed where a space's seed function differs from Space.seed's typing

* Added check that the sample lengths are equal and explicitly provided the number of batched spaces n=1

* Removed relative imports for absolute imports

* Use deepcopy instead of copy

* Replaces `from numpy.testing._private.utils import assert_array_equal` with `from numpy.testing import assert_array_equal`

* Using the seeding `__eq__` function, replace `np_random.bit_generator.state` with `np_random`

* Added docstrings and comments to the tests to explain their purpose

* Remove __eq__ from RandomNumberGenerator and add to tests/vector/utils

* Add sync vector determinism test for issue #2680

* Fixed bug for 462101d384 (r850740825)

* Made the new seeds a list of integers
2022-04-24 12:14:33 -04:00
Gianluca De Cola
227e246ff6 Pyright versioning update. Fix #2700 (#2739)
* 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>
2022-04-07 21:19:52 -04:00
Manuel Goulão
658d4081c0 fix and complete docstrings to match the documentation page (#2697) 2022-04-06 15:12:55 -04:00
Andrea PIERRÉ
e913bc81b8 Improve pre-commit workflow (#2602)
* feat: add `isort` to `pre-commit`

* ci: skip `__init__.py` file for `isort`

* ci: make `isort` mandatory in lint pipeline

* docs: add a section on Git hooks

* ci: check isort diff

* fix: isort from master branch

* docs: add pre-commit badge

* ci: update black + bandit versions

* feat: add PR template

* refactor: PR template

* ci: remove bandit

* docs: add Black badge

* ci: try to remove all `|| true` statements

* ci: remove lint_python job

- Remove `lint_python` CI job
- Move `pyupgrade` job to `pre-commit` workflow

* fix: avoid messing with typing

* docs: add a note on running `pre-cpmmit` manually

* ci: apply `pre-commit` to the whole codebase
2022-03-31 15:50:38 -04:00
Alexis DUBURCQ
108f32c743 gym.spaces.Tuple inherits from collections.abc.Sequence (#2637)
* gym.spaces.Tuple inherits from collections.abc.Sequence

Following the PR I did a few months back (https://github.com/openai/gym/pull/2446), the tuple wrapper of gym should inherits from the abstract interface of Python. It is important for type check via `isinstance` and enable using such objects transparently with libraries such as [dmtree](https://github.com/deepmind/tree). 

It will bring a way helper methods along the way but it cannot be avoided to interoperability: : `__iter__`, `__reversed__`, `index`, and `count`
Personally I don't think it is an issue since it is new features and it is not conflicting.

As the previous PR, this patch is NOT removing any existing feature and should not break backward compatibility.

* Add unit test

* Fix unit tests

* Final fix.

* Remove irrelevant comment.

* Fix black formatter.
2022-03-04 10:25:19 -05:00
Ilya Kamen
ad79b0ad0f typing in gym.spaces (#2541)
* typing in spaces.Box and spaces.Discrete

* adds typing to dict and tuple spaces

* Typecheck all spaces

* Explicit regex to include all files under space folder

* Style: use native types and __future__ annotations

* Allow only specific strings for Box.is_bounded args

* Add typing to changes from #2517

* Remove Literal as it's not supported by py3.7

* Use more recent version of pyright

* Avoid name clash for type checker

* Revert "Avoid name clash for type checker"

This reverts commit 1aaf3e0e0328171623a17a997b65fe734bc0afb1.

* Ignore the error. It's reported as probable bug at https://github.com/microsoft/pyright/issues/2852

* rebase and add typing for `_short_repr`
2022-01-24 17:22:11 -05:00
Xuehai Pan
18c8b988d4 Type cast in spaces families (#2491)
* Type cast for `spaces.Dict`

* Type cast for `spaces.Tuple`

* Type cast for `spaces.Discrete`

* Type cast for `spaces.MultiDiscrete`

* Type cast for `spaces.MultiBinary`
2021-12-16 00:45:37 -05:00
Elijah K
8e5ae02ab1 Py36+ syntax in gym/spaces: derived by running pyupgrade --py36-plus gym/spaces/**.py and flynt gym --ll 120 (#2466)
Co-authored-by: Ilya Kamen <ilya.kamenshchikov@bosch.com>
2021-11-14 08:50:23 -05:00
RaghuSpaceRajan
c571b0d853 Make Tuple and Dicts be seedable with lists and dicts of seeds + make the seed in default initialization controllable (#1774)
* Make the seed in default initialization controllable

Since seed() is being called in default initialization of Space, it should be controllable for reproducibility.

* Updated derived classes of Space to have their seeds controllable at initialization.

* Allow Tuple's spaces to each have their own seed

* Added dict based seeding for Dict space; test cases for Tuple and Dict seeding

* Update discrete.py

* Update test_spaces.py

* Add seed to __init__()

* blacked

* Fix black

* Fix failing tests
2021-09-13 14:08:01 -04:00
Xuehai Pan
bb8e8063e9 Fix seed method for spaces.Tuple and spaces.Dict (#2365)
* Fix seed method for Tuple and Dict

* Improve stochasticity

* Update test cases for seed method

* Update test cases for seed method

Update test cases for seed method

Update test cases for seed method
2021-09-02 10:15:34 -04:00
J K Terry
78d2b512d8 redo black (#2272) 2021-07-29 15:39:42 -04:00
Justin Terry
e9d2c41f2b redo black 2021-07-29 12:42:48 -04:00
Christian Clauss
bb81e141ea Blacken the codebase (#2265) 2021-07-28 20:26:34 -04:00
pzhokhov
9a7f10ece1 fix accidental seed function overriding in Space (#1506)
* fix accidental seed function overriding in Space

* default seed to None in spaces
2019-05-24 18:16:07 -07:00
Xingdong Zuo
f408e2284c Rename tuple_space.py to tuple.py 2019-03-25 00:56:57 +01:00