Skip to content

Commit

Permalink
A VecCheckNan issue (#491)
Browse files Browse the repository at this point in the history
* Update test_vec_check_nan.py

add test for numpy ndarray

* Update vec_check_nan.py

* Update test_vec_check_nan.py

add some space

* Update changelog.rst

* Update changelog.rst

* Update test_vec_check_nan.py

* Update docs/misc/changelog.rst

Co-Authored-By: Antonin RAFFIN <antonin.raffin@ensta.org>

* Update changelog.rst

* Update test_vec_check_nan.py
  • Loading branch information
ruifeng96150 authored and araffin committed Sep 28, 2019
1 parent 46d13b4 commit f6ab57c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/misc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Bug Fixes:
`Issue #430 <https://github.com/hill-a/stable-baselines/issues/430>`_.
- Fix a bug when calling `logger.configure()` with MPI enabled (@keshaviyengar)
- set `allow_pickle=True` for numpy>=1.17.0 when loading expert dataset
- Fix a bug when using VecCheckNan with numpy ndarray as state. `Issue #489 <https://github.com/hill-a/stable-baselines/issues/489>`_.

Deprecations:
^^^^^^^^^^^^^
Expand Down Expand Up @@ -481,4 +482,4 @@ In random order...
Thanks to @bjmuld @iambenzo @iandanforth @r7vme @brendenpetersen @huvar @abhiskk @JohannesAck
@EliasHasle @mrakgr @Bleyddyn @antoine-galataud @junhyeokahn @AdamGleave @keshaviyengar @tperol
@XMaster96 @kantneel @Pastafarianist @GerardMaggiolino @PatrickWalter214 @yutingsz @sc420 @Aaahh @billtubbs
@Miffyli @dwiel @miguelrass @qxcv @jaberkow @eavelardev
@Miffyli @dwiel @miguelrass @qxcv @jaberkow @eavelardev @ruifeng96150
4 changes: 2 additions & 2 deletions stable_baselines/common/vec_env/vec_check_nan.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def _check_val(self, *, async_step, **kwargs):

found = []
for name, val in kwargs.items():
has_nan = any(np.isnan(val))
has_inf = self.check_inf and any(np.isinf(val))
has_nan = np.any(np.isnan(val))
has_inf = self.check_inf and np.any(np.isinf(val))
if has_inf:
found.append((name, "inf"))
if has_nan:
Expand Down
6 changes: 4 additions & 2 deletions tests/test_vec_check_nan.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def __init__(self):

@staticmethod
def step(action):
if all(np.array(action) > 0):
if np.all(np.array(action) > 0):
obs = float('NaN')
elif all(np.array(action) < 0):
elif np.all(np.array(action) < 0):
obs = float('inf')
else:
obs = 0
Expand Down Expand Up @@ -68,3 +68,5 @@ def test_check_nan():
else:
assert False


env.step(np.array([[0, 1], [0, 1]]))

0 comments on commit f6ab57c

Please sign in to comment.