Muscle Action Term
Action term functions and mjlab ActionTerm for MyoSuite environments.
Action Normalisation
All MyoSuite muscle environments use a sigmoid action normalisation by default
(normalize_act=True). Policy output is expected in [-1, 1] and is mapped
to muscle excitation in (0, 1) via:
excitation = 1 / (1 + exp(-5 * (action - 0.5)))
The sigmoid is centred at 0.5, so a policy output of −1 maps to ≈ 0.06% excitation, 0 to ≈ 7.6%, 0.5 to 50% and +1 to ≈ 92.4%: full (100%) excitation is never reached. This is the legacy MyoSuite mapping.
Action space vs. ctrl range: when normalize_act=True the declared
action_space is Box([-1, 1]^n), but the underlying model.actuator_ctrlrange
is [0, 1]^n. If you switch normalize_act=False at inference time or
load a pre-trained policy trained with a different setting, excitations will be
wrong. Always check env.normalize_act before deploying a policy.
muscle_normalize_action is backend-agnostic and uses
accessor.array_module() so it runs identically on CPU (numpy), MJX
(jax.numpy), and mjlab (torch).
Motor noise
motor_noise adds signal-dependent and constant Gaussian noise to muscle
excitations (MotorNoiseCfg, off by default). Both backends apply it after
the action -> excitation mapping and before fatigue; see
docs/wiki/cross-backend-contract.md.
MuscleActionTerm is the mjlab (Isaac Lab manager API) integration wrapper.
- myosuite.terms.base_action.sigmoid_muscle_activation(action, xp)
Apply the canonical MyoSuite sigmoid muscle mapping.
- myosuite.terms.base_action.muscle_normalize_action(accessor, action, **kwargs)
Map policy actions from [-1, 1] to muscle excitation in [0, 1] via sigmoid.
Uses
accessor.array_module()so the same implementation runs on CPU (numpy), MJX (jax.numpy), and mjlab (torch).The sigmoid
σ(5(a − 0.5))is the canonical MyoSuite muscle mapping: it is centred at 0.5, so an action of -1 gives ~0.06% excitation, 0 gives ~7.6% and +1 gives ~92.4% (the output range is [0.00055, 0.924], not the full [0, 1]).- Parameters:
accessor (
EnvAccessor) – Environment state accessor (provides array_module).action (
Any) – Policy output array in [-1, 1], any shape.**kwargs (
Any) – Unused; for uniform call signature.
- Return type:
- Returns:
Muscle excitation array in (0, 1), same shape as action.
- class myosuite.terms.base_action.MotorNoiseCfg(signal_dependent_std=0.0, constant_std=0.0)
Bases:
objectGaussian motor noise on muscle excitations (off by default).
The applied excitation is
clip(u + signal_dependent_std * u * n1 + constant_std * n2, 0, 1)with independent standard normalsn1, n2per muscle, per control step (and per env on mjlab). Signal-dependent noise (Harris & Wolpert 1998) makes the spread grow with the command, the source of the speed-accuracy trade-off; constant noise is independent of it.- Parameters:
- classmethod van_beers_2004()
Levels 0.103 (signal-dependent) and 0.185 (constant).
Fischer et al. (2021, Sci. Rep. 11:14445) take them “following van Beers et al.” (2004, J. Neurophysiol. 91:1050-1063); User-in-the-Box (Ikkala et al., UIST 2022) uses the same defaults.
- Return type:
- myosuite.terms.base_action.motor_noise(excitation, normals_sd, normals_c, signal_dependent_std, constant_std, xp)
Add signal-dependent and constant noise to muscle excitations.
Pure: the standard normals are drawn by the caller, so numpy and torch give the same result on the same draws.
- Parameters:
excitation (
Any) – Excitationsuin[0, 1], any shape.normals_sd (
Any) – Standard normals for the signal-dependent term, same shape.normals_c (
Any) – Standard normals for the constant term, same shape.signal_dependent_std (
float) – Std of the multiplicative term.constant_std (
float) – Std of the additive term.xp (
Any) – Array module (numpy,jax.numpyortorch).
- Return type:
- Returns:
clip(u + signal_dependent_std * u * normals_sd + constant_std * normals_c, 0, 1).
- myosuite.terms.base_action.sample_motor_noise(excitation, cfg, standard_normal, xp)
Draw fresh normals and apply
motor_noise(); a no-op when disabled.A disabled config returns excitation unchanged without drawing, so the caller’s random stream is untouched.
- Parameters:
excitation (
Any) – Muscle excitations, any shape (one draw per element).cfg (
MotorNoiseCfg) – Noise levels.standard_normal (
Callable[[tuple[int,...]],Any]) –f(shape)returning standard normals, e.g.np_random.standard_normalorpartial(torch.randn, device=...).xp (
Any) – Array module matching standard_normal.
- Return type:
- Returns:
The noisy (or unchanged) excitations.
- class myosuite.terms.base_action.MuscleActionTermCfg(entity_name='robot', normalize=True, muscle_fatigue=False, ctrl_dt=0.01)
Bases:
objectConfiguration for MuscleActionTerm.
- Parameters:
entity_name (
str) – Name of the articulation entity in the mjlab scene.normalize (
bool) – If True, map [-1, 1] → [0, 1]. If False, clamp to [0, 1].muscle_fatigue (
bool) – If True, apply 3-compartment cumulative fatigue dynamics to the processed excitations each control step.ctrl_dt (
float) – Control timestep in seconds; used as the integration step for the fatigue model when muscle_fatigue is True.
- class myosuite.terms.base_action.MuscleActionTerm(cfg, env)
Bases:
objectmjlab ActionTerm that drives MuJoCo muscle actuators.
Maps policy output to muscle excitation: - normalize=True: canonical sigmoid mapping. - normalize=False: excitation = clamp(action, 0, 1)
- Parameters:
cfg (
MuscleActionTermCfg) – Action term configuration.env (
Any) – mjlab ManagerBasedRlEnv instance (injected by mjlab).
Example
>>> cfg = MuscleActionTermCfg(entity_name="elbow", normalize=True) >>> term = MuscleActionTerm(cfg, env)
- process_actions(actions)
Convert raw policy actions to muscle excitations.
- reset(env_ids=None)
Reset fatigue state for the given environments.