Skip to content
Snippets Groups Projects
Commit f4bc62a8 authored by adrian_egli2's avatar adrian_egli2
Browse files

Jupyter notebooks are ready for flatland3.

But they should be overworked. Might just one example per use case would be much more clear. TODO - cleanup
parent 009d2b0e
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Simple Animation Demo # Simple Animation Demo
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
%load_ext autoreload %load_ext autoreload
%autoreload 2 %autoreload 2
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from flatland.utils.rendertools import RenderTool from flatland.utils.rendertools import RenderTool
import ipycanvas import ipycanvas
import time import time
from flatland.envs.rail_env import RailEnv from flatland.envs.rail_env import RailEnv
from flatland.envs.rail_env import RailEnvActions as rea from flatland.envs.rail_env import RailEnvActions as rea
from flatland.envs.persistence import RailEnvPersister from flatland.envs.persistence import RailEnvPersister
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
env, env_dict = RailEnvPersister.load_new("complex_scene_2.pkl", load_from_package="env_data.railway") env, env_dict = RailEnvPersister.load_new("complex_scene_2.pkl", load_from_package="env_data.railway")
_ = env.reset() _ = env.reset()
env._max_episode_steps = 100 env._max_episode_steps = 100
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
oRT = RenderTool(env) oRT = RenderTool(env, gl="PILSVG")
oRT.render_env() oRT.render_env(show_observations=False,show_predictions=False)
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
image_arr = oRT.get_image() image_arr = oRT.get_image()
canvas = ipycanvas.Canvas() canvas = ipycanvas.Canvas()
canvas.put_image_data(image_arr) canvas.put_image_data(image_arr)
display(canvas) display(canvas)
done={"__all__":False} done={"__all__":False}
while not done["__all__"]: while not done["__all__"]:
actions = {} actions = {}
for agent_handle, agents in enumerate(env.agents): for agent_handle, agents in enumerate(env.agents):
actions.update({agent_handle:rea.MOVE_FORWARD}) actions.update({agent_handle:rea.MOVE_FORWARD})
obs, rew, done, info = env.step(actions) obs, rew, done, info = env.step(actions)
oRT.render_env() oRT.render_env(show_observations=False,show_predictions=False)
gIm = oRT.get_image() gIm = oRT.get_image()
canvas.put_image_data(gIm) canvas.put_image_data(gIm)
time.sleep(0.1) time.sleep(0.1)
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment