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

Colab Jupyter Notebook Demo #1300

Merged
merged 183 commits into from
Jul 12, 2022
Merged

Colab Jupyter Notebook Demo #1300

merged 183 commits into from
Jul 12, 2022

Conversation

Gamenot
Copy link
Collaborator

@Gamenot Gamenot commented Feb 26, 2022

Mock-up of notebook demos.

@Gamenot Gamenot changed the title Colab Jupyter Notebook Demo [Draft] Colab Jupyter Notebook Demo Feb 26, 2022
Comment on lines 1 to 29
import sys

sys.path.insert(0, "./examples/env")
sys.path.insert(0, "./zoo")
import baseline
import policies.keep_lane_agent

import gym

from smarts.zoo import registry
from smarts.env.wrappers.episode_logger import EpisodeLogger
from smarts.env.wrappers.record import RecordVideo, RenderVideo
from smarts.core.utils.episodes import episode_range

# FormatObs should already be applied
env = gym.make("figure_eight-v0")
# gym.wrappers.Monitor
env: gym.Env = RecordVideo(env, frequency=10)
env: gym.Env = RenderVideo(env)
env: gym.Env = EpisodeLogger(env)

agent = registry.make_agent("zoo.policies:keep-lane-agent-v0")
for episode in episode_range(max_steps=450):
observation = env.reset()
reward, done, info = None, False, None
while episode.register_step(observation, reward, done, info):
action = agent.act(observation)
observation, reward, done, info = env.step(action)

env.close()
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 an experiment that works without errors. Further most work will be within the implementation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Adaickalavan Adaickalavan requested a review from a team March 23, 2022 14:25
@Gamenot Gamenot changed the title [Draft] Colab Jupyter Notebook Demo Colab Jupyter Notebook Demo Mar 23, 2022
# FormatObs should already be applied
env = gym.make("figure_eight-v0")
# gym.wrappers.Monitor
env: gym.Env = RecordVideo(env, frequency=10, name="007-render")
Copy link
Member

Choose a reason for hiding this comment

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

Will the from smarts.env.wrappers.record import RecordVideo solution work with vectorized environments?

Suggestion:

  1. Currently our env.render() in hiway_env.py simply passes.
  2. Move the image rendering to env.render(), whenever the camera-sensor is enabled in smarts.
  3. Then, users can use smarts with the video recorders available from and widely used in gym based codes.
  4. As a result, we will be more gym friendly and we do not need to build and maintain any of our own video recorder.

Examples of existing video recorders:

  1. gym

  2. sb3

  3. sb3

Copy link
Collaborator Author

@Gamenot Gamenot Mar 24, 2022

Choose a reason for hiding this comment

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

Sure, I was trying to avoid keeping around state for gym.render(..).

I believe I could switch the RecordVideo wrapper to something like CameraRender to store the state needed pass out render() frames so that we can use those frameworks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was going about implementing this and found that the gym version that implements this properly is gym>=0.18 due to this: openai/gym#2139 ...

It conflicts with Colab because annoyingly they start Colab with gym==0.17.3 so it requires a reload to use it.

Copy link
Member

@Adaickalavan Adaickalavan Jun 20, 2022

Choose a reason for hiding this comment

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

I somewhat still think that trying to please Colab by matching our package versions to that of Colab results in some funny code and funny package versions in setup.py. It would be better to align our code with other RL libraries instead, and simply reload to update dependencies while using Colab for the time being until there is a better way of using Colab.

@Gamenot
Copy link
Collaborator Author

Gamenot commented Mar 24, 2022

It looks like we may have some problems with grpcio. I may need to split out that dependency since it conflicts with Colab.

gif_num += 1


def show_notebook_videos(path="videos", height="400px", split_html=""):
Copy link
Member

Choose a reason for hiding this comment

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

Compared to writing our own video/image display code, we should consider writing video/image to tensorboard for display.

%load_ext tensorboard
%tensorboard --logdir <summary_directory>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That might be reasonable. I will try it out.

Copy link
Member

Choose a reason for hiding this comment

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

setup.py Outdated Show resolved Hide resolved
from smarts.env.wrappers.record_video import RecordVideo
from smarts.zoo import registry

if __name__ == "__main__":
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps this file can be removed in the final commit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes that is the intention.

"id": "wkR0YvENQni4"
},
"source": [
"**Setup dependencies**"
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we can move this file into SMARTS/examples/env folder and rename it to SMARTS/examples/env/create_run_visualize.ipynb.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A rename is in order I will leave that to the end when I delete demo_test.py.

requirements.txt Outdated Show resolved Hide resolved
@Gamenot Gamenot merged commit 234f374 into develop Jul 12, 2022
@Adaickalavan Adaickalavan deleted the ipynb-test-deps branch January 23, 2023 16:40
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.

5 participants