mujoco icon indicating copy to clipboard operation
mujoco copied to clipboard

USD decoder ignores the NewtonSceneAPI fallback for newton:timeStepsPerSecond

Open andrewkaufman opened this issue 2 weeks ago • 1 comments

My setup

MuJoCo 4.0.1 with mujoco-usd 4.0.1 from PyPI (usd-core 25.11, newton-usd-schemas 0.7.0), Python 3.12, Linux x86_64. The same code is on main.

What's happening? What did you expect?

The decoder applies newton:timeStepsPerSecond only when it has an authored value. When it is not authored, the timestep stays at MuJoCo's default of 0.002 s.

NewtonSceneAPI defines a fallback of 1000 for newton:timeStepsPerSecond, so an applied NewtonSceneAPI with no authored value describes a 0.001 s timestep. Authoring tools commonly skip values that match the schema fallback, and mujoco-usd-converter does, so any MJCF with <option timestep="0.001"/> decodes at 0.002 s and simulates at twice the intended step. In MuJoCo Menagerie this affects google_barkour_v0, google_barkour_vb, and trossen_wxai.

I expected the decoder to use the resolved value of newton:timeStepsPerSecond whenever NewtonSceneAPI is applied, so the unauthored attribute gives 0.001 s. The other two Newton scene attributes the decoder reads have fallbacks that already agree with MuJoCo (newton:maxSolverIterations = -1 means the solver default, and newton:gravityEnabled = true), so only the timestep is affected.

The check is in usd_decoder.cc.

Steps for reproduction

  1. pip install mujoco-usd==4.0.1
  2. Run the code below. It builds the same stage twice, with NewtonSceneAPI and MjcSceneAPI applied to the physics scene as mujoco-usd-converter does, with and without an authored newton:timeStepsPerSecond = 1000.
  3. In both cases the attribute resolves to 1000, but the timestep is 0.002 unless the value is authored.
authored=False: newton:timeStepsPerSecond resolves to 1000, timestep=0.002
authored=True: newton:timeStepsPerSecond resolves to 1000, timestep=0.001

Minimal model for reproduction

The stage is built in memory by the code below. The equivalent MJCF:

minimal XML
<mujoco>
  <option timestep="0.001"/>
  <worldbody>
    <body>
      <freejoint/>
      <geom type="box" size="1 1 1"/>
    </body>
  </worldbody>
</mujoco>

Code required for reproduction

import mujoco
from pxr import Usd, UsdGeom, UsdPhysics


def make_stage(author: bool) -> Usd.Stage:
    stage = Usd.Stage.CreateInMemory()
    UsdGeom.SetStageMetersPerUnit(stage, 1.0)
    UsdGeom.SetStageUpAxis(stage, UsdGeom.Tokens.z)

    scene = UsdPhysics.Scene.Define(stage, "/PhysicsScene").GetPrim()
    scene.ApplyAPI("NewtonSceneAPI")
    scene.ApplyAPI("MjcSceneAPI")
    # Equivalent to <option timestep="0.001"/>. 1000 Hz is the NewtonSceneAPI fallback.
    if author:
        scene.GetAttribute("newton:timeStepsPerSecond").Set(1000)

    body = UsdGeom.Cube.Define(stage, "/World/box")
    UsdPhysics.RigidBodyAPI.Apply(body.GetPrim())
    UsdPhysics.CollisionAPI.Apply(body.GetPrim())
    return stage


for author in (False, True):
    stage = make_stage(author)
    attr = stage.GetPrimAtPath("/PhysicsScene").GetAttribute("newton:timeStepsPerSecond")
    spec = mujoco.MjSpec.from_file(stage.GetRootLayer().identifier)
    model = spec.compile()
    print(f"authored={author}: newton:timeStepsPerSecond resolves to {attr.Get()}, timestep={model.opt.timestep}")

Confirmations

andrewkaufman avatar Nov 20 '26 18:11 andrewkaufman

Reproduced on Windows x86_64 with Python 3.12.14, mujoco-usd/mujoco-core 4.0.1, usd-core 25.11 and newton-usd-schemas 0.7.0.

The unauthored 1000 Hz fallback decodes at 0.002 s for NewtonSceneAPI alone, MjcSceneAPI alone (which includes NewtonSceneAPI), and both together. An explicitly authored 1000 Hz decodes at 0.001 s. Controls preserve 500 Hz -> 0.002 s, a plain PhysicsScene -> 0.002 s, and an authored mjc:option:timestep=0.004 -> 0.004 s.

I'd like to contribute a focused fix: read the resolved Newton timestep value, retain the positive-frequency guard and explicit MJC precedence, and add regression coverage to test/plugin/usd_decoder/usd_decoder_test.cc for these cases. Is that scope welcome, and is anyone already working on it?

The current source at c34af663c retains the authored-value gate. The reproduction above uses the released binary; building the modified C++ plugin and running the native tests in both precisions remains to be done.

duoduohappy avatar Nov 22 '26 06:11 duoduohappy