The Wayback Machine - https://web.archive.org/web/20231028150122/https://github.com/Unity-Technologies/ml-agents/pull/3793
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

Added the first version of the GymToUnityWrapper #3793

Closed
wants to merge 19 commits into from

Conversation

vincentpierre
Copy link
Contributor

@vincentpierre vincentpierre commented Apr 16, 2020

Proposed change(s)

Need to add some tests to make sure it works.
Also need to add some tests for our trainers using gym environments (taking suggestions)
Only workd for single Box observation, Box or Discrete action.

I do not want to change the documentation yet, I would like to first make sure it is useful for our tests.

Outstanding question : Is it okay for us to have a dependency on gym and gym[atari]? One alternative would be to have a try catch in the gym_wrapper at import and raise an error if gym is not installed as well as adding the pip install gym when running our CI tests. Thoughts?

Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)

MLA-707

Types of change(s)

  • Bug fix
  • New feature
  • Code refactor
  • Breaking change
  • Documentation update
  • Other (please describe)

Checklist

  • Added tests that prove my fix is effective or that my feature works
  • Updated the changelog (if applicable)
  • Updated the documentation (if applicable)
  • Updated the migration guide (if applicable)

Other comments

@vincentpierre vincentpierre self-assigned this Apr 16, 2020
@vincentpierre vincentpierre marked this pull request as ready for review April 17, 2020 18:32
"gym",
"cmake",
"atari-py",
"opencv-python",
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a pretty heavyweight package BTW, on some platforms it will need to re-compile opencv.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Outstanding question : Is it okay for us to have a dependency on gym and gym[atari]? One alternative would be to have a try catch in the gym_wrapper at import and raise an error if gym is not installed as well as adding the pip install gym when running our CI tests. Thoughts?

We could make it optional? We could also remove the atari test, this way, no dependency on atari or opencv

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, you should NOT put these in ml-agents-envs. No preference between gym-unity and another package.

@ervteng
Copy link
Contributor

ervteng commented Apr 17, 2020

Wrapper itself looks great!

Should we put the wrapper in gym-unity vs. ml-agents-envs? Not sure if we should have packages like cmake, atari-py, and opencv in our list of requirements for the ml-agents-envs package.

@vincentpierre
Copy link
Contributor Author

Should we put the wrapper in gym-unity vs. ml-agents-envs?

Not sure, if the only reason is dependencies, I would say no.
I think gym-unity serves a specific purpose unity -> gym and not the other way around.

Make another package : ) ?

gym_env = gym.make(name)
env = GymToUnityWrapper(gym_env, name)
assert env.get_behavior_names()[0] == name
if isinstance(gym_env.action_space, gym.spaces.Box):
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is a meaningful test, since you're just duplicating the logic from the code.

A better approach would be having an expected ActionType for each gym env and making sure that's set correctly.

from mlagents_envs.gym_wrapper import GymToUnityWrapper
from mlagents_envs.base_env import ActionType

try:
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment as gym_wrapper.py. Pretty sure that this file will always get imported by pytest, so mlagents-envs will not be runnable on their own.

@chriselion
Copy link
Contributor

Sorry, after looking more at this, I think this should not go in ml-agents-envs. gym-unity is more appropriate and keeps the gym dependency simpler.

@vincentpierre
Copy link
Contributor Author

vincentpierre commented Apr 21, 2020

Sorry, after looking more at this, I think this should not go in ml-agents-envs. gym-unity is more appropriate and keeps the gym dependency simpler.

I disagree, gym has a very specific purpose and also a very specific directory structure (dictated by gym). All the gym code lives in the __init__ file. Dependency matching does not sound like a good enough reason to me, this wrapper creates a UnityEnvironment, as such, I think it should be in ml-agents-envs. @ervteng @awjuliani any thoughts on this? Where do you think it should live?

@awjuliani
Copy link
Contributor

We should have gym-unity and unity-gym.

@vincentpierre
Copy link
Contributor Author

We should have gym-unity and unity-gym.

So, create a new package ?

@chriselion
Copy link
Contributor

In that case, I think either add another package, or add gym to the dependencies in setup.py

@vincentpierre vincentpierre changed the title Added the first version of the GymWrapper Added the first version of the GymToUnityWrapper Apr 21, 2020
@ervteng
Copy link
Contributor

ervteng commented Apr 21, 2020

Sorry, after looking more at this, I think this should not go in ml-agents-envs. gym-unity is more appropriate and keeps the gym dependency simpler.

I disagree, gym has a very specific purpose and also a very specific directory structure (dictated by gym). All the gym code lives in the __init__ file. Dependency matching does not sound like a good enough reason to me, this wrapper creates a UnityEnvironment, as such, I think it should be in ml-agents-envs. @ervteng @awjuliani any thoughts on this? Where do you think it should live?

Are we using the special directory structure that gym requires? It seems they do so b/c of the registry, but we don't register the environment. It also seems that it's OK to have additional files other than __init__.py as long as the init is the entry point for the registry. If we don't plan on using the registry ever, I think adding it to gym-unity (even if it breaks the structure) is OK.

Is the opencv requirement dictated by Gym?

@vincentpierre
Copy link
Contributor Author

Is the opencv requirement dictated by Gym?

Only if we want to use Atari environments (removed it)

@ervteng
Copy link
Contributor

ervteng commented Apr 21, 2020

Is the opencv requirement dictated by Gym?

Only if we want to use Atari environments (removed it)

I think gym by itself is lightweight enough to require in ml-agents-envs if need be, so I'm ok with that.

@vincentpierre
Copy link
Contributor Author

@ervteng If we put this wrapper with the other gym wrapper, would we be okay having our trainers have a dependency on gym-unity? We might want to test our trainers with some gym environments latter.

@ervteng
Copy link
Contributor

ervteng commented Apr 27, 2020

@vincentpierre I think that is OK. Would let us train gym envs using our trainer easily.

@vincentpierre
Copy link
Contributor Author

@ervteng If you want to have a look at the latest commit. We do okay on cartpole (not perfect) but it seems montain-car is posing problems (maybe an issue with the wrapper and max_step)

Base automatically changed from master to main February 25, 2021 19:15
@miguelalonsojr
Copy link
Collaborator

Closing PR as stale.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants