Project 10: a Gymnasium environment that passes review

Level 12 (after Lessons 12.1 and 12.2) · Time 4 hours · Difficulty 3 of 5

Objective

A gymnasium.Env for the push task, written from scratch on models/push.xml, with three action spaces: joint torques, joint targets and end-effector deltas. Every quantity in the observation must have a real-robot source. The environment is reviewed by machine: Gymnasium’s own checker, the course’s five further checks (mjcourse.capstone), and tests of what the actions and observations mean.

Prerequisites

Starter code

starter.py declares PushEnv(action_mode, max_episode_steps, frame_skip, render_mode); its docstring is the specification. Do not subclass mjcourse.envs. Follow the course’s conventions so the checker can inspect your environment: attributes model, data, max_episode_steps and observation_sources, and a method _get_obs().

Expected behaviour

The reference passes mjcourse.capstone.check in all three modes, in 0.1 to 0.2 s each. Its actions do what the docstring says:

Tests

MJC_IMPL=starter pytest projects/p10_gym_env
pytest projects/p10_gym_env

Ten tests:

python tools/mutate_project.py p10_gym_env checks the seven mutants in mutants.json.

Common failures

Extension challenges

  1. A vectorized version (gymnasium.vector.AsyncVectorEnv over 16 processes, started with spawn); measure steps per second against the single environment.
  2. Add an RGB observation from the overview camera, with its source declared, and make the checker accept it.
  3. Add actuator delay and observation noise, both seeded, and confirm that replay is still bit-identical.

Solution

solution.py, about 140 lines.