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

Check If max_episode_length is None is NPO #2193

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/garage/tf/algos/npo.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ def __init__(self,
if pg_loss not in ['vanilla', 'surrogate', 'surrogate_clip']:
raise ValueError('Invalid pg_loss')

if self.max_episode_length == None:
raise ValueError('max_episode_length must not be None')

self._optimizer = make_optimizer(optimizer, **optimizer_args)
self._lr_clip_range = float(lr_clip_range)
self._max_kl_step = float(max_kl_step)
Expand Down
16 changes: 16 additions & 0 deletions tests/garage/tf/algos/test_npo.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ def test_npo_with_invalid_no_entropy_configuration(self):
entropy_method='no_entropy',
policy_ent_coeff=0.02,
)

@pytest.mark.mujoco
def test_npo_with_invalid_max_episode_length(self):
"""Test NPO with invalid max_episode_length."""
with pytest.raises(ValueError):
env = normalize(
GymEnv('InvertedDoublePendulum-v2', max_episode_length=None))
NPO(
env_spec=env.spec,
policy=self.policy,
baseline=self.baseline,
sampler=self.sampler,
discount=0.99,
gae_lambda=0.98,
policy_ent_coeff=0.0
)

def teardown_method(self):
self.env.close()
Expand Down