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

Lazily import locomotion envs to prevent ModuleNotFoundError when labmaze is not installed #125

Merged

Conversation

GaetanLepage
Copy link
Contributor

@GaetanLepage GaetanLepage commented Oct 8, 2024

Description

Context: bumping Shimmy version in nixpkgs

Unfortunately, we don't have labmaze packaged and this prevents shimmy from being imported at all:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 1, in <lambda>
  File "/nix/store/zy22nlap6gznpjhqry4w0hgw5mf62q3f-python3-3.11.9/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/nix/store/q5ry6cvhi5zl8rhhw65a14xk9dal4861-python3.11-shimmy-2.0.0/lib/python3.11/site-packages/shimmy/__init__.py", line 11, in <module>
    register_gymnasium_envs()
  File "/nix/store/q5ry6cvhi5zl8rhhw65a14xk9dal4861-python3.11-shimmy-2.0.0/lib/python3.11/site-packages/shimmy/registration.py", line 180, in register_gymnasium_envs
    _register_dm_control_envs()
  File "/nix/store/q5ry6cvhi5zl8rhhw65a14xk9dal4861-python3.11-shimmy-2.0.0/lib/python3.11/site-packages/shimmy/registration.py", line 102, in _register_dm_control_envs
    from dm_control.locomotion.examples import basic_cmu_2019, basic_rodent_2020
  File "/nix/store/7aqjra9cd3hmwkx0jv81flnbrwwj8jf6-python3.11-dm-control-1.0.23/lib/python3.11/site-packages/dm_control/locomotion/examples/basic_cmu_2019.py", line 22, in <module>
    from dm_control.locomotion.arenas import corridors as corr_arenas
  File "/nix/store/7aqjra9cd3hmwkx0jv81flnbrwwj8jf6-python3.11-dm-control-1.0.23/lib/python3.11/site-packages/dm_control/locomotion/arenas/__init__.py", line 22, in <module>
    from dm_control.locomotion.arenas.labmaze_textures import FloorTextures
  File "/nix/store/7aqjra9cd3hmwkx0jv81flnbrwwj8jf6-python3.11-dm-control-1.0.23/lib/python3.11/site-packages/dm_control/locomotion/arenas/labmaze_textures.py", line 20, in <module>
    from labmaze import assets as labmaze_assets
ModuleNotFoundError: No module named 'labmaze'

This patch gracefully ignores such an ImportError and simply skips the registration of the labmaze-dependent environments in this case.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update (not sure)

Checklist:

  • I have run the pre-commit checks with pre-commit run --all-files (see CONTRIBUTING.md instructions to set it up)
  • I have run pytest -v and no errors are present.
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I solved any possible warnings that pytest -v has generated that are related to my code to the best of my knowledge.
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Member

@pseudo-rnd-thoughts pseudo-rnd-thoughts left a comment

Choose a reason for hiding this comment

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

Thanks for the PR

@pseudo-rnd-thoughts
Copy link
Member

dm_control seems to be failing for reasons unrelated to your PR

@pseudo-rnd-thoughts pseudo-rnd-thoughts merged commit 095d576 into Farama-Foundation:main Oct 8, 2024
7 of 13 checks passed
@GaetanLepage
Copy link
Contributor Author

Thanks !

@GaetanLepage GaetanLepage deleted the lazy-import branch October 8, 2024 14:39
@GaetanLepage GaetanLepage restored the lazy-import branch October 8, 2024 14:39
@GaetanLepage GaetanLepage deleted the lazy-import branch October 8, 2024 14:39
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.

2 participants