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

set_env_attr and get_env_attr not working with current gym release #688

Closed
4 of 8 tasks
seawee1 opened this issue Jul 6, 2022 · 4 comments · Fixed by #695
Closed
4 of 8 tasks

set_env_attr and get_env_attr not working with current gym release #688

seawee1 opened this issue Jul 6, 2022 · 4 comments · Fixed by #695
Labels
bug Something isn't working

Comments

@seawee1
Copy link

seawee1 commented Jul 6, 2022

  • I have marked all applicable categories:
    • exception-raising bug
    • RL algorithm bug
    • documentation request (i.e. "X is missing from the documentation.")
    • new feature request
  • I have visited the source website
  • I have searched through the issue tracker for duplicates
  • I have mentioned version numbers, operating system and environment, where applicable:

For completeness, I struggled to get your env.set_env_attr function to work. I found the error on OpenAI gym's side (see: openai/gym#2952). Maybe you could mention this issue somewhere in the documentation. I use gym 0.24.1.

@Trinkle23897 Trinkle23897 added the bug Something isn't working label Jul 6, 2022
@Trinkle23897
Copy link
Collaborator

Could you please provide an example here to show the bug? Thanks!

@seawee1
Copy link
Author

seawee1 commented Jul 7, 2022

Sure!

import gym
from tianshou.env import DummyVectorEnv

if __name__ == "__main__":
    def create_env():
        env = gym.make("CartPole-v1")
        print(type(env))  # <class 'gym.wrappers.time_limit.TimeLimit'>
        return env

    train_envs = DummyVectorEnv(
        [create_env]
    )

    train_envs.set_env_attr("test_attribute", 1337)
    print(train_envs.get_env_attr("test_attribute"))  # Returns: [1337]
    print(hasattr(train_envs.workers[0].env, "test_attribute"))  # Returns: True
    print(hasattr(train_envs.workers[0].env.unwrapped, "test_attribute"))  # Returns: False

You can see that train_envs.set_env_attr sets the attribute inside the wrapper, not the environment.

@Trinkle23897
Copy link
Collaborator

Fixed in #695

Trinkle23897 added a commit that referenced this issue Jul 15, 2022
@seawee1
Copy link
Author

seawee1 commented Jul 19, 2022

Cool, thanks!

BFAnas pushed a commit to BFAnas/tianshou that referenced this issue May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy