Skip to content

Keep the trajectory's backend when filter_and_extend adds or removes a joint - #12

Open
fylxo wants to merge 1 commit into
amathislab:mainfrom
fylxo:fix/trajectory-backend
Open

fylxo wants to merge 1 commit into
amathislab:mainfrom
fylxo:fix/trajectory-backend

Conversation

@fylxo

@fylxo fylxo commented Nov 4, 2026

Copy link
Copy Markdown

When a trajectory's joints don't exactly match the model's, for example after adding a joint to a model or with motions prepared for a slightly different skeleton, TrajectoryHandler.filter_and_extend adds or removes joints with add_joint() and remove_joints(), which default to jnp. For a numpy trajectory, qpos then comes back JAX while every other field, split_points included, stays numpy. is_numpy is judged on qpos alone, so the environment skips to_jax(), and the first jitted call that indexes split_points fails with a TracerArrayConversionError, which is hard to trace back to the joint mismatch.

This PR passes the data's own backend to those calls (four lines in loco_mujoco/trajectory/handler.py); the default stays jnp for every other caller. tests/unit/test_trajectory_handler_backend.py covers a missing and an extra joint, with the full and the sparse cache: on main (47b653d) all four fail, and with the change all four pass.

add_body and add_site have the same default, but materialize_trajectory rebuilds those fields right after, so I left them alone.

Let me know what you think,
Flavio

…a joint

When a trajectory's joints don't exactly match the model's, for example
after adding a joint to a model or with motions prepared for a slightly
different skeleton, `TrajectoryHandler.filter_and_extend` adds or
removes joints with `add_joint()` and `remove_joints()`, which default
to `jnp`. For a numpy trajectory, `qpos` then comes back JAX while every
other field, `split_points` included, stays numpy. `is_numpy` is judged
on `qpos` alone, so the environment skips `to_jax()`, and the first
jitted call that indexes `split_points` fails with a
`TracerArrayConversionError`, which is hard to trace back to the joint
mismatch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant