harbor run -t openthoughts/tasktrove-exp-rpt-curriculum-easy-curriculum-easy-0263harbor download openthoughts/tasktrove-exp-rpt-curriculum-easy-curriculum-easy-0263# Easier task: a tiny MuJoCo-like shim in /app/
Goal
Create a small, self-contained Python module named mujoco_py (as /app/mujoco_py.py) that provides a minimal MuJoCo-like interface tailored for simple tests. The implementation should be pure Python, rely only on numpy, and expose the exact APIs the tests import.
What you will implement (simplified)
- A lightweight Model object that mainly carries an actuator_type attribute.
- A Data object that holds a 1-DOF state plus a few fields used by a tiny PID/P controller.
- A load_model_from_xml(xml: str) -> Model function that:
- Parses the XML string and sets model.actuator_type based on a simple rule:
- If the actuator block contains a <position ...> tag → actuator_type = "position"
- If a <general ... gainprm="..."> block contains 6 numeric terms → actuator_type = "pid"
- If a <general ... gainprm="200" ...> (only a single number) → actuator_type = "p_only"
- A MjSim class:
- __init__(self, model: Model) -> None
- Creates an internal Data object with qpos and ctrl arrays of length 1, and exposes model and data attributes.
- step(self) to advance the 1-DOF system by a fixed tiny time step (dt = 0.001), using one of three update modes based on model.actuator_type:
- "pid": apply a simple discrete PID to drive qpos toward 0 using gains Kp=200, Ki=10, Kd=0.1; ignore data.ctrl for the PID path. Keep an internal integral and previous error in data.
- "p_only" or "position": apply a simple proportional controller with Kp=200 toward 0.
- A cymj object with a method set_pid_control(model: Model, data: Data) -> None that enables PID control by setting data.pid_enabled = True (and initializing needed state if desired).
- The module should be importable as:
- from mujoco_py import MjSim, load_model_from_xml, cymj
- An extremely small, well-documented, self-contained implementation that does not depend on MuJoCo or any external libraries beyond numpy.
Public API (signatures/tests)
- load_model_from_xml(xml: str) -> Model
- class Model
- actuator_type: str # "pid", "p_only", or "position"
- class Data
- qpos: numpy.ndarray with shape (1,)
- ctrl: numpy.ndarray with shape (1,)
- pid_integral: float
- pid_prev_error: float
- pid_enabled: bool
- class MjSim
- __init__(self, model: Model) -> None
- attributes: model, data
- step(self) -> None
- cymj
- set_pid_control(model: Model, data: Data) -> None
Behavior details for tests (expected flow)
- Tests perturb initial qpos, then drive toward 0.0 using the actuator/pid logic.
- PID mode ("pid"):
- When pid control is active, per-step update uses a discrete PID with:
- Kp = 200, Ki = 10, Kd = 0.1
- dt = 0.001
- error = -qpos[0]
- integral += error * dt
- derivative = (error - pid_prev_error) / dt
- ctrl_effort = Kp*error + Ki*integral + Kd*derivative
- qpos[0] += ctrl_effort * dt
- pid_prev_error updated
- Although tests can set data.ctrl, the PID path should drive the state toward zero.
- Proportional path ("p_only" and "position"):
- Per-step update uses:
- error = -qpos[0]
- ctrl_effort = Kp * error with Kp = 200
- qpos[0] += ctrl_effort * dt
- Time step dt = 0.001 for all updates.
- All updates should operate on a single scalar DOF (qpos[0]) and not rely on MuJoCo.
Implementation hints and a lightweight skeleton
- Keep all code in a single file: /app/mujoco_py.py.
- Use simple Python classes with __init__ to store the fields above; no external dependencies beyond numpy.
- The XML parsing can be a tiny, robust, ad-hoc parser:
- Look for the presence of a <position ...> tag inside an actuator block → "position".
- Look for a <general ... gainprm="..."> attribute:
- If gainprm contains six numeric terms separated by spaces → "pid"
- If gainprm is a single numeric value → "p_only"
- Avoid any complex XML parsing libraries; simple string checks are fine for this task.
- The module should be self-contained and straightforward to test.
Notes
- The task is intentionally minimal: implement just enough to exercise the three control paths (PID, P-only, Position) in a deterministic way.
- Do not modify the tests. The implementation must live under /app/mujoco_py.py and be importable as described.
Optional but helpful (for easier debugging)
- Add docstrings to Model, Data, MjSim, and cymj explaining fields and behavior.
- Include a tiny, optional example usage in a comment at the top of the file showing how the components interact.
Place of implementation
- Implement all of the above in /app/mujoco_py.py. The solution should be self-contained and rely only on numpy.