run_control
¶
HOLD_POLL_SECONDS
module-attribute
¶
HOLD_POLL_SECONDS: float = 1 / 60
How often a held run wakes to check for a stop request and to call RunControl.pump.
TargetKind
¶
RunTarget
dataclass
¶
RunTarget(kind: TargetKind, value: float)
Where a run should pause by itself. Both kinds are readings since the run began, not distances from now.
-
Reference
mujoco_mojoruntime
reached
¶
Whether a run at sim_time that has made steps steps is at or past the target.
Source code in src/mujoco_mojo/runtime/run_control.py
RunControl
dataclass
¶
RunControl(
pump: Callable[[], None] | None = None,
on_hold: Callable[[str | None], None] | None = None,
)
What a user interface asks of a run in progress: hold it, let it carry on, advance it a few steps at a time, or change its speed.
A speed of 0 is manual stepping: the run is held at every step and each step request lets one through. That meaning belongs to this class, so a RuntimeManager used without one still treats a playback_speed of 0 as unpaced.
The interface calls the request methods from its own thread. The RuntimeManager calls wait_while_paused and take_speed at the top of every step, which is the only place a run written as a loop of step calls can be held without any help from the runtime function.
-
Reference
mujoco_mojoutilslayersreloaded
pump
class-attribute
instance-attribute
¶
pump: Callable[[], None] | None = None
Called repeatedly while the run is held, so a viewer that needs regular attention to stay responsive gets it.
on_hold
class-attribute
instance-attribute
¶
Called from the run's own thread each time the run is about to be held. The reason is given when the run held itself on reaching its target, and is None when the interface asked for the hold or the run is stepping manually.
manual
property
¶
manual: bool
Whether the run is stepping manually, held at every step until one is let through.
position
property
¶
The simulation time and step count the run was at when it last asked whether to go on.
pause
¶
resume
¶
Lets a held run carry on, and forgets any steps still owed.
step
¶
step(count: int = 1) -> None
Lets the run take count more steps and then holds it again. A run that is not held yet is held after those steps.
Source code in src/mujoco_mojo/runtime/run_control.py
set_speed
¶
set_speed(speed: float) -> None
Asks for a new playback speed, which the run picks up at its next step. A speed of 0 is manual stepping. Leaving manual stepping leaves the run paused, so changing the speed never starts a run by itself.
Source code in src/mujoco_mojo/runtime/run_control.py
take_speed
¶
take_speed() -> float | None
The speed asked for since the last call, or None if there is no new one.
run_until
¶
run_until(target: RunTarget | None) -> None
Pauses the run once it reaches target, in place of any earlier target. None clears it. A target that is reached pauses the run once and is then forgotten.
Source code in src/mujoco_mojo/runtime/run_control.py
reset
¶
reset(speed: float | None = None) -> None
Clears every request, so the next run starts running. speed is the speed that run was given, which only matters because 0 means it starts out stepping manually.
Source code in src/mujoco_mojo/runtime/run_control.py
wait_while_paused
¶
wait_while_paused(
stop: Event | None = None,
sim_time: float = 0.0,
steps: int = 0,
) -> float
Blocks the calling thread while the run is held, and returns how many seconds it was held for.
It returns at once when the run is not held, when a step is owed, or when stop is set. Calling it from the thread that steps the run is what holds the run. sim_time and steps say where the run is, which is how a target gets noticed: reaching it holds the run, and on_hold hears why.