Skip to content

Commit 806be2e

Browse files
btabacopybara-github
authored andcommitted
Fix notebook.
PiperOrigin-RevId: 716037590 Change-Id: I28a90b1c0a048941ff26dc17d8d51d4955ef6508
1 parent beca9ce commit 806be2e

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

learning/notebooks/locomotion.ipynb

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
"id": "_UbO9uhtBSX5"
3030
},
3131
"source": [
32-
"\u003e \u003cp\u003e\u003csmall\u003e\u003csmall\u003eCopyright 2025 DeepMind Technologies Limited.\u003c/small\u003e\u003c/p\u003e\n",
33-
"\u003e \u003cp\u003e\u003csmall\u003e\u003csmall\u003eLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at \u003ca href=\"http://www.apache.org/licenses/LICENSE-2.0\"\u003ehttp://www.apache.org/licenses/LICENSE-2.0\u003c/a\u003e.\u003c/small\u003e\u003c/small\u003e\u003c/p\u003e\n",
34-
"\u003e \u003cp\u003e\u003csmall\u003e\u003csmall\u003eUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\u003c/small\u003e\u003c/small\u003e\u003c/p\u003e"
32+
"> <p><small><small>Copyright 2025 DeepMind Technologies Limited.</small></p>\n",
33+
"> <p><small><small>Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at <a href=\"http://www.apache.org/licenses/LICENSE-2.0\">http://www.apache.org/licenses/LICENSE-2.0</a>.</small></small></p>\n",
34+
"> <p><small><small>Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.</small></small></p>"
3535
]
3636
},
3737
{
@@ -40,11 +40,11 @@
4040
"id": "dNIJkb_FM2Ux"
4141
},
4242
"source": [
43-
"# Locomotion in The Playground! \u003ca href=\"https://colab.research.google.com/github/google-deepmind/mujoco_playground/blob/main/learning/notebooks/locomotion.ipynb\"\u003e\u003cimg src=\"https://colab.research.google.com/assets/colab-badge.svg\" width=\"140\" align=\"center\"/\u003e\u003c/a\u003e\n",
43+
"# Locomotion in The Playground! <a href=\"https://colab.research.google.com/github/google-deepmind/mujoco_playground/blob/main/learning/notebooks/locomotion.ipynb\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" width=\"140\" align=\"center\"/></a>\n",
4444
"\n",
4545
"In this notebook, we'll walk through a few locomotion environments available in MuJoCo Playground.\n",
4646
"\n",
47-
"**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\".\n"
47+
"**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\".\n"
4848
]
4949
},
5050
{
@@ -107,7 +107,7 @@
107107
" print('Checking that the installation succeeded:')\n",
108108
" import mujoco\n",
109109
"\n",
110-
" mujoco.MjModel.from_xml_string('\u003cmujoco/\u003e')\n",
110+
" mujoco.MjModel.from_xml_string('<mujoco/>')\n",
111111
"except Exception as e:\n",
112112
" raise e from RuntimeError(\n",
113113
" 'Something went wrong during installation. Check the shell output above '\n",
@@ -142,7 +142,7 @@
142142
"\n",
143143
"# Graphics and plotting.\n",
144144
"print(\"Installing mediapy:\")\n",
145-
"!command -v ffmpeg \u003e/dev/null || (apt update \u0026\u0026 apt install -y ffmpeg)\n",
145+
"!command -v ffmpeg >/dev/null || (apt update && apt install -y ffmpeg)\n",
146146
"!pip install -q mediapy\n",
147147
"import mediapy as media\n",
148148
"import matplotlib.pyplot as plt\n",
@@ -476,11 +476,11 @@
476476
"command = jp.array([x_vel, y_vel, yaw_vel])\n",
477477
"\n",
478478
"state = jit_reset(rng)\n",
479-
"if state.info[\"steps_since_last_pert\"] \u003c state.info[\"steps_until_next_pert\"]:\n",
479+
"if state.info[\"steps_since_last_pert\"] < state.info[\"steps_until_next_pert\"]:\n",
480480
" rng = sample_pert(rng)\n",
481481
"state.info[\"command\"] = command\n",
482482
"for i in range(env_cfg.episode_length):\n",
483-
" if state.info[\"steps_since_last_pert\"] \u003c state.info[\"steps_until_next_pert\"]:\n",
483+
" if state.info[\"steps_since_last_pert\"] < state.info[\"steps_until_next_pert\"]:\n",
484484
" rng = sample_pert(rng)\n",
485485
" act_rng, rng = jax.random.split(rng)\n",
486486
" ctrl, _ = jit_inference_fn(state.obs, act_rng)\n",
@@ -651,7 +651,7 @@
651651
" print(f\"Setting x to {x}\")\n",
652652
" command = jp.array([x, 0, 0])\n",
653653
" state.info[\"command\"] = command\n",
654-
" if state.info[\"steps_since_last_pert\"] \u003c state.info[\"steps_until_next_pert\"]:\n",
654+
" if state.info[\"steps_since_last_pert\"] < state.info[\"steps_until_next_pert\"]:\n",
655655
" rng = sample_pert(rng)\n",
656656
" act_rng, rng = jax.random.split(rng)\n",
657657
" ctrl, _ = jit_inference_fn(state.obs, act_rng)\n",
@@ -1103,7 +1103,7 @@
11031103
"id": "yCyibqGMiAca"
11041104
},
11051105
"source": [
1106-
"The final policy should exhibit smoother behavior and have less power output! Feel free to finetune the policy some more using different reward terms to demonstrate even smooth behavior."
1106+
"The final policy should exhibit smoother behavior and have less power output! Feel free to finetune the policy some more using different reward terms to get the best behavior."
11071107
]
11081108
},
11091109
{
@@ -1185,6 +1185,9 @@
11851185
},
11861186
"outputs": [],
11871187
"source": [
1188+
"#@title Rollout and Render\n",
1189+
"from mujoco_playground._src.gait import draw_joystick_command\n",
1190+
"\n",
11881191
"env = registry.load(env_name)\n",
11891192
"eval_env = registry.load(env_name)\n",
11901193
"jit_reset = jax.jit(eval_env.reset)\n",
@@ -1209,18 +1212,13 @@
12091212
" state = jit_reset(rng)\n",
12101213
" state.info[\"phase_dt\"] = phase_dt\n",
12111214
" state.info[\"phase\"] = phase\n",
1212-
" ep_rews = []\n",
12131215
" for i in range(env_cfg.episode_length):\n",
12141216
" act_rng, rng = jax.random.split(rng)\n",
12151217
" ctrl, _ = jit_inference_fn(state.obs, act_rng)\n",
12161218
" state = jit_step(state, ctrl)\n",
1217-
" ep_rews.append(state.reward)\n",
12181219
" if state.done:\n",
12191220
" break\n",
12201221
" state.info[\"command\"] = command\n",
1221-
" rews.append(\n",
1222-
" {k: v for k, v in state.metrics.items() if k.startswith(\"reward/\")}\n",
1223-
" )\n",
12241222
" rollout.append(state)\n",
12251223
"\n",
12261224
" xyz = np.array(state.data.xpos[eval_env.mj_model.body(\"torso\").id])\n",
@@ -1236,7 +1234,6 @@
12361234
" scl=np.linalg.norm(state.info[\"command\"]),\n",
12371235
" )\n",
12381236
" )\n",
1239-
" rews_ep.append(ep_rews)\n",
12401237
"\n",
12411238
"render_every = 1\n",
12421239
"fps = 1.0 / eval_env.dt / render_every\n",
@@ -1301,4 +1298,3 @@
13011298
"nbformat": 4,
13021299
"nbformat_minor": 0
13031300
}
1304-

0 commit comments

Comments
 (0)