-
Notifications
You must be signed in to change notification settings - Fork 192
Description
WIth the current monolithic Model/State design in Newton, it is difficult to add custom attributes in order to read Solver-specific data. See #871 for an example of the modifications needed to (ModelBuilder, Model, State, SolverMujoco) in order to read MjData.qfrc_actuator.
This challenge is not limited to SolverMujoco. For example, SolverFeatherstone also defines custom Model and State attributes inside Solver:
| def allocate_model_aux_vars(self, model): |
| def allocate_state_aux_vars(self, model, target, requires_grad): |
Since not all aspects of MjWarp are exposed to users in Newton currently, users may be discouraged from using newton.SolverMujoco, and instead prefer to use mujoco_warp directly, or use lightweight wrappers on top of it such as mjlab, in order to access the full capabilities of MjWarp.
newton/newton/_src/solvers/mujoco/solver_mujoco.py
Lines 2514 to 2521 in 709422d
| def expand_model_fields(self, mj_model: MjWarpModel, nworld: int): | |
| if nworld == 1: | |
| return | |
| model_fields_to_expand = [ | |
| # "qpos0", | |
| # "qpos_spring", | |
| "body_pos", |
If instead there are custom Model/State for each solver, then Newton may be able to directly use MjWarp.types.Model and MjWarp.types.Data (State). I think this may also make multi-physics solver coupling more explicit. One potential API for backwards compatibility:
model = ModelNewton(model_featherstone, model_vbd)
model._default == "featherstone"
model.body_X_com == model.featherstone.body_X_com
model.particle_hessians # raise AttributeError
model.vbd.particle_hessians = ...
state = StateNewton(state_featherstone, state_vbd)
state._default == "featherstone"
state.joint_tau == state.featherstone.joint_tauAt the very least, I think there should be a solvers/SOLVER/types.py in order to clarify what attributes each solver supports. Currently there is no consistency for how solvers add custom attributes. Style3D, ImplicitMPM, and Featherstone, Mujoco all do it differently. There are also stateful warp arrays as attributes on specific solvers that should belong in Model or State.
I am happy to make an attempt towards this change, but given the complexity and scale of this, thought it would be helpful to hear thoughts before trying.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status