Implementation:Google deepmind Dm control Autowrap CLI
| Knowledge Sources | |
|---|---|
| Domains | Code Generation, Build Tools |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
The autowrap module is a command-line entry point that orchestrates the automatic generation of Python ctypes bindings from MuJoCo C header files, producing constants.py, enums.py, and sizes.py source files.
Description
The CLI accepts --header_paths (space-separated list of MuJoCo header file paths) and --output_dir via abseil flags. It identifies mjmodel.h and mjxmacro.h for special handling, then reads all headers into an ordered dictionary with mjmodel.h sorted first since other headers depend on it.
A BindingGenerator instance is created with pre-seeded hints for "buffer" and "stack" fields. The tool then runs a three-phase parsing pipeline: (1) parse enums from all headers except mjxmacro.h, (2) parse constants and typedefs from the same headers, (3) parse shape hints from mjxmacro.h. Finally, it writes the generated Python source files to the output directory.
This is the top-level build tool for maintaining dm_control's Python bindings to MuJoCo's C API, automating what would otherwise be tedious manual translation of C header declarations into Python.
Usage
Run this script during the build process whenever MuJoCo header files are updated. It ensures that the Python bindings stay synchronized with MuJoCo releases. Both --header_paths and --output_dir flags are required.
Code Reference
Source Location
- Repository: Google_deepmind_Dm_control
- File: dm_control/autowrap/autowrap.py
- Lines: 1-126
Signature
def main(unused_argv):
"""Parses MuJoCo headers and generates Python bindings."""
Import
from dm_control.autowrap import autowrap
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| --header_paths | space-separated list | Yes | Paths to MuJoCo header files (must include mjmodel.h and mjxmacro.h)
|
| --output_dir | string | Yes | Path to output directory for generated Python source files |
Outputs
| Name | Type | Description |
|---|---|---|
| constants.py | file | Generated Python file containing MuJoCo constants |
| enums.py | file | Generated Python file containing MuJoCo enum definitions as namedtuples |
| sizes.py | file | Generated Python file containing array shape information for indexing |
Usage Examples
# Command-line usage:
# autowrap --header_paths='/path/to/mjmodel.h /path/to/mjdata.h /path/to/mjrender.h \
# /path/to/mjui.h /path/to/mjvisualize.h /path/to/mjxmacro.h /path/to/mujoco.h' \
# --output_dir=/path/to/mjbindings