diff --git a/dm_control/mujoco/tutorial.ipynb b/dm_control/mujoco/tutorial.ipynb index 385133ce..689bfc83 100644 --- a/dm_control/mujoco/tutorial.ipynb +++ b/dm_control/mujoco/tutorial.ipynb @@ -38,7 +38,7 @@ "source": [ "This notebook provides an overview tutorial of the **MuJoCo** physics simulator, using the `dm_control` Python bindings. It is similar to the notebook in `dm_control/tutorial.ipynb`, but focuses on teaching MuJoCo itself, rather than the additional features provided by the Python package. \n", "\n", - "**A Colab runtime with GPU acceleration is required.** If you're using a CPU-only runtime, you can switch using the menu \"Runtime \u003e Change runtime type\"." + "**A Colab runtime with GPU acceleration is required.** If you're using a CPU-only runtime, you can switch using the menu \"Runtime > Change runtime type\"." ] }, { @@ -93,7 +93,7 @@ "\"\"\")\n", "\n", "print('Installing dm_control...')\n", - "!pip install -q dm_control\u003e=1.0.16\n", + "!pip install -q dm_control>=1.0.16\n", "\n", "# Configure dm_control to use the EGL rendering backend (requires GPU)\n", "%env MUJOCO_GL=egl\n", @@ -269,13 +269,13 @@ "#@title A static model {vertical-output: true}\n", "\n", "static_model = \"\"\"\n", - "\u003cmujoco\u003e\n", - " \u003cworldbody\u003e\n", - " \u003clight name=\"top\" pos=\"0 0 1\"/\u003e\n", - " \u003cgeom name=\"red_box\" type=\"box\" size=\".2 .2 .2\" rgba=\"1 0 0 1\"/\u003e\n", - " \u003cgeom name=\"green_sphere\" pos=\".2 .2 .2\" size=\".1\" rgba=\"0 1 0 1\"/\u003e\n", - " \u003c/worldbody\u003e\n", - "\u003c/mujoco\u003e\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", "\"\"\"\n", "physics = mujoco.Physics.from_xml_string(static_model)\n", "pixels = physics.render()\n", @@ -312,16 +312,16 @@ "#@title A child body with a joint { vertical-output: true }\n", "\n", "swinging_body = \"\"\"\n", - "\u003cmujoco\u003e\n", - " \u003cworldbody\u003e\n", - " \u003clight name=\"top\" pos=\"0 0 1\"/\u003e\n", - " \u003cbody name=\"box_and_sphere\" euler=\"0 0 -30\"\u003e \n", - " \u003cjoint name=\"swing\" type=\"hinge\" axis=\"1 -1 0\" pos=\"-.2 -.2 -.2\"/\u003e\n", - " \u003cgeom name=\"red_box\" type=\"box\" size=\".2 .2 .2\" rgba=\"1 0 0 1\"/\u003e\n", - " \u003cgeom name=\"green_sphere\" pos=\".2 .2 .2\" size=\".1\" rgba=\"0 1 0 1\"/\u003e\n", - " \u003c/body\u003e\n", - " \u003c/worldbody\u003e\n", - "\u003c/mujoco\u003e\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n", "\"\"\"\n", "physics = mujoco.Physics.from_xml_string(swinging_body)\n", "# Visualize the joint axis.\n", @@ -364,9 +364,9 @@ "# Simulate and display video.\n", "frames = []\n", "physics.reset() # Reset state and time\n", - "while physics.data.time \u003c duration:\n", + "while physics.data.time < duration:\n", " physics.step()\n", - " if len(frames) \u003c physics.data.time * framerate:\n", + " if len(frames) < physics.data.time * framerate:\n", " pixels = physics.render(scene_option=scene_option)\n", " frames.append(pixels)\n", "display_video(frames, framerate)" @@ -424,7 +424,7 @@ "# Shift nearest values to the origin.\n", "depth -= depth.min()\n", "# Scale by 2 mean distances of near rays.\n", - "depth /= 2*depth[depth \u003c= 1].mean()\n", + "depth /= 2*depth[depth <= 1].mean()\n", "# Scale to [0, 255]\n", "pixels = 255*np.clip(depth, 0, 1)\n", "PIL.Image.fromarray(pixels.astype(np.uint8))" @@ -467,7 +467,7 @@ "box_mat = physics.named.data.geom_xmat['red_box'].reshape(3, 3)\n", "box_size = physics.named.model.geom_size['red_box']\n", "offsets = np.array([-1, 1]) * box_size[:, None]\n", - "xyz_local = np.stack(itertools.product(*offsets)).T\n", + "xyz_local = np.stack(list(itertools.product(*offsets))).T\n", "xyz_global = box_pos[:, None] + box_mat @ xyz_local\n", "\n", "# Camera matrices multiply homogenous [x, y, z, 1] vectors.\n", @@ -514,7 +514,7 @@ "\n", "def add_visual_capsule(scene, point1, point2, radius, rgba):\n", " \"\"\"Adds one capsule to an mjvScene.\"\"\"\n", - " if scene.ngeom \u003e= scene.maxgeom:\n", + " if scene.ngeom >= scene.maxgeom:\n", " return\n", " scene.ngeom += 1 # increment ngeom\n", " # initialise a new capsule, add it to the scene using mjv_makeConnector\n", @@ -534,7 +534,7 @@ "\n", "def scene_callback(physics, scn):\n", " \"\"\"Draw position trace, speed modifies width and colours.\"\"\"\n", - " if len(positions) \u003e 1:\n", + " if len(positions) > 1:\n", " for i in range(len(positions)-1):\n", " rgba=np.array((np.clip(speeds[i]/10, 0, 1),\n", " np.clip(1-speeds[i]/10, 0, 1),\n", @@ -550,13 +550,13 @@ "# Simulate and display video.\n", "frames = []\n", "physics.reset() # Reset state and time\n", - "while physics.data.time \u003c duration:\n", + "while physics.data.time < duration:\n", " # append data to the traces\n", " positions.append(physics.named.data.geom_xpos[\"green_sphere\"].copy())\n", " times.append(physics.data.time)\n", " speeds.append(get_geom_speed(physics, \"green_sphere\"))\n", " physics.step()\n", - " if len(frames) \u003c physics.data.time * framerate:\n", + " if len(frames) < physics.data.time * framerate:\n", " camera = mujoco.Camera(physics, max_geom=10000,\n", " scene_callback=scene_callback)\n", " pixels = camera.render()\n", @@ -844,32 +844,32 @@ "#@title The \"tippe-top\" model{vertical-output: true}\n", "\n", "tippe_top = \"\"\"\n", - "\u003cmujoco model=\"tippe top\"\u003e\n", - " \u003coption integrator=\"RK4\"/\u003e\n", - "\n", - " \u003casset\u003e\n", - " \u003ctexture name=\"grid\" type=\"2d\" builtin=\"checker\" rgb1=\".1 .2 .3\" \n", - " rgb2=\".2 .3 .4\" width=\"300\" height=\"300\"/\u003e\n", - " \u003cmaterial name=\"grid\" texture=\"grid\" texrepeat=\"8 8\" reflectance=\".2\"/\u003e\n", - " \u003c/asset\u003e\n", - "\n", - " \u003cworldbody\u003e\n", - " \u003cgeom size=\".2 .2 .01\" type=\"plane\" material=\"grid\"/\u003e\n", - " \u003clight pos=\"0 0 .6\"/\u003e\n", - " \u003ccamera name=\"closeup\" pos=\"0 -.1 .07\" xyaxes=\"1 0 0 0 1 2\"/\u003e\n", - " \u003cbody name=\"top\" pos=\"0 0 .02\"\u003e\n", - " \u003cfreejoint/\u003e\n", - " \u003cgeom name=\"ball\" type=\"sphere\" size=\".02\" /\u003e\n", - " \u003cgeom name=\"stem\" type=\"cylinder\" pos=\"0 0 .02\" size=\"0.004 .008\"/\u003e\n", - " \u003cgeom name=\"ballast\" type=\"box\" size=\".023 .023 0.005\" pos=\"0 0 -.015\" \n", - " contype=\"0\" conaffinity=\"0\" group=\"3\"/\u003e\n", - " \u003c/body\u003e\n", - " \u003c/worldbody\u003e\n", - " \n", - " \u003ckeyframe\u003e\n", - " \u003ckey name=\"spinning\" qpos=\"0 0 0.02 1 0 0 0\" qvel=\"0 0 0 0 1 200\" /\u003e\n", - " \u003c/keyframe\u003e\n", - "\u003c/mujoco\u003e\n", + "\n", + " \n", "\"\"\"\n", "physics = mujoco.Physics.from_xml_string(tippe_top)\n", "PIL.Image.fromarray(physics.render(camera_id='closeup'))" @@ -882,12 +882,12 @@ }, "source": [ "Note several new features of this model definition:\n", - "0. The free joint is added with the `\u003cfreejoint/\u003e` clause, which is similar to `\u003cjoint type=\"free\"/\u003e`, but prohibits unphysical attributes like friction or stiffness.\n", - "1. We use the `\u003coption/\u003e` clause to set the integrator to the more accurate Runge Kutta 4th order.\n", - "2. We define the floor's grid material inside the `\u003casset/\u003e` clause and reference it in the floor geom. \n", + "0. The free joint is added with the `` clause, which is similar to ``, but prohibits unphysical attributes like friction or stiffness.\n", + "1. We use the `