Skip to content

Commit 69c9ac0

Browse files
yuvaltassacopybara-github
authored andcommitted
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
1 parent ec32264 commit 69c9ac0

File tree

19 files changed

+53
-44
lines changed

19 files changed

+53
-44
lines changed

doc/changelog.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ Python bindings
1313
from multiple threads. To run multiple threaded rollouts simultaneously, use the new class ``Rollout`` which
1414
encapsulates the thread pool. Contribution by :github:user:`aftersomemath`.
1515

16+
General
17+
^^^^^^^
18+
19+
.. admonition:: Breaking API changes (minor)
20+
:class: attention
21+
22+
- The field ``mjData.qLDiagSqrtInv`` has been removed. This field is only required for the dual solvers. It is now
23+
computed as-needed rather than unconditionally. Relatedly, added the corresponding argument to :ref:`mj_solveM2`.
24+
1625
Bug fixes
1726
^^^^^^^^^
1827
- Fixed a bug in the box-sphere collider, depth was incorrect for deep penetrations (:github:issue:`2206`).

doc/includes/references.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ struct mjData_ {
273273
// computed by mj_fwdPosition/mj_factorM
274274
mjtNum* qLD; // L'*D*L factorization of M (sparse) (nM x 1)
275275
mjtNum* qLDiagInv; // 1/diag(D) (nv x 1)
276-
mjtNum* qLDiagSqrtInv; // 1/sqrt(diag(D)) (nv x 1)
277276

278277
// computed by mj_collisionTree
279278
mjtNum* bvh_aabb_dyn; // global bounding box (center, size) (nbvhdynamic x 6)
@@ -3221,7 +3220,8 @@ void mj_transmission(const mjModel* m, mjData* d);
32213220
void mj_crb(const mjModel* m, mjData* d);
32223221
void mj_factorM(const mjModel* m, mjData* d);
32233222
void mj_solveM(const mjModel* m, mjData* d, mjtNum* x, const mjtNum* y, int n);
3224-
void mj_solveM2(const mjModel* m, mjData* d, mjtNum* x, const mjtNum* y, int n);
3223+
void mj_solveM2(const mjModel* m, mjData* d, mjtNum* x, const mjtNum* y,
3224+
const mjtNum* sqrtInvD, int n);
32253225
void mj_comVel(const mjModel* m, mjData* d);
32263226
void mj_passive(const mjModel* m, mjData* d);
32273227
void mj_subtreeVel(const mjModel* m, mjData* d);

include/mujoco/mjdata.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,6 @@ struct mjData_ {
301301
// computed by mj_fwdPosition/mj_factorM
302302
mjtNum* qLD; // L'*D*L factorization of M (sparse) (nM x 1)
303303
mjtNum* qLDiagInv; // 1/diag(D) (nv x 1)
304-
mjtNum* qLDiagSqrtInv; // 1/sqrt(diag(D)) (nv x 1)
305304

306305
// computed by mj_collisionTree
307306
mjtNum* bvh_aabb_dyn; // global bounding box (center, size) (nbvhdynamic x 6)

include/mujoco/mjxmacro.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,6 @@
632632
X ( mjtNum, qM, nM, 1 ) \
633633
X ( mjtNum, qLD, nM, 1 ) \
634634
X ( mjtNum, qLDiagInv, nv, 1 ) \
635-
X ( mjtNum, qLDiagSqrtInv, nv, 1 ) \
636635
XMJV( mjtNum, bvh_aabb_dyn, nbvhdynamic, 6 ) \
637636
XMJV( mjtByte, bvh_active, nbvh, 1 ) \
638637
X ( mjtNum, flexedge_velocity, nflexedge, 1 ) \

include/mujoco/mujoco.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ MJAPI void mj_factorM(const mjModel* m, mjData* d);
365365
MJAPI void mj_solveM(const mjModel* m, mjData* d, mjtNum* x, const mjtNum* y, int n);
366366

367367
// Half of linear solve: x = sqrt(inv(D))*inv(L')*y
368-
MJAPI void mj_solveM2(const mjModel* m, mjData* d, mjtNum* x, const mjtNum* y, int n);
368+
MJAPI void mj_solveM2(const mjModel* m, mjData* d, mjtNum* x, const mjtNum* y,
369+
const mjtNum* sqrtInvD, int n);
369370

370371
// Compute cvel, cdof_dot.
371372
MJAPI void mj_comVel(const mjModel* m, mjData* d);

introspect/functions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,6 +1868,12 @@
18681868
inner_type=ValueType(name='mjtNum', is_const=True),
18691869
),
18701870
),
1871+
FunctionParameterDecl(
1872+
name='sqrtInvD',
1873+
type=PointerType(
1874+
inner_type=ValueType(name='mjtNum', is_const=True),
1875+
),
1876+
),
18711877
FunctionParameterDecl(
18721878
name='n',
18731879
type=ValueType(name='int'),

introspect/structs.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5213,14 +5213,6 @@
52135213
doc='1/diag(D)',
52145214
array_extent=('nv',),
52155215
),
5216-
StructFieldDecl(
5217-
name='qLDiagSqrtInv',
5218-
type=PointerType(
5219-
inner_type=ValueType(name='mjtNum'),
5220-
),
5221-
doc='1/sqrt(diag(D))',
5222-
array_extent=('nv',),
5223-
),
52245216
StructFieldDecl(
52255217
name='bvh_aabb_dyn',
52265218
type=PointerType(

mjx/mujoco/mjx/_src/io.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ def make_data(
310310
'qM': (m.nM, float) if support.is_sparse(m) else (m.nv, m.nv, float),
311311
'qLD': (m.nM, float) if support.is_sparse(m) else (m.nv, m.nv, float),
312312
'qLDiagInv': (m.nv, float) if support.is_sparse(m) else (0, float),
313-
'qLDiagSqrtInv': (m.nv, float),
314313
'bvh_aabb_dyn': (m.nbvhdynamic, 6, float),
315314
'bvh_active': (m.nbvh, jp.uint8),
316315
'flexedge_velocity': (m.nflexedge, float),

mjx/mujoco/mjx/_src/types.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,6 @@ class Data(PyTreeNode):
12741274
if dense: (nv, nv)
12751275
qLDiagInv: 1/diag(D) if sparse: (nv,)
12761276
if dense: (0,)
1277-
qLDiagSqrtInv: 1/sqrt(diag(D)) (nv,)
12781277
bvh_aabb_dyn: global bounding box (center, size) (nbvhdynamic, 6)
12791278
bvh_active: volume has been added to collisions (nbvh,)
12801279
flexedge_velocity: flex edge velocities (nflexedge,)
@@ -1404,7 +1403,6 @@ class Data(PyTreeNode):
14041403
qM: jax.Array # pylint:disable=invalid-name
14051404
qLD: jax.Array # pylint:disable=invalid-name
14061405
qLDiagInv: jax.Array # pylint:disable=invalid-name
1407-
qLDiagSqrtInv: jax.Array # pylint:disable=invalid-name
14081406
bvh_aabb_dyn: jax.Array = _restricted_to('mujoco')
14091407
bvh_active: jax.Array = _restricted_to('mujoco')
14101408
# position, velocity dependent:

python/mujoco/functions.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ PYBIND11_MODULE(_functions, pymodule) {
234234
DEF_WITH_OMITTED_PY_ARGS(traits::mj_solveM2, "n")(
235235
pymodule,
236236
[](const raw::MjModel* m, raw::MjData* d, Eigen::Ref<EigenArrayXX> x,
237-
Eigen::Ref<const EigenArrayXX> y) {
237+
Eigen::Ref<const EigenArrayXX> y, Eigen::Ref<const EigenArrayXX> sqrtInvD) {
238238
if (x.rows() != y.rows()) {
239239
throw py::type_error(
240240
"the first dimension of x and y should be of the same size");
@@ -247,8 +247,12 @@ PYBIND11_MODULE(_functions, pymodule) {
247247
throw py::type_error(
248248
"the last dimension of y should be of size nv");
249249
}
250+
if (sqrtInvD.size() != m->nv) {
251+
throw py::type_error(
252+
"the size of sqrtInvD should be nv");
253+
}
250254
return InterceptMjErrors(::mj_solveM2)(
251-
m, d, x.data(), y.data(), y.rows());
255+
m, d, x.data(), y.data(), sqrtInvD.data(), y.rows());
252256
});
253257
Def<traits::mj_comVel>(pymodule);
254258
Def<traits::mj_passive>(pymodule);

0 commit comments

Comments
 (0)