Muscle-Command Stages
Ordered muscle-command stages that wrappers install in a CPU env.
An env maps its action to a muscle excitation (sigmoid, or as-is for the walk
envs) and then runs the installed stages before writing ctrl:
map (10) -> noise (20) -> fatigue (30) -> reroute (40) -> custom stages -> ctrl (100)
No stage is installed by default: a plain env runs only its own map. The
myoFati* / myoReaf* ids and the wrappers install them; noise additionally
needs a nonzero level. The three built-in stages have a fixed order
(STAGE_ORDER), a property of the stage and not of the wrapper nesting, so a stack
built in any order behaves the same. The wrappers in
myosuite.envs.wrappers (MotorNoiseWrapper, FatigueWrapper,
ReafferentationWrapper) install one stage each through
CtrlStageHost.add_ctrl_stage().
Custom stages run after the built-in ones, in the order they were installed (the
wrapping order, or the order of EnvConfig.features): nothing to configure. Only to
insert one earlier, give it an explicit order between MAP_ORDER and
WRITE_ORDER; two stages with the same explicit order run in installation order and
trigger a StageOrderWarning.
Two kinds of custom stages exist:
a portable
ExcitationStage(ExcitationStageWrapper) works on the muscle excitations only, written for numpy and torch, and runs on the CPU env and on its mjlab twin;an env-aware stage (
CtrlStageWrapper) gets the host env and runs on the CPU only.
- myosuite.envs.muscle_stages.MAP_ORDER = 10
Priority of the env’s own action-to-excitation map; stages run after it.
- myosuite.envs.muscle_stages.WRITE_ORDER = 100
Priority of the
ctrlwrite; stages run before it.
- myosuite.envs.muscle_stages.STAGE_ORDER: dict[str, int] = {'fatigue': 30, 'noise': 20, 'reroute': 40}
Priorities of the built-in stages (fixed, ascending).
- myosuite.envs.muscle_stages.LATE_ORDER = 50
after the built-ins, in the order the stages were installed.
- Type:
Priority of a custom stage without an explicit order
- myosuite.envs.muscle_stages.CTRL_STAGE_ORDER: tuple[str, ...] = ('noise', 'fatigue', 'reroute')
Names of the built-in stages in the order they run.
- exception myosuite.envs.muscle_stages.StageOrderWarning
Bases:
UserWarningTwo stages have the same order, so their relative order is only the name order.
- myosuite.envs.muscle_stages.check_custom_order(name, order)
Raise if an explicit order is not strictly between map and ctrl write (
Noneis fine).
- myosuite.envs.muscle_stages.warn_order_clash(name, order, installed, stacklevel=3)
Warn prominently if name has the same order as an installed stage.
- class myosuite.envs.muscle_stages.ExcitationStage
Bases:
objectBase class of a portable custom stage on the muscle excitations.
Subclass it and implement
__call__(u, xp): u holds the muscle excitations ((n_muscles,)numpy on the CPU env,(n_envs, n_muscles)torch on mjlab), xp is the matching array module (numpyortorch); return the new excitations. Use only operations both modules share (xp.clip,xp.where,xp.zeros_like, arithmetic, …) and no randomness unless it comes from xp. Keep state in arrays created from u (xp.zeros_like(u)) so that it has the right shape and device, and clear it inreset().- name
Unique stage name (not a built-in name).
- order
None(default): runs after the built-in stages, in installation order; or a priority strictly betweenMAP_ORDERandWRITE_ORDERto insert it earlier.
- class myosuite.envs.muscle_stages.LowPassStage(alpha=0.3, name='lowpass', order=None)
Bases:
ExcitationStageFirst-order low-pass filter on the excitations (a portable example stage).
y <- y + alpha (u - y); the first step after a reset passes u through.- Parameters:
- myosuite.envs.muscle_stages.CtrlStage
stage(env, ctrl) -> ctrl: edits (a copy of) the control vector.
- myosuite.envs.muscle_stages.ResetStage
reset(env): per-episode reset, called where the env reset its muscle state.
- myosuite.envs.muscle_stages.reject_removed_kwargs(env_cls, kwargs)
Raise
TypeErrorfor the constructor kwargs that wrappers replaced.
- class myosuite.envs.muscle_stages.CtrlStageHost
Bases:
objectMixin of the CPU envs whose action pipeline runs wrapper-installed stages.
The host env provides
model,np_random,_muscle_act_ind(the muscle entries ofctrl) and calls_run_ctrl_stages()on the excitation vector and_run_reset_stages()inreset().- add_ctrl_stage(name, apply, reset=None, order=None)
Install a stage; it runs at its priority, after the env’s map.
- Parameters:
name (
str) – A built-in stage (STAGE_ORDER) or a new unique name.apply (
Callable[[Any,ndarray],ndarray]) –apply(env, ctrl) -> ctrl.reset (
Optional[Callable[[Any],None]]) – Optional per-episode reset of the stage’s state.order (
Optional[float]) –None(default) for a custom stage: after the built-in stages, in installation order. Or a priority strictly betweenMAP_ORDERandWRITE_ORDERto insert it earlier. Built-in stages have a fixed priority (omit it). The same explicit order as another installed stage triggers aStageOrderWarning.
- Raises:
ValueError – If name is already installed, an explicit order is out of range, or a built-in stage gets another order.
- Return type:
- remove_ctrl_stage(name)
Uninstall a stage (no-op if it is not installed).
- property muscle_fatigue: Any
Fatigue model of the installed
FatigueWrapper.- Raises:
AttributeError – If no fatigue stage is installed.
- myosuite.envs.muscle_stages.noise_stage(get_cfg)
Signal-dependent + constant Gaussian noise on the muscle excitations.
- Parameters:
get_cfg (
Callable[[],Any]) – Returns the currentMotorNoiseCfg(read every step, so the wrapper’s config can change). A disabled config draws nothing, so the env’s random stream is untouched.- Return type:
- myosuite.envs.muscle_stages.fatigue_stage(fatigue, get_reset, index=None)
3CC-r fatigue on the muscle excitations and its per-episode reset.
- myosuite.envs.muscle_stages.reroute_stage(model, suffix)
Reafferentation: EIP’s command drives EPL and EIP is silenced.
- myosuite.envs.muscle_stages.muscle_mask(model)
Boolean mask of the muscle actuators of model.
- Return type:
ndarray- Parameters:
model (MjModel)