Skip to content

Tests env #36

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Tests env #36

wants to merge 8 commits into from

Conversation

AboudyKreidieh
Copy link
Collaborator

  • added tests to a few of the environments to make sure that people that they do not change and that special features in each environment are functioning correctly (e.g. the reset in WaveAttenuationEnv)
  • some minor bug fixes that I picked up on in base_env and the Vehicles class while writing the environment tests

Copy link
Collaborator

@nskh nskh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Just two small questions/comments.


self.visible.extend(lane_leaders)
self.visible.extend(lane_followers)
self.visible.extend([lane_follower])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these changes just to more clearly show when the list of visible cars is being changed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is to fix a bug where the list of visible vehicles sometimes includes '' strings

eta = 8 # 0.25
rl_actions = np.array([1])
accel_threshold = 0
np.tanh(np.mean(np.abs(rl_actions)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this line supposed to do anything?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch, will fix

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -124,6 +124,18 @@ def __init__(self, env_params, sumo_params, scenario):
if not hasattr(self.env_params, "evaluate"):
self.env_params.evaluate = False

# list of sorted ids (defaults to regular list of vehicle ids if the
# "sort_vehicles" attribute in env_params is set to False)
self.sorted_ids = deepcopy(self.vehicles.get_ids())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem like it's sorted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, I'll call the method here as well

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


class TestTestEnv(unittest.TestCase):

"""Tests the TestEnv environment in flow/envs/test.py"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a comment, but the name of this class is surreal.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahaha

/ self.env.scenario.max_speed,
self.env.get_x_by_id(veh_id) /
self.env.scenario.length]
for veh_id in self.env.sorted_ids])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sort of agree with Nish, what is the point of tests like these? This is just copying code and checking that the code you've copied is the same. Note, this is meant constructively; I'm sure I'm missing something.

Copy link
Collaborator Author

@AboudyKreidieh AboudyKreidieh Aug 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they're for two reasons:

  • solidifying certain aspects of the codebase that we are not interested in developing on anymore. Personally for me, the environments feel very fragile as is.
  • maintaining some level of confidence that an environment will train. since we cannot easily run RL tests to completion, we can at least ensure that the environments are still the same (I have lost a good deal of time trying to figure out what's changed in an old environment just to find out that I or someone else had introduced new bugs, probably when they were trying something locally)

generally speaking, tests for environments should cover more intricate methods, but the ones I tested were pretty generic, minus I guess testing the reset method for WaveAttenuationEnv

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'm convinced of the value of this for now. We should replace these later with some sort of regression testing (TBD).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in conclusion, it's a saved version of the envs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, I was thinking the same about regression testing. these could just be a sanity test for now

@eugenevinitsky
Copy link
Collaborator

Broadly, what's the point of these tests of the envs? It seems like the code is copied from the original env and then we check that the code has been copied correctly.

kjang96 pushed a commit to kjang96/flow that referenced this pull request Aug 17, 2018
@@ -29,17 +29,20 @@ class and returns a real number.

@property
def action_space(self):
return Box(low=0, high=0, shape=0, dtype=np.float32)
return Box(low=0, high=0, shape=(0,), dtype=np.float32)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should not be named test.py as it's a little confusing

self.assertAlmostEqual(self.env.vehicles.get_speed("rl_0"), 0.1, 2)


class TestLaneChangeAccelEnv(unittest.TestCase):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this test is specific to the loop, it's a little misnamed

Copy link
Collaborator

@eugenevinitsky eugenevinitsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, see +1 comment as it is unaddressed I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants