Giter Club home page Giter Club logo

Comments (5)

ahalev avatar ahalev commented on August 25, 2024 1

So I determined the issue, although I still think this behavior is suboptimal.

The problem is that I was using a wrapper like this

import gym
class BadWrapper(gym.Wrapper):
    def __getattr__(self, name):
        return getattr(self.env, name)

in order to be able to access protected variables of an environment if necessary. But this doesn't work when you deepcopy; you end up in an infinite recursion because __getattr__ continuously calls itself:

bad_wrapped_env = BadWrapper(gym.make('Pong-v0')) 
bad_copied_env = deepcopy(bad_wrapped_env) # This doesn't work

which raises

Traceback (most recent call last):
  File "/home/ahalev/.pycharm_helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/ahalev/mgrid/dev/garage_sandbox/wrapper_ex.py", line 17, in <module>
    bad_copied_env = deepcopy(bad_wrapped_env)
  File "/home/ahalev/.conda/envs/remote_env/lib/python3.6/copy.py", line 180, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/home/ahalev/.conda/envs/remote_env/lib/python3.6/copy.py", line 281, in _reconstruct
    if hasattr(y, '__setstate__'):
  File "/home/ahalev/mgrid/dev/garage_sandbox/wrapper_ex.py", line 10, in __getattr__
    return getattr(self.env, name)
  File "/home/ahalev/mgrid/dev/garage_sandbox/wrapper_ex.py", line 10, in __getattr__
    return getattr(self.env, name)
  File "/home/ahalev/mgrid/dev/garage_sandbox/wrapper_ex.py", line 10, in __getattr__
    return getattr(self.env, name)
  [Previous line repeated 992 more times]
  File "/home/ahalev/mgrid/dev/garage_sandbox/wrapper_ex.py", line 5, in __getattr__
    def __getattr__(self, name):
RecursionError: maximum recursion depth exceeded
python-BaseException
Traceback (most recent call last):
  File "/home/ahalev/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_resolver.py", line 213, in resolve
    return dict[key]
KeyError: '__exception__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/ahalev/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 1765, in do_it
    var_obj = pydevd_vars.getVariable(self.thread_id, self.frame_id, scope, attrs)
  File "/home/ahalev/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_vars.py", line 240, in getVariable
    var = resolver.resolve(var, k)
  File "/home/ahalev/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_resolver.py", line 215, in resolve
    return getattr(dict, key)
AttributeError: 'dict' object has no attribute '__exception__'

I guess this is why the original __getattr__ is written the way that it is, but it seems a little hack-y to me. Maybe even changing __getattr__ to

def __getattr__(self, name):
    if name.startswith("__"): # this allows for deepcopy
        raise AttributeError(
            "attempted to get missing private attribute '{}'".format(name)
        )
    return getattr(self.env, name)

would be better.

from acme.

qstanczyk avatar qstanczyk commented on August 25, 2024

This should be fixed at head now.

from acme.

ahalev avatar ahalev commented on August 25, 2024

I am also having this issue, with gym 0.21.0. Is there a fix available in a different version?

from acme.

qstanczyk avatar qstanczyk commented on August 25, 2024

Can you share a minimal repro of the problem?

from acme.

qstanczyk avatar qstanczyk commented on August 25, 2024

Yeah, I think we can give your suggestion a try. Thanks

from acme.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.