Skip to content

Commit 6b46d13

Browse files
authored
Add CI coverage for examples that use remote resources (#439)
by adding support for prefetching with no-sandbox, so that each test doesn't have to re-download the resources.
1 parent a0df407 commit 6b46d13

File tree

14 files changed

+176
-86
lines changed

14 files changed

+176
-86
lines changed

.github/workflows/main.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ jobs:
6363
run: ./setup/submodule_checkout
6464
shell: bash
6565
- name: post-checkout setup
66-
run: ./book/htmlbook/workflows/ci/jammy/setup
66+
run: |
67+
./book/htmlbook/workflows/ci/jammy/setup
68+
bazel run //manipulation:prefetch_remotes
6769
shell: bash
6870
# - name: Check disk space
6971
# run: |
@@ -85,7 +87,9 @@ jobs:
8587
run: ./setup/submodule_checkout
8688
shell: zsh -efuo pipefail {0}
8789
- name: setup
88-
run: ./book/htmlbook/workflows/ci/sonoma/setup
90+
run: |
91+
./book/htmlbook/workflows/ci/sonoma/setup
92+
bazel run //manipulation:prefetch_remotes
8993
shell: zsh -efuo pipefail {0}
9094
- name: test
9195
run: ./book/htmlbook/workflows/ci/sonoma/test
@@ -148,6 +152,7 @@ jobs:
148152
pip install -U manipulation[all] --extra-index-url https://drake-packages.csail.mit.edu/whl/nightly/
149153
truncate -s0 requirements.txt
150154
sed -i '/PYTHONNOUSERSITE/d' .bazelrc
155+
bazel run //manipulation:prefetch_remotes
151156
shell: bash
152157
- name: test
153158
run: EXCLUDE_TESTS="//book/htmlbook/..." ./book/htmlbook/workflows/ci/jammy/test
@@ -179,6 +184,7 @@ jobs:
179184
pip install manipulation --extra-index-url https://drake-packages.csail.mit.edu/whl/nightly/
180185
truncate -s0 requirements.txt
181186
sed -i '/PYTHONNOUSERSITE/d' .bazelrc
187+
bazel run //manipulation:prefetch_remotes
182188
shell: bash
183189
- name: test
184190
run: |
@@ -216,6 +222,7 @@ jobs:
216222
pip install manipulation[all] --extra-index-url https://drake-packages.csail.mit.edu/whl/nightly/
217223
truncate -s0 requirements.txt
218224
sed -i '/PYTHONNOUSERSITE/d' .bazelrc
225+
bazel run //manipulation:prefetch_remotes
219226
shell: bash
220227
- name: test
221228
run: |

book/mobile/BUILD.bazel

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ rt_ipynb_test(
2626
],
2727
)
2828

29-
30-
# TODO(russt): Pre-download the model
31-
#rt_ipynb_test(
32-
# name = "spot",
33-
# srcs = ["spot.ipynb"],
34-
# deps = [
35-
# "//manipulation",
36-
# ],
37-
#)
29+
rt_ipynb_test(
30+
name = "spot",
31+
srcs = ["spot.ipynb"],
32+
tags = ["requires-network", "no-sandbox"],
33+
deps = [
34+
"//manipulation",
35+
"//manipulation:remotes",
36+
"//manipulation:station",
37+
],
38+
)
3839

3940
rt_ipynb_test(
4041
name = "pr2",

book/mobile/spot.ipynb

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"from pydrake.all import ModelVisualizer, PackageMap, Simulator, StartMeshcat\n",
2727
"\n",
2828
"from manipulation import ConfigureParser, FindResource, running_as_notebook\n",
29+
"from manipulation.remotes import AddSpotRemote\n",
2930
"from manipulation.station import LoadScenario, MakeHardwareStation"
3031
]
3132
},
@@ -40,25 +41,6 @@
4041
"meshcat = StartMeshcat()"
4142
]
4243
},
43-
{
44-
"cell_type": "code",
45-
"execution_count": null,
46-
"metadata": {},
47-
"outputs": [],
48-
"source": [
49-
"def AddSpotRemote(parser):\n",
50-
" parser.package_map().AddRemote(\n",
51-
" package_name=\"spot_description\",\n",
52-
" params=PackageMap.RemoteParams(\n",
53-
" urls=[\n",
54-
" f\"https://github.com/wrangel-bdai/spot_ros2/archive/20965ef7bba98598ee10878c7b54e6ef28a300c6.tar.gz\"\n",
55-
" ],\n",
56-
" sha256=(\"20a4f12896b04cc73e186cf876bf2c7e905ee88f8add8ea51bf52dfc888674b4\"),\n",
57-
" strip_prefix=\"spot_ros2-20965ef7bba98598ee10878c7b54e6ef28a300c6/spot_description/\",\n",
58-
" ),\n",
59-
" )"
60-
]
61-
},
6244
{
6345
"cell_type": "markdown",
6446
"id": "7112a8be",
@@ -82,7 +64,7 @@
8264
"source": [
8365
"visualizer = ModelVisualizer(meshcat=meshcat)\n",
8466
"ConfigureParser(visualizer.parser())\n",
85-
"AddSpotRemote(visualizer.parser())\n",
67+
"AddSpotRemote(visualizer.parser().package_map())\n",
8668
"visualizer.AddModels(\n",
8769
" url=\"package://manipulation/spot/spot_with_arm_and_floating_base_actuators.urdf\"\n",
8870
")\n",
@@ -109,7 +91,11 @@
10991
" \"models/spot/spot_with_arm_and_floating_base_actuators.scenario.yaml\"\n",
11092
" )\n",
11193
")\n",
112-
"station = MakeHardwareStation(scenario, meshcat, parser_preload_callback=AddSpotRemote)\n",
94+
"station = MakeHardwareStation(\n",
95+
" scenario,\n",
96+
" meshcat,\n",
97+
" parser_preload_callback=lambda parser: AddSpotRemote(parser.package_map()),\n",
98+
")\n",
11399
"simulator = Simulator(station)\n",
114100
"context = simulator.get_mutable_context()\n",
115101
"x0 = station.GetOutputPort(\"spot.state_estimated\").Eval(context)\n",

book/pick/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ rt_ipynb_test(
3636

3737
rt_ipynb_test(
3838
name = "qdot_vs_v",
39+
data = ["@drake_models"],
3940
srcs = ["qdot_vs_v.ipynb"],
4041
deps = [
4142
requirement("drake"),

book/robot/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,22 @@ rt_ipynb_test(
1818
rt_ipynb_test(
1919
name = "menagerie",
2020
srcs = ["menagerie.ipynb"],
21+
tags = ["requires-network", "no-sandbox"],
2122
deps = [
2223
"//manipulation",
2324
"//manipulation:make_drake_compatible_model",
25+
"//manipulation:remotes",
2426
],
2527
)
2628

2729
rt_ipynb_test(
2830
name = "gymnasium_robotics",
2931
srcs = ["gymnasium_robotics.ipynb"],
32+
tags = ["requires-network", "no-sandbox"],
3033
deps = [
3134
"//manipulation",
3235
"//manipulation:make_drake_compatible_model",
36+
"//manipulation:remotes",
3337
],
3438
)
3539

book/robot/gymnasium_robotics.ipynb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"\n",
2929
"from manipulation import running_as_notebook\n",
3030
"from manipulation.make_drake_compatible_model import MakeDrakeCompatibleModel\n",
31+
"from manipulation.remotes import AddGymnasiumRobotics\n",
3132
"from manipulation.utils import ApplyDefaultVisualization"
3233
]
3334
},
@@ -68,16 +69,7 @@
6869
" plant = builder.plant()\n",
6970
" parser = Parser(plant)\n",
7071
" package_map = parser.package_map()\n",
71-
" package_map.AddRemote(\n",
72-
" package_name=\"gymnasium_robotics\",\n",
73-
" params=PackageMap.RemoteParams(\n",
74-
" urls=[\n",
75-
" f\"https://github.com/Farama-Foundation/Gymnasium-Robotics/archive/refs/tags/v1.3.1.tar.gz\"\n",
76-
" ],\n",
77-
" sha256=(\"d274b3ee1d34337aa35d4686447fda6a6d20dfcb4d375eab91b4e49b1108afde\"),\n",
78-
" strip_prefix=\"Gymnasium-Robotics-1.3.1/gymnasium_robotics/envs/assets/\",\n",
79-
" ),\n",
80-
" )\n",
72+
" AddGymnasiumRobotics(package_map)\n",
8173
" original_file = package_map.ResolveUrl(\n",
8274
" \"package://gymnasium_robotics/kitchen_franka/kitchen_assets/kitchen_env_model.xml\"\n",
8375
" )\n",

book/robot/menagerie.ipynb

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
"\n",
3939
"from manipulation import running_as_notebook\n",
4040
"from manipulation.make_drake_compatible_model import MakeDrakeCompatibleModel\n",
41-
"from manipulation.utils import AddMujocoMenagerie, ApplyDefaultVisualization"
41+
"from manipulation.remotes import AddMujocoMenagerie\n",
42+
"from manipulation.utils import ApplyDefaultVisualization"
4243
]
4344
},
4445
{
@@ -150,8 +151,24 @@
150151
" \"universal_robots_ur10e\": (\"scene.xml\", \"ur10e.png\"),\n",
151152
" \"universal_robots_ur5e\": (\"scene.xml\", \"ur5e.png\"),\n",
152153
" \"wonik_allegro\": (\"scene_left.xml\", \"allegro_hand.png\"),\n",
153-
"}\n",
154-
"\n",
154+
"}"
155+
]
156+
},
157+
{
158+
"cell_type": "markdown",
159+
"id": "3ee27292",
160+
"metadata": {},
161+
"source": [
162+
"Show a particular model."
163+
]
164+
},
165+
{
166+
"cell_type": "code",
167+
"execution_count": null,
168+
"id": "e80d70ed",
169+
"metadata": {},
170+
"outputs": [],
171+
"source": [
155172
"if running_as_notebook:\n",
156173
" show_model(\"unitree_g1\")"
157174
]
@@ -197,17 +214,16 @@
197214
"metadata": {},
198215
"outputs": [],
199216
"source": [
200-
"if running_as_notebook:\n",
201-
" vis = ModelVisualizer(meshcat=meshcat)\n",
202-
" parser = vis.parser()\n",
203-
" AddMujocoMenagerie(parser.package_map())\n",
204-
" model_path = parser.package_map().ResolveUrl(\n",
205-
" \"package://mujoco_menagerie/agility_cassie/scene.xml\"\n",
206-
" )\n",
207-
" drake_model_path = model_path.replace(\".xml\", \".drake.xml\")\n",
208-
" MakeDrakeCompatibleModel(model_path, drake_model_path, overwrite=True)\n",
209-
" vis.AddModels(drake_model_path)\n",
210-
" vis.Run(loop_once=False)"
217+
"vis = ModelVisualizer(meshcat=meshcat)\n",
218+
"parser = vis.parser()\n",
219+
"AddMujocoMenagerie(parser.package_map())\n",
220+
"model_path = parser.package_map().ResolveUrl(\n",
221+
" \"package://mujoco_menagerie/agility_cassie/scene.xml\"\n",
222+
")\n",
223+
"drake_model_path = model_path.replace(\".xml\", \".drake.xml\")\n",
224+
"MakeDrakeCompatibleModel(model_path, drake_model_path, overwrite=True)\n",
225+
"vis.AddModels(drake_model_path)\n",
226+
"vis.Run(loop_once=not running_as_notebook)"
211227
]
212228
},
213229
{
@@ -221,7 +237,7 @@
221237
],
222238
"metadata": {
223239
"kernelspec": {
224-
"display_name": "Python 3 (ipykernel)",
240+
"display_name": "venv",
225241
"language": "python",
226242
"name": "python3"
227243
},

manipulation/BUILD.bazel

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
# Licensed under the BSD 3-Clause License. See LICENSE.TXT for details.
66

77
load("@pip_deps//:requirements.bzl", "requirement")
8-
load("//book/htmlbook/tools/python:defs.bzl", "rt_py_library", "rt_py_test")
8+
load("//book/htmlbook/tools/python:defs.bzl", "rt_py_library", "rt_py_test", "rt_py_binary")
99

1010
rt_py_library(
1111
name = "manipulation",
1212
srcs = [
1313
"__init__.py",
1414
"utils.py",
1515
],
16+
data = [
17+
"@drake_models",
18+
],
1619
imports = [".."],
1720
visibility = ["//visibility:public"],
1821
deps = [
@@ -65,6 +68,23 @@ rt_py_library(
6568
visibility = ["//visibility:public"],
6669
)
6770

71+
rt_py_library(
72+
name = "remotes",
73+
srcs = ["remotes.py"],
74+
imports = [".."],
75+
deps = [
76+
requirement("drake"),
77+
],
78+
visibility = ["//visibility:public"],
79+
)
80+
81+
rt_py_binary(
82+
name = "prefetch_remotes",
83+
tags = ["requires-network", "no-sandbox"],
84+
srcs = ["prefetch_remotes.py"],
85+
deps = ["remotes"],
86+
)
87+
6888
rt_py_library(
6989
name = "directives_tree",
7090
deps = [
@@ -152,12 +172,15 @@ rt_py_test(
152172
name = "test_make_drake_compatible_model",
153173
srcs = ["test/test_make_drake_compatible_model.py"],
154174
imports = [".."],
175+
tags = ["requires-network", "no-sandbox"],
176+
timeout = "moderate", # TODO(russt): consider moving the menagerie work to the prefetch_remotes
155177
data = [
156178
"//manipulation/test/models:models",
157179
],
158180
deps = [
159181
"manipulation",
160182
"//manipulation:make_drake_compatible_model",
183+
"//manipulation:remotes",
161184
],
162185
)
163186

manipulation/prefetch_remotes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from manipulation.remotes import PrefetchAllRemotePackages
2+
3+
if __name__ == "__main__":
4+
PrefetchAllRemotePackages()

manipulation/remotes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# `manipulation.remotes`
2+
3+
```{eval-rst}
4+
.. automodule:: manipulation.remotes
5+
:members:

0 commit comments

Comments
 (0)