backends
¶
ConnectionInfo
dataclass
¶
How to reach a browser based viewer, shown in the Reloaded terminal UI.
-
Reference
mujoco_mojoutilslayersreloadedbackends
-
Reference
mujoco_mojoutilslayersreloadedcontrollerconnection_lines
OnReloadCallback
¶
ViewerBackend
¶
Bases: Protocol
What Reloaded needs from a viewer.
A backend only shows state. It never owns the command loop, so the terminal UI and the unit tests can drive every backend the same way.
failure
property
¶
failure: str | None
Why the viewer stopped when it was not the user closing it, or None.
viewer_lock
property
¶
viewer_lock: (
Callable[[], AbstractContextManager[Any]] | None
)
Lock the RuntimeManager holds while mutating model and data, or None if the viewer works on its own copy.
attach
¶
attach(controls: ViewerControls) -> None
Hands the viewer what its own buttons may ask for. Called once, before start.
close
¶
on_reload
¶
on_reload(state: MjState) -> None
Shows a new or refreshed model. Called once the model is generated and again after a run finishes.
sync_hook
¶
sync_hook(
state: MjState,
arrows: list[ArrowConfig],
lines: list[LineConfig],
) -> None
Pushes the current physics state and overlays to the viewer. Called by the RuntimeManager after every step.
Source code in src/mujoco_mojo/utils/layers/reloaded/backends/base.py
pump
¶
connection_info
¶
connection_info() -> ConnectionInfo | None
ViewerControls
¶
OpenGLBackend
dataclass
¶
The classic MuJoCo viewer (mujoco.viewer.launch_passive): a native window drawn with OpenGL.
It needs a display, so over SSH it needs X11 forwarding. The viewer reads the model and data from its own thread, which is why the RuntimeManager holds viewer_lock while it steps physics.
StudioBackend
dataclass
¶
StudioBackend(
xml_path: Callable[[], Path],
web: bool,
port: int | None = None,
gfx: StudioGraphics = DEFAULT,
title: str = "MuJoCo Mojo Reloaded",
studio: ReloadedStudioSettings = ReloadedStudioSettings(),
)
MuJoCo Studio, in a native window or in a browser.
Studio keeps its own copy of the model and data and shows what sync hands it, so unlike the classic viewer it never reads Mojo's data on its own. Mojo's runtime steps the physics, and this backend calls sync after steps and, when the runtime is not doing so, from a thread of its own, which keeps the viewer's buttons and camera alive. The viewer writes some things back into the data during sync (the Inspector's edits, dragging a body), so every sync and every step of the physics happens under one lock.
xml_path
instance-attribute
¶
Gives the file the current model was written to, which Studio shows in its title and keeps its camera by.
web
instance-attribute
¶
web: bool
Whether to show Studio in a browser instead of a native window.
port
class-attribute
instance-attribute
¶
port: int | None = None
The first port to try for the browser viewer, or DEFAULT_WEB_PORT when not given.
gfx
class-attribute
instance-attribute
¶
gfx: StudioGraphics = DEFAULT
How the native window is drawn. The browser viewer ignores it.
studio
class-attribute
instance-attribute
¶
studio: ReloadedStudioSettings = field(
default_factory=ReloadedStudioSettings
)
Which parts of Studio are showing when it opens.
ViewerUnavailableError
¶
Bases: RuntimeError
The chosen viewer cannot run here. The message says why and what to use instead.
check_studio_available
¶
check_studio_available(ui: UserInterface) -> None
Raises ViewerUnavailableError if the Studio viewer chosen by ui cannot run with the installed MuJoCo.
Source code in src/mujoco_mojo/utils/layers/reloaded/backends/studio.py
route_web_server_logs
¶
Has the browser viewer's server log through Reloaded's own logging, once the viewer is up.
The server reports each browser that connects or leaves, and why one is turned away, but it does so with a handler fixed to the terminal's stdout. Under the terminal UI that writes over the screen, and the messages are never seen. This swaps it for one that forwards to the root logger, and turns the server's debug messages on, since those say why a page is refused or is still waiting for the UI. They are few: one or two per page.
The server module is imported first. It sets up its logger the moment it is first imported, and gives up if the logger already has a handler, which would leave its quiet log level and its filter for harmless handshake errors unset.
Source code in src/mujoco_mojo/utils/layers/reloaded/backends/studio.py
studio_available
¶
studio_available() -> bool
Whether the installed MuJoCo includes Studio. Released builds do not yet, so this is only true for a build made from the MuJoCo source.
Source code in src/mujoco_mojo/utils/layers/reloaded/backends/studio.py
web_client_available
¶
web_client_available() -> bool
Whether the browser viewer can run: MuJoCo has its native state_payload bindings, and there is a client to serve. The client is the one in the mujoco-studio-wasm package (MuJoCo 4.0.1 and later), the one built into the mujoco.studio.web package (earlier releases), or the one MUJOCO_WEB_VIEWER_DIST points at.
Some builds (e.g. the 4.0.0 Windows wheel) have neither bindings nor a client, and a client from MUJOCO_WEB_VIEWER_DIST cannot make up for missing bindings.
The bindings are imported, not looked up with find_spec. They are a submodule of MuJoCo's compiled extension that mujoco.studio.web registers in sys.modules when it is first imported, so there is no file for find_spec to find, and it only reports them once something else has imported that package (the first call here used to say no and the second yes).