[go: nahoru, domu]

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

PyEnvironmentBaseWrapper doesn't forward batch_size and batched calls. #69

Closed
npfp opened this issue Apr 8, 2019 · 2 comments
Closed
Labels
contributions welcome type:bug Something isn't working

Comments

@npfp
Copy link
Contributor
npfp commented Apr 8, 2019

Hi,

We found what seems as a bug in ActionDiscretizeWrapper. The following piece of code won't raise any exceptions even through we believe it should:

class TestBug(tf.test.TestCase):

    def testBugWrapper(self):
        obs_spec = array_spec.BoundedArraySpec((2, 3), np.int32, -10, 10)
        action_spec = array_spec.BoundedArraySpec((1,), np.int32, -10, 10)
        nested_env = random_py_environment.RandomPyEnvironment(
            obs_spec,
            action_spec,
            reward_fn=lambda *_: np.array([1.0]),
            batch_size=2)
        env = wrappers.ActionDiscretizeWrapper(nested_env, num_actions=100)
        self.assertNotEqual(env.batched, nested_env.batched)  # Don't raise when it should
        self.assertNotEqual(nested_env.batch_size, env.batch_size)  # Don't raise when it should

Issue comes from

class PyEnvironmentBaseWrapper(py_environment.PyEnvironment):
  """PyEnvironment wrapper forwards calls to the given environment."""

  def __getattr__(self, name):
    """Forward all other calls to the base environment."""
    return getattr(self._env, name)

which doesn't forward the batched and batch_size properties to the wrapped environment as they are defined in the parent class.

Adding explicit calls to the properties would fix the issue:

  @property
  def batched(self):
    return self._env.bacthed

  @property
  def batch_size(self):
    return self._env.batch_size
@sguada
Copy link
Member
sguada commented Apr 8, 2019

Thanks for reporting this bug, if you want to make a PR to fix it, happy to review it. Include the fix and the test.

@sguada sguada added type:bug Something isn't working contributions welcome labels Apr 8, 2019
@npfp
Copy link
Contributor Author
npfp commented Apr 8, 2019

Sure, I'll make a PR later on today.

tf-agents-copybara pushed a commit that referenced this issue Apr 10, 2019
PiperOrigin-RevId: 242788821
Change-Id: I2665958ad85a3cfd0965c1891654e26f34d9da98
@sguada sguada closed this as completed Apr 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributions welcome type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants