Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,14 @@ jobs:
# it benchmarks numeric IK solver performance and uses the
# websocket-based Swift visualizer, neither of which is meaningful
# or functional inside the Pyodide sandbox -- it stays Colab-only.
# ik-symbolic.ipynb is excluded until it has been tried in Pyodide: it
# needs SymPy, and deriving the equations without python-flint may be
# very slow in the browser.
# ik-symbolic.ipynb is included: SymPy is one of Pyodide's own packages
# and the derivation takes 1 to 10 s without python-flint (timed in
# docs/lite/wasm_check, which checks it on every build).
run: |
mkdir -p docs/lite/files
rsync -a --exclude '.ipynb_checkpoints' --exclude '__pycache__' \
--exclude 'Untitled*.ipynb' --exclude '*.py' --exclude 'Makefile' --exclude 'README.md' \
--exclude 'ik_benchmark.ipynb' \
--exclude 'ik-symbolic.ipynb' \
docs/notebooks/ docs/lite/files/

- name: Adapt staged notebooks for JupyterLite
Expand Down
14 changes: 13 additions & 1 deletion docs/lite/wasm_check/check_pyodide_install.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,22 @@ async def _redirect_wheel_install(requirements, **kwargs):
return await _real_install(requirements, **kwargs)
micropip.install = _redirect_wheel_install

await bootstrap.ensure_installed()
await bootstrap.ensure_installed(extras=['ik'])

import roboticstoolbox as rtb # noqa: F401
rtb.models.DH.Panda().fkine([0, 0, 0, 0, 0, 0, 0])

