Repository navigation
Require mujoco-core 4.0 and remove MuJoCo version shims - #1927
adenzler-nvidia merged 3 commits into
Conversation
mujoco-warp declared mujoco>=3.13.0, but it fails to import with MuJoCo 3.13 through 3.15 because ConDataField references mjtConDataField.mjCONDATA_LINVEL at import time. MuJoCo 4.0 also split the Python distribution: mujoco is now a metapackage that adds MuJoCo Studio, Filament, glfw and PyOpenGL on top of mujoco-core, none of which the library uses. Depend on mujoco-core>=4.0.0 and add a viewer extra (mujoco-core[rendering], pillow) for mjwarp-viewer, mjwarp-record and mujoco.Renderer. benchmarks/run.py --view, the README and the tutorial notebook use the extra, and the nightly workflow upgrades mujoco-core. The lock moves to the latest MuJoCo nightly, since py.mujoco.org has no final 4.0.0 and 4.0.0 dev builds sort below it. Every MuJoCo version check is satisfied by 4.0.0, so remove them with the code they guarded: the eq_data padding, plasticity and tendon_type defaults and host-side surfacevel computation in put_model and put_data, the rod record size probe that compiled a model at import, the kernel branches on ROD_HINGE_SIZE, FLEX_STIFFNESS_3D and FLEX_INTERP_PHYS_JAC, and the version-dependent skips and expectations in the tests. The flex_internal check goes too, as MuJoCo 4.0 has no such field. util_pkg.check_version stays for features of unreleased MuJoCo builds.
|
@thowell this is just a suggestion, feel free to close if you think there is a better way to do this. |
thowell
left a comment
There was a problem hiding this comment.
Thanks @adenzler-nvidia! Great cleanup switching to mujoco-core>=4.0.0, adding the viewer extra, and removing the pre-4.0 shims — looks ready to merge once two minor mujoco-core packaging edge cases are addressed:
1. pyproject.toml (lines 49--52) & uv.lock
- Issue:
mjviserindevdeclares an unversionedmujocodependency, which still pullsmujocoandmujoco-studiointouv.lock. Becausemujocowas removed from[tool.uv.sources], runninguv lock --upgrade-package mujoco-coreoruv lock --upgrade(as in.github/workflows/nightly.yml) resolvesmujocofrom PyPI (mujoco==4.0.0conflicts withmujoco-core==4.0.1.dev*and backtracks tomujoco==3.17.0), causinguv sync --all-extrasto fail onimport mujoco(OSError: libmujoco.so.3.17.0: cannot open shared object file). - Recommendation: Override the transitive
mujocometapackage dependency under[tool.uv](mjviserruns directly againstmujoco-core[rendering]) and regenerateuv.lock(UV_NO_CONFIG=1 uv lock --default-index https://pypi.org/simple), which also dropsmujocoandmujoco-studiofromuv.lock.
[tool.uv]
override-dependencies = ["mujoco ; python_version < '0'"]
[tool.uv.sources]
warp-lang = {index = "nvidia"}
mujoco-core = {index = "mujoco"}2. mujoco_warp/_src/util_pkg.py (lines 75--86)
- Issue: When only
mujoco-coreis installed (nomujocodist-info),util_pkg.check_version("mujoco>=4.0.1.dev...")hitsPackageNotFoundErrorand falls back tomujoco.__version__, which on nightlymujoco-corewheels reports"4.0.1"without the.dev*suffix and falsely evaluates toTrueagainst newer.dev*thresholds. Conversely, passing"mujoco-core>=..."without wheel metadata fails in the fallback because the importable module ismujoco. - Recommendation: Check both
"mujoco"and"mujoco-core"distribution metadata before falling back to importingmujoco.
dist_names = (
(package_name, "mujoco-core" if package_name == "mujoco" else "mujoco")
if package_name in ("mujoco", "mujoco-core")
else (package_name,)
)
for dist_name in dist_names:
try:
installed_str = importlib.metadata.version(dist_name)
break
except importlib.metadata.PackageNotFoundError:
pass
else:
# Fallback: import the package and read __version__
try:
import importlib as _importlib # noqa: F811
mod_name = "mujoco" if package_name == "mujoco-core" else package_name
mod = _importlib.import_module(mod_name)
installed_str = mod.__version__
except (ImportError, AttributeError) as err:
raise importlib.metadata.PackageNotFoundError(package_name) from errmjviser depends on an unversioned mujoco, which kept the mujoco metapackage and mujoco-studio in uv.lock. Nothing pins that transitive dependency to py.mujoco.org, so when a different index takes priority (for example a default index passed on the command line), upgrading the lock resolves mujoco 3.17 from PyPI next to a mujoco-core 4.0 nightly and the environment no longer imports. Override the dependency away, since mjviser only needs the mujoco module that mujoco-core provides, and regenerate the lock.
With only mujoco-core installed there is no mujoco distribution, so check_version("mujoco>=...") fell back to mujoco.__version__. That string has no .dev suffix on nightly wheels, so the check passed against newer nightly thresholds. A "mujoco-core>=..." spec without metadata failed in the fallback instead, because the module is named mujoco.
Look up both distribution names before falling back, and import the mujoco module for mujoco-core.
|
Thanks @thowell, both addressed.
|
…at-frames types_test drops the quaternion field substitution with the other version shims: MjData of MuJoCo 4.0 has xiquat, geom_xquat and site_xquat.
thowell
left a comment
There was a problem hiding this comment.
thanks @adenzler-nvidia!
mujoco-warp declares
mujoco>=3.13.0, but it no longer imports with MuJoCo 3.13 through 3.15:ConDataFieldreferencesmjtConDataField.mjCONDATA_LINVELat import time since #1813, which fails withAttributeError. This is the same failure #1777 fixed for 3.12, and it went unnoticed because CI never installs the declared minimum. MuJoCo 4.0 also split the Python distribution, somujocois now a metapackage that pulls in MuJoCo Studio, Filament, glfw and PyOpenGL on top ofmujoco-core. The library uses none of these. Onlymjwarp-viewer,mjwarp-recordand the tutorial notebook'smujoco.Renderercells need them.This change depends on
mujoco-core>=4.0.0and adds aviewerextra (mujoco-core[rendering],pillow) for those tools;devincludes it.pillowwas previously only indev, somjwarp-recordfailed on a plain install.benchmarks/run.py --view, the README and the tutorial notebook now use the extra, and the nightly workflow upgradesmujoco-coreinstead ofmujoco. The lock moves to the nightly4.0.1.dev1017127398, because py.mujoco.org has no final 4.0.0 and4.0.0.devNsorts below4.0.0.Every
check_version("mujoco>=...")in the package is satisfied by 4.0.0, so this removes them together with the code they guarded:put_modelandput_data: theeq_datapadding, the plasticity andtendon_typedefaults, and the host-sidesurfacevelcomputation.ROD_HINGE_SIZE,FLEX_STIFFNESS_3DandFLEX_INTERP_PHYS_JAC. The first two are now plain constants.The
flex_internalcheck input_modelgoes too, because MuJoCo 4.0 has no such field.util_pkg.check_versionstays, for features of MuJoCo nightlies that haven't been released yet.The tradeoff is that MuJoCo older than 4.0 is no longer supported. 3.13–3.15 were already broken, and 3.16–3.17 were never tested by CI. The packaging change and the shim removal are independent, so I'm happy to split them if that's easier to review.