Skip to content

Commit

Permalink
Fix pretty printing in mjspec notebook.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 721367994
Change-Id: Ia1c4ee5b64540ff2f9c08a1953295ff366e0c72b
  • Loading branch information
yuvaltassa authored and copybara-github committed Jan 30, 2025
1 parent 2680bd3 commit 767be23
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions python/mjspec.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@
"print('Installation successful.')\n",
"\n",
"# Other imports and helper functions\n",
"import time\n",
"import itertools\n",
"import numpy as np\n",
"\n",
"# Graphics and plotting.\n",
Expand All @@ -106,8 +104,10 @@
"import mediapy as media\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# More legible printing from numpy.\n",
"# Printing.\n",
"np.set_printoptions(precision=3, suppress=True, linewidth=100)\n",
"import pygments\n",
"from google.colab import output\n",
"\n",
"from IPython.display import clear_output, HTML, display\n",
"clear_output()\n",
Expand All @@ -121,13 +121,17 @@
"!git clone https://github.com/google-deepmind/mujoco_menagerie\n",
"franka_file = 'mujoco_menagerie/franka_fr3/fr3.xml'\n",
"\n",
"\n",
"is_dark = output.eval_js('document.documentElement.matches(\"[theme=dark]\")')\n",
"print_style = 'monokai' if is_dark else 'lovelace'\n",
"\n",
"def print_xml(xml_string):\n",
" formatter = pygments.formatters.HtmlFormatter(style='lovelace')\n",
" formatter = pygments.formatters.HtmlFormatter(style=print_style)\n",
" lexer = pygments.lexers.XmlLexer()\n",
" highlighted = pygments.highlight(xml_string, lexer, formatter)\n",
" display(HTML(f\"<style>{formatter.get_style_defs()}</style>{highlighted}\"))\n",
"\n",
"def render(model, data=None, height=250):\n",
"def render(model, data=None, height=300):\n",
" if data is None:\n",
" data = mj.MjData(model)\n",
" with mj.Renderer(model, 480, 640) as renderer:\n",
Expand Down Expand Up @@ -254,7 +258,7 @@
" pixels = renderer.render()\n",
" frames.append(pixels)\n",
"\n",
"media.show_video(frames, fps=framerate)\n"
"media.show_video(frames, fps=framerate)"
]
},
{
Expand Down Expand Up @@ -812,9 +816,6 @@
"metadata": {
"accelerator": "GPU",
"colab": {
"collapsed_sections": [
"sJFuNetilv4m"
],
"gpuClass": "premium",
"private_outputs": true
},
Expand Down

0 comments on commit 767be23

Please sign in to comment.