`import mujoco.mjx` fails with TypeError when warp-lang is too old

Aperta Adatta ai principianti
#3,738 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 6 giorni

@moah0911 ci sta già lavorando.

Dal 29/10/2026.

  • #3739 di @moah0911 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Inizia leggendo mjx/warp/__init__.py intorno alle righe 36–42 e l’errore di importazione descritto per mujoco.mjx.third_party.mujoco_warp. Riproducilo con mujoco-mjx 3.17.0 e warp-lang 1.12.1, poi verifica che l’importazione riesca e che MJX possa usare il backend JAX quando l’importazione del Warp incluso non riesce. L’issue suggerisce di ampliare le eccezioni intercettate e menziona il miglioramento del messaggio sulla versione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
Intro

Hi!

I just finished my PhD at Inria Scool (France), I use MuJoCo for my research on Reinforcement Learning.

My setup

mujoco 3.17.0, mujoco-mjx 3.17.0 (Python API), warp-lang 1.12.1, jax 0.11.2, Python 3.12.8, macOS 15.7.4 on Apple M4 Pro (arm64), CPU only.

What's happening? What did you expect?

import mujoco.mjx raises a TypeError, instead of falling back to the JAX backend, when the installed warp-lang is older than the bundled mujoco_warp needs. I expected the import to succeed and MJX to use the JAX backend, as it does when warp-lang is not installed.

Where (main):

  • mjx/warp/init.py#L36-L42 always tries to import the bundled mujoco_warp, and catches only ImportError and RuntimeError:
  try:
    from mujoco.mjx.third_party import mujoco_warp
    from mujoco.mjx.third_party.mujoco_warp._src import types as mjwp_types
    from mujoco.mjx.third_party.mujoco_warp._src import io as mjwp_io
  except (ImportError, RuntimeError) as e:
    print('Failed to import mujoco_warp:', e)
    pass

The warp extra pins warp-lang==1.18.0 (mjx/pyproject.toml#L38-L41), but nothing stops another package from bringing an older one. For example, MuJoCo Playground 0.2.0 declares mujoco-mjx>=3.6.0 and warp-lang>=1.11, so a resolver can pick exactly this pair. Then import mujoco.mjx fails, even for users who only need the JAX backend. The docs' pip install mujoco-mjx[warp] avoids this; here the older warp-lang comes from another package. Related, but the other way round: #2894 (a warp-lang too new for impl='warp').

A possible fix is to catch any exception from the bundled import:

     from mujoco.mjx.third_party.mujoco_warp._src import io as mjwp_io
-  except (ImportError, RuntimeError) as e:
+  except Exception as e:  # pylint: disable=broad-exception-caught
+    # e.g. TypeError when warp-lang is older than the bundled mujoco_warp needs.
     print('Failed to import mujoco_warp:', e)

With this change applied to a local copy of 3.17.0, the import succeeds with warp-lang 1.12.1, prints the message, and mjx.step runs on the JAX backend. Naming the required warp-lang version in the message could also help. I'm happy to send a PR.

Steps for reproduction
  1. Install mujoco-mjx 3.17.0 together with warp-lang 1.12.1 (and jax).
  2. Run the code below.
  3. The import fails:
  File ".../mujoco/mjx/warp/__init__.py", line 37, in <module>
    from mujoco.mjx.third_party import mujoco_warp
  ...
  File ".../mujoco/mjx/third_party/mujoco_warp/_src/solver.py", line 1677, in <module>
    @wp.kernel(grid_stride=True)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: kernel() got an unexpected keyword argument 'grid_stride'

Without warp-lang installed, the same import prints the two "Failed to import" messages and succeeds.

Minimal model for reproduction

Not needed: the error happens at import mujoco.mjx, before any model is loaded.

Code required for reproduction
import importlib.metadata as md

for dist in ("mujoco", "mujoco-mjx", "warp-lang", "jax"):
    try:
        print(dist, md.version(dist))
    except md.PackageNotFoundError:
        print(dist, "not installed")

import mujoco.mjx  # noqa: E402,F401

print("import mujoco.mjx: ok")
Confirmations
Lingua principale
C++
Stelle
18.3k
Fork
2.2k
Merge medio
9g 11h
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di google-deepmind/mujoco

Tutte le issue di google-deepmind/mujoco

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.