myosuite.terms.base_action

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.

Classes

MotorNoiseCfg

Gaussian motor noise on muscle excitations (off by default).

MuscleActionTermCfg

Configuration for MuscleActionTerm.

MuscleActionTerm

mjlab ActionTerm that drives MuJoCo muscle actuators.

Functions

sigmoid_muscle_activation(action, xp)

Apply the canonical MyoSuite sigmoid muscle mapping.

muscle_normalize_action(accessor, action, **kwargs)

Map policy actions from [-1, 1] to muscle excitation in [0, 1] via sigmoid.

motor_noise(excitation, normals_sd, normals_c, ...)

Add signal-dependent and constant noise to muscle excitations.

sample_motor_noise(excitation, cfg, standard_normal, xp)

Draw fresh normals and apply motor_noise(); a no-op when disabled.

Module Contents

myosuite.terms.base_action.sigmoid_muscle_activation(action, xp)

Apply the canonical MyoSuite sigmoid muscle mapping.

Parameters:
  • action (Any) – Input activation-like array.

  • xp (Any) – Array module (numpy, jax.numpy, or torch).

Returns:

Array with element-wise 1 / (1 + exp(-5 * (a - 0.5))).

Return type:

Any

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.

Returns:

Muscle excitation array in (0, 1), same shape as action.

Return type:

Any

class myosuite.terms.base_action.MotorNoiseCfg

Gaussian 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 normals n1, n2 per 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:
  • signal_dependent_std (float) – Std of the multiplicative noise (fraction of u).

  • constant_std (float) – Std of the additive noise (excitation units).

signal_dependent_std: float = 0.0
constant_std: float = 0.0
property enabled: bool

Whether any noise is added.

Return type:

bool

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:

MotorNoiseCfg

classmethod from_value(value)

Coerce a registration kwarg (cfg, field dict or None) to a cfg.

Parameters:

value (MotorNoiseCfg | Mapping[str, float] | None) – MotorNoiseCfg, a dict of its fields, or None (off).

Returns:

The config.

Return type:

MotorNoiseCfg

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) – Excitations u in [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.numpy or torch).

Returns:

clip(u + signal_dependent_std * u * normals_sd + constant_std * normals_c, 0, 1).

Return type:

Any

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_normal or partial(torch.randn, device=...).

  • xp (Any) – Array module matching standard_normal.

Returns:

The noisy (or unchanged) excitations.

Return type:

Any

class myosuite.terms.base_action.MuscleActionTermCfg

Configuration 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.

entity_name: str = 'robot'
normalize: bool = True
muscle_fatigue: bool = False
ctrl_dt: float = 0.01
class myosuite.terms.base_action.MuscleActionTerm(cfg, env)

mjlab 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)
cfg
property action_dim: int

Number of muscle actuators in the entity.

Return type:

int

process_actions(actions)

Convert raw policy actions to muscle excitations.

Parameters:

actions (Any) – Policy output tensor, shape (N, action_dim).

Return type:

None

reset(env_ids=None)

Reset fatigue state for the given environments.

Parameters:

env_ids (Any | None) – Environment indices to reset, or None for all.

Return type:

None

apply_actions()

Write processed excitations to the simulation entity.

Return type:

None