# the notebook ik-symbolic.ipynb: SymPy only, since python-flint is not usable in
# Pyodide 0.27. A closed-form arm and a general 6R arm (the slow one, about 10 s).
import time, warnings
warnings.simplefilter("ignore")
for name in ("Puma560", "Jaco"):
robot = getattr(rtb.models.DH, name)()
t = time.time()
ik = robot.analytic_ik()
sol = ik.solve(robot.fkine([0.1] * robot.n))
assert len(sol.q) > 0, name
print(f"analytic_ik {name}: {type(ik).__name__}, {time.time() - t:.1f}s")
print("import roboticstoolbox: OK")
`;

Expand Down
16 changes: 14 additions & 2 deletions docs/notebooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,17 @@ run in the `docs.yml` workflow, and `tests/test_notebook_bootstrap.py` tests the
`docs/lite/wasm_check/` runs the bootstrap in Pyodide under Node.js against the wheel
just built, in CI. See its README.

`ik-symbolic.ipynb` has no bootstrap cell yet: it needs the `ik` extra (SymPy and
python-flint), and is not part of the JupyterLite site.
## Extras

A notebook that needs a toolbox extra says so in its own metadata, not in the cell:

```json
"metadata": {"rtb_bootstrap": {"extras": ["ik"]}}
```

`sync_bootstrap.py` then generates `ensure_installed(extras=['ik'])`. For `ik`, Colab
installs `roboticstoolbox-python[ik]`, a local install is told what to install if SymPy
is missing, and in the browser SymPy comes from Pyodide's own packages. python-flint is
not installed in the browser: the one bundled with Pyodide 0.27 is too old, and the
toolbox then uses SymPy alone (about 2x slower; 10 s for a general 6R arm).
`ik-symbolic.ipynb` is the one notebook that does this.
31 changes: 22 additions & 9 deletions docs/notebooks/_rtb_nb_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
from pathlib import Path


async def ensure_installed() -> bool:
async def ensure_installed(extras: tuple[str, ...] | list[str] = ()) -> bool:
"""Install roboticstoolbox-python if needed, and report the environment.

:param extras: toolbox extras the notebook needs, for example ``["ik"]``. They
are set per notebook in its metadata (``rtb_bootstrap.extras``) and
passed here by the generated cell.
:returns: True if running on Google Colab, False otherwise.
"""
if sys.platform == "emscripten":
Expand All @@ -31,6 +34,12 @@ async def ensure_installed() -> bool:
# (rai-opensource/spatialmath-python#250).
await micropip.install("spatialmath-python", deps=False)
await micropip.install("ipympl")
if "ik" in extras:
# SymPy is one of Pyodide's own packages. python-flint is not installed:
# the one bundled with Pyodide 0.27 is too old for the toolbox, which
# then uses SymPy for the polynomial steps, about 2x slower for a
# general 6R arm (10 s to derive a Kinova Jaco).
await micropip.install("sympy")

wheels = sorted(Path("/pypi").glob("roboticstoolbox_python-*.whl"))
if wheels:
Expand All @@ -47,17 +56,21 @@ async def ensure_installed() -> bool:
import google.colab # noqa: F401
except ImportError:
where, colab = "locally", False
if "ik" in extras:
try:
import sympy # noqa: F401
except ImportError:
print(
"This notebook needs SymPy: "
"pip install 'roboticstoolbox-python[ik]'"
)
else:
print("Installing roboticstoolbox-python...")
requirement = "roboticstoolbox-python"
if extras:
requirement += "[" + ",".join(extras) + "]"
subprocess.run(
[
sys.executable,
"-m",
"pip",
"install",
"-q",
"roboticstoolbox-python",
],
[sys.executable, "-m", "pip", "install", "-q", requirement],
check=True,
)
where, colab = "on Colab", True
Expand Down
31 changes: 22 additions & 9 deletions docs/notebooks/branched-robot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
"from pathlib import Path\n",
"\n",
"\n",
"async def ensure_installed() -> bool:\n",
"async def ensure_installed(extras: tuple[str, ...] | list[str] = ()) -> bool:\n",
" \"\"\"Install roboticstoolbox-python if needed, and report the environment.\n",
"\n",
" :param extras: toolbox extras the notebook needs, for example ``[\"ik\"]``. They\n",
" are set per notebook in its metadata (``rtb_bootstrap.extras``) and\n",
" passed here by the generated cell.\n",
" :returns: True if running on Google Colab, False otherwise.\n",
" \"\"\"\n",
" if sys.platform == \"emscripten\":\n",
Expand All @@ -45,6 +48,12 @@
" # (rai-opensource/spatialmath-python#250).\n",
" await micropip.install(\"spatialmath-python\", deps=False)\n",
" await micropip.install(\"ipympl\")\n",
" if \"ik\" in extras:\n",
" # SymPy is one of Pyodide's own packages. python-flint is not installed:\n",
" # the one bundled with Pyodide 0.27 is too old for the toolbox, which\n",
" # then uses SymPy for the polynomial steps, about 2x slower for a\n",
" # general 6R arm (10 s to derive a Kinova Jaco).\n",
" await micropip.install(\"sympy\")\n",
"\n",
" wheels = sorted(Path(\"/pypi\").glob(\"roboticstoolbox_python-*.whl\"))\n",
" if wheels:\n",
Expand All @@ -61,17 +70,21 @@
" import google.colab # noqa: F401\n",
" except ImportError:\n",
" where, colab = \"locally\", False\n",
" if \"ik\" in extras:\n",
" try:\n",
" import sympy # noqa: F401\n",
" except ImportError:\n",
" print(\n",
" \"This notebook needs SymPy: \"\n",
" \"pip install 'roboticstoolbox-python[ik]'\"\n",
" )\n",
" else:\n",
" print(\"Installing roboticstoolbox-python...\")\n",
" requirement = \"roboticstoolbox-python\"\n",
" if extras:\n",
" requirement += \"[\" + \",\".join(extras) + \"]\"\n",
" subprocess.run(\n",
" [\n",
" sys.executable,\n",
" \"-m\",\n",
" \"pip\",\n",
" \"install\",\n",
" \"-q\",\n",
" \"roboticstoolbox-python\",\n",
" ],\n",
" [sys.executable, \"-m\", \"pip\", \"install\", \"-q\", requirement],\n",
" check=True,\n",
" )\n",
" where, colab = \"on Colab\", True\n",
Expand Down
31 changes: 22 additions & 9 deletions docs/notebooks/dynamics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
"from pathlib import Path\n",
"\n",
"\n",
"async def ensure_installed() -> bool:\n",
"async def ensure_installed(extras: tuple[str, ...] | list[str] = ()) -> bool:\n",
" \"\"\"Install roboticstoolbox-python if needed, and report the environment.\n",
"\n",
" :param extras: toolbox extras the notebook needs, for example ``[\"ik\"]``. They\n",
" are set per notebook in its metadata (``rtb_bootstrap.extras``) and\n",
" passed here by the generated cell.\n",
" :returns: True if running on Google Colab, False otherwise.\n",
" \"\"\"\n",
" if sys.platform == \"emscripten\":\n",
Expand All @@ -45,6 +48,12 @@
" # (rai-opensource/spatialmath-python#250).\n",
" await micropip.install(\"spatialmath-python\", deps=False)\n",
" await micropip.install(\"ipympl\")\n",
" if \"ik\" in extras:\n",
" # SymPy is one of Pyodide's own packages. python-flint is not installed:\n",
" # the one bundled with Pyodide 0.27 is too old for the toolbox, which\n",
" # then uses SymPy for the polynomial steps, about 2x slower for a\n",
" # general 6R arm (10 s to derive a Kinova Jaco).\n",
" await micropip.install(\"sympy\")\n",
"\n",
" wheels = sorted(Path(\"/pypi\").glob(\"roboticstoolbox_python-*.whl\"))\n",
" if wheels:\n",
Expand All @@ -61,17 +70,21 @@
" import google.colab # noqa: F401\n",
" except ImportError:\n",
" where, colab = \"locally\", False\n",
" if \"ik\" in extras:\n",
" try:\n",
" import sympy # noqa: F401\n",
" except ImportError:\n",
" print(\n",
" \"This notebook needs SymPy: \"\n",
" \"pip install 'roboticstoolbox-python[ik]'\"\n",
" )\n",
" else:\n",
" print(\"Installing roboticstoolbox-python...\")\n",
" requirement = \"roboticstoolbox-python\"\n",
" if extras:\n",
" requirement += \"[\" + \",\".join(extras) + \"]\"\n",
" subprocess.run(\n",
" [\n",
" sys.executable,\n",
" \"-m\",\n",
" \"pip\",\n",
" \"install\",\n",
" \"-q\",\n",
" \"roboticstoolbox-python\",\n",
" ],\n",
" [sys.executable, \"-m\", \"pip\", \"install\", \"-q\", requirement],\n",
" check=True,\n",
" )\n",
" where, colab = \"on Colab\", True\n",
Expand Down
31 changes: 22 additions & 9 deletions docs/notebooks/ets.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@
"from pathlib import Path\n",
"\n",
"\n",
"async def ensure_installed() -> bool:\n",
"async def ensure_installed(extras: tuple[str, ...] | list[str] = ()) -> bool:\n",
" \"\"\"Install roboticstoolbox-python if needed, and report the environment.\n",
"\n",
" :param extras: toolbox extras the notebook needs, for example ``[\"ik\"]``. They\n",
" are set per notebook in its metadata (``rtb_bootstrap.extras``) and\n",
" passed here by the generated cell.\n",
" :returns: True if running on Google Colab, False otherwise.\n",
" \"\"\"\n",
" if sys.platform == \"emscripten\":\n",
Expand All @@ -53,6 +56,12 @@
" # (rai-opensource/spatialmath-python#250).\n",
" await micropip.install(\"spatialmath-python\", deps=False)\n",
" await micropip.install(\"ipympl\")\n",
" if \"ik\" in extras:\n",
" # SymPy is one of Pyodide's own packages. python-flint is not installed:\n",
" # the one bundled with Pyodide 0.27 is too old for the toolbox, which\n",
" # then uses SymPy for the polynomial steps, about 2x slower for a\n",
" # general 6R arm (10 s to derive a Kinova Jaco).\n",
" await micropip.install(\"sympy\")\n",
"\n",
" wheels = sorted(Path(\"/pypi\").glob(\"roboticstoolbox_python-*.whl\"))\n",
" if wheels:\n",
Expand All @@ -69,17 +78,21 @@
" import google.colab # noqa: F401\n",
" except ImportError:\n",
" where, colab = \"locally\", False\n",
" if \"ik\" in extras:\n",
" try:\n",
" import sympy # noqa: F401\n",
" except ImportError:\n",
" print(\n",
" \"This notebook needs SymPy: \"\n",
" \"pip install 'roboticstoolbox-python[ik]'\"\n",
" )\n",
" else:\n",
" print(\"Installing roboticstoolbox-python...\")\n",
" requirement = \"roboticstoolbox-python\"\n",
" if extras:\n",
" requirement += \"[\" + \",\".join(extras) + \"]\"\n",
" subprocess.run(\n",
" [\n",
" sys.executable,\n",
" \"-m\",\n",
" \"pip\",\n",
" \"install\",\n",
" \"-q\",\n",
" \"roboticstoolbox-python\",\n",
" ],\n",
" [sys.executable, \"-m\", \"pip\", \"install\", \"-q\", requirement],\n",
" check=True,\n",
" )\n",
" where, colab = \"on Colab\", True\n",
Expand Down
31 changes: 22 additions & 9 deletions docs/notebooks/graphics-test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
"from pathlib import Path\n",
"\n",
"\n",
"async def ensure_installed() -> bool:\n",
"async def ensure_installed(extras: tuple[str, ...] | list[str] = ()) -> bool:\n",
" \"\"\"Install roboticstoolbox-python if needed, and report the environment.\n",
"\n",
" :param extras: toolbox extras the notebook needs, for example ``[\"ik\"]``. They\n",
" are set per notebook in its metadata (``rtb_bootstrap.extras``) and\n",
" passed here by the generated cell.\n",
" :returns: True if running on Google Colab, False otherwise.\n",
" \"\"\"\n",
" if sys.platform == \"emscripten\":\n",
Expand All @@ -45,6 +48,12 @@
" # (rai-opensource/spatialmath-python#250).\n",
" await micropip.install(\"spatialmath-python\", deps=False)\n",
" await micropip.install(\"ipympl\")\n",
" if \"ik\" in extras:\n",
" # SymPy is one of Pyodide's own packages. python-flint is not installed:\n",
" # the one bundled with Pyodide 0.27 is too old for the toolbox, which\n",
" # then uses SymPy for the polynomial steps, about 2x slower for a\n",
" # general 6R arm (10 s to derive a Kinova Jaco).\n",
" await micropip.install(\"sympy\")\n",
"\n",
" wheels = sorted(Path(\"/pypi\").glob(\"roboticstoolbox_python-*.whl\"))\n",
" if wheels:\n",
Expand All @@ -61,17 +70,21 @@
" import google.colab # noqa: F401\n",
" except ImportError:\n",
" where, colab = \"locally\", False\n",
" if \"ik\" in extras:\n",
" try:\n",
" import sympy # noqa: F401\n",
" except ImportError:\n",
" print(\n",
" \"This notebook needs SymPy: \"\n",
" \"pip install 'roboticstoolbox-python[ik]'\"\n",
" )\n",
" else:\n",
" print(\"Installing roboticstoolbox-python...\")\n",
" requirement = \"roboticstoolbox-python\"\n",
" if extras:\n",
" requirement += \"[\" + \",\".join(extras) + \"]\"\n",
" subprocess.run(\n",
" [\n",
" sys.executable,\n",
" \"-m\",\n",
" \"pip\",\n",
" \"install\",\n",
" \"-q\",\n",
" \"roboticstoolbox-python\",\n",
" ],\n",
" [sys.executable, \"-m\", \"pip\", \"install\", \"-q\", requirement],\n",
" check=True,\n",
" )\n",
" where, colab = \"on Colab\", True\n",
Expand Down
Loading
Loading