Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Flatland
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pranjal_dhole
Flatland
Commits
e04f9679
Commit
e04f9679
authored
4 years ago
by
hagrid67
Browse files
Options
Downloads
Patches
Plain Diff
adding flatland-animate notebook. Simple animation.
parent
991618a8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
notebooks/flatland-animate.ipynb
+226
-0
226 additions, 0 deletions
notebooks/flatland-animate.ipynb
with
226 additions
and
0 deletions
notebooks/flatland-animate.ipynb
0 → 100644
+
226
−
0
View file @
e04f9679
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Simple Animation Demo"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from flatland.utils.rendertools import RenderTool\n",
"import ipycanvas\n",
"import time\n",
"from flatland.envs.rail_env import RailEnv\n",
"from flatland.envs.rail_env import RailEnvActions as rea\n",
"from flatland.envs.persistence import RailEnvPersister"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"env, env_dict = RailEnvPersister.load_new(\"test_env_loop.pkl\", load_from_package=\"env_data.tests\")\n",
"oRT = RenderTool(env)\n",
"oRT.render_env()\n",
"image_arr = oRT.get_image()\n",
"canvas = ipycanvas.Canvas()\n",
"canvas.put_image_data(image_arr)\n",
"display(canvas)\n",
"\n",
"for iEp in range(5):\n",
" env.reset(False, False, True)\n",
" env._max_episode_steps = 100\n",
"\n",
" done={\"__all__\":False}\n",
" while not done[\"__all__\"]:\n",
" obs, rew, done, info = env.step(action_dict_={int(0):rea.MOVE_FORWARD})\n",
" oRT.render_env()\n",
" gIm = oRT.get_image()\n",
" canvas.put_image_data(gIm)\n",
" time.sleep(0.1)"
]
}
],
"metadata": {
"hide_input": false,
"kernelspec": {
"display_name": "ve367",
"language": "python",
"name": "ve367"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
"autoclose": false,
"autocomplete": true,
"bibliofile": "biblio.bib",
"cite_by": "apalike",
"current_citInitial": 1,
"eqLabelWithNumbers": true,
"eqNumInitial": 1,
"hotkeys": {
"equation": "Ctrl-E",
"itemize": "Ctrl-I"
},
"labels_anchors": false,
"latex_user_defs": false,
"report_style_numbering": false,
"user_envs_cfg": false
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {
"2433ff4d1b324fac968f6109f0a61185": {
"model_module": "@jupyter-widgets/base",
"model_module_version": "1.2.0",
"model_name": "LayoutModel",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": "500px",
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": "700px"
}
},
"f2dc1da3e8c74208b9627e97e8630a5f": {
"model_module": "ipycanvas",
"model_module_version": "^0.4.1",
"model_name": "CanvasModel",
"state": {
"_dom_classes": [],
"_model_module": "ipycanvas",
"_model_module_version": "^0.4.1",
"_model_name": "CanvasModel",
"_view_count": null,
"_view_module": "ipycanvas",
"_view_module_version": "^0.4.1",
"_view_name": "CanvasView",
"image_data": null,
"layout": "IPY_MODEL_2433ff4d1b324fac968f6109f0a61185",
"size": [
700,
500
],
"sync_image_data": false
}
}
},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
%% Cell type:markdown id: tags:
# Simple Animation Demo
%% Cell type:code id: tags:
```
python
%
load_ext
autoreload
%
autoreload
2
```
%% Cell type:code id: tags:
```
python
from
flatland.utils.rendertools
import
RenderTool
import
ipycanvas
import
time
from
flatland.envs.rail_env
import
RailEnv
from
flatland.envs.rail_env
import
RailEnvActions
as
rea
from
flatland.envs.persistence
import
RailEnvPersister
```
%% Cell type:code id: tags:
```
python
env
,
env_dict
=
RailEnvPersister
.
load_new
(
"
test_env_loop.pkl
"
,
load_from_package
=
"
env_data.tests
"
)
oRT
=
RenderTool
(
env
)
oRT
.
render_env
()
image_arr
=
oRT
.
get_image
()
canvas
=
ipycanvas
.
Canvas
()
canvas
.
put_image_data
(
image_arr
)
display
(
canvas
)
for
iEp
in
range
(
5
):
env
.
reset
(
False
,
False
,
True
)
env
.
_max_episode_steps
=
100
done
=
{
"
__all__
"
:
False
}
while
not
done
[
"
__all__
"
]:
obs
,
rew
,
done
,
info
=
env
.
step
(
action_dict_
=
{
int
(
0
):
rea
.
MOVE_FORWARD
})
oRT
.
render_env
()
gIm
=
oRT
.
get_image
()
canvas
.
put_image_data
(
gIm
)
time
.
sleep
(
0.1
)
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment