Skip to content

replace SPARSE_CONSTRAINT_JACOBIAN with m.is_sparse#1223

Merged
thowell merged 3 commits intogoogle-deepmind:mainfrom
thowell:sparse_constraint_jacobian_is_sparse
Mar 18, 2026
Merged

replace SPARSE_CONSTRAINT_JACOBIAN with m.is_sparse#1223
thowell merged 3 commits intogoogle-deepmind:mainfrom
thowell:sparse_constraint_jacobian_is_sparse

Conversation

@thowell
Copy link
Collaborator

@thowell thowell commented Mar 12, 2026

almost ready to enable the sparse constraint jacobian with m.is_sparse

(don't think these todos need to be block for this pr)
todos:


three humanoids

mjwarp-testspeed benchmarks/humanoid/three_humanoids.xml --nworld=8192 --nconmax=100 --njmax=192

main eaa287f

  • SPARSE_CONSTRAINT_JACOBAIN=False so the dense efc_J code path is utilized
Loading model from: benchmarks/humanoid/three_humanoids.xml...

Model
  nq: 84 nv: 81 nu: 63 nbody: 49 ngeom: 58
Option
  integrator: EULER
  cone: PYRAMIDAL
  solver: NEWTON iterations: 100 ls_iterations: 50
  is_sparse: True
  ls_parallel: False
  broadphase: NXN broadphase_filter: PLANE|SPHERE|OBB
Data
  nworld: 8192 naconmax: 819200 njmax: 192
Rolling out 1000 steps at dt = 0.005...

Summary for 8192 parallel rollouts

Total JIT time: 0.43 s
Total simulation time: 16.19 s
Total steps per second: 506,108
Total realtime factor: 2,530.54 x
Total time per step: 1975.86 ns
Total converged worlds: 8192 / 8192

this pr

  • sparse constraint jacobian is enabled by default via m.is_sparse
Loading model from: benchmarks/humanoid/three_humanoids.xml...

Model
  nq: 84 nv: 81 nu: 63 nbody: 49 ngeom: 58
Option
  integrator: EULER
  cone: PYRAMIDAL
  solver: NEWTON iterations: 100 ls_iterations: 50
  is_sparse: True
  ls_parallel: False
  broadphase: NXN broadphase_filter: PLANE|SPHERE|OBB
Data
  nworld: 8192 naconmax: 819200 njmax: 192
Rolling out 1000 steps at dt = 0.005...

Summary for 8192 parallel rollouts

Total JIT time: 0.45 s
Total simulation time: 13.07 s
Total steps per second: 626,670
Total realtime factor: 3,133.35 x
Total time per step: 1595.74 ns
Total converged worlds: 8192 / 8192

@thowell thowell force-pushed the sparse_constraint_jacobian_is_sparse branch from 9ad351b to da65528 Compare March 12, 2026 19:39
@Kenny-Vilella
Copy link
Collaborator

I investigated from newton side the effect of the sparse Jacobian:
Used 6 cases spanning DoF Numbers from 36 to 135, for most cases, several units of the same robot were added to get higher DoF count.

Results is that the new sparse version is 20-40% faster for both Newton and CG solver and for both pyramidal and elliptic cone friction.
All the UTs are also passing.
Great work !

I am quite sure that it also gives us a lot of new opportunity for optimization.

@thowell thowell force-pushed the sparse_constraint_jacobian_is_sparse branch from da65528 to 97a6a26 Compare March 16, 2026 18:42
@thowell
Copy link
Collaborator Author

thowell commented Mar 16, 2026

minor bug fix, needed to zero the solver context newton solver hessian ctx.h.zero_(). pr description is updated with updated results.

@thowell thowell marked this pull request as ready for review March 16, 2026 19:04
Copy link
Collaborator

@erikfrey erikfrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heck yes - ship it!

@thowell thowell merged commit 820d892 into google-deepmind:main Mar 18, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants