mujoco-uni-runtime 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mujoco_uni_runtime-0.2.1/LICENSE +201 -0
- mujoco_uni_runtime-0.2.1/MANIFEST.in +1 -0
- mujoco_uni_runtime-0.2.1/PKG-INFO +396 -0
- mujoco_uni_runtime-0.2.1/README.md +384 -0
- mujoco_uni_runtime-0.2.1/pyproject.toml +46 -0
- mujoco_uni_runtime-0.2.1/setup.cfg +4 -0
- mujoco_uni_runtime-0.2.1/setup.py +65 -0
- mujoco_uni_runtime-0.2.1/src/mujoco_uni/__init__.py +50 -0
- mujoco_uni_runtime-0.2.1/src/mujoco_uni/batch_env.py +17 -0
- mujoco_uni_runtime-0.2.1/src/mujoco_uni/compiled/__init__.py +64 -0
- mujoco_uni_runtime-0.2.1/src/mujoco_uni/metadata.py +23 -0
- mujoco_uni_runtime-0.2.1/src/mujoco_uni/mujoco_runtime/__init__.py +5 -0
- mujoco_uni_runtime-0.2.1/src/mujoco_uni/mujoco_runtime/api.py +29 -0
- mujoco_uni_runtime-0.2.1/src/mujoco_uni/mujoco_runtime/version_control.py +353 -0
- mujoco_uni_runtime-0.2.1/src/mujoco_uni/native/__init__.py +1 -0
- mujoco_uni_runtime-0.2.1/src/mujoco_uni/native/batch_env.cc +1934 -0
- mujoco_uni_runtime-0.2.1/src/mujoco_uni/native/compat/absl/base/attributes.h +16 -0
- mujoco_uni_runtime-0.2.1/src/mujoco_uni/native/threadpool.cc +87 -0
- mujoco_uni_runtime-0.2.1/src/mujoco_uni/native/threadpool.h +80 -0
- mujoco_uni_runtime-0.2.1/src/mujoco_uni/runtime/__init__.py +49 -0
- mujoco_uni_runtime-0.2.1/src/mujoco_uni/runtime/batch.py +592 -0
- mujoco_uni_runtime-0.2.1/src/mujoco_uni_runtime.egg-info/PKG-INFO +396 -0
- mujoco_uni_runtime-0.2.1/src/mujoco_uni_runtime.egg-info/SOURCES.txt +27 -0
- mujoco_uni_runtime-0.2.1/src/mujoco_uni_runtime.egg-info/dependency_links.txt +1 -0
- mujoco_uni_runtime-0.2.1/src/mujoco_uni_runtime.egg-info/requires.txt +2 -0
- mujoco_uni_runtime-0.2.1/src/mujoco_uni_runtime.egg-info/top_level.txt +1 -0
- mujoco_uni_runtime-0.2.1/tests/test_batch_env.py +69 -0
- mujoco_uni_runtime-0.2.1/tests/test_batch_env_parity.py +377 -0
- mujoco_uni_runtime-0.2.1/tests/test_version_control.py +210 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
recursive-include src/mujoco_uni/native *.cc *.h
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mujoco-uni-runtime
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: Standalone MuJoCoUni batched executor layer
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Requires-Python: <3.14,>=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: mujoco<3.11,>=3.5
|
|
10
|
+
Requires-Dist: numpy
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# MuJoCoUni
|
|
14
|
+
|
|
15
|
+
English | [简体中文](README_zh.md)
|
|
16
|
+
|
|
17
|
+
MuJoCoUni is the standalone UniLab batch-executor layer for official MuJoCo.
|
|
18
|
+
It provides the `BatchEnvPool` API used by UniLab without modifying MuJoCo
|
|
19
|
+
solver, contact, integrator, or source-tree internals.
|
|
20
|
+
|
|
21
|
+
## System Boundary
|
|
22
|
+
|
|
23
|
+
MuJoCoUni sits between UniLab and official MuJoCo.
|
|
24
|
+
|
|
25
|
+
```text
|
|
26
|
+
MJCF / XML asset
|
|
27
|
+
|
|
|
28
|
+
v
|
|
29
|
+
official MuJoCo compiler
|
|
30
|
+
|
|
|
31
|
+
v
|
|
32
|
+
mjModel
|
|
33
|
+
|
|
|
34
|
+
v
|
|
35
|
+
MuJoCoUni BatchEnvPool
|
|
36
|
+
- captures/copies mjModel
|
|
37
|
+
- owns model pool
|
|
38
|
+
- owns worker mjData
|
|
39
|
+
- calls official MuJoCo C APIs
|
|
40
|
+
^
|
|
41
|
+
|
|
|
42
|
+
UniLab backend
|
|
43
|
+
- receives task/training command
|
|
44
|
+
- owns rollout pace
|
|
45
|
+
- packs state/control/reset arrays
|
|
46
|
+
- unpacks state/sensor arrays
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Responsibility split:
|
|
50
|
+
|
|
51
|
+
```text
|
|
52
|
+
UniLab:
|
|
53
|
+
task config, commands, rewards, rollout pace, CPU/GPU bridge,
|
|
54
|
+
training orchestration, logging
|
|
55
|
+
|
|
56
|
+
MuJoCoUni:
|
|
57
|
+
BatchEnvPool, model cloning, worker mjData, local thread pool,
|
|
58
|
+
batched step/forward/reset/query execution
|
|
59
|
+
|
|
60
|
+
MuJoCo:
|
|
61
|
+
MJCF compiler, mjModel/mjData definitions, solver, contact,
|
|
62
|
+
integrator, sensor layout, official C API
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
For larger CPU/GPU training, UniLab remains the bridge above local MuJoCoUni
|
|
66
|
+
executors:
|
|
67
|
+
|
|
68
|
+
```text
|
|
69
|
+
CPU rollout side
|
|
70
|
+
MuJoCoUni BatchEnvPool instances
|
|
71
|
+
produce observation/reward/done/sensor data
|
|
72
|
+
request action tensors
|
|
73
|
+
|
|
|
74
|
+
v
|
|
75
|
+
UniLab bridge
|
|
76
|
+
batches rollout traffic
|
|
77
|
+
routes data toward GPU learner/action service
|
|
78
|
+
routes actions/control commands back to CPU workers
|
|
79
|
+
|
|
|
80
|
+
v
|
|
81
|
+
GPU side
|
|
82
|
+
consumes training data
|
|
83
|
+
performs learner/inference work
|
|
84
|
+
returns action tensors or policy-side feedback through UniLab
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Version Policy
|
|
88
|
+
|
|
89
|
+
MuJoCoUni has its own package version, independent of the MuJoCo solver version.
|
|
90
|
+
|
|
91
|
+
Current release:
|
|
92
|
+
|
|
93
|
+
```text
|
|
94
|
+
mujoco-uni-runtime==0.2.1
|
|
95
|
+
mujoco>=3.5,<3.11
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The public metadata is available from Python:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
import mujoco_uni
|
|
102
|
+
|
|
103
|
+
print(mujoco_uni.__version__)
|
|
104
|
+
print(mujoco_uni.MUJOCO_VERSION)
|
|
105
|
+
print(mujoco_uni.MUJOCO_VERSION_SPEC)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
MuJoCoUni supports one official MuJoCo solver version per Python environment.
|
|
109
|
+
The native extension records the MuJoCo version used at build time, and the
|
|
110
|
+
runtime fails fast if the loaded `mujoco` package does not match that native
|
|
111
|
+
build target.
|
|
112
|
+
|
|
113
|
+
Version switching is active but process-level: MuJoCoUni selects an existing
|
|
114
|
+
versioned uv environment, then runs the target command in that environment
|
|
115
|
+
before Python imports `mujoco`. Normal training launch does not create, install,
|
|
116
|
+
or rebuild environments.
|
|
117
|
+
|
|
118
|
+
```text
|
|
119
|
+
env-mj35 -> mujoco==3.5.x -> build/install mujoco-uni-runtime
|
|
120
|
+
env-mj36 -> mujoco==3.6.x -> build/install mujoco-uni-runtime
|
|
121
|
+
env-mj37 -> mujoco==3.7.x -> build/install mujoco-uni-runtime
|
|
122
|
+
env-mj38 -> mujoco==3.8.x -> build/install mujoco-uni-runtime
|
|
123
|
+
env-mj39 -> mujoco==3.9.x -> build/install mujoco-uni-runtime
|
|
124
|
+
env-mj310 -> mujoco==3.10.x -> build/install mujoco-uni-runtime
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Default and fallback selection prefer discovered environments in this order:
|
|
128
|
+
|
|
129
|
+
```text
|
|
130
|
+
3.8 > 3.10 > 3.9 > 3.7 > 3.6 > 3.5
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
If the requested version is not found, MuJoCoUni prints a warning and falls back
|
|
134
|
+
to the preferred existing environment. If no MuJoCo environment exists, launch
|
|
135
|
+
fails with a clear setup error.
|
|
136
|
+
|
|
137
|
+
For UniLab training, the normal task command is the only user-facing launcher.
|
|
138
|
+
Set the process selector when running the command:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
MUJOCO_UNI_VERSION=3.8 uv run train --algo ppo --task go2_joystick_flat --sim mujoco
|
|
142
|
+
MUJOCO_UNI_VERSION=3.10 uv run train --algo ppo --task go2_joystick_flat --sim mujoco
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Unset `MUJOCO_UNI_VERSION` keeps the active Python environment behavior. Exact
|
|
146
|
+
requests such as `3.8.0` require that exact runtime; minor requests such as
|
|
147
|
+
`3.8` accept a compatible `3.8.x` runtime.
|
|
148
|
+
|
|
149
|
+
MuJoCoUni owns the internal discovery and spawning services used by UniLab.
|
|
150
|
+
Explicit environment preparation is a setup operation, not part of the normal
|
|
151
|
+
training launch path.
|
|
152
|
+
|
|
153
|
+
The required MuJoCo Python model pointer helpers, `_address` and
|
|
154
|
+
`_from_model_ptr`, are checked at import time.
|
|
155
|
+
|
|
156
|
+
## Roadmap
|
|
157
|
+
|
|
158
|
+
Further development is tracked in [ROADMAP.md](ROADMAP.md).
|
|
159
|
+
|
|
160
|
+
## Package Layout
|
|
161
|
+
|
|
162
|
+
The structure mirrors the DrakeUni split between runtime code, native source,
|
|
163
|
+
and compiled artifacts:
|
|
164
|
+
|
|
165
|
+
```text
|
|
166
|
+
src/mujoco_uni/
|
|
167
|
+
__init__.py
|
|
168
|
+
metadata.py # MuJoCoUni package metadata and supported range
|
|
169
|
+
batch_env.py # Stable public BatchEnvPool API
|
|
170
|
+
mujoco_runtime/
|
|
171
|
+
api.py # MuJoCoUni-owned access to official mujoco
|
|
172
|
+
version_control.py # MuJoCo solver-version control
|
|
173
|
+
runtime/
|
|
174
|
+
batch.py # Python API, validation, compatibility behavior
|
|
175
|
+
compiled/
|
|
176
|
+
__init__.py # Native extension loader and diagnostics
|
|
177
|
+
_batch_env*.so # Generated extension after local build
|
|
178
|
+
native/
|
|
179
|
+
batch_env.cc # Native pybind11 executor
|
|
180
|
+
threadpool.h/.cc # Local thread pool
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
The stable import path is:
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
from mujoco_uni.batch_env import BatchEnvPool, SUPPORTED_FIELDS
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Execution Model
|
|
190
|
+
|
|
191
|
+
`BatchEnvPool` accepts one `mujoco.MjModel` or a compatible sequence of
|
|
192
|
+
`mujoco.MjModel` objects. At construction time it reads the official MuJoCo
|
|
193
|
+
model pointer from Python, copies the model with `mj_copyModel`, and stores
|
|
194
|
+
pool-owned models internally.
|
|
195
|
+
|
|
196
|
+
The hot path is native C++ calling the official MuJoCo C API. The pool uses:
|
|
197
|
+
|
|
198
|
+
- one logical pool-owned `mjModel` assignment per environment slot,
|
|
199
|
+
- one reusable `mjData` per worker thread,
|
|
200
|
+
- disjoint environment chunks,
|
|
201
|
+
- disjoint output slots,
|
|
202
|
+
- one synchronization point per batch operation.
|
|
203
|
+
|
|
204
|
+
There is no MPI or OpenMP inside the base `BatchEnvPool` executor. Large-scale
|
|
205
|
+
multi-process, multi-socket, or multi-node collection composes multiple local
|
|
206
|
+
executors from a layer above `BatchEnvPool`.
|
|
207
|
+
|
|
208
|
+
## Public API
|
|
209
|
+
|
|
210
|
+
The stable public API is `mujoco_uni.batch_env`.
|
|
211
|
+
|
|
212
|
+
Exported symbols:
|
|
213
|
+
|
|
214
|
+
- `BatchEnvPool`
|
|
215
|
+
- `SUPPORTED_FIELDS`
|
|
216
|
+
- `batch_available`
|
|
217
|
+
- `batch_import_error`
|
|
218
|
+
|
|
219
|
+
Supported randomization/model fields:
|
|
220
|
+
|
|
221
|
+
```text
|
|
222
|
+
body_mass
|
|
223
|
+
body_ipos
|
|
224
|
+
body_iquat
|
|
225
|
+
body_inertia
|
|
226
|
+
dof_armature
|
|
227
|
+
gravity
|
|
228
|
+
geom_friction
|
|
229
|
+
kp
|
|
230
|
+
kd
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Core `BatchEnvPool` behavior:
|
|
234
|
+
|
|
235
|
+
- construct from one model or a sequence of length `1` / `nbatch`,
|
|
236
|
+
- `step` over the full pool and return final state, optionally with final
|
|
237
|
+
sensor data,
|
|
238
|
+
- `forward` over the full pool and return sensor data,
|
|
239
|
+
- sparse `reset` with optional model-field randomization,
|
|
240
|
+
- site Jacobian queries,
|
|
241
|
+
- hfield height sampling,
|
|
242
|
+
- non-owning model views through `get_model`, `get_models`, and
|
|
243
|
+
`get_all_models`.
|
|
244
|
+
|
|
245
|
+
Returned model views remain valid only while the pool is alive.
|
|
246
|
+
|
|
247
|
+
## Installation
|
|
248
|
+
|
|
249
|
+
MuJoCoUni is published on PyPI as `mujoco-uni-runtime` (source distribution):
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
pip install "mujoco>=3.5,<3.11" pybind11 numpy setuptools wheel
|
|
253
|
+
pip install mujoco-uni-runtime --no-build-isolation
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
There are no prebuilt wheels on purpose: the native extension is compiled
|
|
257
|
+
against the `mujoco` package present at build time and refuses to load against
|
|
258
|
+
any other MuJoCo version, so a prebuilt wheel would silently bind you to one
|
|
259
|
+
MuJoCo release. Building from source requires a C++17 toolchain. Install with
|
|
260
|
+
`--no-build-isolation` (as above) so the extension is compiled against the
|
|
261
|
+
`mujoco` version of your target environment instead of a throwaway isolated
|
|
262
|
+
one.
|
|
263
|
+
|
|
264
|
+
uv projects declare the same setup:
|
|
265
|
+
|
|
266
|
+
```toml
|
|
267
|
+
[project.optional-dependencies]
|
|
268
|
+
mujoco = ["mujoco>=3.5,<3.11", "mujoco-uni-runtime==0.2.1", "pybind11>=2.12", "wheel"]
|
|
269
|
+
|
|
270
|
+
[tool.uv]
|
|
271
|
+
no-build-isolation-package = ["mujoco-uni-runtime"]
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
For development beside UniLab:
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
cd /path/to/mujoco_uni
|
|
278
|
+
uv sync
|
|
279
|
+
uv pip install --force-reinstall --no-deps --no-build-isolation -e .
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
UniLab imports through its compatibility/backend layer, which in turn imports:
|
|
283
|
+
|
|
284
|
+
```python
|
|
285
|
+
from mujoco_uni.batch_env import BatchEnvPool, SUPPORTED_FIELDS
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Rebuilding The Native Extension
|
|
289
|
+
|
|
290
|
+
Editable installs are useful while developing MuJoCoUni in one environment.
|
|
291
|
+
They generate a local extension such as:
|
|
292
|
+
|
|
293
|
+
```text
|
|
294
|
+
src/mujoco_uni/compiled/_batch_env.cpython-313-darwin.so
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
That artifact is tied to the active Python environment, platform, and MuJoCo
|
|
298
|
+
patch version. Rebuild after switching virtual environments, Python versions, or
|
|
299
|
+
MuJoCo versions:
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
uv pip install "mujoco==3.10.0" pybind11 wheel
|
|
303
|
+
uv pip install --force-reinstall --no-deps --no-build-isolation -e .
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
After selecting a solver version, run local checks without an automatic sync if
|
|
307
|
+
you want to preserve the already-built native target:
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
uv run --no-sync pytest -q
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## Validation
|
|
314
|
+
|
|
315
|
+
Standalone checks:
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
uv run ruff check .
|
|
319
|
+
uv run pytest -q
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
Version-matrix checks:
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
uv run python tools/version_matrix.py --pytest
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
The default matrix covers:
|
|
329
|
+
|
|
330
|
+
```text
|
|
331
|
+
3.5.0 3.6.0 3.7.0 3.8.0 3.8.1 3.9.0 3.10.0
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Full UniLab task validation is separate from the quick package matrix:
|
|
335
|
+
|
|
336
|
+
```bash
|
|
337
|
+
uv run python tools/version_matrix.py --versions 3.5.0 3.10.0 --unilab
|
|
338
|
+
uv run python tools/version_matrix.py --versions 3.5.0 3.10.0 --unilab-train
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
The `--unilab-train` mode runs a short one-iteration training smoke in each
|
|
342
|
+
selected MuJoCo environment.
|
|
343
|
+
|
|
344
|
+
UniLab integration checks:
|
|
345
|
+
|
|
346
|
+
```bash
|
|
347
|
+
cd ../UniLab
|
|
348
|
+
uv run pytest \
|
|
349
|
+
tests/base/test_mujoco_batch_env_randomization.py \
|
|
350
|
+
tests/base/test_mujoco_batch_env_jacobian.py \
|
|
351
|
+
tests/base/backend/test_mujoco_site_jacobian.py \
|
|
352
|
+
tests/envs/locomotion/test_go2_rough_height_scan.py \
|
|
353
|
+
tests/envs/locomotion/test_go2_footstand.py \
|
|
354
|
+
tests/envs/locomotion/test_go2_terrain_spawn.py \
|
|
355
|
+
-q
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
Training smoke:
|
|
359
|
+
|
|
360
|
+
```bash
|
|
361
|
+
cd ../UniLab
|
|
362
|
+
uv run python scripts/train_rsl_rl.py \
|
|
363
|
+
task=go2_joystick_flat/mujoco \
|
|
364
|
+
algo.seed=1 \
|
|
365
|
+
algo.num_envs=256 \
|
|
366
|
+
algo.num_steps_per_env=24 \
|
|
367
|
+
algo.max_iterations=2 \
|
|
368
|
+
algo.save_interval=100 \
|
|
369
|
+
training.no_play=true \
|
|
370
|
+
training.logger=tensorboard \
|
|
371
|
+
training.device=cpu \
|
|
372
|
+
training.log_root=logs/mujoco_uni_smoke
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
## Thread Safety
|
|
376
|
+
|
|
377
|
+
Built-in MuJoCo sensors are read from `mjData.sensordata` and are supported by
|
|
378
|
+
the batch executor.
|
|
379
|
+
|
|
380
|
+
Custom sensors, plugins, and global MuJoCo callbacks are thread-safety-sensitive.
|
|
381
|
+
If `nthread > 1`, any global mutable callback/plugin state is the caller's
|
|
382
|
+
responsibility.
|
|
383
|
+
|
|
384
|
+
## Scope Boundaries
|
|
385
|
+
|
|
386
|
+
MuJoCoUni stays outside these responsibilities:
|
|
387
|
+
|
|
388
|
+
- MuJoCo source-code changes,
|
|
389
|
+
- MuJoCo solver/contact/integrator forks,
|
|
390
|
+
- distributed factorization of one MuJoCo solve across MPI ranks,
|
|
391
|
+
- OpenMP inside the MuJoCoUni executor,
|
|
392
|
+
- UniLab task YAMLs, rollout code, reward functions, and DrakeUni behavior.
|
|
393
|
+
|
|
394
|
+
## License
|
|
395
|
+
|
|
396
|
+
Apache-2.0.
|