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

A VecCheckNan issue #489

Closed
ruifeng96150 opened this issue Sep 28, 2019 · 2 comments · Fixed by #491
Closed

A VecCheckNan issue #489

ruifeng96150 opened this issue Sep 28, 2019 · 2 comments · Fixed by #491
Labels
bug Something isn't working

Comments

@ruifeng96150
Copy link

when I enable the Nan Check env

 env = VecCheckNan(env, raise_exception=True)

the system will have a error like:

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/stable_baselines/ppo2/ppo2.py", line 318, in learn
    runner = Runner(env=self.env, model=self, n_steps=self.n_steps, gamma=self.gamma, lam=self.lam)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/stable_baselines/ppo2/ppo2.py", line 442, in __init__
    super().__init__(env=env, model=model, n_steps=n_steps)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/stable_baselines/common/runners.py", line 19, in __init__
    self.obs[:] = env.reset()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/stable_baselines/common/vec_env/vec_check_nan.py", line 46, in reset
    self._check_val(async_step=False, observations=observations)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/stable_baselines/common/vec_env/vec_check_nan.py", line 58, in _check_val
    has_nan = any(np.isnan(val))
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

And I find that is cause by 2d array like following test:

import numpy as np

#val = np.array([0, 0, 1, 0]) # it is run ok
val = np.array([[0, 0, 1, 0], [0, 0, 1, 0]]) # it is run same error as above
has_nan = any(np.isnan(val))
print(has_nan)

and the stable-baselines at vec_check_nan like this:

def _check_val(self, *, async_step, **kwargs):
        # if warn and warn once and have warned once: then stop checking
        if not self.raise_exception and self.warn_once and self._user_warned:
            return

        found = []
        for name, val in kwargs.items():
            has_nan = any(np.isnan(val))
            has_inf = self.check_inf and any(np.isinf(val))
            if has_inf:
                found.append((name, "inf"))
            if has_nan:
                found.append((name, "nan"))

To fix this problem, I think that need change from 'any' to 'np.any'.

System Info
Describe the characteristic of your environment:

  • Describe how the library was installed (pip)
  • GPU models and configuration Mac
  • Python version 3.6.8
  • Tensorflow version 1.4.0
@araffin araffin added the bug Something isn't working label Sep 28, 2019
@araffin
Copy link
Collaborator

araffin commented Sep 28, 2019

Hello,

Thanks for reporting the bug.
In fact there was an (incomplete) PR for solving it: #386
We would appreciate if you could complete it ;) (especially writing a test)

@ruifeng96150
Copy link
Author

Ok I just add test and modify the code, please review
#491

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