Commit Graph

122 Commits

Author SHA1 Message Date
Omar Younis
9acf9cd367 Render API (#2671)
* add pygame GUI for frozen_lake.py env

* add new line at EOF

* pre-commit reformat

* improve graphics

* new images and dynamic window size

* darker tile borders and fix ICC profile

* pre-commit hook

* adjust elf and stool size

* Update frozen_lake.py

* reformat

* fix #2600

* #2600

* add rgb_array support

* reformat

* test render api change on FrozenLake

* add render support for reset on frozenlake

* add clock on pygame render

* new render api for blackjack

* new render api for cliffwalking

* new render api for Env class

* update reset method, lunar and Env

* fix wrapper

* fix reset lunar

* new render api for box2d envs

* new render api for mujoco envs

* fix bug

* new render api for classic control envs

* fix tests

* add render_mode None for CartPole

* new render api for test fake envs

* pre-commit hook

* fix FrozenLake

* fix FrozenLake

* more render_mode to super - frozenlake

* remove kwargs from frozen_lake new

* pre-commit hook

* add deprecated render method

* add backwards compatibility

* fix test

* add _render

* move pygame.init() (avoid pygame dependency on init)

* fix pygame dependencies

* remove collect_render() maintain multi-behaviours .render()

* add type hints

* fix renderer

* don't call .render() with None

* improve docstring

* add single_rgb_array to all envs

* remove None from metadata["render_modes"]

* add type hints to test_env_checkers

* fix lint

* add comments to renderer

* add comments to single_depth_array and single_state_pixels

* reformat

* add deprecation warnings and env.render_mode declaration

* fix lint

* reformat

* fix tests

* add docs

* fix car racing determinism

* remove warning test envs, customizable modes on renderer

* remove commments and add todo for env_checker

* fix car racing

* replace render mode check with assert

* update new mujoco

* reformat

* reformat

* change metaclass definition

* fix tests

* implement mark suggestions (test, docs, sets)

* check_render

Co-authored-by: J K Terry <jkterry0@gmail.com>
2022-06-07 18:20:56 -04:00
Mark Towers
9fa7ede1e3 Forwards all np_random assignments to the actual environment and prevent access to the _np_random in wrappers (#2857) 2022-06-06 09:56:51 -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
bf688c3efe Pydocstyle wrappers docstrings (#2787) 2022-05-13 08:58:19 -04:00
Mark Towers
1c62d3c6ad Add Pydocstyle to CI (#2785)
* 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

* 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

* Update the step docstring placing the return type in the as a note.

* Updated step return type to include each element

* Update maths notation to reward range

* Fixed infinity maths notation
2022-05-10 10:35:45 -04:00
Mark Towers
bf093c6890 Update the flake8 pre-commit ignores (#2778)
* Remove additional ignores from flake8

* Remove all unused imports

* Remove all unused imports

* Update flake8 and pyupgrade

* F841, removed unused variables

* E731, removed lambda assignment to variables

* Remove E731, F403, F405, F524

* Remove E722, bare exceptions

* Remove E712, compare variable == True or == False to is True or is False

* Remove E402, module level import not at top of file

* Added --pre-file-ignores

* Add --per-file-ignores removing E741, E302 and E704

* Add E741, do not use variables named ‘l’, ‘O’, or ‘I’ to ignore issues in classic control

* Fixed issues for pytest==6.2

* Remove unnecessary # noqa

* Edit comment with the removal of E302

* Added warnings and declared module, attr for pyright type hinting

* Remove unused import

* Removed flake8 E302

* Updated flake8 from 3.9.2 to 4.0.1

* Remove unused variable
2022-04-26 11:18:37 -04:00
efokschaner
feb7ec3bc2 Fix docstring format on seed arg to reset (#2775)
I have a copy of this string in another project and it failed the darglint docstring style check.
This fixes that, if it's something you care to fix.
2022-04-24 13:01:20 -04:00
Ariel Kwiatkowski
00a60e6cc8 Rewriting of the registration mechanism (#2748)
* First version of the new registration

* Almost done

* Hopefully final commit

* Minor fixes

* Missing error

* Type fixes

* Type fixes

* Add some type hinting stuff

* Fix an error?

* Fix literal import

* Add a comment

* Add some docstrings

Remove old tests

* Add some docstrings, rename helper functions

* Rename a function

* Registration check fix

* Consistently use `register` instead of `envs.register` in tests

* Fix the malformed registration error message to not use a write-only format

* Change an error back to a warning when double-registering an environment
2022-04-21 14:41:15 -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
Alexis DUBURCQ
214a835e76 Wrapper should not overwrite default render mode (#2706) 2022-03-31 16:28:17 -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
H4sh3
64a0eb0193 make error message on accessing private attributes more representative (#2714) 2022-03-24 14:10:06 -04:00
trigaten
35b78ac0ab Rename render modes/fps (#2654)
* Update pendulum.py

* version warnings

* black

* try except

* update notices version

* Exception

* nosec

* black

* no loop, stderr

* black

* convert ## to ###

* correct subheader

* black

* despace

* spacing

* frozen lake fixes

* rename render modes/fps

* fix API test

* fix API test

* fix more API tests

* black

* add render fps
2022-02-28 15:54:03 -05:00
Ariel Kwiatkowski
29a093ad5a Setter-based approach for the fix (#2626) 2022-02-17 19:38:22 -05:00
Ariel Kwiatkowski
3fa10a2360 Fix return_info for wrappers (#2612)
* Fix `return_info` for Observation wrappers, Atari (?) and framestack

* Make type checkers and IDEs happier

* Merge in #2454

* Update the info dict based on no-op steps
Some type hints

* Bug fix

* Handle resets during frameskip
2022-02-17 12:03:35 -05:00
Markus
1400cfbcac Changed docstrings (#2611) 2022-02-12 19:39:03 -05:00
Ilya Kamen
2be9e60a4d Typecheck classic control environments (#2589)
* Typecheck classic control environments

* consistent imports + comments

* Don't use seed method

Although this code is exact duplication, we at least don't call deprecated method.

* Update core.py
2022-02-10 12:24:41 -05:00
John Balis
15049e22d7 Adding return_info argument to reset to allow for optional info dict as a second return value (#2546)
* initial draft of optional info dict in reset function, implemented for cartpole, tests seem to be passing

* merged core.py

* updated return type annotation for reset function in core.py

* optional metadata with return_info from reset added for all first party environments, with corresponding tests. Incomplete implementation for wrappers and vector wrappers

* removed Optional type for return_info arguments

* added tests for return_info to normalize wrapper and sync_vector_env

* autoformatted using black

* added optional reset metadata tests to several wrappers

* added return_info capability to async_vector_env.py and test to verify functionality

* added optional return_info test for record_video.py

* removed tests for mujoco environments

* autoformatted

* improved test coverage for optional reset return_info

* re-removed unit test envs accidentally reintroduced in merge

* removed unnecessary import

* changes based on code-review

* small fix to core wrapper typing and autoformatted record_epsisode_stats

* small change to pass flake8 style
2022-02-06 18:28:27 -05:00
Ilya Kamen
cf634bb444 Add typing to Wrapper signatures (#2590) 2022-02-05 11:25:47 -05:00
Ariel Kwiatkowski
925823661d Add options to the signature of env.reset (#2515)
* First find/replace, now tests

* Fixes to the vector env

* Make seed keyword only in wrappers

* (try to) fix the bug with old environments using new wrappers (with the seed keyword)

* black

* Change **kwargs to options, try to make it work; black

* Add OrderEnforcing wrapper to wrapper exports
Add a test for compatibility with old (pybullet-like) envs

* Add OrderEnforcing wrapper to wrapper exports
Add a test for compatibility with old (pybullet-like) envs
black

* Update the env checker

* Update the env checker

* Update the env checker to use inspect (might fail tests, let's see)

* Allow the signature to include kwargs in env_checker

* Minor fix
2022-01-19 17:28:59 -05:00
Ilya Kamen
65eeb73366 Typing/basics (#2529)
* Typing in gym/envs/registration.py

* Add registration to type checked list

* Adds type hints to space.py

* Typing in gym.core.Env

* Typing in seeding.py

* fixup Typing after rebase

* revert accidental change

* Install dependencies in pyright runner

* fix: can only install dependencies after checkout

* fix: install types in a venv

* fix path

* skip env activation, install directly from venv interpreter

* absolute path to venv

* use central python installation

* skip one more typecheck

* cleanup gh actions .yml

* Add py.typed to signal using sources for typechecking

* black!

Co-authored-by: sj_petterson <sj_petterson@gmail.com>
Co-authored-by: J K Terry <justinkterry@gmail.com>
2021-12-22 13:12:57 -05:00
Seungjae Ryan Lee
616b071158 Remove Robotics environments from Gym (#2516)
* Remove registration of Robotics envs

* Remove Robotics environments

* Update setup.py

* Update unit tests

* Remove unused GoalEnv class
2021-12-21 09:46:24 -05:00
Ariel Kwiatkowski
c364506710 Seeding update (#2422)
* Ditch most of the seeding.py and replace np_random with the numpy default_rng. Let's see if tests pass

* Updated a bunch of RNG calls from the RandomState API to Generator API

* black; didn't expect that, did ya?

* Undo a typo

* blaaack

* More typo fixes

* Fixed setting/getting state in multidiscrete spaces

* Fix typo, fix a test to work with the new sampling

* Correctly (?) pass the randomly generated seed if np_random is called with None as seed

* Convert the Discrete sample to a python int (as opposed to np.int64)

* Remove some redundant imports

* First version of the compatibility layer for old-style RNG. Mainly to trigger tests.

* Removed redundant f-strings

* Style fixes, removing unused imports

* Try to make tests pass by removing atari from the dockerfile

* Try to make tests pass by removing atari from the setup

* Try to make tests pass by removing atari from the setup

* Try to make tests pass by removing atari from the setup

* First attempt at deprecating `env.seed` and supporting `env.reset(seed=seed)` instead. Tests should hopefully pass but throw up a million warnings.

* black; didn't expect that, didya?

* Rename the reset parameter in VecEnvs back to `seed`

* Updated tests to use the new seeding method

* Removed a bunch of old `seed` calls.

Fixed a bug in AsyncVectorEnv

* Stop Discrete envs from doing part of the setup (and using the randomness) in init (as opposed to reset)

* Add explicit seed to wrappers reset

* Remove an accidental return

* Re-add some legacy functions with a warning.

* Use deprecation instead of regular warnings for the newly deprecated methods/functions
2021-12-08 16:14:15 -05:00
Elijah K
a4da53c210 Py36+ syntax in gym/*.py: derived by running pyupgrade --py36-plus gym/*.py and flynt gym --ll 120 (#2473)
Co-authored-by: Ilya Kamen <ilya.kamenshchikov@bosch.com>
2021-11-14 08:50:40 -05:00
Tristan Deleu
d35d211fee Forward environment properties to the wrapper (#2373)
* Forward environment properties to the wrapper, fixes #2175

* Add tests for property forwarding in Wrapper

* Rename klass to class_ in test_core
2021-09-17 18:02:59 -04:00
Paweł Gajewski
ee0a568004 docstring fix for compute_reward (#2380) 2021-09-01 14:12:36 -04:00
J K Terry
267916b9d2 try removing dead code (#2305) 2021-08-10 10:50:59 -04:00
Justin Terry
ddd650a3fe black 2021-08-05 10:35:48 -04:00
Jakob Stigenberg
936dc6de36 mark abstract methods as abstract (#2158)
Co-authored-by: J K Terry <justinkterry@gmail.com>
2021-08-05 10:35:07 -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
Jim Turner
abb815c871 Clarify relationship between reset() and RNGs (#2019)
The current docstring for `reset()` seems to indicate that the
environment will be identical after separate calls to `reset()`.
However, the `reset()` function isn't supposed to reset the states of
the environment's RNGs [1]. This change clarifies the relationship
between the `reset()` function and the RNGs.

[1]: https://github.com/openai/gym/issues/250
2020-08-28 14:58:35 -07:00
Dan Timbrell
3bd5ef71c2 Clean some docstrings (#1854)
* add type of argument

* fix typos

* split lines for formatting

* reformat string, add ellipsis, remove r string

* make docstring stylistically consistent

* make docstrings a little more elaboratet

* reduce by 1 space

* make line wrap 120

* remove unnecessary line

* add returns to docstring

* add docstring, make code more pep8 and delete some unused print functions

* more pep8

* file docstring instead of comments

* delete unused variables, add file docstring and add some pep8 spring cleaning

* add file docstring, fix typos and add some pep8 correections

Co-authored-by: Dan <daniel.timbrell@ing.com>
2020-04-24 16:10:27 -05:00
Xingdong Zuo
0cd9266d98 Update core.py (#1627) 2019-10-25 15:48:21 -07:00
Kristian Hartikainen
a49c3e0fc8 Feature/pixel observation wrapper (#1499)
* Implement PixelObservationWrapper

* Change MujocoEnv.render to support custom camera_{name,id}

* Implement tests for PixelObservationWrapper

* Use env.get_pixels instead of direct env.render

* Fix camera_{id,name} check in pixel observation wrapper

* Fix rendering with explicit camera_id

* Add Wrapperget_pixels to allow call to be propagated to wrapped env

* Remove use of unnecessary `get_pixels` method

* Update PixelObservationWrapper to support multiple pixel keys

* Remove unnecessary `rgb_rendering_tracking` argument

* Remove rgb_rendering_tracking logic
2019-08-23 15:02:33 -07:00
pzhokhov
cd7f96e4db add spec property to wrapper to be forwarded to wrapped env. Fixes 1554 (#1574) 2019-06-28 15:27:43 -07:00
Christopher Hesse
cf06aeff9f docstring change, fixes #744 (#1493) 2019-05-24 14:29:01 -07:00
pzhokhov
5861d95ecd fix #1425 (#1459)
* fixes #1266

* test for correct observation space keys in GoalEnv

* fix import leading to test failures

* fix test failures
2019-05-10 15:00:01 -07:00
Xingdong Zuo
e801ccfdb0 [Update core.py] Remove underscore methods and its deprecation warning (#1320)
* Update core.py

* Update core.py

* Update core.py

* Update core.py

* Update core.py

* Update core.py
2019-05-03 14:53:31 -07:00
Yulun Li
3394e24572 Bugfix: wrapper should make spec optional for backward compatibility (#1424) 2019-04-08 19:29:13 -07:00
Xingdong Zuo
5744b25a6c [Update core.py]: support Wrapper for registering global methods with nested wrapping (#1347)
* Update core.py

* Update core.py
2019-03-25 12:11:53 -07:00
Xingdong Zuo
97a416fa14 [Update core.py] Remove unnecessary parts (#1406)
* Update core.py

* Update core.py
2019-03-25 10:23:14 -07:00
Sid Mysore
52e94a2b50 kwargs on reset for Reward and Action Wrapper (#1340) 2019-03-01 14:15:39 -08:00
Will Douglas
b5a3367fd5 Finish removing close as an option from render (#1009)
This cleans up some leftover changes after PR #836
2019-02-25 17:01:54 -07:00
Tom Alcorn
6c7e22245a Implement context handler protocol for Env (#1012)
This enables writing
```
import gym

with gym.make(...) as env:
    ...
```
without the need to remember to call `env.close()` later.
2019-02-25 16:53:58 -07:00
Xingdong Zuo
6497c9f1c6 Delete prng.py (#1196)
* Delete prng.py

Since it seems like this seeding function is rarely used.

* Update __init__.py

* Update kellycoinflip.py

* Update core.py

* Update box.py

* Update discrete.py

* Update multi_binary.py

* Update multi_discrete.py

* Update test_determinism.py

* Update test_determinism.py

* Update test_determinism.py

* Update core.py

* Update box.py

* Update test_determinism.py

* Update core.py

* Update box.py

* Update discrete.py

* Update multi_binary.py

* Update multi_discrete.py

* Update dict_space.py

* Update tuple_space.py

* Update core.py

* Create space.py

* Update __init__.py

* Update __init__.py

* Update box.py

* Update dict_space.py

* Update discrete.py

* Update dict_space.py

* Update multi_binary.py

* Update multi_discrete.py

* Update tuple_space.py

* Update discrete.py

* Update box.py

* Update dict_space.py

* Update multi_binary.py

* Update multi_discrete.py

* Update tuple_space.py

* Update multi_discrete.py

* Update multi_binary.py

* Update dict_space.py

* Update box.py

* Update test_determinism.py

* Update kellycoinflip.py

* Update space.py
2019-01-30 13:39:55 -08:00
Balázs Kossovics
e8349e3668 Fix in keyword with Spaces (#1261)
Binding `__contains__` to the Space class' contains method this way prevents overriding it in subclasses, which leads to `NotImplementedException`s when trying to do things like `2 in gym.spaces.Discrete(2)`.
2019-01-28 14:52:41 -08:00