studio
¶
SYNC_PERIOD
module-attribute
¶
The shortest time between two syncs from the runtime. Physics may step thousands of times a second, and the viewer cannot show them all.
PUMP_PERIOD
module-attribute
¶
How often the viewer is synced while the runtime is not doing it, i.e. when idle, paused, or stepping slowly.
START_TIMEOUT
module-attribute
¶
How long to wait for the browser viewer to come up before giving up.
SETTLE_SECONDS
module-attribute
¶
How long the browser viewer is given, after the first model is published, before anything can connect to it. Studio's own code crashes, intermittently and without a Python error, if a page's UI connection arrives within the first few tenths of a second.
DEFAULT_WEB_PORT
module-attribute
¶
The first port tried for the browser viewer when none is given.
ViewerUnavailableError
¶
Bases: RuntimeError
The chosen viewer cannot run here. The message says why and what to use instead.
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.
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).
Source code in src/mujoco_mojo/utils/utils.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
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.