Commit Graph

100 Commits

Author SHA1 Message Date
DeepMind c34826ef1a mujoco.renderer.render to output copy of pixel array.
Previously, it returned a view into the internal rgb array, which can be confusing to the user.

PiperOrigin-RevId: 517630186
Change-Id: Ibc1e86b6b6345269523bb4c82c37dd325961a8ec
2023-03-18 05:30:46 -07:00
Saran Tunyasuvunakool 7b91567585 Exit mjpython if any pthread function call fails.
PiperOrigin-RevId: 517401871
Change-Id: I2050769085690d50d331f2955ed1e09ca4c8414c
2023-03-17 06:58:26 -07:00
Saran Tunyasuvunakool 0c4e191dd6 Compatibility fixes for mjpython.
- Find Python functions in the interpreter binary itself rather than trying to find libpython.dylib, because this doesn't exist when using Conda. (https://github.com/conda-forge/python-feedstock/issues/595#issuecomment-1311275470)

- Increase the stack size of both the Python main thread and the OS main thread to 16MiB, to match what Python normally uses on macOS. (https://github.com/python/cpython/blob/3.11/configure#L11038)

- Check whether dlfcn and pthread function calls actually succeeds. Emit error messages and exit on failure rather than continuing the program (which generally leads to segfaults).

- Fix pixelated shadow in the icon.

PiperOrigin-RevId: 517390522
Change-Id: Ib91679b4baa63bac5f6b5893e634712d72161ea5
2023-03-17 05:37:35 -07:00
Alessio Quaglino 70959c1a2c Added a collision midphase on geom pairs using rotated AABBs static trees.
PiperOrigin-RevId: 517357695
Change-Id: I068fee714d9638be2fb6d042d5d86f8ff970635b
2023-03-17 02:37:29 -07:00
Copybara-Service 7690965d73 Merge pull request #769 from milutter:plugin_loading
PiperOrigin-RevId: 517231543
Change-Id: Ia3f0929650da235589e9434db84500b3d9f17df1
2023-03-16 14:40:25 -07:00
Saran Tunyasuvunakool e20ab6c96f Add a number of missing struct fields to Python bindings.
It is quite possible that there are a few other fields still missing since we currently do not yet have automated testing of struct field existence.

Fixes #747.

PiperOrigin-RevId: 517189048
Change-Id: I7c1d95e700eaea05aaa3cde1fd05e1a259553117
2023-03-16 12:05:50 -07:00
Saran Tunyasuvunakool 230e2780de Add viewer.launch_passive and a mjpython launcher for macOS.
The `launch_passive` function launches the GUI viewer in a non-blocking manner, allowing the Python script or REPL to continue execution. The viewer is automatically kept up to date with any subsequent modifications to mjModel and mjData.

Note that when run inside a REPL (including IPython), `launch_passive` is functionally identical to `launch_repl`.

On Linux and Windows, this is achieved by spawning a new thread and launching the GUI there.

On macOS, this is not possible as all Cocoa API calls must be made on the "macOS main thread", which is always the first thread launched in a process and carries the `com.apple.main-thread` dispatch queue. We also cannot simply trampoline from a Python script on the main thread into the user's script on a side thread because CPython's signal handler can only be installed on the "Python main thread". Putting the user's script in a side thread means that it cannot e.g. gracefully handle SIGINT by catching a KeyboardInterrupt exception. To work around this, we ship a custom Python launcher on macOS called `mjpython`. This launcher is a native binary that spawns a pthread and initialize the Python interpreter on that thread, thus allowing "Python main thread" and "macOS main thread" to represent two distinct threads. From Python's point of view, the "macOS main thread" is a secondary thread that runs a loop that continuously empties a Queue of (mjModel, mjData) and launches a viewer.

PiperOrigin-RevId: 517167868
Change-Id: Icac9d2126bbb4760d47e0b9300e0a979cffa4338
2023-03-16 10:53:11 -07:00
mlutter 5215992d55 review comments 2023-03-15 20:51:47 -04:00
mlutter 3cb0121474 fix typo 2023-03-14 14:28:31 -04:00
milutter 53ab95c792 Ensure that loaded plugins are a shared library 2023-03-14 14:21:16 -04:00
Kyle Bayes d3d789cf7d Convert mju_error and mju_warning to variadic functions, supporting printf-like arguments. The functions mju_error_i, mju_error_s, mju_warning_i, and mju_warning_s are now deprecated.
PiperOrigin-RevId: 515431052
Change-Id: I440de0cb417ce216b6d636a5d86dc9ef6cc1fc06
2023-03-09 13:51:27 -08:00
Nimrod Gileadi ac78f8aee9 Update CMake dependencies to latest versions.
Upgrade abseil and pybind11.

PiperOrigin-RevId: 514397331
Change-Id: I4a35dc9f3b9dcc79bdd13016a5326f72cd3fc67f
2023-03-06 07:12:22 -08:00
Kyle Bayes 50bebcb4ee Precount number of non-zeros for constraint Jacobian sparse matrix.
PiperOrigin-RevId: 512947632
Change-Id: I9605e81b4e51fbc90854c13153e4fee38ad48fb9
2023-02-28 08:57:56 -08:00
Saran Tunyasuvunakool ace5b74f83 Rename inteval attribute in mjLROpt to interval.
PiperOrigin-RevId: 509275105
Change-Id: I0ffb9cf485a504843ed255f0b4f24e9285a1c273
2023-02-13 10:54:25 -08:00
Saran Tunyasuvunakool db28c31f05 Rename <required> tag to <plugin>.
PiperOrigin-RevId: 509237786
Change-Id: I35e812830b479004ac5025cbd9477888f51fb43e
2023-02-13 08:41:52 -08:00
Saran Tunyasuvunakool 5e989d18c3 Enable compiler errors for implicit switch case fallthroughs.
Also unify warning options across Clang and GCC and fix minor issues that was surfaced by this.

PiperOrigin-RevId: 508619655
Change-Id: I59b777bf2dfea4422485670e2427c7d3f5cf6405
2023-02-10 03:49:00 -08:00
Saran Tunyasuvunakool 71c5f1794d Remove efc_ fields from joint indexers.
Since the introduction of arena memory, these fields now have dynamic sizes that change between time steps depending on the number of active constraints. This breaks strict correspondence between joints and `efc_` rows.

Note that these fields can still be accessed directly as attributes on the `MjData` object.

PiperOrigin-RevId: 508342388
Change-Id: I610ae6ca462f6bb5cf8bc199a3436bed3d1a5371
2023-02-09 05:02:11 -08:00
Saran Tunyasuvunakool 7d8e810ab1 Fix IPython history corruption when using launch_repl.
PiperOrigin-RevId: 508064761
Change-Id: I58fa2e4f35b57a1ab68c3172ba5c0d4495e40ced
2023-02-08 06:37:42 -08:00
Alessio Quaglino dd632b7ccc Bump MuJoCo version to 2.3.2.
PiperOrigin-RevId: 507720557
Change-Id: I7a5b577094ac1a7f468a84c484f62f61dc6b409f
2023-02-07 02:35:17 -08:00
Saran Tunyasuvunakool f1af86cf82 Fix msan failure in __repr__ when upgraded to NumPy 1.24.
PiperOrigin-RevId: 505661236
Change-Id: I37ea339679870d23886e3c95f51451349fa1de2c
2023-01-30 05:11:25 -08:00
Peter Hawkins cd99fbd59d Fix test failures under NumPy 1.24.
The use of `np.empty` triggers an msan use-of-uninitialized-value error when upgraded.

PiperOrigin-RevId: 503975799
Change-Id: I337c8227c8c1e3bd415d7a798fc5e764c88c0875
2023-01-23 07:04:33 -08:00
Nimrod Gileadi d7844aa5be Fix links to documentation.
1. Links to the programming chapter were broken after 69c74f850e. They're now fixed with a redirect in readthedocs.io, but this commit updates them to the latest URL.

2. Most docs links should point to "stable" instead of "latest", since most users will want the docs for the released version, not the upcoming version. The exceptions are the programming chapter, and instructions for building the Python bindings from source.

PiperOrigin-RevId: 502821526
Change-Id: If0a55ab2be4751ba0165bf644030464234083133
2023-01-18 02:55:41 -08:00
Saran Tunyasuvunakool d022cd1a31 Fix broken launch_repl in the Python viewer.
The REPL functionality was broken in 9fcf3b0c2e.

PiperOrigin-RevId: 501818153
Change-Id: I3fe2f14d78839e63deb43c1017527e7a1cf79e3c
2023-01-13 04:59:22 -08:00
Saran Tunyasuvunakool e40775fab3 Abstract out GLFW calls from Simulate.
PiperOrigin-RevId: 500129478
Change-Id: I7ba998e20439575ad9a3fe1a866c3db4c36b9328
2023-01-06 02:45:56 -08:00
Kevin Zakka a173e01f42 Prevent division by zero in Ornstein–Uhlenbeck control noise.
PiperOrigin-RevId: 498753494
Change-Id: Ib43e165a4da524c12fab4ea05848b084b2e7713c
2022-12-31 10:29:03 -08:00
Saran Tunyasuvunakool 725b45b577 Internal Python bindings cleanup.
PiperOrigin-RevId: 495868304
Change-Id: Ib9cfe5f7a1d49126659176207bd6b4a314f8516a
2022-12-16 07:22:48 -08:00
Copybara-Service 3a00e025ce Merge pull request #619 from traversaro:fixpypytests
PiperOrigin-RevId: 494129535
Change-Id: I301cb505a224eaa26df4896924d36c623b1a4a26
2022-12-09 03:39:22 -08:00
Nimrod Gileadi 91455b3e1e Add a naive test of mujoco.viewer.
It just tries to import mujoco.viewer and sees that nothing crashes.

PiperOrigin-RevId: 493998120
Change-Id: I56ee696283a3c28f6c8b72de45c8fdbedb41b05f
2022-12-08 14:35:20 -08:00
Silvio Traversaro bfe1017fc8 Skip tests that cannot run on PyPy 2022-12-07 19:19:21 +01:00
Saran Tunyasuvunakool 0d608282dd Fix viewer.py for Python 3.7 and 3.8.
PiperOrigin-RevId: 493301329
Change-Id: I44ffe5b33595d2dec7cd1aefbdd77d535901d894
2022-12-06 07:36:25 -08:00
Yuval Tassa 687bd15e05 Make comment more precise
PiperOrigin-RevId: 493165357
Change-Id: Ibdd86de67caf0e528e20ff6829e8ed4a8b967d4c
2022-12-05 18:15:14 -08:00
Kyle Bayes 73fb61e3e2 Bump version number to 2.3.1.
PiperOrigin-RevId: 493076656
Change-Id: I48c7a45b503c4a7363ea1455a4a3788262d007f7
2022-12-05 12:13:55 -08:00
Kyle Bayes ef695bb8a8 Add Renderer class to Python native bindings.
PiperOrigin-RevId: 492994751
Change-Id: Iebbe5980668a15b1cd62c0076cc131255462b2eb
2022-12-05 06:54:33 -08:00
Kyle Bayes 341578450f Update dependency versions for Benchmark and Pybind11.
PiperOrigin-RevId: 492978119
Change-Id: Id48037950a6beac2f04f5e08448bd2fb3cb88678
2022-12-05 05:20:08 -08:00
Saran Tunyasuvunakool 0846f38c82 Rename Python mujoco.simulate to mujoco.viewer.
PiperOrigin-RevId: 492701386
Change-Id: I059c572e2a63bd5529e863a9404720973df8ea46
2022-12-03 10:09:42 -08:00
Saran Tunyasuvunakool 9fcf3b0c2e Modify Python simulate so that the Reload button works.
Also allow a `Callable[[], [MjModel, MjData]]` to be provided as an argument to `launch` instead of a fixed MjModel/MjData instance. This allows users to customise the behaviour of the Reload button.

Context: https://github.com/deepmind/mujoco/discussions/576#discussioncomment-4161429
PiperOrigin-RevId: 492296268
Change-Id: Ic4b797d2ea8a6967f7e3e7316f2184ea94a86d8b
2022-12-01 14:12:35 -08:00
Saran Tunyasuvunakool df25d7d602 Raise an informative error when running on macOS under Rosetta 2.
Current users only get a cryptic "Illegal instruction" crash.

Context: https://github.com/deepmind/mujoco/issues/611
PiperOrigin-RevId: 491705647
Change-Id: I1285897a36e858300ee3d125957e90754be9a7f7
2022-11-29 12:19:06 -08:00
Kyle Bayes fdb81f3388 Fix location of MuJoCo tutorial Colab notebook.
PiperOrigin-RevId: 491436998
Change-Id: I93c1ea3ae142d69dc8a8fe893f014e539cb33746
2022-11-28 14:00:57 -08:00
Kyle Bayes 5a8e861152 Add MuJoCo tutorial Colab using the native Python bindings.
PiperOrigin-RevId: 491424124
Change-Id: I5bdeb68fd1bd1b4bc92fb40e0b876d9dcfc568cb
2022-11-28 13:09:51 -08:00
Saran Tunyasuvunakool fa0f6399d5 Make Python bindings buildable with older versions of CMake.
Context: https://discourse.cmake.org/t/alias-and-not-globally-visible-targets/6305
PiperOrigin-RevId: 489051335
Change-Id: I1bbe189413d6f8abe97d3d8ceccf6541de69e2ae
2022-11-16 15:12:01 -08:00
Saran Tunyasuvunakool 9ecade0707 Move plugin loading and scanning logic from Simulate to MuJoCo library.
PiperOrigin-RevId: 489020177
Change-Id: I1c29d931b47d5252e57e1d797cc7c17645859ffc
2022-11-16 13:15:51 -08:00
Saran Tunyasuvunakool 985b3f1c9e Remove custom code path when run under type checking.
PiperOrigin-RevId: 487584485
Change-Id: I1b1c773240bb033e50205648f4611f4702c0e6e8
2022-11-10 10:56:32 -08:00
Kyle Bayes 601963beb2 Automated rollback of 39d20f20ea.
*** Reason for rollback ***

Breakage at https://github.com/deepmind/mujoco/actions/runs/3427459759

*** Original change description ***

Add test to catch missing Python function bindings.

***

PiperOrigin-RevId: 487505205
Change-Id: Iec3b588380b4b6fc7a3249ccdef08e48b42a7892
2022-11-10 05:07:24 -08:00
Copybara-Service f7b256de91 Merge pull request #419 from aftersomemath:simulate-python
PiperOrigin-RevId: 487496285
Change-Id: I17d15bd2a3886e5ce1631f4eb78afa94830d08cc
2022-11-10 04:12:34 -08:00
Kyle Bayes 39d20f20ea Add test to catch missing Python function bindings.
PiperOrigin-RevId: 487187845
Change-Id: Iddf8afd16abb9a22bba6a53a0ecc0423208f41e6
2022-11-09 02:45:11 -08:00
Alessio Quaglino fd4d47e4a5 Format memory warning in human-friendly way.
PiperOrigin-RevId: 486610408
Change-Id: I6beecb12059e69f4407e921d20efc54ce6b3f491
2022-11-07 02:56:07 -08:00
Yuval Tassa 36b30e4500 Allow more than 1 activation state per actuator, but only for dyntype user.
Fixes #305.

PiperOrigin-RevId: 486597273
Change-Id: I3eb806f60949e68ebe6cbe35a6e66218a167ed45
2022-11-07 01:43:02 -08:00
Nimrod Gileadi 0514010928 Disable deprecated-builtins warnings in clang.
Since upgrading to Clang 15, abseil fails to build, because of abseil/abseil-cpp#1201.

PiperOrigin-RevId: 486190797
Change-Id: Ibaa1c03b8d21ae4a83c3825c8d56363aa2f89505
2022-11-04 11:35:49 -07:00
Yuval Tassa c83be2bc05 Add mju_clip, mju_fill, mju_eye and mju_symmetrize to python bindings.
- Also change signatures of `mju_fill` and `mju_symmetrize` to conform to standard.

PiperOrigin-RevId: 485613824
Change-Id: I8dd618bac92ef40aa6c76380fa73302e81968687
2022-11-02 09:22:28 -07:00
Yuval Tassa 0eb7f871b9 Remove requirement that stateless actuators come before stateful actuators.
PiperOrigin-RevId: 484332415
Change-Id: I1dae92c0f8e027e4ca71c20ea3f68b2926526f53
2022-10-27 13:18:57 -07:00