Commit Graph

55 Commits

Author SHA1 Message Date
Mark Towers
3c17911700 Merge main into array-api (#1401)
Co-authored-by: Martin Schuck <57562633+amacati@users.noreply.github.com>
Co-authored-by: Kallinteris Andreas <30759571+Kallinteris-Andreas@users.noreply.github.com>
Co-authored-by: James Mochizuki-Freeman <jameymmf@gmail.com>
2025-06-10 14:16:42 +01:00
Mark Towers
e4c1f901e9 Add probability masking to space.sample (#1310)
Co-authored-by: Mario Jerez <jerezmario1@gmail.com>
2025-02-21 13:39:23 +00:00
Mark Towers
c6c581538f Revert OrderedDict key ordering in Dict space (#1291) 2025-01-08 22:05:57 +00:00
Mark Towers
b40a899251 Revert #941 (#1165) 2024-09-19 12:18:43 +01:00
Mark Towers
64fac8e80b Add (A)syncVectorEnv support for sub-envs with different observation spaces (#1140)
Co-authored-by: Reggie <72816837+reginald-mclean@users.noreply.github.com>
Co-authored-by: Reggie McLean <reginald.mclean@ryerson.ca>
2024-08-29 16:52:43 +01:00
Ariel Kwiatkowski
8161d7d0a0 Add compatibility with numpy 2.0 (#1094)
Co-authored-by: Mark Towers <mark.m.towers@gmail.com>
2024-06-28 18:48:01 +02:00
Trey Wager
df97b31ebc Add shape check to MultiDiscrete __eq__ (#1044) (#1045) 2024-05-08 13:39:09 +12:00
Mark Towers
8bf2543e34 Modify Space.seed such that the return can be used as seeding values (#1033) 2024-04-28 16:10:35 +01:00
Mark Towers
0fe94efa26 Fix OneOf shared memory and add pytest.skip to tests (#999) 2024-04-06 13:20:10 +01:00
James Mochizuki-Freeman
89bedf1f33 Fix Box casting and sampling edge-cases (#774)
Co-authored-by: Mark Towers <mark.m.towers@gmail.com>
2024-03-23 16:19:52 +00:00
Mark Towers
15d179087e Remove ordereddict in favour of python dict (#977) 2024-03-22 11:19:41 +00:00
Ariel Kwiatkowski
2b2e853536 Add a OneOf space for exclusive unions (#812)
Co-authored-by: pseudo-rnd-thoughts <mark.m.towers@gmail.com>
2024-03-11 12:30:50 +00:00
Mark Towers
78fe890f9a Fixed key in Dict.keys() always being false (#608) 2023-07-14 15:48:50 +01:00
Mark Towers
f39931938a Add MultiDiscrete.__setstate__ for new start attribute (#582) 2023-07-03 11:01:40 +01:00
Franois
5a3630df26 Adding starting values to MultiDiscrete spaces (#557) 2023-06-16 15:36:42 +01:00
Mark Towers
22a00c2a75 Misc bug fixes (#516) 2023-05-23 15:35:49 +01:00
Jet
1554830759 Disallow Box low > high and low == inf and high == -inf (#495)
Co-authored-by: Mark Towers <mark.m.towers@gmail.com>
2023-05-15 14:07:57 +01:00
Mark Towers
a7d9146b1d Update vector space utility functions for all spaces (#223) 2023-02-22 15:05:58 +00:00
Mark Towers
b3685f51a2 Update the experimental vector shared memory util functions (#339) 2023-02-20 16:02:12 +00:00
Mahdi Khodabandeh
76559ed553 Fixed Box.sample bug for up-bounded discrete or boolean dtypes (#249)
Co-authored-by: Mark Towers <mark.m.towers@gmail.com>
2023-02-06 11:00:09 +00:00
Kevlyn Kadamala
8031da71e6 Add Stack to Sequence space - #217 (#284)
Co-authored-by: StringTheory <mark.m.towers@gmail.com>
2023-01-30 12:57:32 +00:00
Pierre Mardon
6ba886abce Add explicit error messages when unflatten discrete and multidiscrete fail (#267) 2023-01-18 17:32:54 +00:00
Ian Fan
b34c25b368 Fix type annotations of callable to Callable (#259) 2023-01-11 20:09:37 +00:00
Jet
c2a387702c Allow sequence to accept stacked np arrays if the feature space is Box (#241) 2023-01-05 20:46:37 +00:00
Mark Towers
d71a135882 Replace np.bool8 with np.bool_ for numpy 1.24 (#221) 2022-12-19 12:53:06 +00:00
Xuehai Pan
7e88559763 Update and rerun pre-commit hooks for better code quality (#179) 2022-12-04 14:24:02 +00:00
Mark Towers
37b4c0b0a8 Update the spaces for complete type hinting (and updates numpy to 1.21) (#37) 2022-11-15 14:09:22 +00:00
Olaf Lipinski
dec9f2cd85 Fix integer overflow in MultiDiscrete.flatten() (#55)
Signed-off-by: Olaf Lipinski <o.lipinski@soton.ac.uk>
2022-10-14 12:08:22 +01:00
Mark Towers
8589523a77 Change import gymnasium to import gymnasium as gym (#20) 2022-09-16 23:41:27 +01:00
pseudo-rnd-thoughts
47ba48b611 Rename to gymnasium 2022-09-08 10:11:31 +01:00
pseudo-rnd-thoughts
640c509109 Rename to gymnasium 2022-09-08 10:10:07 +01:00
Ariel Kwiatkowski
d818750547 Add a complete compatibility wrapper (#3066)
* Added a new compatibility wrapper along with tests

* Fix for 3.6 typing

* Fix for 3.6 typing again

* Add make integration

* Unrelated change that for some reason is necessary to fix pyright

* Ignore weird (and very non-critical) type check bug

* Adjust old tests

* Rename the compatibility argument in make

* Rename the compatibility argument in register and envspec

* Documentation updates

* Remove test envs from the registry

* Some rogue renames

* Add nicer str and repr to the compatibility layer

* Reorder the compatibility layer application

* Add metadata to test envs

* Add proper handling of automatic human rendering

* Add auto human rendering to reset

* Enable setting render_mode in gym.make

* Documentation update

* Fix an unrelated stochastic test
2022-09-06 11:20:04 -04:00
Mark Towers
f39747d6a2 Update Composite spaces with full coverage (#3047)
* Update composite space and tests

* Pre-commit

* pyright

* Fix pyright

* retrigger actions

* Code review by Arjun

* Code review by Arjun

* Code review by Omar
2022-09-03 18:39:23 -04:00
Mark Towers
8e74fe3b62 Add testing for Fundamental spaces with full coverage (#3048)
* initial commit

* Fix the multi-binary sample and upgrade multi-discrete sample

* Fix MultiBinary sample tests and pre-commit

* Adds coverage tests and updates test_utils.py to use the utils.py spaces. Fix bug in text.py

* pre-commit
2022-09-03 17:56:29 -04:00
Mark Towers
ab3e02db83 Reduce the number of unexpected warnings during testing (#3050)
* Initial commit

* Remove unnecessary `warnings.simplefilters`

* Fix tests for new step API

* Fix testing

Co-authored-by: Markus28 <montcyril@gmail.com>
2022-08-30 14:47:26 -04:00
Markus Krimmel
63ea5f2517 Add Sequence space, update flatten functions (#2968)
* Added Sequence space, updated flatten functions to work with Sequence, Graph. WIP.

* Small fixes, added Sequence space to tests

* Replace Optional[Any] by Any

* Added tests for flattening of non-numpy-flattenable spaces

* Return all seeds
2022-08-15 11:11:32 -04:00
Mark Towers
634afec9bc Text space (#2959)
* Allows a new RNG to be generated with seed=-1 and updated env_checker to fix bug if environment doesn't use np_random in reset

* Revert "fixed `gym.vector.make` where the checker was being applied in the opposite case than was intended to (#2871)"

This reverts commit 519dfd9117.

* Remove bad pushed commits

* Fixed spelling in core.py

* Pins pytest to the last py 3.6 version

* Add Text space

* Add Text space

* Added Text space

* Updated comment

* Allow Box automatic scalar shape

* Add test box and change default from () to (1,)

* Refactored conditional

* Refactored contains()

* update Box shape inference with more strict checking

* Update the box shape and add check on the custom Box shape

* Removed incorrect shape type and assert shape code

* Update the Box and associated tests

* Move dependency error to inside the atari environment

* Update the gym version to v0.25.0

* Fixed bugs in Text space and tests

* Code review by Drew

Co-authored-by: Ryan Rudes <ryanrudes@gmail.com>
2022-07-11 11:39:04 -04:00
Ariel Kwiatkowski
9c1d288a2d [WIP] Typing fixes (#2939)
* Update pyproject.toml

* Maybe fix typing for frozen lake and taxi

* Clean up pyproject a bit

* Reenable box2d pyright

* Disable box2d pyright

* Fix typing for toy text envs

* Narrow down pyright excludes for almost everything except mujoco

* Fix a wrapper test typing

* Remove env checker from excludes

* Remove redundant type hints which mess up pyright. And a typo fix.

* Remove test_spaces exclude

* Remove some redundant warnings

* Change pyright ignore to more specific

* Fix a weird private variable which gets explicitly exported for whatever reason. It's still exported for backwards compatibility, but internal code now uses a public variable.

* re-export the private variable

* Fix lunar_lander typing

* Remove lunar lander from excludes

* Small fix
2022-06-30 12:04:14 -04:00
Mark Towers
7f6effbc0d Inferring Box scalar shape (#2911)
* Allows a new RNG to be generated with seed=-1 and updated env_checker to fix bug if environment doesn't use np_random in reset

* Revert "fixed `gym.vector.make` where the checker was being applied in the opposite case than was intended to (#2871)"

This reverts commit 519dfd9117.

* Remove bad pushed commits

* Fixed spelling in core.py

* Pins pytest to the last py 3.6 version

* Allow Box automatic scalar shape

* Add test box and change default from () to (1,)

* update Box shape inference with more strict checking

* Update the box shape and add check on the custom Box shape

* Removed incorrect shape type and assert shape code

* Update the Box and associated tests
2022-06-29 11:17:25 -04:00
Mark Towers
024b0f5160 Added Action masking for Space.sample() (#2906)
* Allows a new RNG to be generated with seed=-1 and updated env_checker to fix bug if environment doesn't use np_random in reset

* Revert "fixed `gym.vector.make` where the checker was being applied in the opposite case than was intended to (#2871)"

This reverts commit 519dfd9117.

* Remove bad pushed commits

* Fixed spelling in core.py

* Pins pytest to the last py 3.6 version

* Add support for action masking in Space.sample(mask=...)

* Fix action mask

* Fix action_mask

* Fix action_mask

* Added docstrings, fixed bugs and added taxi examples

* Fixed bugs

* Add tests for sample

* Add docstrings and test space sample mask Discrete and MultiBinary

* Add MultiDiscrete sampling and tests

* Remove sample mask from graph

* Update gym/spaces/multi_discrete.py

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

* Updates based on Marcus28 and jjshoots for Graph.py

* Updates based on Marcus28 and jjshoots for Graph.py

* jjshoot review

* jjshoot review

* Update assert check

* Update type hints

Co-authored-by: Markus Krimmel <montcyril@gmail.com>
2022-06-26 18:23:15 -04:00
Jet
a6274a55f0 Add Graph to Spaces (#2869) 2022-06-09 10:42:58 -04:00
Jordan Terry
0e99e3c624 Added support for unpickling legacy Box (#2851) (#2854)
Co-authored-by: Mark Towers <mark.m.towers@gmail.com>
2022-05-31 23:53:13 -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
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
Mark Towers
850247f888 Reduces warnings produced by pytest from ~1500 to 13 (#2660)
* Updated cartpole-v0 to v1 to prevent warning and added pytest.mark.filterwarnings for tests where warnings are unavoidable

* Change np.bool to bool as numpy raises a warning and bool is the suggested solution

* Seeding randint is deprecated in the future, integers is new solution

* Fixed errors thrown when the video recorder is deleted but not closed

* spaces.Box expects a floating array, updated all cases where this was not true and modified float32 to float64 as float array default to float64. Otherwise space.Box raises warning that dtype precision (float32) is lower than array precision (float64).

* Added pytest.mark.filterwarnings to preventing the raising of an intended warning

* Added comment to explain why a warning is raised that can't be prevented without version update to the environment

* Added comment to explain why warning is raised

* Changed values to float as expected by the box which default to float64

* Removed --forked from pytest as the pytest-forked project is no being maintained and was not raising warnings as expected

* When AsyncVectorEnv has shared_memory=True then a ValueError is raised before _state is initialised. Therefore, on the destruction on the env an error is thrown in .close_extra as _state does not exist

* Possible fix that was causing an error in test_call_async_vector_env by ensuring that pygame resources are released

* Pygame throws an error with ALSA when closed, using a fix from PettingZoo (https://github.com/Farama-Foundation/PettingZoo/blob/master/pettingzoo/__init__.py). We use the dsp audiodriver to prevent this issue

* Modification due to running pre-commit locally

* Updated cartpole-v0 to v1 to prevent warning and added pytest.mark.filterwarnings for tests where warnings are unavoidable

* Change np.bool to bool as numpy raises a warning and bool is the suggested solution

* Seeding randint is deprecated in the future, integers is new solution

* Fixed errors thrown when the video recorder is deleted but not closed

* spaces.Box expects a floating array, updated all cases where this was not true and modified float32 to float64 as float array default to float64. Otherwise space.Box raises warning that dtype precision (float32) is lower than array precision (float64).

* Added pytest.mark.filterwarnings to preventing the raising of an intended warning

* Added comment to explain why a warning is raised that can't be prevented without version update to the environment

* Added comment to explain why warning is raised

* Changed values to float as expected by the box which default to float64

* Removed --forked from pytest as the pytest-forked project is no being maintained and was not raising warnings as expected

* When AsyncVectorEnv has shared_memory=True then a ValueError is raised before _state is initialised. Therefore, on the destruction on the env an error is thrown in .close_extra as _state does not exist

* Possible fix that was causing an error in test_call_async_vector_env by ensuring that pygame resources are released

* Pygame throws an error with ALSA when closed, using a fix from PettingZoo (https://github.com/Farama-Foundation/PettingZoo/blob/master/pettingzoo/__init__.py). We use the dsp audiodriver to prevent this issue

* Modification due to running pre-commit locally
2022-03-14 10:27:03 -04:00
Tristan Deleu
e671aa168c Fix space utils for Discrete with non-zero start (#2645)
* Fix flatten utils to handle Discrete.start

* Fix vector space utils to handle Discrete.start

* More granular dispatch in vector utils

* Fix Box including the high end of the interval
2022-03-04 15:17:16 -05: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
Daniel
b2a2e6735d compatibility for loading legacy Discrete states (#2646)
* compatibility for loading legacy Discrete states

* super

* format
2022-03-02 11:14:59 -05:00
Edward Rusu
d1f35fe587 Box Boundedness determined using get_inf instead of np.inf (#2630)
* Box Boundedness determined using get_inf instead of np.inf

* Store original array entries for determining boundedness

* Capture the boundedness before casting away the np.inf

* Removed requirement that integer spaces be bounded above and below

* np full casts away the inf, so using dtype float for boundedness evaluation

* Removed commented code

* But the type ignore hint back in

* Spacing change from black code formatter
2022-03-02 10:51:06 -05:00
JYX
15b5c6c29f Fix RandomNumberGenerator pickling (#2639)
* Fix RandomNumberGenerator pickling

* Add test for RNG pickling fix

* Fix Python 3.7 compatibility about tuple unpacking

See: https://bugs.python.org/issue32117

* Fix formatting issue

* Add test for space pickling
2022-03-02 10:38:26 -05:00