Commit Graph

528 Commits

Author SHA1 Message Date
Alessio Quaglino 86ace5e562 Remove body.spec() function from the Python API
We can only use the MjSpec wrapper, not the raw::MjSpec struct in the API.

PiperOrigin-RevId: 722589064
Change-Id: I007150f92738487f27211d7435e328cab86214f7
2025-02-03 03:31:35 -08:00
Yuval Tassa 767be23207 Fix pretty printing in mjspec notebook.
PiperOrigin-RevId: 721367994
Change-Id: Ia1c4ee5b64540ff2f9c08a1953295ff366e0c72b
2025-01-30 06:32:35 -08:00
Alessio Quaglino 904b49848f Add worldbody assertions in attach tests.
This clarifies the difference between attaching a full spec, which converts the worldbody to a frame, and attaching a specific body (or frame).

PiperOrigin-RevId: 721297010
Change-Id: Iff87fe99b81746e6ab3a189a3057b274d3c9a939
2025-01-30 01:35:55 -08:00
Alessio Quaglino 0643017346 Add asset argument to MjSpec constructors.
PiperOrigin-RevId: 720628689
Change-Id: I189aa34973e58b9fb87951e34cb923d94e081a55
2025-01-28 10:39:27 -08:00
Alessio Quaglino 5b330ca19c Change keyword argument asset to include in spec.from_file and spec.from_string.
PiperOrigin-RevId: 720611881
Change-Id: I92f5e72cece8d3223bc552ea4f2ef742c47cb8c9
2025-01-28 09:55:48 -08:00
Alessio Quaglino 2546fcefa0 Add mujoco.MjSpec.to_zip()
PiperOrigin-RevId: 719003836
Change-Id: I310ac96b0080b3313c325cee76d3bf7f81fa9df0
2025-01-23 14:01:06 -08:00
Yuval Tassa f9fd2e4ba4 Add a test showing how to implement scipy's 'soft_l1' loss in minimize.least_squares
PiperOrigin-RevId: 718649580
Change-Id: I5cec0e2850c805301407c9eb543ab3ba69d42e79
2025-01-22 18:25:44 -08:00
Yuval Tassa 0090e1e908 Rename rollout variable nroll to nbatch.
PiperOrigin-RevId: 718196100
Change-Id: Ic36b1a96ea1af2de351539115d4eee051d195aaf
2025-01-21 21:04:15 -08:00
Copybara-Service ac76540eb8 Merge pull request #2377 from aftersomemath:rollout-fix-ndata-check
PiperOrigin-RevId: 718181763
Change-Id: Ie88bf1d26c77478ce3a5ca8fdf29ae90e54b5834
2025-01-21 20:11:33 -08:00
Alessio Quaglino 6a7a7a5f80 Add the override_assets attribute to MjSpec.
When specified, child asset with repeated names will override parent's, rather than throw an error. Default behavior is to override.

PiperOrigin-RevId: 717979621
Change-Id: I18022dc266619b4ba1a8636d1c60f85b0eb5f862
2025-01-21 10:39:02 -08:00
Alessio Quaglino 1412a29dac Merge child asset dictionary into parent spec during attach().
PiperOrigin-RevId: 717939728
Change-Id: I54f8ac87062cf19f55a16af37b777701545ed865
2025-01-21 08:57:09 -08:00
Alessio Quaglino 4bb6aeb19f Change site and frame attach API.
Old API:
```
site.attach(child_spec)
frame.attach(child_spec)
```

New API:
```
parent_spec.attach(child_spec, frame=frame_name_or_object)
parent_spec.attach(site_spec, site=site_name_or_object)
```

This enables accessing the parent object during attach, which will be used in a follow-up CL to automatically append the child assets to the parent.

PiperOrigin-RevId: 717908589
Change-Id: I0fb27e99694c954cb8ba8a8c98484ffd53a4d6db
2025-01-21 07:29:27 -08:00
Levi Burner cee122116e rollout: fix bugs in checking list lengths, add tests 2025-01-21 00:36:52 -05:00
Yuval Tassa baf1c43b3c Fix more misleading line for creating list of models in rollout_test.py
PiperOrigin-RevId: 717628943
Change-Id: I83a314565ce4ec683afeea18c8c8ce9e23d5452e
2025-01-20 14:27:31 -08:00
Yuval Tassa ff4783482c Fix misleading line for creating list of models in rollout_test.py
PiperOrigin-RevId: 717582208
Change-Id: I1b4e40fc5ccbfe68fb7dc240715c704f1f68d9fe
2025-01-20 11:13:21 -08:00
Alessio Quaglino 699a6765e3 Add find functions for joints, lights, and cameras to mjSpec bindings.
PiperOrigin-RevId: 717578768
Change-Id: I2087ccbb9cf8b3b8ec03e9eb2edb0707d4a4cac1
2025-01-20 11:02:34 -08:00
Silvia Cruciani 4903d5321c add find_geom property to mjSpec
PiperOrigin-RevId: 716225290
Change-Id: Ie6e229b0e802e7df06148f994d598334592e8ad1
2025-01-16 07:20:19 -08:00
Alessio Quaglino c2138c3fb0 Do not copy the spec during attach.
Use a reference count for managing the memory.

PiperOrigin-RevId: 716169486
Change-Id: Id270c4858c17b9250115e9544d5ea143584e2d5f
2025-01-16 03:53:17 -08:00
Gabe Oppenheimer 6436055c6c Update the version number to 3.2.8 following the 3.2.7 release.
PiperOrigin-RevId: 715870970
Change-Id: I9fc9a09d959043f3029faa7296a717ea56f75c89
2025-01-15 11:13:27 -08:00
Alessio Quaglino 05d4c3d670 Add mjs_getParent to retrieve the parent body of an object.
PiperOrigin-RevId: 715794859
Change-Id: Ib9792787cdb966f579938dde3f94ebabca8ef1fc
2025-01-15 07:42:43 -08:00
Alessio Quaglino 10c7207cea Process asset path before adding VFS buffer.
Also, handle VFS errors.

PiperOrigin-RevId: 715755127
Change-Id: Iaf455d448f16e37ab89ceaa5797319135acd73c9
2025-01-15 05:10:00 -08:00
Gabe Oppenheimer 61973a33c9 Update eigen3 and the changelog ahead of the 3.2.7 release.
PiperOrigin-RevId: 715467319
Change-Id: I4a6a168bc981c976890c46b784e94805afc86323
2025-01-14 11:51:12 -08:00
Alessio Quaglino ba183adb67 Add assets to MjSpec wrapper.
This enables associating assets with a spec object.

Also, remove `spec.compile(assets)` and replace it with the `spec.assets` attribute, which must be be set before compile if assets are present.

PiperOrigin-RevId: 714981385
Change-Id: Ic3a33c3b75d3a7e14868622aadb57b2a8461a649
2025-01-13 08:41:51 -08:00
Andrea Gesmundo 1c32b5d2dd Fix attach logic.
Replace .attach() with .attach_body() where a body is passed as a first argument instead of a spec that is expected by .attach().
+Fix typo.

PiperOrigin-RevId: 714933134
Change-Id: Idb242fbef0fe164075826c01d4e1995c7d4ae565
2025-01-13 05:41:49 -08:00
Yuval Tassa 2409a6e537 Add mjData.nA the number of non-zeros in the constraint inverse inertia matrix.
PiperOrigin-RevId: 714076988
Change-Id: I4c323a6e81dfb23f7972b662719bbcb688bacf4a
2025-01-10 09:23:55 -08:00
Alessio Quaglino 90049343b9 Fix texture indexing bug in bindings.
Fixes #2341.

PiperOrigin-RevId: 713667648
Change-Id: I7fa5da1506306c5374febf762ce54aff9146079b
2025-01-09 07:38:22 -08:00
Andrea Gesmundo 419da17395 Fix plot label.
PiperOrigin-RevId: 713635908
Change-Id: Icbeef26053b10747024ea65b23ca86816f4fdb2e
2025-01-09 05:23:32 -08:00
Saran Tunyasuvunakool 40ef08c8ed Don't pollute the global namespace when using mjpython.
Fixes #2265

PiperOrigin-RevId: 713442833
Change-Id: If155d9f57d4deef8b848478ebd8077a00417d5c5
2025-01-08 15:48:20 -08:00
Yuval Tassa 69c9ac074a Remove mjData.qLDiagSqrtInv, add corresponding argument to mj_solveM2.
- `qLDiagSqrtInv` is only required for the dual solvers. It is now computed as-needed rather than unconditionally.
- `mj_solveM2` now requires a new input array `sqrtInvD` which contains the square root of the inverse diagonal D (formerly saved in `qLDiagSqrtInv`).

PiperOrigin-RevId: 710805133
Change-Id: I0622d6a8da3882916824e9c10bad9223c122c321
2024-12-30 15:24:36 -08:00
Alessio Quaglino 644dfc7fb5 Fix assigning bytes to texture data.
PiperOrigin-RevId: 706747323
Change-Id: I6b0ee67d4f35db3a149ba8d9979546d3c712bb8b
2024-12-16 10:05:23 -08:00
Levi Burner a7eb6efd4e Copybara import of the project:
--
3a95b62f59e81bfef0f076afb173ecc14b27943d by Levi Burner <leviburner@gmail.com>:

rollout prototype native threadpool for comparing to python threads

--
efd8be1124ac839b902de45973a3ca8b9f2215e6 by Levi Burner <leviburner@gmail.com>:

copy mjpcs threadpool into python bindings

--
75603eea3e8362e354a9675e8a6cd14e56ec3d28 by Levi Burner <leviburner@gmail.com>:

rollout use threadpool as translation unit

--
06b90febd021663f6cc81fd7895e4d6e2008ed97 by Levi Burner <leviburner@gmail.com>:

rollout add chunk_divisor parameter

--
298ab2f3c0d6e12530832c3cdbf784dd92d54806 by Levi Burner <leviburner@gmail.com>:

rollout add native threading test

--
169cf9978e7abad6edd1392b8e6aab995e4f8f10 by Levi Burner <leviburner@gmail.com>:

rollout exchange chunk_divisor arg for chunk_size

--
265af851d74432d261277d3dbda11cdef1841bc8 by Levi Burner <leviburner@gmail.com>:

rollout fix cosmetics

--
1e8bffa88bf36190501b334bef31147e23db39f7 by Levi Burner <leviburner@gmail.com>:

make native rollout a class instead of a function

--
ba788214b047577f58c41ce0ab6c62c277cd8b0d by Levi Burner <leviburner@gmail.com>:

rollout update docs and changelog

--
e4cb7732319e04cba2ab2c2ad848c659f6309808 by Levi Burner <leviburner@gmail.com>:

rollout don't register atexit handler for Rollout objects

--
5a08d2efdbbbb01d4b1231ff9a36a1dc44f4d9ee by Levi Burner <leviburner@gmail.com>:

rollout nthread kwarg, rename shutdown_pool to close, fixups

--
f622378543596a208339af0208fa3a70bf2a8007 by Levi Burner <leviburner@gmail.com>:

rollout add missing .close() calls

--
50f3ebca43c53eac03f03943c34bb1e46967bd4f by Levi Burner <leviburner@gmail.com>:

rollout return immediately

COPYBARA_INTEGRATE_REVIEW=https://github.com/google-deepmind/mujoco/pull/2282 from aftersomemath:rollout-threaded 50f3ebca43c53eac03f03943c34bb1e46967bd4f
PiperOrigin-RevId: 706744277
Change-Id: I1ab2263b7d6ce30cf1908aec8fd5f2eb976a19e6
2024-12-16 09:57:08 -08:00
Yuval Tassa 2691887500 Add engine-internal convenience macro for allocating typed arrays, improve error message.
PiperOrigin-RevId: 705126655
Change-Id: I2bd8fada6d33a919d2fb82297f93ac57958355a4
2024-12-11 09:04:44 -08:00
Yuval Tassa f4593d5d79 Highlight XML strings using pygments in mjSpec notebook.
PiperOrigin-RevId: 704751058
Change-Id: Iaf7fae7f13ef12d59bac762170a6dfca01494164
2024-12-10 10:06:52 -08:00
Baruch Tabanpour f3b3024291 Add pyink and isort config. Reformat.
PiperOrigin-RevId: 704533915
Change-Id: I37e9fd51261bd166b725c7460fc65d02fed2b391
2024-12-09 21:10:50 -08:00
Alessio Quaglino 41968f1527 Support body.find_all("joint") in bindings.
PiperOrigin-RevId: 703071822
Change-Id: I6457ca0561c794447cc06aab29dcd0aac82c49a0
2024-12-05 04:54:42 -08:00
Alessio Quaglino a729acb4fa Add spec find_sensor, find_actuator functions.
PiperOrigin-RevId: 703054696
Change-Id: Ie384f1a31de3ecd9b22b7f4be43234d452e7bb88
2024-12-05 03:42:26 -08:00
Alessio Quaglino 503e5e1815 Change site.attach to accept a spec instead of a body.
Add site.attach_body for attaching a body to a site.

PiperOrigin-RevId: 703047770
Change-Id: Ibc1f916f8741872135220461cda7cebc4b418913
2024-12-05 03:10:17 -08:00
Alessio Quaglino a3b9f986c0 Add spec.find_site().
PiperOrigin-RevId: 702733068
Change-Id: I4cc7fd2b9b59185a4458fdac8537f8287af1f295
2024-12-04 08:20:57 -08:00
Alessio Quaglino d1b02556ef Allow keyword arguments in attach.
PiperOrigin-RevId: 702718597
Change-Id: I1f1a5e9c88c8e102d5cbe5984511e7923ec7be3e
2024-12-04 07:32:31 -08:00
Gabe Oppenheimer c90a63a926 Update the version number to 3.2.7 following the 3.2.6 release.
PiperOrigin-RevId: 702103729
Change-Id: Id5581cc823a17360e7bb98ac0aa4342020c1aefa
2024-12-02 15:30:52 -08:00
Gabe Oppenheimer 0f64959e27 Update the version of eigen3 ahead of the 3.2.6 release
PiperOrigin-RevId: 702026493
Change-Id: Ibb0447b7106e9b873386c153283c81685583350f
2024-12-02 11:12:39 -08:00
Levi Burner e6eab04dd0 rollout fixups and correctly initialize unspecified controls 2024-11-27 07:04:23 -05:00
Levi Burner 41b325785a fix creation of std::vector 2024-11-26 16:42:08 -05:00
Levi Burner 5ba4d58497 replace array on stack with std::vector 2024-11-26 13:16:05 -05:00
Levi Burner 943eb6bc7e rollout accepts a list of models of length nroll 2024-11-25 21:29:14 -05:00
Levi Burner 96a8f002bc Remove nroll argument from rollout
nroll can always be implied from the other arguments of rollout.

Add tests for nroll inference.
2024-11-25 14:10:42 -05:00
Alessio Quaglino 7e46e21ef3 Add mju_mat2Rot.
This function extracts the 3D rotation from an arbitrary 3x3 matrix by refining the input quaternion. It is based on the paper "A robust method to extract the rotational part of deformations" by Müller, Matthias, Jan Bender, Nuttapong Chentanez, and Miles Macklin.

PiperOrigin-RevId: 700006006
Change-Id: I77550993233dea9cdf68601762a3ae7ded749bdf
2024-11-25 09:19:10 -08:00
Alessio Quaglino c6ba8f27fd Add bind() method to MjModel and MjData.
This method allows users to bind a spec to a model or data object, making it less verbose to access its arrays.

PiperOrigin-RevId: 699952211
Change-Id: I6b71a88d5a6968bc0f902bd49db7c568b46a4dfb
2024-11-25 05:53:58 -08:00
Alessio Quaglino f909d63cdf Enable to attach a spec to a frame.
PiperOrigin-RevId: 699703988
Change-Id: Idbddcbce1e68286248458eb0bd24d5080451a58a
2024-11-24 07:35:14 -08:00
Alessio Quaglino 3a12db9ad2 Remove id attribute from mjSpec objects in Python bindings.
Using ids is error prone in scenarios of repeated attachment and detachment. Python users are encouraged to use names for unique identification of model elements.

PiperOrigin-RevId: 699227286
Change-Id: Ifd83e6d85d36ff72ea43caf8b82eab9e4d552440
2024-11-22 11:05:14 -08:00