vimmoos@Thor commited on
Commit
68a1b29
·
1 Parent(s): 903d8df

some profiling + optimization

Browse files
poetry.lock CHANGED
@@ -1196,6 +1196,28 @@ files = [
1196
  {file = "nvidia_nvtx_cu12-12.1.105-py3-none-win_amd64.whl", hash = "sha256:65f4d98982b31b60026e0e6de73fbdfc09d08a96f4656dd3665ca616a11e1e82"},
1197
  ]
1198
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1199
  [[package]]
1200
  name = "packaging"
1201
  version = "24.1"
@@ -1559,6 +1581,46 @@ files = [
1559
  [package.extras]
1560
  windows-terminal = ["colorama (>=0.4.6)"]
1561
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1562
  [[package]]
1563
  name = "pylatexenc"
1564
  version = "2.10"
@@ -2023,6 +2085,21 @@ files = [
2023
  [package.dependencies]
2024
  streamlit = ">=0.75"
2025
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2026
  [[package]]
2027
  name = "swig"
2028
  version = "4.2.1"
@@ -2329,4 +2406,4 @@ watchmedo = ["PyYAML (>=3.10)"]
2329
  [metadata]
2330
  lock-version = "2.0"
2331
  python-versions = "3.10.14"
2332
- content-hash = "f767bbf8a5395a83cb5196ec5a0313fcc057af9023b4430c635f5135e65c1eff"
 
1196
  {file = "nvidia_nvtx_cu12-12.1.105-py3-none-win_amd64.whl", hash = "sha256:65f4d98982b31b60026e0e6de73fbdfc09d08a96f4656dd3665ca616a11e1e82"},
1197
  ]
1198
 
1199
+ [[package]]
1200
+ name = "opencv-python"
1201
+ version = "4.10.0.84"
1202
+ description = "Wrapper package for OpenCV python bindings."
1203
+ optional = false
1204
+ python-versions = ">=3.6"
1205
+ files = [
1206
+ {file = "opencv-python-4.10.0.84.tar.gz", hash = "sha256:72d234e4582e9658ffea8e9cae5b63d488ad06994ef12d81dc303b17472f3526"},
1207
+ {file = "opencv_python-4.10.0.84-cp37-abi3-macosx_11_0_arm64.whl", hash = "sha256:fc182f8f4cda51b45f01c64e4cbedfc2f00aff799debebc305d8d0210c43f251"},
1208
+ {file = "opencv_python-4.10.0.84-cp37-abi3-macosx_12_0_x86_64.whl", hash = "sha256:71e575744f1d23f79741450254660442785f45a0797212852ee5199ef12eed98"},
1209
+ {file = "opencv_python-4.10.0.84-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:09a332b50488e2dda866a6c5573ee192fe3583239fb26ff2f7f9ceb0bc119ea6"},
1210
+ {file = "opencv_python-4.10.0.84-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9ace140fc6d647fbe1c692bcb2abce768973491222c067c131d80957c595b71f"},
1211
+ {file = "opencv_python-4.10.0.84-cp37-abi3-win32.whl", hash = "sha256:2db02bb7e50b703f0a2d50c50ced72e95c574e1e5a0bb35a8a86d0b35c98c236"},
1212
+ {file = "opencv_python-4.10.0.84-cp37-abi3-win_amd64.whl", hash = "sha256:32dbbd94c26f611dc5cc6979e6b7aa1f55a64d6b463cc1dcd3c95505a63e48fe"},
1213
+ ]
1214
+
1215
+ [package.dependencies]
1216
+ numpy = [
1217
+ {version = ">=1.21.4", markers = "python_version >= \"3.10\" and platform_system == \"Darwin\""},
1218
+ {version = ">=1.21.2", markers = "platform_system != \"Darwin\" and python_version >= \"3.10\""},
1219
+ ]
1220
+
1221
  [[package]]
1222
  name = "packaging"
1223
  version = "24.1"
 
1581
  [package.extras]
1582
  windows-terminal = ["colorama (>=0.4.6)"]
1583
 
1584
+ [[package]]
1585
+ name = "pyinstrument"
1586
+ version = "4.1.1"
1587
+ description = "Call stack profiler for Python. Shows you why your code is slow!"
1588
+ optional = false
1589
+ python-versions = ">=3.7"
1590
+ files = [
1591
+ {file = "pyinstrument-4.1.1-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:fd0b92d9dfe97222e65ecec811e2923776f096f8df8a53ece24db18683755131"},
1592
+ {file = "pyinstrument-4.1.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:15837ac5188334d684555f1edc7ea3cf4e859ccb12fc813353cff30f327ea23f"},
1593
+ {file = "pyinstrument-4.1.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f7dad2844048cf1438dfccdc1a126711a422cc1fb4b2989685b727ae85af27d7"},
1594
+ {file = "pyinstrument-4.1.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:848d7cd1e8a6b6d8efc3a0658f949ca8e05e0fd008101d22ec2c720079840ae0"},
1595
+ {file = "pyinstrument-4.1.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:d156d80cea866a3f67fab750acce6b2e8c7f3dcb6aceb33c20f0baee49ff078e"},
1596
+ {file = "pyinstrument-4.1.1-cp310-cp310-win32.whl", hash = "sha256:4776484afbdf9cc1ec090f5933ec297a4b38e545dace4728b29d3d338c037898"},
1597
+ {file = "pyinstrument-4.1.1-cp310-cp310-win_amd64.whl", hash = "sha256:917017b100efce161b9de0cd3aa60a8bc177a95ce8c6c195269b4b4a9fbea169"},
1598
+ {file = "pyinstrument-4.1.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:ad9e4bc40939eced2621fd41740d4e730fa9ef3efe10250b4307a51ed679de65"},
1599
+ {file = "pyinstrument-4.1.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6262c876534b0734bcd23ca65004a1f40c47b7af60e801612a876562d1792b54"},
1600
+ {file = "pyinstrument-4.1.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:5b0228271c8799504d0638255a0666a68db45f9938dc6e739d7facc8d5aa65dd"},
1601
+ {file = "pyinstrument-4.1.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:75eade68081645d5deb073e93c18a0c1194724ebe63e43d94b13d922714209fe"},
1602
+ {file = "pyinstrument-4.1.1-cp37-cp37m-win32.whl", hash = "sha256:01920b3b3d1d5fb063e1f7ae00711f2bcbdb1ab987133ed46ef208e9c0d59a3a"},
1603
+ {file = "pyinstrument-4.1.1-cp37-cp37m-win_amd64.whl", hash = "sha256:54c94dd9f196ed3510cfb951b6930d89162e5279cc0f793b456e68e3b5f2c087"},
1604
+ {file = "pyinstrument-4.1.1-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:a2b112a9b1d59017dede3e965aafe1faed716e671d3be4c3e507a3c0bbb76d20"},
1605
+ {file = "pyinstrument-4.1.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:a1fabafc10bec10e431a0b9fb535c90f96e40cd9b185292c01e8bbeb774b4132"},
1606
+ {file = "pyinstrument-4.1.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e73c05b393ea48fefd5e06a78fb90385eecdc0c6ad8b83ffb95b00ff3fe00a22"},
1607
+ {file = "pyinstrument-4.1.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:88d358ca7de27b65dbe88a8926922ebca236172072620bdaab0bb85933d0e665"},
1608
+ {file = "pyinstrument-4.1.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:f7c4589f5027ac9bdd24d59f76ee7f31091a92ca1f60dac22262789bba97db2c"},
1609
+ {file = "pyinstrument-4.1.1-cp38-cp38-win32.whl", hash = "sha256:f9b94bd788a3c07df4dbc4275ffab258a19b927462b3e0463a95a8963b04b9c6"},
1610
+ {file = "pyinstrument-4.1.1-cp38-cp38-win_amd64.whl", hash = "sha256:50a0a260e0867717991d0b8b35568e03451d4e4adcdf3e693fc0dd0e01a2a86a"},
1611
+ {file = "pyinstrument-4.1.1-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:5a562ed5febecf7e76f9b58bb1a77e4c76973dee3fe96d63c7df6d861b8198ef"},
1612
+ {file = "pyinstrument-4.1.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:0fc6a26a2088471e5fa5dba8e410044eba62f8206ab7dc59c8e44ae8291b472d"},
1613
+ {file = "pyinstrument-4.1.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:beb4b3347b3f1403d34f32d864540c1a57b322268fc632f422d05ceb826f6eb2"},
1614
+ {file = "pyinstrument-4.1.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:634f431037fdf3311fc7592e4f250e2657f82e97c4592234de567d674fd9d8e1"},
1615
+ {file = "pyinstrument-4.1.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:d59ca2ff6929e87b60eca6ce1405d160db7ce048d57f4b681790c29778c023be"},
1616
+ {file = "pyinstrument-4.1.1-cp39-cp39-win32.whl", hash = "sha256:8a57444ce2098777b031b7b88d80832f93162b44a930c95d86b55d96b11d39f8"},
1617
+ {file = "pyinstrument-4.1.1-cp39-cp39-win_amd64.whl", hash = "sha256:864fd4ef0651bca4c304a89da8736400a6c12469b28d6799d961e0f4babb3033"},
1618
+ {file = "pyinstrument-4.1.1.tar.gz", hash = "sha256:1dc2791d2cd2fd3459cb55010004a5cc2a9a8b4625a0cbea45a4b1aebbe2c3a2"},
1619
+ ]
1620
+
1621
+ [package.extras]
1622
+ jupyter = ["ipython"]
1623
+
1624
  [[package]]
1625
  name = "pylatexenc"
1626
  version = "2.10"
 
2085
  [package.dependencies]
2086
  streamlit = ">=0.75"
2087
 
2088
+ [[package]]
2089
+ name = "streamlit-profiler"
2090
+ version = "0.2.4"
2091
+ description = "Runtime profiler for Streamlit, powered by pyinstrument"
2092
+ optional = false
2093
+ python-versions = ">=3.7,<4.0"
2094
+ files = [
2095
+ {file = "streamlit-profiler-0.2.4.tar.gz", hash = "sha256:0d87494abdbd9d8372fc004360e06e18dfce316432853d210334026bf616cd2b"},
2096
+ {file = "streamlit_profiler-0.2.4-py3-none-any.whl", hash = "sha256:66b0a95da4bd2377ee1c7c9020f5b535bb03cd77ffe801b341dfaa2490676506"},
2097
+ ]
2098
+
2099
+ [package.dependencies]
2100
+ pyinstrument = "4.1.1"
2101
+ streamlit = ">=1.0.0,<2.0.0"
2102
+
2103
  [[package]]
2104
  name = "swig"
2105
  version = "4.2.1"
 
2406
  [metadata]
2407
  lock-version = "2.0"
2408
  python-versions = "3.10.14"
2409
+ content-hash = "416c59da9e4c75ce8414c2caab4106cebf9547e4ced9b170e8572bbdc4658041"
pyproject.toml CHANGED
@@ -34,6 +34,8 @@ streamlit = "^1.39.0"
34
  st-pages = "^1.0.1"
35
  streamlit-javascript = "^0.1.5"
36
  pylatexenc = "^2.10"
 
 
37
 
38
 
39
  [build-system]
 
34
  st-pages = "^1.0.1"
35
  streamlit-javascript = "^0.1.5"
36
  pylatexenc = "^2.10"
37
+ streamlit-profiler = "^0.2.4"
38
+ opencv-python = "^4.10.0.84"
39
 
40
 
41
  [build-system]
requirements.txt CHANGED
@@ -4,7 +4,7 @@ blinker==1.8.2
4
  box2d-py==2.3.5
5
  cachetools==5.5.0
6
  certifi==2024.8.30
7
- charset-normalizer==3.3.2
8
  click==8.1.7
9
  cloudpickle==3.0.0
10
  contourpy==1.3.0
@@ -25,12 +25,12 @@ jsonschema-specifications==2024.10.1
25
  kiwisolver==1.4.7
26
  lazy_loader==0.4
27
  markdown-it-py==3.0.0
28
- MarkupSafe==3.0.0
29
  matplotlib==3.9.2
30
  mdurl==0.1.2
31
  mpmath==1.3.0
32
- narwhals==1.9.1
33
- networkx==3.3
34
  numpy==1.24.4
35
  nvidia-cublas-cu12==12.1.3.1
36
  nvidia-cuda-cupti-cu12==12.1.105
@@ -44,6 +44,7 @@ nvidia-cusparse-cu12==12.1.0.106
44
  nvidia-nccl-cu12==2.20.5
45
  nvidia-nvjitlink-cu12==12.6.77
46
  nvidia-nvtx-cu12==12.1.105
 
47
  packaging==24.1
48
  pandas==2.2.3
49
  pillow==10.4.0
@@ -52,6 +53,7 @@ pyarrow==17.0.0
52
  pydeck==0.9.1
53
  pygame==2.6.1
54
  Pygments==2.18.0
 
55
  pylatexenc==2.10
56
  pyparsing==3.1.4
57
  python-dateutil==2.9.0.post0
@@ -68,6 +70,7 @@ smmap==5.0.1
68
  st-pages==1.0.1
69
  streamlit==1.39.0
70
  streamlit-javascript==0.1.5
 
71
  swig==4.2.1
72
  sympy==1.13.3
73
  tenacity==9.0.0
 
4
  box2d-py==2.3.5
5
  cachetools==5.5.0
6
  certifi==2024.8.30
7
+ charset-normalizer==3.4.0
8
  click==8.1.7
9
  cloudpickle==3.0.0
10
  contourpy==1.3.0
 
25
  kiwisolver==1.4.7
26
  lazy_loader==0.4
27
  markdown-it-py==3.0.0
28
+ MarkupSafe==3.0.1
29
  matplotlib==3.9.2
30
  mdurl==0.1.2
31
  mpmath==1.3.0
32
+ narwhals==1.9.2
33
+ networkx==3.4
34
  numpy==1.24.4
35
  nvidia-cublas-cu12==12.1.3.1
36
  nvidia-cuda-cupti-cu12==12.1.105
 
44
  nvidia-nccl-cu12==2.20.5
45
  nvidia-nvjitlink-cu12==12.6.77
46
  nvidia-nvtx-cu12==12.1.105
47
+ opencv-python==4.10.0.84
48
  packaging==24.1
49
  pandas==2.2.3
50
  pillow==10.4.0
 
53
  pydeck==0.9.1
54
  pygame==2.6.1
55
  Pygments==2.18.0
56
+ pyinstrument==4.1.1
57
  pylatexenc==2.10
58
  pyparsing==3.1.4
59
  python-dateutil==2.9.0.post0
 
70
  st-pages==1.0.1
71
  streamlit==1.39.0
72
  streamlit-javascript==0.1.5
73
+ streamlit-profiler==0.2.4
74
  swig==4.2.1
75
  sympy==1.13.3
76
  tenacity==9.0.0
resources/Acrobot-v1/info.json CHANGED
@@ -1,11 +1,11 @@
1
  {
2
  "env_name": "Acrobot-v1",
3
  "state": {
4
- "0":["$\\sin{\\theta_1}$","Sine of the first link" ],
5
- "1":["$\\cos{\\theta_1}$","Cosine of the first link" ],
6
- "2":["$\\sin{\\theta_2}$","Sine of the second link" ],
7
- "3":["$\\cos{\\theta_2}$","Cosine of the second link" ],
8
- "4":["$\\dot{\\theta}_1$","Angular velocity of first link" ],
9
- "5":["$\\dot{\\theta}_2$","Angular velocity of second link" ]
10
  }
11
  }
 
1
  {
2
  "env_name": "Acrobot-v1",
3
  "state": {
4
+ "0":["$\\sin{\\theta_1}$","Sine of 1st link" ],
5
+ "1":["$\\cos{\\theta_1}$","Cosine of 1st link" ],
6
+ "2":["$\\sin{\\theta_2}$","Sine of 2nd link" ],
7
+ "3":["$\\cos{\\theta_2}$","Cosine of 2nd link" ],
8
+ "4":["$\\dot{\\theta}_1$","Angular vel 1st link" ],
9
+ "5":["$\\dot{\\theta}_2$","Angular vel 2nd link" ]
10
  }
11
  }
udrl/app/sim.py CHANGED
@@ -15,6 +15,7 @@ from udrl.policies import SklearnPolicy, NeuralPolicy
15
  import altair as alt
16
  import pandas as pd
17
  import json
 
18
 
19
  # from pylatexenc.latex2text import LatexNodes2Text
20
 
@@ -63,9 +64,15 @@ def next_epoch(state: State):
63
 
64
  def update_frame(state: State):
65
  state.prev_frame = state.frame
66
- state.frame = resize(state.env.render(), (400, 600, 3))
 
 
 
67
  while len(state.frame) < 1:
68
- state.frame = resize(state.env.render(), (400, 600, 3))
 
 
 
69
 
70
 
71
  def reset_env(state: State):
@@ -226,7 +233,6 @@ def make_viz(state):
226
  {
227
  "f": state.feature_importances,
228
  "index": [
229
- # LatexNodes2Text().latex_to_text(v[0])
230
  v[1][:17]
231
  for v in load_env_info(state.env_name)[
232
  "state"
@@ -250,7 +256,7 @@ def make_viz(state):
250
  )
251
 
252
  st.altair_chart(
253
- base + base.mark_text(align="left", dx=2),
254
  use_container_width=True,
255
  )
256
 
@@ -381,7 +387,11 @@ def run(state: State):
381
  sidebar_container = st.sidebar.container()
382
  with sidebar_container:
383
  st.slider(
384
- "Refresh Rate", min_value=1, max_value=20, key="refresh_rate"
 
 
 
 
385
  )
386
  st.header("Environment Info")
387
  for line in env_info_md(state.env_name).split("\n"):
@@ -406,4 +416,7 @@ def run(state: State):
406
  if "sim" not in st.session_state:
407
  st.session_state.sim = init()
408
 
 
 
 
409
  run(st.session_state.sim)
 
15
  import altair as alt
16
  import pandas as pd
17
  import json
18
+ import cv2
19
 
20
  # from pylatexenc.latex2text import LatexNodes2Text
21
 
 
64
 
65
  def update_frame(state: State):
66
  state.prev_frame = state.frame
67
+ # state.frame = resize(state.env.render(), (400, 600, 3))
68
+ state.frame = cv2.resize(
69
+ state.env.render(), (600, 400), interpolation=cv2.INTER_AREA
70
+ )
71
  while len(state.frame) < 1:
72
+ state.frame = cv2.resize(
73
+ state.env.render(), (600, 400), interpolation=cv2.INTER_AREA
74
+ )
75
+ # state.frame = resize(state.env.render(), (400, 600, 3))
76
 
77
 
78
  def reset_env(state: State):
 
233
  {
234
  "f": state.feature_importances,
235
  "index": [
 
236
  v[1][:17]
237
  for v in load_env_info(state.env_name)[
238
  "state"
 
256
  )
257
 
258
  st.altair_chart(
259
+ base,
260
  use_container_width=True,
261
  )
262
 
 
387
  sidebar_container = st.sidebar.container()
388
  with sidebar_container:
389
  st.slider(
390
+ "Refresh Rate",
391
+ min_value=1,
392
+ max_value=15,
393
+ key="refresh_rate",
394
+ value=7,
395
  )
396
  st.header("Environment Info")
397
  for line in env_info_md(state.env_name).split("\n"):
 
416
  if "sim" not in st.session_state:
417
  st.session_state.sim = init()
418
 
419
+ # from streamlit_profiler import Profiler
420
+ # with Profiler():
421
+ # run(st.session_state.sim)
422
  run(st.session_state.sim)