Rendering applications#
torchrl.render provides reusable utilities behind the rlrender and
torchrl-render commands. The command-line entry point imports trusted user
policy and environment factories, loads a local checkpoint, collects one or more
rollouts, captures RGB frames from TensorDict pixels or env.render(), and
writes a reproducible artifact.
Notebook artifacts can also include an optional MuJoCo WASM sidecar viewer. In
that mode, the notebook imports helper functions from torchrl.render to
start a local Vite viewer, load an MJCF scene in browser-side MuJoCo, and stream
qpos trajectories into the live iframe. When the environment exposes native
MuJoCo state or wraps a Gymnasium MuJoCo environment,
MujocoStateReader records qpos directly from
the simulator rather than deriving it from policy observations. By default,
rlrender collects and saves trajectories before writing the notebook. Use
--notebook-rollout-mode live to write a notebook that constructs the policy
and environment inside the kernel and generates trajectories when its cells
are run. Use --notebook-rollout-mode both to save collected rollouts and
also keep an in-notebook collection cell. The generated notebook should stay
thin: reusable display, playback, rollout, and acknowledgement helpers live in
TorchRL rather than being copied into each notebook.
The MuJoCo WASM viewer requires Node.js and either npm or pnpm. The
viewer installs the generated Vite project’s pinned JavaScript dependencies
when node_modules is absent, which requires network access. The generated
node_modules directory is reused when present.
Factories can be addressed as module.submodule:callable or as a local file
path such as /path/to/render_factories.py:make_env. The base TorchRL package
does not install video or image encoders for this feature. Use the optional
rendering dependencies when writing MP4, GIF, PNG, or YAML-backed configs:
uv run --extra rendering rlrender --help
Core API#
|
Renders a policy according to |
|
Builds and prepares an environment for rendering. |
|
Builds and prepares a policy for rendering. |
|
Collects sequential render rollouts. |
|
Writes the configured render artifact and sidecar metadata. |
|
Imports an object from a |
|
Calls a user factory with a spec object or supported keyword arguments. |
|
Loads a local PyTorch checkpoint. |
|
Writes a checkpoint in the layout expected by rlrender factories. |
|
Compute a SHA256 digest over all checkpoint bytes. |
|
Infers a model state dict from common checkpoint payload layouts. |
|
Parses dotted strings into TensorDict nested keys. |
|
Formats a TensorDict nested key for config and metadata output. |
|
Normalizes a policy into a TensorDict-compatible callable. |
|
Adds a |
|
Seeds an environment if it exposes a known seed method. |
|
Normalizes external environments into TorchRL wrappers when feasible. |
|
Writes a local Vite viewer for MuJoCo WASM notebook rendering. |
|
Starts and displays a generated MuJoCo WASM viewer in a notebook. |
|
Sends one qpos vector to a live MuJoCo WASM notebook viewer. |
|
Plays a qpos trajectory in a live MuJoCo WASM notebook viewer. |
|
Extracts a qpos trajectory from a rollout TensorDict. |
Configuration and results#
|
Configuration for rendering policy rollouts. |
|
Context object passed to environment factories. |
|
Context object passed to policy factories. |
|
Result returned by |
|
One rendered step containing one or more named camera frames. |
|
Adapts plain tensor policies to a TensorDict policy callable. |
Backends#
|
Protocol implemented by rlrender frame-capture backends. |
Reads simulator state from TorchRL-native and Gym MuJoCo environments. |
|
Captures frames from TensorDict pixel entries. |
|
Captures frames by calling |
|
Fallback backend used when no RGB renderer is available. |
Lower-level helpers#
Builds the rlrender command-line parser. |
|
|
Constructs a |
|
Entry point for |
|
Builds a minimal reproducible render report notebook. |
|
Writes a render report notebook as plain ipynb JSON. |
|
Converts a tensor-like image into an |
|
Normalizes renderer output into named RGB frames. |
|
Composes multiple frames into one RGB image. |
|
Encodes RGB frames as an MP4 using TorchRL's torchcodec writer. |
|
Encodes RGB frames as an animated GIF using Pillow. |
|
Writes one RGB frame as a PNG file using Pillow. |