Runtime manager
runtime_manager
¶
SimulationStopped
¶
Bases: Exception
Raised by RuntimeManager.step to unwind a running simulation when the user requests a stop.
RuntimeManager
dataclass
¶
RuntimeManager(
signal_manager: SignalManager | None = None,
loads: list[Load] = list(),
proximities: list[Proximity] = list(),
tracers: list[Tracer] = list(),
video_recorders: list[VideoRecorder] = list(),
requirements: RequirementsManager = RequirementsManager(),
playback_speed: float = 1.0,
_sync_hook: SyncHook | None = None,
_viewer_lock: Callable[[], AbstractContextManager[Any]]
| None = None,
_skip_recording: bool = False,
_stop_event: Event | None = None,
_resolved: bool = False,
)
__enter__
¶
__enter__() -> Self
Prime the model and prepare results. Also makes this instance available via RuntimeManager.current() for the duration of the with block.
Source code in src/mujoco_mojo/runtime/runtime_manager.py
__exit__
¶
Ensure all telemetry is flushed even if the simulation crashed. Also saves recordings
Source code in src/mujoco_mojo/runtime/runtime_manager.py
current
classmethod
¶
current() -> RuntimeManager
Returns the RuntimeManager of the innermost enclosing with block. Raises if called outside of one.
Source code in src/mujoco_mojo/runtime/runtime_manager.py
resolve
¶
add_requirement
¶
add_requirement(
fn: RequirementFn,
*,
name: str | None = None,
every: int | None = None,
terminate_on_fail: bool = False,
terminate_on_pass: bool = False,
latch_on_fail: bool = True,
latch_on_pass: bool = False,
post_result: bool = True,
) -> None
Register a named pass/fail check evaluated at end of trial and optionally during simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
RequirementFn
|
Callable |
required |
name
|
str | None
|
Label for this check in results and telemetry. Defaults to |
None
|
every
|
int | None
|
If |
None
|
terminate_on_fail
|
bool
|
When |
False
|
terminate_on_pass
|
bool
|
When |
False
|
latch_on_fail
|
bool
|
When |
True
|
latch_on_pass
|
bool
|
When |
False
|
post_result
|
bool
|
Post a telemetry column to the signal manager after evaluating the requirement if True. |
True
|
Source code in src/mujoco_mojo/runtime/runtime_manager.py
requirement
¶
requirement(
name: str | None = None,
*,
every: int | None = None,
terminate_on_fail: bool = False,
terminate_on_pass: bool = False,
latch_on_fail: bool = True,
latch_on_pass: bool = False,
post_result: bool = True,
) -> Callable[[RequirementFn], RequirementFn]
Registers a pass/fail check that runs automatically when the trial ends. Results are collected in requirements.results and written to requirements.json alongside the trial telemetry.
The decorated function must accept (mojo_model: MojoModel, state: MjState, df: MojoDataFrame | None) and return (passed, message) where passed is True, False, or None (undetermined yet; a no-op during live checks, a failure if still undetermined at end of trial). mojo_model provides access to user data and named values. state is the last simulation state. df is the full trial telemetry parquet at end-of-trial, or None during live evaluations (see every).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Label for this check in results and telemetry. Defaults to the function's |
None
|
every
|
int | None
|
When set, the check also runs inside |
None
|
terminate_on_fail
|
bool
|
When |
False
|
terminate_on_pass
|
bool
|
When |
False
|
latch_on_fail
|
bool
|
When |
True
|
latch_on_pass
|
bool
|
When |
False
|
post_result
|
bool
|
Post a telemetry column to the signal manager after evaluating the requirement if True. |
True
|
Example
@rm.requirement(every=100, terminate_on_fail=True)
def upright(mojo_model, state, df): return state.data.qpos[2] > 0.1, "ok"
Source code in src/mujoco_mojo/runtime/runtime_manager.py
last_passed
¶
Returns the cached live-check result for a requirement at the current sim time, or None if there is no verdict yet.
Accepts either the requirement's name or the function itself. The decorator returns the original function unchanged, so the reference from @rm.requirement(...) can be passed directly instead of retyping its name. Passing a function that was never registered raises ValueError.
None covers two cases callers can't tell apart: the check hasn't run at this exact sim time (every > 1 only evaluates on some steps), or it ran and explicitly returned undetermined (None). Either way, treat None as "no verdict yet", not as failure.
Example
Source code in src/mujoco_mojo/runtime/runtime_manager.py
step
¶
step(
state: MjState,
clear_xfrc_applied: bool = True,
clear_qfrc_applied: bool = True,
clear_ctrl: bool = True,
)
Calculates forces, integratess physics, and handles telemetry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
MjState
|
The paired MuJoCo model and data instance. |
required |
clear_xfrc_applied
|
bool
|
If True, zero |
True
|
clear_qfrc_applied
|
bool
|
If True, zero |
True
|
clear_ctrl
|
bool
|
If True, zero |
True
|
Source code in src/mujoco_mojo/runtime/runtime_manager.py
| Python | |
|---|---|
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | |