Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gymnasium Compatibility #735

Merged
merged 64 commits into from
Sep 23, 2023
Merged

Conversation

ernestum
Copy link
Collaborator

@ernestum ernestum commented Jun 29, 2023

Description

Make imitation compatible with gymnasium because the old gym is outdated.

Main changes:

  • import gym -> import gymnasium as gym
  • Adoption of the new gymnasium API (.seed(x) -> .reset(seed=x), done -> terminated/truncated, .reset() not returns a tuple)
  • Added some extra checks because the new API does not guarantee that spaces have a shape
  • We don't import seals any more and rather use the seals: prefix on environment names.
  • make_vec_env does not mess with TimeLimit wrappers any more (gymnasium does that for us)

To be changed before merging

  • Update the models on HuggingFace model hub (they are already trained on rnn, I just need to push them)
  • Stop installing gym as part of the pipeline (that was just so we can load the current models)
  • Depend on upstream seals and not on a branch of it.

Notes on the failing pipeline

Testing

No new tests have been added but all tests pass now.


Thanks to all the people that helped coding and reviewing!
@AdamGleave, @araffin, @EdoardoPona, @Rocamonde, @simoninithomas,

This PR has been possible due to lots of work in our dependencies:

@ernestum ernestum linked an issue Jun 29, 2023 that may be closed by this pull request
@ernestum ernestum marked this pull request as draft June 29, 2023 11:49
@Rocamonde
Copy link
Member

Linking HumanCompatibleAI/seals#72 to this

@Rocamonde
Copy link
Member

I am getting some weird pytype error that it cannot import packages. I remember facing this at some point in the past. @ernestum do you know what the cause of this is?

$ pytype -j auto
Computing dependencies
Analyzing 107 sources with 0 local dependencies
ninja: Entering directory `.pytype'
[1/64] check test_benchmarking
FAILED: /home/rocamonde/HumanCompatibleAI/imitation/.pytype/pyi/test_benchmarking.pyi 
/home/rocamonde/HumanCompatibleAI/imitation/venv/bin/python -m pytype.single --imports_info /home/rocamonde/HumanCompatibleAI/imitation/.pytype/imports/test_benchmarking.imports --module-name test_benchmarking --platform linux -V 3.10 -o /home/rocamonde/HumanCompatibleAI/imitation/.pytype/pyi/test_benchmarking.pyi --analyze-annotated --nofail --quick /home/rocamonde/HumanCompatibleAI/imitation/tests/test_benchmarking.py
File "/home/rocamonde/HumanCompatibleAI/imitation/tests/test_benchmarking.py", line 6, in <module>: Can't find module 'imitation.scripts.train_adversarial'. [import-error]
File "/home/rocamonde/HumanCompatibleAI/imitation/tests/test_benchmarking.py", line 6, in <module>: Can't find module 'imitation.scripts.train_imitation'. [import-error]

@ernestum
Copy link
Collaborator Author

ernestum commented Jul 5, 2023

@ernestum do you know what the cause of this is?

No I have never seen this error before 🤷

@ernestum
Copy link
Collaborator Author

Note @ernestum : ensure to treat all open comments in #765 here.

@ernestum ernestum self-assigned this Aug 28, 2023
@ernestum ernestum force-pushed the 734-gymnasium-compatibility-of-imitation branch 3 times, most recently from 4ddbba0 to 1fdee56 Compare September 12, 2023 12:41
@ernestum ernestum marked this pull request as ready for review September 12, 2023 14:11
@ernestum ernestum added this to the Release v1.0 milestone Sep 19, 2023
@AdamGleave
Copy link
Member

@dan-pandori could you review this since Juan is busy with an ICLR submission right now? Please do tag me in any areas of the code you're uncertain about.

Copy link
Contributor

@dan-pandori dan-pandori left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for cleaning up types in several places and the detailed PR description.

I just added a few minor nits about comments etc. I don't deeply understand the behavior of resetting the seed vs using seed(), so you should ask Adam if you want a better opinion on that.

docs/getting-started/installation.rst Show resolved Hide resolved
src/imitation/algorithms/density.py Show resolved Hide resolved
src/imitation/data/buffer.py Show resolved Hide resolved
src/imitation/data/rollout.py Outdated Show resolved Hide resolved
tests/algorithms/test_mce_irl.py Outdated Show resolved Hide resolved
tests/algorithms/test_mce_irl.py Outdated Show resolved Hide resolved
@AdamGleave AdamGleave merged commit 8db6bfb into master Sep 23, 2023
1 of 2 checks passed
@AdamGleave AdamGleave deleted the 734-gymnasium-compatibility-of-imitation branch September 23, 2023 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gymnasium compatibility of imitation Gym dependency will not install Add Gym/Gymnasium 0.26 support
5 participants