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

[Enhancement] Deprecate --gym-packages argument #390

Open
1 task done
ernestum opened this issue Jul 5, 2023 · 5 comments
Open
1 task done

[Enhancement] Deprecate --gym-packages argument #390

ernestum opened this issue Jul 5, 2023 · 5 comments
Labels
enhancement New feature or request help wanted Help from contributors is needed

Comments

@ernestum
Copy link
Collaborator

ernestum commented Jul 5, 2023

🚀 Feature

Deprecate or even remove the --gym-packages argument.

Motivation

Since gym 0.21.0 you can pass <package>:<gym_id> to gym.make() to make it automatically import the given package. This turns the --gym-packages flag into duplicate functionality that unnecessarily clutters the interface.

Pitch

Remove the argument and add a hint about the feature in the documentation.

Alternatives

No response

Additional context

I learned about this feature by @RedTachyon here

Checklist

  • I have checked that there is no similar issue in the repo
@ernestum ernestum added the enhancement New feature or request label Jul 5, 2023
@araffin
Copy link
Member

araffin commented Jul 5, 2023

Since gym 0.21.0 you can pass :<gym_id> to gym.make() to make it automatically import the given package.

Interesting... I didn't know about that undocumented feature. Yes, makes sense then (and we need to double check but the yaml/python config file should work too with this). The other thing we need to double check is the name convention for the envs.

@RedTachyon
Copy link

To explain in some more detail how it works: if you do gym.make("module_name:envid-v0"), then internally it gets split on the colon into module_name and envid-v0. Internally then it calls importlib.import_module("module_name"), i.e. roughly the same as import package_name

If this module registers some environments upon being imported, then those environments are then in scope and are created with the usual gym.make("envid-v0")

FWIW the feature is documented in Gymnasium, but maybe not as exposed as it should be

@araffin araffin changed the title [Enhencement] Deprecate --gym-packages argument [Enhancement] Deprecate --gym-packages argument Jul 5, 2023
@araffin
Copy link
Member

araffin commented Jul 5, 2023

To explain in some more detail how it works: if you do gym.make("module_name:envid-v0"), then internally it gets split on the colon into module_name and envid-v0. Internally then it calls importlib.import_module("module_name")

yes, that's what --gym-packages is doing too.

After a quick check, gym.make("module:env-id") works but not gym.spec("module:env-id"), we need to see if we still need that.

# Define make_env here so it works with subprocesses
# when the registry was modified with `--gym-packages`
# See https://github.com/HumanCompatibleAI/imitation/pull/160
try:
spec = gym.spec(self.env_name.gym_id)

@araffin
Copy link
Member

araffin commented Jul 5, 2023

We will also have another problem:

registered_envs = set(gym.envs.registry.keys()) # pytype: disable=module-attr
# Add gym 0.26 envs
registered_envs.update(gym26.envs.registry.keys()) # pytype: disable=module-attr
# If the environment is not found, suggest the closest match
if env_id not in registered_envs:
try:
closest_match = difflib.get_close_matches(env_id, registered_envs, n=1)[0]
except IndexError:
closest_match = "'no close match found...'"
raise ValueError(f"{env_id} not found in gym registry, you maybe meant {closest_match}?")

EDIT: we can skip that check when module:env-id is passed.

@ernestum
Copy link
Collaborator Author

ernestum commented Jul 5, 2023

BTW: environment name normalization for gym_ids with this prefix should be fixed soonish: huggingface/huggingface_sb3#32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Help from contributors is needed
Projects
None yet
Development

No branches or pull requests

3 participants