MjLab Framework¶
This section contains documentation for the MjLab framework adapter, which provides tools for exporting policies from MjLab to ONNX format using exploy.
Environment¶
The exportable environment adapter for MjLab.
- class exploy.exporter.frameworks.mjlab.env.MjlabExportableEnvironment(env, policy_obs_group_name='actor')[source]¶
Bases:
ExportableEnvironmentWraps a MjLab
ManagerBasedRlEnvfor ONNX export.Replaces each entity’s
_datawith an ONNX-traceableEntityDataSourceproxy so that all observation computations use managed tensors that become ONNX graph inputs. Only entity data is replaced — scene sensors and other state are left intact.After export,
cleanup()restores the original entity data objects.- property env: mjlab.envs.ManagerBasedRlEnv¶
- prepare_export()[source]¶
Prepare the environment for export. Called before each export.
- Return type:
- compute_observations()[source]¶
Compute and return the observations of the environment.
- Return type:
- apply_actions()[source]¶
Apply processed actions (e.g., joint targets) to the environment
- Return type:
- register_evaluation_hooks(update, evaluate_substep)[source]¶
Register evaluation hooks by injecting a dummy sensor and command term.
MjLab iterates
scene._sensorsat each substep and callssensor.update(), and callscommand_manager.compute()after each step. We inject dummy objects into those dictionaries so our callbacks fire at the right times.- Return type:
Actor¶
Actor wrappers for RSL-RL v5 policy networks.
- class exploy.exporter.frameworks.mjlab.actor.RslRlV5Actor(model)[source]¶
Bases:
ExportableActorWraps an RSL-RL v5
MLPModel(non-recurrent) for ONNX export.Converts the flat observation tensor into the
TensorDictformat thatMLPModel.forwardexpects, using the model’s ownobs_groupslist to know which keys are needed.
- class exploy.exporter.frameworks.mjlab.actor.RslRlV5RecurrentActor(model)[source]¶
Bases:
ExportableActorWraps an RSL-RL v5
RNNModel(recurrent) for ONNX export.Same TensorDict wrapping as
RslRlV5Actorbut also exposes the RNN’s hidden state viaget_state()so thatadd_actor_memorycan register it as an ONNX input/output.- __init__(model)[source]¶
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- exploy.exporter.frameworks.mjlab.actor.make_exportable_actor(env, actor_model, device)[source]¶
Create an exportable actor from an RSL-RL v5
MLPModelorRNNModel.- Parameters:
env (ExportableEnvironment) – The exportable environment that the actor will be used in.
actor_model (MLPModel | RNNModel) – The RSL-RL v5 actor model (
PPO.actor).device (str) – The device to place the actor on.
- Return type:
ExportableActor
Inputs¶
Utilities for registering sensor and command inputs from MjLab managers.
- exploy.exporter.frameworks.mjlab.inputs.add_base_com_vel(entities, context_manager)[source]¶
Add root COM linear and angular velocity inputs for all entities.
Reads from
entity.data.root_com_lin_vel_bandroot_com_ang_vel_b, which go through theEntityDataSourceproxy and are therefore traced as ONNX graph inputs.- Parameters:
entities (
dict) – Dict mapping entity name to Entity objects.context_manager (
ContextManager) – The context manager to add inputs to.
- Return type:
- exploy.exporter.frameworks.mjlab.inputs.add_body_pos_and_quat(entities, context_manager)[source]¶
Add body position and orientation inputs for all entities.
Reads from
entity.data.body_link_pos_wandbody_link_quat_wsliced per body, going through the proxy so the slice is an ONNX graph input.- Parameters:
entities (
dict) – Dict mapping entity name to Entity objects.context_manager (
ContextManager) – The context manager to add inputs to.
- Return type:
- exploy.exporter.frameworks.mjlab.inputs.add_joint_pos_and_vel(entities, context_manager)[source]¶
Add joint position and velocity inputs for all entities.
- Parameters:
entities (
dict) – Dict mapping entity name to Entity objects.context_manager (
ContextManager) – The context manager to add inputs to.
- Return type:
- exploy.exporter.frameworks.mjlab.inputs.add_commands(command_manager, context_manager)[source]¶
Add command inputs from the command manager to the context manager.
Iterates all active command terms and adds them as inputs. Currently supports
UniformVelocityCommand.- Parameters:
command_manager – The MjLab command manager containing active command terms.
context_manager (
ContextManager) – The context manager to add command inputs to.
- Return type:
- exploy.exporter.frameworks.mjlab.inputs.add_sensor_inputs(sensors, context_manager)[source]¶
Add sensor inputs to the context manager.
Iterates all sensors and adds their data as inputs. Currently supports
RayCastSensor.- Parameters:
sensors (
dict) – Dictionary mapping sensor names to sensor objects.context_manager (
ContextManager) – The context manager to add sensor inputs to.
- Return type:
Outputs¶
Utilities for registering action outputs from MjLab managers.
- exploy.exporter.frameworks.mjlab.outputs.add_outputs(action_manager, context_manager)[source]¶
Add joint target outputs for all action terms in the action manager.
Iterates all active action terms and adds their joint target outputs. Currently supports
BaseAction(and all its subclasses such asJointPositionAction,JointVelocityAction,JointEffortAction).- Parameters:
action_manager (
ActionManager) – The MjLab action manager containing active action terms.context_manager (
ContextManager) – The context manager to add components to.
- Return type:
Memory¶
Utilities for registering memory components from MjLab managers.
- exploy.exporter.frameworks.mjlab.memory.add_memory(env, context_manager)[source]¶
Add memory components for the action manager.
Registers the latest actions and processed actions (one per active action term) as Memory components so they are available as ONNX graph inputs.
- Parameters:
env – The MjLab ManagerBasedRlEnv.
context_manager (
ContextManager) – The context manager to add components to.
- Return type:
- exploy.exporter.frameworks.mjlab.memory.add_term_memory(action_manager, context_manager, action_term_name, attr_name)[source]¶
Register an arbitrary attribute of an action term as a Memory component.
- Parameters:
action_manager – The MjLab action manager.
context_manager (
ContextManager) – The context manager to add components to.action_term_name (
str) – Name of the action term in the action manager.attr_name (
str) – Attribute name on the action term to expose as memory.
- Return type:
Data Sources¶
Adaptor classes that mirror MjLab data interfaces while managing their own tensor data for ONNX export.
- class exploy.exporter.frameworks.mjlab.entity_data.EntityDataSource(entity)[source]¶
Bases:
objectMimic the interface of an
EntityData, but manage its own ONNX-traceable tensor data.Replaces
entity._dataduring ONNX export so that observation functions access managed tensors instead of live simulation buffers. These managed tensors become ONNX graph inputs because they are the same Python objects returned byentity.data.*during tracing.After export, the original
entity._datais restored byMjlabExportableEnvironment.cleanup().- update(*args, **kwargs)[source]¶
No-op update to mimic simulator data-source interfaces.
- Return type:
- property root_link_pose_w: Tensor¶
Root link pose [pos, quat] in simulation world frame. Shape is (num_instances, 7).
- property root_com_pose_w: Tensor¶
Root COM pose [pos, quat] in simulation world frame. Shape is (num_instances, 7).
- property projected_gravity_b: Tensor¶
Projection of gravity direction on base frame. Shape is (num_instances, 3).
- property root_link_pos_w: Tensor¶
Root link position in world frame. Shape is (num_instances, 3).
This is the base stored data - position of the root body’s link frame.
- property root_link_quat_w: Tensor¶
Root link orientation (w, x, y, z) in world frame. Shape is (num_instances, 4).
This is the base stored data - orientation of the root body’s link frame.
- property root_link_lin_vel_w: Tensor¶
Root link linear velocity in world frame. Shape is (num_instances, 3).
Computed from COM velocity by subtracting the velocity offset due to COM offset.
- property root_link_ang_vel_w: Tensor¶
Root link angular velocity in world frame. Shape is (num_instances, 3).
Angular velocity is the same for link and COM frames.
- property root_link_lin_vel_b: Tensor¶
Root link linear velocity in base frame. Shape is (num_instances, 3).
- property root_link_ang_vel_b: Tensor¶
Root link angular velocity in base frame. Shape is (num_instances, 3).
- property root_com_quat_w: Tensor¶
Root COM orientation (w, x, y, z) in world frame. Shape is (num_instances, 4).
- property root_com_lin_vel_w: Tensor¶
Root COM linear velocity in world frame. Shape is (num_instances, 3).
Computed by transforming from body frame to world frame.
- property root_com_ang_vel_w: Tensor¶
Root COM angular velocity in world frame. Shape is (num_instances, 3).
Computed by transforming from body frame to world frame.
- property root_com_lin_vel_b: Tensor¶
Root COM linear velocity in base frame. Shape is (num_instances, 3).
This is the base stored data - linear velocity of the root body’s COM in body frame.
- property root_com_ang_vel_b: Tensor¶
Root COM angular velocity in base frame. Shape is (num_instances, 3).
This is the base stored data - angular velocity of the root body’s COM in body frame.
- property body_link_pose_w: Tensor¶
Poses [pos, quat] of all body links in world frame. Shape is (num_instances, num_bodies, 7).
- property body_link_pos_w: Tensor¶
Positions of all body links in world frame.
This is the base stored data - positions of all bodies’ link frames.
- property body_link_quat_w: Tensor¶
Orientations (w, x, y, z) of all body links in world frame.
This is the base stored data - orientations of all bodies’ link frames.
- property body_link_lin_vel_w: Tensor¶
Linear velocities of all body links in world frame.
Computed from COM velocity by subtracting the velocity offset due to COM offset.
- property body_link_ang_vel_w: Tensor¶
Angular velocities of all body links in world frame.
Angular velocity is the same for link and COM frames.
- property body_com_pose_w: Tensor¶
Poses [pos, quat] of all body COMs in world frame. Shape is (num_instances, num_bodies, 7).
- property body_com_lin_vel_w: Tensor¶
Linear velocities of all body COMs in world frame.
Computed by transforming from body frame to world frame.
- class exploy.exporter.frameworks.mjlab.raycaster_data.RayCasterDataSource(sensor, entities)[source]¶
Bases:
objectProxy for raycaster sensor data that holds ONNX-traceable tensors.
Replaces
sensor._dataduring ONNX export so that raycaster height observations use managed tensors that become ONNX graph inputs.
- class exploy.exporter.frameworks.mjlab.sensor_proxy.MjLabBuiltinSensorProxy(original_sensor)[source]¶
Bases:
objectDuck-type proxy for
BuiltinSensorthat returns a managed ONNX-traceable tensor.Replaces a
BuiltinSensorinscene._sensorsso that calls toscene["robot/imu_lin_vel"].data(and similar) return a plain PyTorch tensor that can be traced for ONNX export.After each simulation sense step,
sync_from(original_sensor)must be called to refresh the managed tensor with the current sensor reading.
Utilities¶
Helper functions for MjLab integration.
- exploy.exporter.frameworks.mjlab.utils.get_observation_names(observation_manager, group_name='actor')[source]¶
Compute a list of observation names for the flattened observation buffer.
- exploy.exporter.frameworks.mjlab.utils.get_entity_actuator_gains(entity)[source]¶
Extract stiffness and damping gains from a MjLab entity’s actuator config.
Iterates the entity’s actuators and returns a dict mapping joint name to
{"stiffness": float, "damping": float}. Only actuators that exposecfg.stiffness/cfg.damping(e.g.IdealPdActuator) contribute gains; other actuator types map to zeros.