Developer guide¶
The user-facing interfaces are covered in Interfaces and Available plugins. For the full
architecture and — importantly — the porting playbook for reworking existing MuJoCo code into
plugins, see the Architecture & porting playbook document: the plugin lifecycle in depth, the concurrency model
(single-writer + ctx.post command queue), rendering, the foreseen synchronous/lockstep mode,
performance/benchmarking, conventions, and the porting playbook (a decision tree and recipes for
turning monolithic MuJoCo code into cooperating plugins).
- Architecture & porting playbook
- 1. Overview & goals
- 2. Lifecycle reference
- 3. API contracts
- 4. Config & registry
- 5. Plugin-type catalog
- 6. Porting playbook
- 7. Concurrency & threading model
- 8. Rendering
- 9. Sensor noise
- 10. Synchronous / lockstep mode [planned — seams exist, behaviour inert]
- 11. Performance & benchmarking
- 12. Conventions
- 13. Robot interface & transport bridges
- 14. Glossary & FAQ
Repository layout¶
Each package is a sibling directory with its own pyproject.toml, which states what it depends
on; ros2_ws/src/ holds the colcon packages. Installation says what each one holds.
scenario_execution_roqsim is the only package that imports scenario_execution.
Golden rules¶
Single-writer: only the physics thread (the one calling
engine.step()) touchesmodel/data. External input goes throughctx.post(cmd).No mid-run recompile: modify the
MjSpeconly inbuild(); at runtime use mocap/qpos writes or a pre-compiled entity pool.Keep the core ROS-free. The ROS bridge is just another plugin.
A config key whose meaning changes gets a new name. The old name is then unknown and refused, so a document written for the old meaning fails at load instead of being read with the new one.
Read a model field through ``int()`` before matching it against an ``mjt*`` enum.
model.jnt_type[j]is a numpy scalar, andx in (mjJNT_HINGE, mjJNT_SLIDE)puts the enum on the left of==— which MuJoCo 3.12 answersFalsewhere 3.11 answeredTrue. A barevalue == enumstill works, so the break is silent and partial: the filter just returns nothing, and an arm reports no joints instead of raising.int()on the model value (or plain-intmembers, as incapture._SCALAR_JOINTS) is correct on every version.
Developer workflow¶
make venv # create .venv and install everything
make test # unit tests (+ nav2 integration when ROS is sourced)
make format # ruff format + autofix
make lint # ruff check (no changes)
make smoke # headless-run every shipped world
make doc # build HTML docs into build/html
make view-doc # build + open in a browser
make test runs the packages in parallel over pytest-xdist. The worker count is JOBS,
and it is bounded by memory rather than by cores: a full run peaks at roughly 3 GB per worker,
because between them the tests import mujoco, torch, cv2 and matplotlib and load every robot mesh
in the tree. The default is deliberately small – raise it if you have the RAM, and drop to the
serial path if a parallel run ever looks flaky:
make test JOBS=6 # more workers, if there is memory for them
make test JOBS=1 # serial; the fallback when a parallel run looks wrong
make test-roqsim_sensors # just one package, for the edit/run loop
make test tests the packages installed in .venv with everything they declare. A package that
is not installed, or is installed without a requirement it declares (an image built without network,
pip install --no-deps), is left out by name: tools/test_packages.py prints NOT TESTED
<package>: <what it lacks> before the run and again after it, with their count, and a test that reads the
whole tree (the README’s counts, the plugin guard) leaves out what that package would register.
Without pytest-xdist the run is serial and says so. make venv installs every package with
what it declares, after which nothing is left out.
roqsim export gltf is checked by the Khronos glTF Validator, a Node.js program pinned in
tools/gltf_validator. make test runs it over an export of a small world when it is installed
and reports a skip when it is not; make test-gltf installs it (npm ci), requires it, and holds
an export of every world roqsim_scenes ships to no error and no warning:
make test-gltf # needs node and npm on PATH
The simulated FR3’s FCI is held to Franka’s own client library: make test-franka builds libfranka
at the release roqsim_manipulation/tests/upstream/franka/SOURCES.toml pins, with its own
CMake build, and runs it against the simulated arm. It needs a C++ toolchain, CMake, Eigen3, Poco
and fmt, so make test leaves it out. It fails, rather than skips, when libfranka cannot be built:
make test-franka # needs g++, cmake, libeigen3-dev, libpoco-dev, libfmt-dev
scenario-execution is scenario_execution_roqsim’s [osc] extra, so make venv leaves it
out and make test skips every test that needs it. make test-osc runs those tests – the OSC
actions and library, a world running a scenario, the reset test’s scenario case, the handling
scenes’ OpenSCENARIO twins against their Python forms – in a venv
that has the extra, and fails rather than skips when it is missing; the CI job osc runs it:
.venv/bin/pip install -e "scenario_execution_roqsim[osc]"
make test-osc
make smoke runs every world a package or ros2_ws ships, headless, for SMOKE_STEPS
(200) steps (tools/smoke.py, tested by make test). A world passes when roqsim sim exits
0 on it, so its MJCF compiles, its plugins load and its assets resolve. A world with a scene (a
Python scenario or an OpenSCENARIO scenario: entry) must also finish that scene within the run:
roqsim sim exits 6 on a scene the run cut short (Exit status), and smoke reports the
world as a scene that did not finish, so a passing smoke still means every shipped scene runs to its
end. Shorten the scene, or let the world say how long it needs with a comment line in its own file,
which the world loader ignores and only smoke reads:
# smoke-steps: 3000
The budget is a comment rather than a world key because a world refuses keys it does not know, and
the number is smoke’s alone; it sits beside the scene it budgets, so changing one shows the other.
To smoke a few worlds rather than all of them, name them:
python3 tools/smoke.py --roqsim roqsim --steps 200 <world.yaml>....
A world that needs an asset make external-resources generates, or a CUDA GPU the machine does
not have, is reported as skipped.
Adding a tool¶
Every tool is a subcommand of roqsim, so roqsim --help is the whole inventory and nobody has to know
a path or which package a tool lives in:
roqsim --help # the core's commands and a group per package with tools
roqsim scenes --help # one line per tool in that group
roqsim scenes sdf-to-scene --help # that tool's own options
python -m pydoc roqsim_scenes.cli.sdf_to_scene # the reasoning behind it
The core’s own verbs are top-level rather than in a group: roqsim sim runs a world, roqsim render
draws one, bake bakes its lighting with Blender (Baked lighting), rebuild produces a
recorded run’s sensor streams, and state, check, health,
catalog, plugins and renderers read a world, a run or the
registries, views prints the conventions of a views file; the core’s exporters are the roqsim export group. Every package tool is
roqsim <group> <tool> (roqsim/src/roqsim/commands.py).
Write it standalone, then link it in — in the same commit.
Draft it as a script under
<pkg>/tools/<name>.pywith amain(argv)and a__main__block.Move the logic to
<pkg>/src/<pkg>/cli/<name>.pyand register it with one line in that package’s group (src/<pkg>/cli/__init__.py):group.add_command(tool("<pkg>.cli.<name>"))
Leave
<pkg>/tools/<name>.pyas a three-line wrapper, so running it from the folder still works:#!/usr/bin/env python3 """Run-from-the-folder wrapper for `roqsim scenes <name>`; the logic is in roqsim_scenes.cli.<name>.""" from roqsim_scenes.cli.<name> import main raise SystemExit(main())
A package that ships its first tool also declares the group itself, in its pyproject.toml:
[project.entry-points."roqsim.commands"]
scenes = "roqsim_scenes.cli:scenes"
That is the whole mechanism: any installed package can contribute a group this way, including one maintained outside this repository. It never edits the core.
A ROQSIM_* environment variable is registered, then read. Code reads one with
roqsim.env.get(name), which raises for a name that is not registered, and a run refuses every
ROQSIM_* variable that is not (roqsim/tests/test_env.py checks every name the tree spells).
The core’s own are roqsim.env.VARIABLES; any other package declares the ones it reads as a mapping
of name to a one-line description, under its own entry point:
[project.entry-points."roqsim.environment"]
roqsim_scenes = "roqsim_scenes.environment:VARIABLES"
You write no help text. All three levels come from the docstring you already wrote — click takes
the listing line from its first line, --help is your own argparse, and python -m pydoc
prints the rest. There is no short_help to fill in and no flag to add. Two conventions carry it,
both ordinary Python:
the docstring’s first line is a one-line summary — it is what a listing shows, so keep it plain prose (a terminal prints
\`\`markup\`\`verbatim);the parser says
ArgumentParser(description=__doc__.split("\n")[0]). Handing it the whole docstring can make a single--helpcost more than the rest of the tree together.
make test fails while a tool with a __main__ block is unregistered, while a wrapper carries
logic, or while a --help grows an essay. These are checks (roqsim/tests/test_command_registry.py),
not conventions — a convention nothing checks decays silently, until a checked-in Makefile calls a
binary that does not exist.
A tool that runs inside Blender is registered with tool(..., blender=True): it cannot be imported
here, so the command locates blender and runs the module inside it.
An input the tool cannot load is one sentence, not a traceback. Report the errors you understand
yourself; where a world, model or recording does not resolve (PluginError, ModelError,
RecordingError) or a named file is not there (FileNotFoundError) and your main lets it
through, the tree prints roqsim <group> <tool>: <reason> and exits 2, or 4 for a recording that
exists and cannot be read. -v keeps the traceback, for the case where the missing file is the tool’s
own.
Exit statuses come from roqsim.exit_status and nowhere else. Return its constants, give
the parser epilog=exit_status.epilog(<the codes this tool returns>), and report a caught error with
return exit_status.fail("roqsim <group> <tool>", err). An error class whose status is not a bad input
says so with an exit_status class attribute, so every tool that catches it agrees. Never return 1:
it is Python’s status for a crash. The table is in Exit status.
Sensor coverage (analysis layer)¶
roqsim_sensors.coverage is an offline analysis layer over a compiled world — not part of the
tick pipeline. It answers “how much of the room / which objects do these sensors see, and by how
many?” (user docs: Sensor coverage). Design worth knowing when extending it:
One shared FOV, per-type extraction.
coverage/fov.pydefines a singleSensorFov(a posed angular sector: cameraFRUSTUMvia pinhole intrinsics, lidarCONE_BANDvia azimuth/elevation bands) and thein_fovmembership test — it knows nothing about specific sensors.coverage/ adapters.pyis the only module that does: a per-type registry (@register_adapter) that builds aSensorFovfrom a sensor’s own parameters, reusing each plugin’s resolution logic (a camera’s MJCFfovy/resolution; a lidar plugin’s resolved attributes). A new sensor gets a new adapter there; the sensor plugins are never edited. This is the extension seam — keep every other coverage module dependent onSensorFovalone.Engine.
coverage/engine.pygates each point range → angular FOV (numpy) → line of sight (one batchedroqsim.raycast.cast()per sensor — the same seam every raycaster in the tree uses). The raycastgeomgroupmask excludes group 4, so an absent entity cannot occlude (and group 5, a sensor’s window, which is drawn and passed through); that is the seam’s default, so it holds without each call site remembering it. A model’s FOV-visualisation mesh is kept out by a different axis — it is alpha 0, andmj_rayskips a geom exactly when its resolved alpha is 0, whatever the mask says (its group is 2, not 4/5). Masking by group is still required, because raycasts hit visible geometry regardless of contact flags.Sampling (
coverage/sampling.py) is model-based (works for any world source) and uses only numpy + MuJoCo raycasts (viaraycast.cast_many:mj_multiRaycasts from one origin, so six axis rays from each of P grid points is irreducibly P calls — what the helper buys is the flat buffers, so the classification vectorises over all points at once instead of per point) — no scipy/trimesh (they are broken under numpy 2 in the system venv, and the layer must not depend on them). Free-space classification is deliberately conservative (drops are safe: they only make coverage look worse).Two front doors, one core: the
sensor_coverage_probeplugin (world-YAML toggle,plugins/sensor_coverage_probe.py) and theroqsim sensors coverageCLI (coverage/cli.py), whosesweptcommand accumulates a moving sensor’s field of view over a recorded run (coverage/swept.py, each sample’s state restored throughroqsim.recording.open_recording()). All of them build their points withcoverage/sampling.py’ssample_seton purpose: two coverage figures are comparable only if they sampled the same way. Thecoverageextra (matplotlib, for the 2D heatmap) is optional; the 3D render needs only MuJoCo.