diffneusim 1.0.0__py3-none-any.whl

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.
Files changed (682) hide show
  1. diffneusim/__init__.py +1 -0
  2. diffneusim/_cache.py +42 -0
  3. diffneusim/_paths.py +5 -0
  4. diffneusim/bindings/rew14_ext.cu +115 -0
  5. diffneusim/bindings/soft14_capi.cpp +443 -0
  6. diffneusim/bindings/soft14_engine_ext.cu +596 -0
  7. diffneusim/bindings/soft_capi.cpp +782 -0
  8. diffneusim/bindings/soft_engine_ext.cu +495 -0
  9. diffneusim/core/cpu_engine/build.sh +40 -0
  10. diffneusim/core/cpu_engine/fiber/cuda_runtime.h +445 -0
  11. diffneusim/core/cpu_engine/x14_cpu.cpp +283 -0
  12. diffneusim/core/diff/dual.h +126 -0
  13. diffneusim/core/include/diffneusim/macros.h +35 -0
  14. diffneusim/core/kin/kinematic_tree.h +273 -0
  15. diffneusim/core/math/so3.h +182 -0
  16. diffneusim/core/soft/adj/out_adj.h +102 -0
  17. diffneusim/core/soft/adj/rnea_adj.h +425 -0
  18. diffneusim/core/soft/adj/rows_adj.h +439 -0
  19. diffneusim/core/soft/adj/rows_functor.h +89 -0
  20. diffneusim/core/soft/adj/rows_lanes.h +443 -0
  21. diffneusim/core/soft/adj/shell_adj.h +243 -0
  22. diffneusim/core/soft/adj/tree_adj.h +356 -0
  23. diffneusim/core/soft/collide.h +183 -0
  24. diffneusim/core/soft/gpu/adj14.cuh +233 -0
  25. diffneusim/core/soft/gpu/adj14_mus.cuh +98 -0
  26. diffneusim/core/soft/gpu/adj_shell.cuh +50 -0
  27. diffneusim/core/soft/gpu/adj_tab.cuh +49 -0
  28. diffneusim/core/soft/gpu/body14.cuh +47 -0
  29. diffneusim/core/soft/gpu/chol_rn.cuh +458 -0
  30. diffneusim/core/soft/gpu/chol_small.cuh +123 -0
  31. diffneusim/core/soft/gpu/chol_split.cuh +193 -0
  32. diffneusim/core/soft/gpu/engine_launch.cuh +263 -0
  33. diffneusim/core/soft/gpu/fk_rn.cuh +109 -0
  34. diffneusim/core/soft/gpu/generated/body_019e20820f86_mmfloor.cuh +28 -0
  35. diffneusim/core/soft/gpu/generated/body_62f77a4bb16b_mmfloor.cuh +52 -0
  36. diffneusim/core/soft/gpu/generated/body_77dbb7213f26_mmfloor_rampsb3l_n6t12.cuh +28 -0
  37. diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rampsb3l_n6t12.cuh +28 -0
  38. diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rhlsd05_n6t12.cuh +28 -0
  39. diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rhlsdef_n6t12.cuh +28 -0
  40. diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rhlsmjd_n6t12.cuh +28 -0
  41. diffneusim/core/soft/gpu/generated/body_a1e8b196b2cd_mmfloor_rampsb3l_n6t12.cuh +52 -0
  42. diffneusim/core/soft/gpu/generated/body_a944653edd64_mmfloor.cuh +25 -0
  43. diffneusim/core/soft/gpu/generated/body_a944653edd64_mmfloor_rampsb3l_n6t12.cuh +25 -0
  44. diffneusim/core/soft/gpu/generated/g1_soft_5db44fd45286.cuh +74 -0
  45. diffneusim/core/soft/gpu/generated/split_62f77a4bb16b_mmfloor.cuh +18 -0
  46. diffneusim/core/soft/gpu/generated/split_a1e8b196b2cd_mmfloor_rampsb3l_n6t12.cuh +18 -0
  47. diffneusim/core/soft/gpu/generated/x14_soft_019e20820f86_mmfloor.cuh +123 -0
  48. diffneusim/core/soft/gpu/generated/x14_soft_62f77a4bb16b_mmfloor.cuh +129 -0
  49. diffneusim/core/soft/gpu/generated/x14_soft_77dbb7213f26_mmfloor_rampsb3l_n6t12.cuh +123 -0
  50. diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rampsb3l_n6t12.cuh +123 -0
  51. diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rhlsd05_n6t12.cuh +123 -0
  52. diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rhlsdef_n6t12.cuh +123 -0
  53. diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rhlsmjd_n6t12.cuh +123 -0
  54. diffneusim/core/soft/gpu/generated/x14_soft_a1e8b196b2cd_mmfloor_rampsb3l_n6t12.cuh +129 -0
  55. diffneusim/core/soft/gpu/generated/x14_soft_a944653edd64_mmfloor.cuh +123 -0
  56. diffneusim/core/soft/gpu/generated/x14_soft_a944653edd64_mmfloor_rampsb3l_n6t12.cuh +123 -0
  57. diffneusim/core/soft/gpu/k_mus.cuh +1038 -0
  58. diffneusim/core/soft/gpu/k_mus_host.cuh +377 -0
  59. diffneusim/core/soft/gpu/k_pre.cuh +52 -0
  60. diffneusim/core/soft/gpu/kernel_p.cuh +490 -0
  61. diffneusim/core/soft/gpu/kp14.cuh +465 -0
  62. diffneusim/core/soft/gpu/l2v2.cuh +367 -0
  63. diffneusim/core/soft/gpu/l2x14.cuh +319 -0
  64. diffneusim/core/soft/gpu/l3.cuh +1483 -0
  65. diffneusim/core/soft/gpu/model_view.cuh +48 -0
  66. diffneusim/core/soft/gpu/mus_case_fits.h +15 -0
  67. diffneusim/core/soft/gpu/mus_classes.h +182 -0
  68. diffneusim/core/soft/gpu/mus_row_cf.h +44 -0
  69. diffneusim/core/soft/gpu/rew14.cuh +177 -0
  70. diffneusim/core/soft/gpu/rows_ctab.cuh +44 -0
  71. diffneusim/core/soft/gpu/tree_m.cuh +247 -0
  72. diffneusim/core/soft/gpu/x14_engine_kernels.cuh +260 -0
  73. diffneusim/core/soft/gpu/x14_rowcf.h +14 -0
  74. diffneusim/core/soft/hand.h +124 -0
  75. diffneusim/core/soft/impedance.h +115 -0
  76. diffneusim/core/soft/jvp.h +202 -0
  77. diffneusim/core/soft/kin.h +250 -0
  78. diffneusim/core/soft/muscle.h +1208 -0
  79. diffneusim/core/soft/newton.h +371 -0
  80. diffneusim/core/soft/rows.h +176 -0
  81. diffneusim/core/soft/step.h +188 -0
  82. diffneusim/core/soft/tape.h +313 -0
  83. diffneusim/core/soft/x14/collide14.h +69 -0
  84. diffneusim/core/soft/x14/jvp14.h +182 -0
  85. diffneusim/core/soft/x14/law14.h +453 -0
  86. diffneusim/core/soft/x14adj/collide14_adj.h +134 -0
  87. diffneusim/core/soft/x14adj/passive14_adj.h +162 -0
  88. diffneusim/core/soft/x14adj/reward14.h +484 -0
  89. diffneusim/core/soft/x14adj/rows14_adj.h +400 -0
  90. diffneusim/core/soft/x14adj/scan14.h +349 -0
  91. diffneusim/core/soft/x14adj/shell14_adj.h +122 -0
  92. diffneusim/core/soft/x14adj/sweep14.h +255 -0
  93. diffneusim/core/soft/x14adj/tree14_adj.h +500 -0
  94. diffneusim/core/soft/x14adj/x14adj_common.h +96 -0
  95. diffneusim/data/mirror/H1622v2k_geyer_hfdeq.npz +0 -0
  96. diffneusim/data/mirror/H1622v2k_hfd.npz +0 -0
  97. diffneusim/data/mirror/H1622v2k_millard_hfdeq.npz +0 -0
  98. diffneusim/data/mirror/fullbody_contact.npz +0 -0
  99. diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard.npz +0 -0
  100. diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_p2str.npz +0 -0
  101. diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_p2str_rigid.npz +0 -0
  102. diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.npz +0 -0
  103. diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid.npz +0 -0
  104. diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq.npz +0 -0
  105. diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin.npz +0 -0
  106. diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_calf2_pe.npz +0 -0
  107. diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc.npz +0 -0
  108. diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_axfix.npz +0 -0
  109. diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_axfixlegs01.npz +0 -0
  110. diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_jd01.npz +0 -0
  111. diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_jd01legs.npz +0 -0
  112. diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_jd01lumbar.npz +0 -0
  113. diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_lumbfix.npz +0 -0
  114. diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_lumbfixlegs01.npz +0 -0
  115. diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.npz +0 -0
  116. diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1a.npz +0 -0
  117. diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n2.npz +0 -0
  118. diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_rom23.npz +0 -0
  119. diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair.npz +0 -0
  120. diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc.npz +0 -0
  121. diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_hinge.npz +0 -0
  122. diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.npz +0 -0
  123. diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1a.npz +0 -0
  124. diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n2.npz +0 -0
  125. diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_rom23.npz +0 -0
  126. diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_lspine_girdle_osimeq.npz +0 -0
  127. diffneusim/data/mirror/fullbody_contact_spinecoupled_lspine_girdle_millard.npz +0 -0
  128. diffneusim/data/mirror/fullbody_contact_spinecoupled_lspine_girdle_osimeq.npz +0 -0
  129. diffneusim/data/mirror/myoleg26_3d_compound_g14eq.npz +0 -0
  130. diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq.npz +0 -0
  131. diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose.npz +0 -0
  132. diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin.npz +0 -0
  133. diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30.npz +0 -0
  134. diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30_hip30.npz +0 -0
  135. diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30_hip30_luispe.npz +0 -0
  136. diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30_hip30_trunk0701.npz +0 -0
  137. diffneusim/data/muscle_fit/wang_mass_volume_14t.json +91 -0
  138. diffneusim/data/muscle_fit/wang_mass_volume_14t_axfix.json +91 -0
  139. diffneusim/data/muscle_fit/wang_mass_volume_14t_axfixlegs01.json +91 -0
  140. diffneusim/data/muscle_fit/wang_mass_volume_14t_jd01.json +91 -0
  141. diffneusim/data/muscle_fit/wang_mass_volume_14t_jd01legs.json +91 -0
  142. diffneusim/data/muscle_fit/wang_mass_volume_14t_jd01lumbar.json +91 -0
  143. diffneusim/data/muscle_fit/wang_mass_volume_14t_lumbfix.json +91 -0
  144. diffneusim/data/muscle_fit/wang_mass_volume_14t_lumbfixlegs01.json +91 -0
  145. diffneusim/data/muscle_fit/wang_mass_volume_14t_n1.json +91 -0
  146. diffneusim/data/muscle_fit/wang_mass_volume_14t_n1a.json +91 -0
  147. diffneusim/data/muscle_fit/wang_mass_volume_14t_n2.json +91 -0
  148. diffneusim/data/muscle_fit/wang_mass_volume_14t_rom23.json +91 -0
  149. diffneusim/data/reference/musclemimic/myofullbody_mimic_sites.json +261 -0
  150. diffneusim/data/reference/pose3/pose3_scone.json +305 -0
  151. diffneusim/data/reference/pose3/pose3_scone.txt +3 -0
  152. diffneusim/data/reference/pose3/pose3_scone_gait.npz +0 -0
  153. diffneusim/data/reference/pose3/pose3_scone_mirror.npz +0 -0
  154. diffneusim/data/reference/pose3/pose3_scone_stand.npz +0 -0
  155. diffneusim/data/reference/x016run/MD5SUMS +241 -0
  156. diffneusim/data/reference/x016run/x016run_states.txt +240 -0
  157. diffneusim/data/reference/x016run/x016run_v3p00_s0_l0.npz +0 -0
  158. diffneusim/data/reference/x016run/x016run_v3p00_s0_l1.npz +0 -0
  159. diffneusim/data/reference/x016run/x016run_v3p00_s0_l2.npz +0 -0
  160. diffneusim/data/reference/x016run/x016run_v3p00_s0_l3.npz +0 -0
  161. diffneusim/data/reference/x016run/x016run_v3p00_s0_r0.npz +0 -0
  162. diffneusim/data/reference/x016run/x016run_v3p00_s0_r1.npz +0 -0
  163. diffneusim/data/reference/x016run/x016run_v3p00_s0_r2.npz +0 -0
  164. diffneusim/data/reference/x016run/x016run_v3p00_s0_r3.npz +0 -0
  165. diffneusim/data/reference/x016run/x016run_v3p00_s1_l0.npz +0 -0
  166. diffneusim/data/reference/x016run/x016run_v3p00_s1_l1.npz +0 -0
  167. diffneusim/data/reference/x016run/x016run_v3p00_s1_l2.npz +0 -0
  168. diffneusim/data/reference/x016run/x016run_v3p00_s1_l3.npz +0 -0
  169. diffneusim/data/reference/x016run/x016run_v3p00_s1_r0.npz +0 -0
  170. diffneusim/data/reference/x016run/x016run_v3p00_s1_r1.npz +0 -0
  171. diffneusim/data/reference/x016run/x016run_v3p00_s1_r2.npz +0 -0
  172. diffneusim/data/reference/x016run/x016run_v3p00_s1_r3.npz +0 -0
  173. diffneusim/data/reference/x016run/x016run_v3p00_s2_l0.npz +0 -0
  174. diffneusim/data/reference/x016run/x016run_v3p00_s2_l1.npz +0 -0
  175. diffneusim/data/reference/x016run/x016run_v3p00_s2_l2.npz +0 -0
  176. diffneusim/data/reference/x016run/x016run_v3p00_s2_l3.npz +0 -0
  177. diffneusim/data/reference/x016run/x016run_v3p00_s2_r0.npz +0 -0
  178. diffneusim/data/reference/x016run/x016run_v3p00_s2_r1.npz +0 -0
  179. diffneusim/data/reference/x016run/x016run_v3p00_s2_r2.npz +0 -0
  180. diffneusim/data/reference/x016run/x016run_v3p00_s2_r3.npz +0 -0
  181. diffneusim/data/reference/x016run/x016run_v3p00_s3_l0.npz +0 -0
  182. diffneusim/data/reference/x016run/x016run_v3p00_s3_l1.npz +0 -0
  183. diffneusim/data/reference/x016run/x016run_v3p00_s3_l2.npz +0 -0
  184. diffneusim/data/reference/x016run/x016run_v3p00_s3_l3.npz +0 -0
  185. diffneusim/data/reference/x016run/x016run_v3p00_s3_r0.npz +0 -0
  186. diffneusim/data/reference/x016run/x016run_v3p00_s3_r1.npz +0 -0
  187. diffneusim/data/reference/x016run/x016run_v3p00_s3_r2.npz +0 -0
  188. diffneusim/data/reference/x016run/x016run_v3p00_s3_r3.npz +0 -0
  189. diffneusim/data/reference/x016run/x016run_v3p00_s4_l0.npz +0 -0
  190. diffneusim/data/reference/x016run/x016run_v3p00_s4_l1.npz +0 -0
  191. diffneusim/data/reference/x016run/x016run_v3p00_s4_l2.npz +0 -0
  192. diffneusim/data/reference/x016run/x016run_v3p00_s4_l3.npz +0 -0
  193. diffneusim/data/reference/x016run/x016run_v3p00_s4_r0.npz +0 -0
  194. diffneusim/data/reference/x016run/x016run_v3p00_s4_r1.npz +0 -0
  195. diffneusim/data/reference/x016run/x016run_v3p00_s4_r2.npz +0 -0
  196. diffneusim/data/reference/x016run/x016run_v3p00_s4_r3.npz +0 -0
  197. diffneusim/data/reference/x016run/x016run_v3p00_s5_l0.npz +0 -0
  198. diffneusim/data/reference/x016run/x016run_v3p00_s5_l1.npz +0 -0
  199. diffneusim/data/reference/x016run/x016run_v3p00_s5_l2.npz +0 -0
  200. diffneusim/data/reference/x016run/x016run_v3p00_s5_l3.npz +0 -0
  201. diffneusim/data/reference/x016run/x016run_v3p00_s5_r0.npz +0 -0
  202. diffneusim/data/reference/x016run/x016run_v3p00_s5_r1.npz +0 -0
  203. diffneusim/data/reference/x016run/x016run_v3p00_s5_r2.npz +0 -0
  204. diffneusim/data/reference/x016run/x016run_v3p00_s5_r3.npz +0 -0
  205. diffneusim/data/reference/x016run/x016run_v3p00_s6_l0.npz +0 -0
  206. diffneusim/data/reference/x016run/x016run_v3p00_s6_l1.npz +0 -0
  207. diffneusim/data/reference/x016run/x016run_v3p00_s6_l2.npz +0 -0
  208. diffneusim/data/reference/x016run/x016run_v3p00_s6_l3.npz +0 -0
  209. diffneusim/data/reference/x016run/x016run_v3p00_s6_r0.npz +0 -0
  210. diffneusim/data/reference/x016run/x016run_v3p00_s6_r1.npz +0 -0
  211. diffneusim/data/reference/x016run/x016run_v3p00_s6_r2.npz +0 -0
  212. diffneusim/data/reference/x016run/x016run_v3p00_s6_r3.npz +0 -0
  213. diffneusim/data/reference/x016run/x016run_v3p00_s7_l0.npz +0 -0
  214. diffneusim/data/reference/x016run/x016run_v3p00_s7_l1.npz +0 -0
  215. diffneusim/data/reference/x016run/x016run_v3p00_s7_l2.npz +0 -0
  216. diffneusim/data/reference/x016run/x016run_v3p00_s7_l3.npz +0 -0
  217. diffneusim/data/reference/x016run/x016run_v3p00_s7_r0.npz +0 -0
  218. diffneusim/data/reference/x016run/x016run_v3p00_s7_r1.npz +0 -0
  219. diffneusim/data/reference/x016run/x016run_v3p00_s7_r2.npz +0 -0
  220. diffneusim/data/reference/x016run/x016run_v3p00_s7_r3.npz +0 -0
  221. diffneusim/data/reference/x016run/x016run_v3p25_s0_l0.npz +0 -0
  222. diffneusim/data/reference/x016run/x016run_v3p25_s0_l1.npz +0 -0
  223. diffneusim/data/reference/x016run/x016run_v3p25_s0_l2.npz +0 -0
  224. diffneusim/data/reference/x016run/x016run_v3p25_s0_l3.npz +0 -0
  225. diffneusim/data/reference/x016run/x016run_v3p25_s0_r0.npz +0 -0
  226. diffneusim/data/reference/x016run/x016run_v3p25_s0_r1.npz +0 -0
  227. diffneusim/data/reference/x016run/x016run_v3p25_s0_r2.npz +0 -0
  228. diffneusim/data/reference/x016run/x016run_v3p25_s0_r3.npz +0 -0
  229. diffneusim/data/reference/x016run/x016run_v3p25_s1_l0.npz +0 -0
  230. diffneusim/data/reference/x016run/x016run_v3p25_s1_l1.npz +0 -0
  231. diffneusim/data/reference/x016run/x016run_v3p25_s1_l2.npz +0 -0
  232. diffneusim/data/reference/x016run/x016run_v3p25_s1_l3.npz +0 -0
  233. diffneusim/data/reference/x016run/x016run_v3p25_s1_r0.npz +0 -0
  234. diffneusim/data/reference/x016run/x016run_v3p25_s1_r1.npz +0 -0
  235. diffneusim/data/reference/x016run/x016run_v3p25_s1_r2.npz +0 -0
  236. diffneusim/data/reference/x016run/x016run_v3p25_s1_r3.npz +0 -0
  237. diffneusim/data/reference/x016run/x016run_v3p25_s2_l0.npz +0 -0
  238. diffneusim/data/reference/x016run/x016run_v3p25_s2_l1.npz +0 -0
  239. diffneusim/data/reference/x016run/x016run_v3p25_s2_l2.npz +0 -0
  240. diffneusim/data/reference/x016run/x016run_v3p25_s2_l3.npz +0 -0
  241. diffneusim/data/reference/x016run/x016run_v3p25_s2_r0.npz +0 -0
  242. diffneusim/data/reference/x016run/x016run_v3p25_s2_r1.npz +0 -0
  243. diffneusim/data/reference/x016run/x016run_v3p25_s2_r2.npz +0 -0
  244. diffneusim/data/reference/x016run/x016run_v3p25_s2_r3.npz +0 -0
  245. diffneusim/data/reference/x016run/x016run_v3p25_s3_l0.npz +0 -0
  246. diffneusim/data/reference/x016run/x016run_v3p25_s3_l1.npz +0 -0
  247. diffneusim/data/reference/x016run/x016run_v3p25_s3_l2.npz +0 -0
  248. diffneusim/data/reference/x016run/x016run_v3p25_s3_l3.npz +0 -0
  249. diffneusim/data/reference/x016run/x016run_v3p25_s3_r0.npz +0 -0
  250. diffneusim/data/reference/x016run/x016run_v3p25_s3_r1.npz +0 -0
  251. diffneusim/data/reference/x016run/x016run_v3p25_s3_r2.npz +0 -0
  252. diffneusim/data/reference/x016run/x016run_v3p25_s3_r3.npz +0 -0
  253. diffneusim/data/reference/x016run/x016run_v3p25_s4_l0.npz +0 -0
  254. diffneusim/data/reference/x016run/x016run_v3p25_s4_l1.npz +0 -0
  255. diffneusim/data/reference/x016run/x016run_v3p25_s4_l2.npz +0 -0
  256. diffneusim/data/reference/x016run/x016run_v3p25_s4_l3.npz +0 -0
  257. diffneusim/data/reference/x016run/x016run_v3p25_s4_r0.npz +0 -0
  258. diffneusim/data/reference/x016run/x016run_v3p25_s4_r1.npz +0 -0
  259. diffneusim/data/reference/x016run/x016run_v3p25_s4_r2.npz +0 -0
  260. diffneusim/data/reference/x016run/x016run_v3p25_s4_r3.npz +0 -0
  261. diffneusim/data/reference/x016run/x016run_v3p25_s5_l0.npz +0 -0
  262. diffneusim/data/reference/x016run/x016run_v3p25_s5_l1.npz +0 -0
  263. diffneusim/data/reference/x016run/x016run_v3p25_s5_l2.npz +0 -0
  264. diffneusim/data/reference/x016run/x016run_v3p25_s5_l3.npz +0 -0
  265. diffneusim/data/reference/x016run/x016run_v3p25_s5_r0.npz +0 -0
  266. diffneusim/data/reference/x016run/x016run_v3p25_s5_r1.npz +0 -0
  267. diffneusim/data/reference/x016run/x016run_v3p25_s5_r2.npz +0 -0
  268. diffneusim/data/reference/x016run/x016run_v3p25_s5_r3.npz +0 -0
  269. diffneusim/data/reference/x016run/x016run_v3p25_s6_l0.npz +0 -0
  270. diffneusim/data/reference/x016run/x016run_v3p25_s6_l1.npz +0 -0
  271. diffneusim/data/reference/x016run/x016run_v3p25_s6_l2.npz +0 -0
  272. diffneusim/data/reference/x016run/x016run_v3p25_s6_l3.npz +0 -0
  273. diffneusim/data/reference/x016run/x016run_v3p25_s6_r0.npz +0 -0
  274. diffneusim/data/reference/x016run/x016run_v3p25_s6_r1.npz +0 -0
  275. diffneusim/data/reference/x016run/x016run_v3p25_s6_r2.npz +0 -0
  276. diffneusim/data/reference/x016run/x016run_v3p25_s6_r3.npz +0 -0
  277. diffneusim/data/reference/x016run/x016run_v3p25_s7_l0.npz +0 -0
  278. diffneusim/data/reference/x016run/x016run_v3p25_s7_l1.npz +0 -0
  279. diffneusim/data/reference/x016run/x016run_v3p25_s7_l2.npz +0 -0
  280. diffneusim/data/reference/x016run/x016run_v3p25_s7_l3.npz +0 -0
  281. diffneusim/data/reference/x016run/x016run_v3p25_s7_r0.npz +0 -0
  282. diffneusim/data/reference/x016run/x016run_v3p25_s7_r1.npz +0 -0
  283. diffneusim/data/reference/x016run/x016run_v3p25_s7_r2.npz +0 -0
  284. diffneusim/data/reference/x016run/x016run_v3p25_s7_r3.npz +0 -0
  285. diffneusim/data/reference/x016run/x016run_v3p50_s0_l0.npz +0 -0
  286. diffneusim/data/reference/x016run/x016run_v3p50_s0_l1.npz +0 -0
  287. diffneusim/data/reference/x016run/x016run_v3p50_s0_l2.npz +0 -0
  288. diffneusim/data/reference/x016run/x016run_v3p50_s0_l3.npz +0 -0
  289. diffneusim/data/reference/x016run/x016run_v3p50_s0_r0.npz +0 -0
  290. diffneusim/data/reference/x016run/x016run_v3p50_s0_r1.npz +0 -0
  291. diffneusim/data/reference/x016run/x016run_v3p50_s0_r2.npz +0 -0
  292. diffneusim/data/reference/x016run/x016run_v3p50_s0_r3.npz +0 -0
  293. diffneusim/data/reference/x016run/x016run_v3p50_s1_l0.npz +0 -0
  294. diffneusim/data/reference/x016run/x016run_v3p50_s1_l1.npz +0 -0
  295. diffneusim/data/reference/x016run/x016run_v3p50_s1_l2.npz +0 -0
  296. diffneusim/data/reference/x016run/x016run_v3p50_s1_l3.npz +0 -0
  297. diffneusim/data/reference/x016run/x016run_v3p50_s1_r0.npz +0 -0
  298. diffneusim/data/reference/x016run/x016run_v3p50_s1_r1.npz +0 -0
  299. diffneusim/data/reference/x016run/x016run_v3p50_s1_r2.npz +0 -0
  300. diffneusim/data/reference/x016run/x016run_v3p50_s1_r3.npz +0 -0
  301. diffneusim/data/reference/x016run/x016run_v3p50_s2_l0.npz +0 -0
  302. diffneusim/data/reference/x016run/x016run_v3p50_s2_l1.npz +0 -0
  303. diffneusim/data/reference/x016run/x016run_v3p50_s2_l2.npz +0 -0
  304. diffneusim/data/reference/x016run/x016run_v3p50_s2_l3.npz +0 -0
  305. diffneusim/data/reference/x016run/x016run_v3p50_s2_r0.npz +0 -0
  306. diffneusim/data/reference/x016run/x016run_v3p50_s2_r1.npz +0 -0
  307. diffneusim/data/reference/x016run/x016run_v3p50_s2_r2.npz +0 -0
  308. diffneusim/data/reference/x016run/x016run_v3p50_s2_r3.npz +0 -0
  309. diffneusim/data/reference/x016run/x016run_v3p50_s3_l0.npz +0 -0
  310. diffneusim/data/reference/x016run/x016run_v3p50_s3_l1.npz +0 -0
  311. diffneusim/data/reference/x016run/x016run_v3p50_s3_l2.npz +0 -0
  312. diffneusim/data/reference/x016run/x016run_v3p50_s3_l3.npz +0 -0
  313. diffneusim/data/reference/x016run/x016run_v3p50_s3_r0.npz +0 -0
  314. diffneusim/data/reference/x016run/x016run_v3p50_s3_r1.npz +0 -0
  315. diffneusim/data/reference/x016run/x016run_v3p50_s3_r2.npz +0 -0
  316. diffneusim/data/reference/x016run/x016run_v3p50_s3_r3.npz +0 -0
  317. diffneusim/data/reference/x016run/x016run_v3p50_s5_l0.npz +0 -0
  318. diffneusim/data/reference/x016run/x016run_v3p50_s5_l1.npz +0 -0
  319. diffneusim/data/reference/x016run/x016run_v3p50_s5_l2.npz +0 -0
  320. diffneusim/data/reference/x016run/x016run_v3p50_s5_l3.npz +0 -0
  321. diffneusim/data/reference/x016run/x016run_v3p50_s5_r0.npz +0 -0
  322. diffneusim/data/reference/x016run/x016run_v3p50_s5_r1.npz +0 -0
  323. diffneusim/data/reference/x016run/x016run_v3p50_s5_r2.npz +0 -0
  324. diffneusim/data/reference/x016run/x016run_v3p50_s5_r3.npz +0 -0
  325. diffneusim/data/reference/x016run/x016run_v3p50_s6_l0.npz +0 -0
  326. diffneusim/data/reference/x016run/x016run_v3p50_s6_l1.npz +0 -0
  327. diffneusim/data/reference/x016run/x016run_v3p50_s6_l2.npz +0 -0
  328. diffneusim/data/reference/x016run/x016run_v3p50_s6_l3.npz +0 -0
  329. diffneusim/data/reference/x016run/x016run_v3p50_s6_r0.npz +0 -0
  330. diffneusim/data/reference/x016run/x016run_v3p50_s6_r1.npz +0 -0
  331. diffneusim/data/reference/x016run/x016run_v3p50_s6_r2.npz +0 -0
  332. diffneusim/data/reference/x016run/x016run_v3p50_s6_r3.npz +0 -0
  333. diffneusim/data/reference/x016run/x016run_v3p50_s7_l0.npz +0 -0
  334. diffneusim/data/reference/x016run/x016run_v3p50_s7_l1.npz +0 -0
  335. diffneusim/data/reference/x016run/x016run_v3p50_s7_l2.npz +0 -0
  336. diffneusim/data/reference/x016run/x016run_v3p50_s7_l3.npz +0 -0
  337. diffneusim/data/reference/x016run/x016run_v3p50_s7_r0.npz +0 -0
  338. diffneusim/data/reference/x016run/x016run_v3p50_s7_r1.npz +0 -0
  339. diffneusim/data/reference/x016run/x016run_v3p50_s7_r2.npz +0 -0
  340. diffneusim/data/reference/x016run/x016run_v3p50_s7_r3.npz +0 -0
  341. diffneusim/data/reference/x016run/x016run_v3p75_s0_l0.npz +0 -0
  342. diffneusim/data/reference/x016run/x016run_v3p75_s0_l1.npz +0 -0
  343. diffneusim/data/reference/x016run/x016run_v3p75_s0_l2.npz +0 -0
  344. diffneusim/data/reference/x016run/x016run_v3p75_s0_l3.npz +0 -0
  345. diffneusim/data/reference/x016run/x016run_v3p75_s0_r0.npz +0 -0
  346. diffneusim/data/reference/x016run/x016run_v3p75_s0_r1.npz +0 -0
  347. diffneusim/data/reference/x016run/x016run_v3p75_s0_r2.npz +0 -0
  348. diffneusim/data/reference/x016run/x016run_v3p75_s0_r3.npz +0 -0
  349. diffneusim/data/reference/x016run/x016run_v3p75_s1_l0.npz +0 -0
  350. diffneusim/data/reference/x016run/x016run_v3p75_s1_l1.npz +0 -0
  351. diffneusim/data/reference/x016run/x016run_v3p75_s1_l2.npz +0 -0
  352. diffneusim/data/reference/x016run/x016run_v3p75_s1_l3.npz +0 -0
  353. diffneusim/data/reference/x016run/x016run_v3p75_s1_r0.npz +0 -0
  354. diffneusim/data/reference/x016run/x016run_v3p75_s1_r1.npz +0 -0
  355. diffneusim/data/reference/x016run/x016run_v3p75_s1_r2.npz +0 -0
  356. diffneusim/data/reference/x016run/x016run_v3p75_s1_r3.npz +0 -0
  357. diffneusim/data/reference/x016run/x016run_v3p75_s2_l0.npz +0 -0
  358. diffneusim/data/reference/x016run/x016run_v3p75_s2_l1.npz +0 -0
  359. diffneusim/data/reference/x016run/x016run_v3p75_s2_l2.npz +0 -0
  360. diffneusim/data/reference/x016run/x016run_v3p75_s2_l3.npz +0 -0
  361. diffneusim/data/reference/x016run/x016run_v3p75_s2_r0.npz +0 -0
  362. diffneusim/data/reference/x016run/x016run_v3p75_s2_r1.npz +0 -0
  363. diffneusim/data/reference/x016run/x016run_v3p75_s2_r2.npz +0 -0
  364. diffneusim/data/reference/x016run/x016run_v3p75_s2_r3.npz +0 -0
  365. diffneusim/data/reference/x016run/x016run_v3p75_s3_l0.npz +0 -0
  366. diffneusim/data/reference/x016run/x016run_v3p75_s3_l1.npz +0 -0
  367. diffneusim/data/reference/x016run/x016run_v3p75_s3_l2.npz +0 -0
  368. diffneusim/data/reference/x016run/x016run_v3p75_s3_l3.npz +0 -0
  369. diffneusim/data/reference/x016run/x016run_v3p75_s3_r0.npz +0 -0
  370. diffneusim/data/reference/x016run/x016run_v3p75_s3_r1.npz +0 -0
  371. diffneusim/data/reference/x016run/x016run_v3p75_s3_r2.npz +0 -0
  372. diffneusim/data/reference/x016run/x016run_v3p75_s3_r3.npz +0 -0
  373. diffneusim/data/reference/x016run/x016run_v3p75_s5_l0.npz +0 -0
  374. diffneusim/data/reference/x016run/x016run_v3p75_s5_l1.npz +0 -0
  375. diffneusim/data/reference/x016run/x016run_v3p75_s5_l2.npz +0 -0
  376. diffneusim/data/reference/x016run/x016run_v3p75_s5_l3.npz +0 -0
  377. diffneusim/data/reference/x016run/x016run_v3p75_s5_r0.npz +0 -0
  378. diffneusim/data/reference/x016run/x016run_v3p75_s5_r1.npz +0 -0
  379. diffneusim/data/reference/x016run/x016run_v3p75_s5_r2.npz +0 -0
  380. diffneusim/data/reference/x016run/x016run_v3p75_s5_r3.npz +0 -0
  381. diffneusim/data/reference/x016run/x016run_v3p75_s6_l0.npz +0 -0
  382. diffneusim/data/reference/x016run/x016run_v3p75_s6_l1.npz +0 -0
  383. diffneusim/data/reference/x016run/x016run_v3p75_s6_l2.npz +0 -0
  384. diffneusim/data/reference/x016run/x016run_v3p75_s6_l3.npz +0 -0
  385. diffneusim/data/reference/x016run/x016run_v3p75_s6_r0.npz +0 -0
  386. diffneusim/data/reference/x016run/x016run_v3p75_s6_r1.npz +0 -0
  387. diffneusim/data/reference/x016run/x016run_v3p75_s6_r2.npz +0 -0
  388. diffneusim/data/reference/x016run/x016run_v3p75_s6_r3.npz +0 -0
  389. diffneusim/data/reference/x016run/x016run_v3p75_s7_l0.npz +0 -0
  390. diffneusim/data/reference/x016run/x016run_v3p75_s7_l1.npz +0 -0
  391. diffneusim/data/reference/x016run/x016run_v3p75_s7_l2.npz +0 -0
  392. diffneusim/data/reference/x016run/x016run_v3p75_s7_l3.npz +0 -0
  393. diffneusim/data/reference/x016run/x016run_v3p75_s7_r0.npz +0 -0
  394. diffneusim/data/reference/x016run/x016run_v3p75_s7_r1.npz +0 -0
  395. diffneusim/data/reference/x016run/x016run_v3p75_s7_r2.npz +0 -0
  396. diffneusim/data/reference/x016run/x016run_v3p75_s7_r3.npz +0 -0
  397. diffneusim/data/state_prior/lumbar_poly_fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc.npz +0 -0
  398. diffneusim/engine/__init__.py +0 -0
  399. diffneusim/engine/build_tag.py +52 -0
  400. diffneusim/engine/case_tables.py +46 -0
  401. diffneusim/engine/d16_body.py +80 -0
  402. diffneusim/engine/engine14.py +367 -0
  403. diffneusim/engine/gen_split.py +159 -0
  404. diffneusim/engine/hand_format.py +69 -0
  405. diffneusim/engine/live14.py +149 -0
  406. diffneusim/engine/phase_b_tree.py +137 -0
  407. diffneusim/engine/soft14.py +130 -0
  408. diffneusim/engine/soft_capi.py +373 -0
  409. diffneusim/engine/soft_engine.py +165 -0
  410. diffneusim/engine/step14.py +132 -0
  411. diffneusim/engine/tape_format.py +89 -0
  412. diffneusim/engine/x14cpu.py +163 -0
  413. diffneusim/env/__init__.py +0 -0
  414. diffneusim/env/absent.py +20 -0
  415. diffneusim/env/cpu14.py +105 -0
  416. diffneusim/env/e0loop14.py +224 -0
  417. diffneusim/env/env14.py +568 -0
  418. diffneusim/env/kin_contact14.py +193 -0
  419. diffneusim/env/mimic_sites_x14.json +366 -0
  420. diffneusim/env/old_count.py +78 -0
  421. diffneusim/env/rew14.py +114 -0
  422. diffneusim/env/rew14_hook.py +105 -0
  423. diffneusim/g1/__init__.py +1 -0
  424. diffneusim/g1/arm_a2.py +165 -0
  425. diffneusim/g1/arm_a3.py +576 -0
  426. diffneusim/g1/read_a3.py +79 -0
  427. diffneusim/g1/rg1_read.py +89 -0
  428. diffneusim/model/__init__.py +66 -0
  429. diffneusim/model/case.py +17 -0
  430. diffneusim/model/dnmodel.py +79 -0
  431. diffneusim/model/fuse_fixed.py +281 -0
  432. diffneusim/model/monitor.py +834 -0
  433. diffneusim/models/BODIES.toml +48 -0
  434. diffneusim/models/MANIFEST.toml +979 -0
  435. diffneusim/models/cases/G290/case.bin +0 -0
  436. diffneusim/models/cases/G290/case.json +1 -0
  437. diffneusim/models/cases/G356-SRC/case.bin +0 -0
  438. diffneusim/models/cases/G356-SRC/case.json +1 -0
  439. diffneusim/models/cases/G416/case.bin +0 -0
  440. diffneusim/models/cases/G416/case.json +1 -0
  441. diffneusim/models/cases/M290C-SRC/case.bin +0 -0
  442. diffneusim/models/cases/M290C-SRC/case.json +1 -0
  443. diffneusim/models/cases/M290R-SRC/case.bin +0 -0
  444. diffneusim/models/cases/M290R-SRC/case.json +1 -0
  445. diffneusim/models/cases/M356C-SRC/case.bin +0 -0
  446. diffneusim/models/cases/M356C-SRC/case.json +1 -0
  447. diffneusim/models/cases/M356R-SRC/case.bin +0 -0
  448. diffneusim/models/cases/M356R-SRC/case.json +1 -0
  449. diffneusim/models/cases/M416C-SRC/case.bin +0 -0
  450. diffneusim/models/cases/M416C-SRC/case.json +1 -0
  451. diffneusim/models/derived/d16_expanded_62f77a4bb16b1e67_mmfloor.xml +673 -0
  452. diffneusim/models/derived/d16_expanded_a1e8b196b2cd7b3c_mmfloor.xml +673 -0
  453. diffneusim/models/derived/d16_soft_law_019e20820f8633b9_mmfloor.json +7844 -0
  454. diffneusim/models/derived/d16_soft_law_62f77a4bb16b1e67_mmfloor.json +16855 -0
  455. diffneusim/models/derived/d16_soft_law_77dbb7213f26e821_mmfloor_rampsb3l_n6t12.json +7883 -0
  456. diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rampsb3l_n6t12.json +7883 -0
  457. diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rhlsd05_n6t12.json +7868 -0
  458. diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rhlsdef_n6t12.json +7868 -0
  459. diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rhlsmjd_n6t12.json +7868 -0
  460. diffneusim/models/derived/d16_soft_law_a1e8b196b2cd7b3c_mmfloor_rampsb3l_n6t12.json +16894 -0
  461. diffneusim/models/derived/d16_soft_law_a944653edd642082_mmfloor.json +12655 -0
  462. diffneusim/models/derived/d16_soft_law_a944653edd642082_mmfloor_rampsb3l_n6t12.json +12700 -0
  463. diffneusim/models/derived/unitree_g1_soft_law.json +15580 -0
  464. diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.dnmodel +28913 -0
  465. diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_qk.txt +1 -0
  466. diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid.dnmodel +29202 -0
  467. diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid_qk.txt +1 -0
  468. diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_axfixlegs01.dnmodel +1 -0
  469. diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.dnmodel +1 -0
  470. diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1_qk.txt +1 -0
  471. diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.dnmodel +46970 -0
  472. diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_qk.txt +1 -0
  473. diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.dnmodel +1 -0
  474. diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1_qk.txt +1 -0
  475. diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.dnmodel +38570 -0
  476. diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_qk.txt +1 -0
  477. diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid.dnmodel +38923 -0
  478. diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid_qk.txt +1 -0
  479. diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.dnmodel +1 -0
  480. diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1_qk.txt +1 -0
  481. diffneusim/models/fullbody_meshes/1mc.stl +0 -0
  482. diffneusim/models/fullbody_meshes/2distph.stl +0 -0
  483. diffneusim/models/fullbody_meshes/2mc.stl +0 -0
  484. diffneusim/models/fullbody_meshes/2midph.stl +0 -0
  485. diffneusim/models/fullbody_meshes/2proxph.stl +0 -0
  486. diffneusim/models/fullbody_meshes/3distph.stl +0 -0
  487. diffneusim/models/fullbody_meshes/3mc.stl +0 -0
  488. diffneusim/models/fullbody_meshes/3midph.stl +0 -0
  489. diffneusim/models/fullbody_meshes/3proxph.stl +0 -0
  490. diffneusim/models/fullbody_meshes/4distph.stl +0 -0
  491. diffneusim/models/fullbody_meshes/4mc.stl +0 -0
  492. diffneusim/models/fullbody_meshes/4midph.stl +0 -0
  493. diffneusim/models/fullbody_meshes/4proxph.stl +0 -0
  494. diffneusim/models/fullbody_meshes/5distph.stl +0 -0
  495. diffneusim/models/fullbody_meshes/5mc.stl +0 -0
  496. diffneusim/models/fullbody_meshes/5midph.stl +0 -0
  497. diffneusim/models/fullbody_meshes/5proxph.stl +0 -0
  498. diffneusim/models/fullbody_meshes/NOTICE +2 -0
  499. diffneusim/models/fullbody_meshes/capitate.stl +0 -0
  500. diffneusim/models/fullbody_meshes/clavicle.stl +0 -0
  501. diffneusim/models/fullbody_meshes/hamate.stl +0 -0
  502. diffneusim/models/fullbody_meshes/hat_cervical.stl +0 -0
  503. diffneusim/models/fullbody_meshes/hat_jaw.stl +0 -0
  504. diffneusim/models/fullbody_meshes/hat_skull.stl +0 -0
  505. diffneusim/models/fullbody_meshes/humerus.stl +0 -0
  506. diffneusim/models/fullbody_meshes/l_bofoot.stl +0 -0
  507. diffneusim/models/fullbody_meshes/l_femur.stl +0 -0
  508. diffneusim/models/fullbody_meshes/l_fibula.stl +0 -0
  509. diffneusim/models/fullbody_meshes/l_foot.stl +0 -0
  510. diffneusim/models/fullbody_meshes/l_patella.stl +0 -0
  511. diffneusim/models/fullbody_meshes/l_pelvis.stl +0 -0
  512. diffneusim/models/fullbody_meshes/l_talus.stl +0 -0
  513. diffneusim/models/fullbody_meshes/l_tibia.stl +0 -0
  514. diffneusim/models/fullbody_meshes/lumbar1.stl +0 -0
  515. diffneusim/models/fullbody_meshes/lumbar2.stl +0 -0
  516. diffneusim/models/fullbody_meshes/lumbar3.stl +0 -0
  517. diffneusim/models/fullbody_meshes/lumbar4.stl +0 -0
  518. diffneusim/models/fullbody_meshes/lumbar5.stl +0 -0
  519. diffneusim/models/fullbody_meshes/lunate.stl +0 -0
  520. diffneusim/models/fullbody_meshes/pisiform.stl +0 -0
  521. diffneusim/models/fullbody_meshes/r_bofoot.stl +0 -0
  522. diffneusim/models/fullbody_meshes/r_femur.stl +0 -0
  523. diffneusim/models/fullbody_meshes/r_fibula.stl +0 -0
  524. diffneusim/models/fullbody_meshes/r_foot.stl +0 -0
  525. diffneusim/models/fullbody_meshes/r_patella.stl +0 -0
  526. diffneusim/models/fullbody_meshes/r_pelvis.stl +0 -0
  527. diffneusim/models/fullbody_meshes/r_talus.stl +0 -0
  528. diffneusim/models/fullbody_meshes/r_tibia.stl +0 -0
  529. diffneusim/models/fullbody_meshes/radius.stl +0 -0
  530. diffneusim/models/fullbody_meshes/sacrum.stl +0 -0
  531. diffneusim/models/fullbody_meshes/scaphoid.stl +0 -0
  532. diffneusim/models/fullbody_meshes/scapula.stl +0 -0
  533. diffneusim/models/fullbody_meshes/thoracic10_s.stl +0 -0
  534. diffneusim/models/fullbody_meshes/thoracic11_s.stl +0 -0
  535. diffneusim/models/fullbody_meshes/thoracic12_s.stl +0 -0
  536. diffneusim/models/fullbody_meshes/thoracic1_s.stl +0 -0
  537. diffneusim/models/fullbody_meshes/thoracic2_s.stl +0 -0
  538. diffneusim/models/fullbody_meshes/thoracic3_s.stl +0 -0
  539. diffneusim/models/fullbody_meshes/thoracic4_s.stl +0 -0
  540. diffneusim/models/fullbody_meshes/thoracic5_s.stl +0 -0
  541. diffneusim/models/fullbody_meshes/thoracic6_s.stl +0 -0
  542. diffneusim/models/fullbody_meshes/thoracic7_s.stl +0 -0
  543. diffneusim/models/fullbody_meshes/thoracic8_s.stl +0 -0
  544. diffneusim/models/fullbody_meshes/thoracic9_s.stl +0 -0
  545. diffneusim/models/fullbody_meshes/thorax.stl +0 -0
  546. diffneusim/models/fullbody_meshes/thumbdist.stl +0 -0
  547. diffneusim/models/fullbody_meshes/thumbprox.stl +0 -0
  548. diffneusim/models/fullbody_meshes/trapezium.stl +0 -0
  549. diffneusim/models/fullbody_meshes/trapezoid.stl +0 -0
  550. diffneusim/models/fullbody_meshes/triquetrum.stl +0 -0
  551. diffneusim/models/fullbody_meshes/ulna.stl +0 -0
  552. diffneusim/models/source/myo_fullbody/UPSTREAM.md +91 -0
  553. diffneusim/models/source/myoleg/UPSTREAM.md +52 -0
  554. diffneusim/models/source/unitree_g1/LICENSE.mjlab +202 -0
  555. diffneusim/models/source/unitree_g1/UPSTREAM.md +38 -0
  556. diffneusim/models/source/unitree_g1/assets/head_link.STL +0 -0
  557. diffneusim/models/source/unitree_g1/assets/left_ankle_pitch_link.STL +0 -0
  558. diffneusim/models/source/unitree_g1/assets/left_ankle_roll_link.STL +0 -0
  559. diffneusim/models/source/unitree_g1/assets/left_elbow_link.STL +0 -0
  560. diffneusim/models/source/unitree_g1/assets/left_hip_pitch_link.STL +0 -0
  561. diffneusim/models/source/unitree_g1/assets/left_hip_roll_link.STL +0 -0
  562. diffneusim/models/source/unitree_g1/assets/left_hip_yaw_link.STL +0 -0
  563. diffneusim/models/source/unitree_g1/assets/left_knee_link.STL +0 -0
  564. diffneusim/models/source/unitree_g1/assets/left_rubber_hand.STL +0 -0
  565. diffneusim/models/source/unitree_g1/assets/left_shoulder_pitch_link.STL +0 -0
  566. diffneusim/models/source/unitree_g1/assets/left_shoulder_roll_link.STL +0 -0
  567. diffneusim/models/source/unitree_g1/assets/left_shoulder_yaw_link.STL +0 -0
  568. diffneusim/models/source/unitree_g1/assets/left_wrist_pitch_link.STL +0 -0
  569. diffneusim/models/source/unitree_g1/assets/left_wrist_roll_link.STL +0 -0
  570. diffneusim/models/source/unitree_g1/assets/left_wrist_yaw_link.STL +0 -0
  571. diffneusim/models/source/unitree_g1/assets/logo_link.STL +0 -0
  572. diffneusim/models/source/unitree_g1/assets/pelvis.STL +0 -0
  573. diffneusim/models/source/unitree_g1/assets/pelvis_contour_link.STL +0 -0
  574. diffneusim/models/source/unitree_g1/assets/right_ankle_pitch_link.STL +0 -0
  575. diffneusim/models/source/unitree_g1/assets/right_ankle_roll_link.STL +0 -0
  576. diffneusim/models/source/unitree_g1/assets/right_elbow_link.STL +0 -0
  577. diffneusim/models/source/unitree_g1/assets/right_hip_pitch_link.STL +0 -0
  578. diffneusim/models/source/unitree_g1/assets/right_hip_roll_link.STL +0 -0
  579. diffneusim/models/source/unitree_g1/assets/right_hip_yaw_link.STL +0 -0
  580. diffneusim/models/source/unitree_g1/assets/right_knee_link.STL +0 -0
  581. diffneusim/models/source/unitree_g1/assets/right_rubber_hand.STL +0 -0
  582. diffneusim/models/source/unitree_g1/assets/right_shoulder_pitch_link.STL +0 -0
  583. diffneusim/models/source/unitree_g1/assets/right_shoulder_roll_link.STL +0 -0
  584. diffneusim/models/source/unitree_g1/assets/right_shoulder_yaw_link.STL +0 -0
  585. diffneusim/models/source/unitree_g1/assets/right_wrist_pitch_link.STL +0 -0
  586. diffneusim/models/source/unitree_g1/assets/right_wrist_roll_link.STL +0 -0
  587. diffneusim/models/source/unitree_g1/assets/right_wrist_yaw_link.STL +0 -0
  588. diffneusim/models/source/unitree_g1/assets/torso_link_rev_1_0.STL +0 -0
  589. diffneusim/models/source/unitree_g1/assets/waist_roll_link_rev_1_0.STL +0 -0
  590. diffneusim/models/source/unitree_g1/assets/waist_yaw_link_rev_1_0.STL +0 -0
  591. diffneusim/models/source/unitree_g1/dump_mjlab_reference.py +30 -0
  592. diffneusim/models/source/unitree_g1/g1.xml +308 -0
  593. diffneusim/models/source/unitree_g1/g1_constants.py +298 -0
  594. diffneusim/models/source/unitree_g1/mjlab_compiled_reference.json +857 -0
  595. diffneusim/models/unitree_g1.dnmodel +4393 -0
  596. diffneusim/models/unitree_g1_selfcol.dnmodel +20824 -0
  597. diffneusim/rl/__init__.py +2 -0
  598. diffneusim/rl/dynsyn_layer.py +146 -0
  599. diffneusim/rl/footstep_plan.py +337 -0
  600. diffneusim/rl/g1_bm_env.py +572 -0
  601. diffneusim/rl/g1_bm_eval.py +168 -0
  602. diffneusim/rl/g1_bm_fused.py +275 -0
  603. diffneusim/rl/g1_bm_ppo.py +622 -0
  604. diffneusim/rl/g1_bm_sapo.py +551 -0
  605. diffneusim/rl/g1_ppo.py +395 -0
  606. diffneusim/rl/g1_sapo_soft.py +240 -0
  607. diffneusim/rl/g1_soft_env.py +452 -0
  608. diffneusim/rl/g1_soft_grad.py +145 -0
  609. diffneusim/rl/geyer_curves_torch.py +108 -0
  610. diffneusim/rl/gpu_fullbody_vec_env.py +1241 -0
  611. diffneusim/rl/imitation.py +2027 -0
  612. diffneusim/rl/imitation_reward_v2.py +248 -0
  613. diffneusim/rl/imitation_reward_v3.py +349 -0
  614. diffneusim/rl/latent_task.py +175 -0
  615. diffneusim/rl/llc_reward.py +316 -0
  616. diffneusim/rl/millard_curves_torch.py +154 -0
  617. diffneusim/rl/mirror_symmetry.py +212 -0
  618. diffneusim/rl/model_path.py +35 -0
  619. diffneusim/rl/mvae_recon.py +123 -0
  620. diffneusim/rl/nets_shac.py +599 -0
  621. diffneusim/rl/reset_pool.py +154 -0
  622. diffneusim/rl/sapo_capture.py +873 -0
  623. diffneusim/rl/sapo_vec.py +1051 -0
  624. diffneusim/rl/shac_vec.py +346 -0
  625. diffneusim/rl/state_prior.py +151 -0
  626. diffneusim/rl/step_library.py +105 -0
  627. diffneusim/rl/task_walk_env.py +1793 -0
  628. diffneusim/rl/task_walk_reward.py +3300 -0
  629. diffneusim/run.py +23 -0
  630. diffneusim/run_env.py +46 -0
  631. diffneusim/tasks/__init__.py +147 -0
  632. diffneusim/tasks/legacy_names.py +63 -0
  633. diffneusim/tasks/paths.py +79 -0
  634. diffneusim/tasks/settings.py +202 -0
  635. diffneusim/third_party/instantmimic_947430ee/LICENSE +202 -0
  636. diffneusim/third_party/instantmimic_947430ee/NOTICE +19 -0
  637. diffneusim/third_party/instantmimic_947430ee/README.md +31 -0
  638. diffneusim/third_party/instantmimic_947430ee/instantmimic/envs/unitree_g1/tasks/beyondmimic_tracking/benchmark_protocol.py +106 -0
  639. diffneusim/third_party/instantmimic_947430ee/instantmimic/envs/unitree_g1/tasks/beyondmimic_tracking/metrics.py +214 -0
  640. diffneusim/third_party/instantmimic_947430ee/instantmimic/envs/unitree_g1/tasks/beyondmimic_tracking/reference.py +513 -0
  641. diffneusim/third_party/instantmimic_947430ee/instantmimic/motion/quaternion.py +193 -0
  642. diffneusim/train/__init__.py +0 -0
  643. diffneusim/train/eval_ckpt.py +239 -0
  644. diffneusim/train/eval_mimic.py +133 -0
  645. diffneusim/train/gait_report.py +203 -0
  646. diffneusim/train/gcot_chain.py +51 -0
  647. diffneusim/train/levers.py +135 -0
  648. diffneusim/train/masked_reset.py +314 -0
  649. diffneusim/train/rl_algorithm_suite.py +917 -0
  650. diffneusim/train/train14.py +240 -0
  651. diffneusim/train/train_tw14.py +674 -0
  652. diffneusim/viz/__init__.py +5 -0
  653. diffneusim/viz/__main__.py +41 -0
  654. diffneusim/viz/camera.py +115 -0
  655. diffneusim/viz/dnrec.py +118 -0
  656. diffneusim/viz/dnrec_io.py +686 -0
  657. diffneusim/viz/hud.py +565 -0
  658. diffneusim/viz/meshes.py +458 -0
  659. diffneusim/viz/play.py +237 -0
  660. diffneusim/viz/record.py +74 -0
  661. diffneusim/viz/render.py +1402 -0
  662. diffneusim/viz/renderer.py +268 -0
  663. diffneusim/viz/rl_env_render.py +635 -0
  664. diffneusim/viz/snapshot.py +54 -0
  665. diffneusim/viz/strobe.py +124 -0
  666. diffneusim/viz/to_mp4.py +58 -0
  667. diffneusim/viz/ui.py +481 -0
  668. diffneusim/viz/viewer.py +2086 -0
  669. diffneusim-1.0.0.dist-info/METADATA +226 -0
  670. diffneusim-1.0.0.dist-info/RECORD +682 -0
  671. diffneusim-1.0.0.dist-info/WHEEL +5 -0
  672. diffneusim-1.0.0.dist-info/licenses/LICENSE +201 -0
  673. diffneusim-1.0.0.dist-info/licenses/LICENSES/BSD-3-Clause-NC-ARMS-hand-wrist-4.3.txt +20 -0
  674. diffneusim-1.0.0.dist-info/licenses/LICENSES/BSD-3-Clause-NC-MoBL-ARMS.txt +25 -0
  675. diffneusim-1.0.0.dist-info/licenses/LICENSES/CC-BY-3.0-OpenSim-geometry.txt +25 -0
  676. diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Christophy2012-lumbarspine.txt +10 -0
  677. diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Lai2017-model-high-flex.txt +10 -0
  678. diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Lee2015-hand_muscle.txt +11 -0
  679. diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Rajagopal2016-full_body.txt +11 -0
  680. diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Uhlrich2022-fbmodpassivecal.txt +10 -0
  681. diffneusim-1.0.0.dist-info/licenses/NOTICE +274 -0
  682. diffneusim-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,834 @@
1
+ """Runtime monitors for `.dnmodel` rollouts.
2
+
3
+ The helpers here are intentionally model-data driven. They do not pick a
4
+ model-specific extension and they do not affect gradients; training code can use
5
+ them to log contact penetration and joint-limit penetration from the same
6
+ `.dnmodel` that drives the engine.
7
+ """
8
+ from __future__ import annotations
9
+
10
+ import json
11
+ import os
12
+ import pathlib
13
+ import re
14
+
15
+ import torch
16
+
17
+
18
+ def _load_jsonc(path: str | pathlib.Path) -> dict:
19
+ text = re.sub(r"^\s*//.*$", "", pathlib.Path(path).read_text(), flags=re.MULTILINE)
20
+ return json.loads(text)
21
+
22
+
23
+ def _quat_mul(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor:
24
+ aw, ax, ay, az = a[0], a[1], a[2], a[3]
25
+ bw, bx, by, bz = b[0], b[1], b[2], b[3]
26
+ return torch.stack(
27
+ (
28
+ aw * bw - ax * bx - ay * by - az * bz,
29
+ aw * bx + ax * bw + ay * bz - az * by,
30
+ aw * by - ax * bz + ay * bw + az * bx,
31
+ aw * bz + ax * by - ay * bx + az * bw,
32
+ ),
33
+ dim=0,
34
+ )
35
+
36
+
37
+ def _quat_normalize(q: torch.Tensor) -> torch.Tensor:
38
+ return q / q.norm(dim=0, keepdim=True).clamp_min(1e-12)
39
+
40
+
41
+ def _quat_axis_angle(axis: torch.Tensor, theta: torch.Tensor) -> torch.Tensor:
42
+ axis = axis[:, None]
43
+ half = 0.5 * theta[None, :]
44
+ return torch.cat((torch.cos(half), axis * torch.sin(half)), dim=0)
45
+
46
+
47
+ def _quat_rotate(q: torch.Tensor, v: torch.Tensor) -> torch.Tensor:
48
+ w, x, y, z = q[0], q[1], q[2], q[3]
49
+ vx, vy, vz = v[0], v[1], v[2]
50
+ return torch.stack(
51
+ (
52
+ (1 - 2 * (y * y + z * z)) * vx + 2 * (x * y - z * w) * vy + 2 * (x * z + y * w) * vz,
53
+ 2 * (x * y + z * w) * vx + (1 - 2 * (x * x + z * z)) * vy + 2 * (y * z - x * w) * vz,
54
+ 2 * (x * z - y * w) * vx + 2 * (y * z + x * w) * vy + (1 - 2 * (x * x + y * y)) * vz,
55
+ ),
56
+ dim=0,
57
+ )
58
+
59
+
60
+ # --- contracted quaternion algebra (same results, ~10x fewer dispatches) -------------------------------
61
+ # _quat_mul / _quat_rotate spell the products out elementwise: ~33 and ~28 aten dispatches each. Both are
62
+ # BILINEAR, so they can be written as one contraction against a constant tensor. In the reduced FK almost
63
+ # every product has a CONSTANT operand (a pre-composed welded chain, or a joint axis), which folds the
64
+ # contraction down to a single (4,4) @ (4,n) matmul. See body_poses_subset; the elementwise forms above
65
+ # stay as the reference oracle that python/tests/test_reduced_fk_parity.py checks the fast path against.
66
+
67
+ # T[i,j,k] = coefficient of a_j*b_k in (a (x) b)_i
68
+ _QMUL_T = torch.zeros(4, 4, 4, dtype=torch.float64)
69
+ for _i, _terms in enumerate((
70
+ ((1, 0, 0), (-1, 1, 1), (-1, 2, 2), (-1, 3, 3)),
71
+ ((1, 0, 1), (1, 1, 0), (1, 2, 3), (-1, 3, 2)),
72
+ ((1, 0, 2), (-1, 1, 3), (1, 2, 0), (1, 3, 1)),
73
+ ((1, 0, 3), (1, 1, 2), (-1, 2, 1), (1, 3, 0)))):
74
+ for _c, _j, _k in _terms:
75
+ _QMUL_T[_i, _j, _k] = _c
76
+
77
+ # R(q)[i][j] as quadratic monomials in q=(w,x,y,z): list of (coef, a, b) meaning coef*q_a*q_b (unit q)
78
+ _ROT_MONOMIALS = (
79
+ (((1, 0, 0), (1, 1, 1), (-1, 2, 2), (-1, 3, 3)), ((2, 1, 2), (-2, 0, 3)), ((2, 1, 3), (2, 0, 2))),
80
+ (((2, 1, 2), (2, 0, 3)), ((1, 0, 0), (-1, 1, 1), (1, 2, 2), (-1, 3, 3)), ((2, 2, 3), (-2, 0, 1))),
81
+ (((2, 1, 3), (-2, 0, 2)), ((2, 2, 3), (2, 0, 1)), ((1, 0, 0), (-1, 1, 1), (-1, 2, 2), (1, 3, 3))),
82
+ )
83
+
84
+
85
+ def _qmul_right_matrix(b: torch.Tensor) -> torch.Tensor:
86
+ """(4,4) matrix M with M @ a == a (x) b, for a CONSTANT right operand b."""
87
+ return torch.einsum("ijk,k->ij", _QMUL_T.to(device=b.device, dtype=b.dtype), b)
88
+
89
+
90
+ def _qrot_form(c: torch.Tensor) -> torch.Tensor:
91
+ """(3,4,4) symmetric forms A with (A q) . q == R(q) @ c, for a CONSTANT vector c and UNIT q."""
92
+ A = torch.zeros(3, 4, 4, dtype=c.dtype, device=c.device)
93
+ for i in range(3):
94
+ for j in range(3):
95
+ for coef, a, b in _ROT_MONOMIALS[i][j]:
96
+ if a == b:
97
+ A[i, a, a] += coef * c[j]
98
+ else:
99
+ A[i, a, b] += 0.5 * coef * c[j]
100
+ A[i, b, a] += 0.5 * coef * c[j]
101
+ return A
102
+
103
+
104
+ # DN_FK_POINTWISE=1 (opt-in): inside a torch.compile trace the FK's constant contractions below (and the hinge spin)
105
+ # are spelled as broadcast products summed over the contracted 4-axis, which Inductor unrolls into the surrounding fused
106
+ # kernels; as matmuls each is a cuBLAS call of its own (~180 forward and ~180 backward per E0 control step). Eager calls
107
+ # keep the matmul, one dispatch. Equal to roundoff against the compiled matmul form.
108
+ _FK_POINTWISE = os.environ.get("DN_FK_POINTWISE", "0")
109
+ assert _FK_POINTWISE in ("0", "1"), f"DN_FK_POINTWISE={_FK_POINTWISE!r} must be exactly '0' or '1'"
110
+ _FK_POINTWISE = _FK_POINTWISE == "1"
111
+
112
+
113
+ def _cmm(M: torch.Tensor, a: torch.Tensor) -> torch.Tensor:
114
+ """M @ a for a small constant M over the leading 4-axis of a (see _FK_POINTWISE)."""
115
+ if _FK_POINTWISE and torch.compiler.is_compiling():
116
+ return (M.unsqueeze(-1) * a.unsqueeze(-3)).sum(-2)
117
+ return torch.matmul(M, a)
118
+
119
+
120
+ def _qmul_const(M: torch.Tensor, a: torch.Tensor) -> torch.Tensor:
121
+ """a (x) b for a constant b, via its precomputed right-multiply matrix M. One dispatch."""
122
+ return _cmm(M, a)
123
+
124
+
125
+ def _qmul_fast(a: torch.Tensor, b: torch.Tensor, T: torch.Tensor) -> torch.Tensor:
126
+ """General a (x) b as one contraction against _QMUL_T (3 dispatches instead of ~33)."""
127
+ return (_cmm(T, b) * a.unsqueeze(0)).sum(1)
128
+
129
+
130
+ def _qrot_const(A: torch.Tensor, q: torch.Tensor) -> torch.Tensor:
131
+ """R(q) @ c for a constant c via its precomputed form A (3 dispatches instead of ~28)."""
132
+ return (_cmm(A, q) * q.unsqueeze(0)).sum(1)
133
+
134
+
135
+ def _quat_rotate_batched(q: torch.Tensor, v: torch.Tensor) -> torch.Tensor:
136
+ """_quat_rotate over a leading BODY axis: q `(F,4,n)`, v `(F,3,1|n)` -> `(F,3,n)`. Same algebra as
137
+ _quat_rotate but one dispatch per term instead of F of them -- used by the composite-COM sum."""
138
+ w, x, y, z = q.unbind(1)
139
+ vx, vy, vz = v.unbind(1)
140
+ return torch.stack(
141
+ (
142
+ (1 - 2 * (y * y + z * z)) * vx + 2 * (x * y - z * w) * vy + 2 * (x * z + y * w) * vz,
143
+ 2 * (x * y + z * w) * vx + (1 - 2 * (x * x + z * z)) * vy + 2 * (y * z - x * w) * vz,
144
+ 2 * (x * z - y * w) * vx + 2 * (y * z + x * w) * vy + (1 - 2 * (x * x + y * y)) * vz,
145
+ ),
146
+ dim=1,
147
+ )
148
+
149
+
150
+ def _zero_vec(n_env: int, dtype: torch.dtype, device: torch.device) -> torch.Tensor:
151
+ return torch.zeros(3, n_env, dtype=dtype, device=device)
152
+
153
+
154
+ def _identity_quat(n_env: int, dtype: torch.dtype, device: torch.device) -> torch.Tensor:
155
+ q = torch.zeros(4, n_env, dtype=dtype, device=device)
156
+ q[0] = 1.0
157
+ return q
158
+
159
+
160
+ class DnModelMonitor:
161
+ """Batch FK + scalar rollout diagnostics for a `.dnmodel`."""
162
+
163
+ def __init__(self, model_path: str | pathlib.Path, device: str | torch.device = "cuda"):
164
+ self.model_path = str(model_path)
165
+ self.jm = _load_jsonc(model_path)
166
+ self.device = torch.device(device)
167
+ self.bodies = self.jm["bodies"]
168
+ self.contact_geoms = self.jm.get("contact", {}).get("geoms", [])
169
+ # Ground-plane normal (optional "contact.normal"; default flat +z). Kept in sync with the
170
+ # engine: core/io/dnmodel.h reads the same field into ContactParams.gnrm, so a sloped model
171
+ # measures the same gap here as the kernel does.
172
+ _gn = self.jm.get("contact", {}).get("normal", [0.0, 0.0, 1.0])
173
+ _gn = [float(x) for x in _gn]
174
+ _ln = sum(x * x for x in _gn) ** 0.5
175
+ assert _ln > 1e-9 and _gn[2] > 0.0, f"contact.normal must point up out of the ground: {_gn}"
176
+ self.ground_normal = [x / _ln for x in _gn]
177
+
178
+ self.parents = [int(b["parent"]) for b in self.bodies]
179
+ self.body_pos = [
180
+ torch.tensor(b.get("pos", [0.0, 0.0, 0.0]), dtype=torch.float32, device=self.device)
181
+ for b in self.bodies
182
+ ]
183
+ self.body_quat = [
184
+ torch.tensor(b.get("quat", [1.0, 0.0, 0.0, 0.0]), dtype=torch.float32, device=self.device)
185
+ for b in self.bodies
186
+ ]
187
+ self.contact_body = [int(g["body"]) for g in self.contact_geoms]
188
+ self.contact_center = [
189
+ torch.tensor(g["center"], dtype=torch.float32, device=self.device)
190
+ for g in self.contact_geoms
191
+ ]
192
+ self.contact_radius = [float(g["radius"]) for g in self.contact_geoms]
193
+ # Cache joint axes as GPU tensors ONCE. body_poses() previously rebuilt them every call via
194
+ # torch.tensor(axis, device=) -- a per-step host->device copy (hundreds/step at full body) that
195
+ # both costs throughput AND makes the step un-capturable by CUDA graphs (HtoD is illegal mid-capture).
196
+ self.body_axis = [] # per body: hinge/slide axis tensor, else None
197
+ self.joint_axes = [] # per body: list of composite-prim axis tensors, else None
198
+ for _b in self.bodies:
199
+ if "joints" in _b:
200
+ self.joint_axes.append([torch.tensor(_p["axis"], dtype=torch.float32, device=self.device)
201
+ for _p in _b["joints"]])
202
+ self.body_axis.append(None)
203
+ elif _b.get("joint") in ("hinge", "revolute", "slide", "prismatic"):
204
+ self.body_axis.append(torch.tensor(_b["axis"], dtype=torch.float32, device=self.device))
205
+ self.joint_axes.append(None)
206
+ else:
207
+ self.body_axis.append(None)
208
+ self.joint_axes.append(None)
209
+ self.limit_specs = []
210
+ for body_i, body in enumerate(self.bodies):
211
+ qa = int(body["qadr"])
212
+ body_name = body.get("name") or f"body{body_i}"
213
+ if "joints" in body:
214
+ for k, prim in enumerate(body["joints"]):
215
+ if not prim.get("limited", False):
216
+ continue
217
+ lo, hi = prim["range"]
218
+ name = prim.get("name") or f"{body_name}.joint{k}"
219
+ self.limit_specs.append(
220
+ {"qadr": qa + k, "lo": float(lo), "hi": float(hi), "label": name}
221
+ )
222
+ continue
223
+ if body.get("joint") not in ("hinge", "revolute", "slide", "prismatic"):
224
+ continue
225
+ if not body.get("limited", False):
226
+ continue
227
+ lo, hi = body["range"]
228
+ name = body.get("name") or f"{body_name}.{body.get('joint')}"
229
+ self.limit_specs.append({"qadr": qa, "lo": float(lo), "hi": float(hi), "label": name})
230
+ self._build_reduced_fk()
231
+ # FUSED reduced FK (opt-in, DN_FK_COMPILE=1): body_poses_subset traced once per call signature by
232
+ # torch.compile, so its forward AND its backward run as a handful of generated kernels instead of ~900
233
+ # autograd nodes. Measured 2026-10-01 (RTX 3080 Ti laptop GPU, taskwalk SAPO): one FK+COM call = 909 nodes, ~90% of the
234
+ # backward nodes the taskwalk reward adds over the SHAC reward -- and on the 4090 the step is bound by
235
+ # dispatching them. Same maths, reassociated by the compiler: equal to roundoff, not bit-identical, so
236
+ # it is a flag and every cell that turns it on reads against a same-flag control.
237
+ _fc = os.environ.get("DN_FK_COMPILE", "0")
238
+ assert _fc in ("0", "1"), f"DN_FK_COMPILE={_fc!r} must be exactly '0' or '1'"
239
+ self._fk_compile = _fc == "1"
240
+ self._fk_compiled = {} # (bodies, need_com, dtype, n_env, device) -> compiled fn
241
+ # FUSED twist recursion (opt-in, DN_TWIST_COMPILE=1): body_twists_from_poses traced once per call signature,
242
+ # the same contract as the reduced FK above. On the MuscleMimic reward the twists of the 17 sites' chains were the
243
+ # largest source of kernel launches left (tools/dispatch_attribution.py, 2026-10-27: the generic _quat_rotate
244
+ # alone ~7k of ~21k launches per control step, backward included). Equal to roundoff (tools/twist_compile_gate.py).
245
+ _tc = os.environ.get("DN_TWIST_COMPILE", "0")
246
+ assert _tc in ("0", "1"), f"DN_TWIST_COMPILE={_tc!r} must be exactly '0' or '1'"
247
+ self._tw_compile = _tc == "1"
248
+ self._tw_compiled = {} # (bodies, frames, dtype, n_env, device) -> compiled fn
249
+
250
+ def body_poses(self, q: torch.Tensor) -> tuple[list[torch.Tensor], list[torch.Tensor]]:
251
+ """Return world body positions/quaternions for batched q `[nq, n_env]`."""
252
+ assert q.dim() == 2, q.shape
253
+ n_env = q.shape[1]
254
+ dtype, device = q.dtype, q.device
255
+ positions: list[torch.Tensor] = []
256
+ quats: list[torch.Tensor] = []
257
+ for i, body in enumerate(self.bodies):
258
+ parent = self.parents[i]
259
+ if parent < 0:
260
+ parent_p = _zero_vec(n_env, dtype, device)
261
+ parent_q = _identity_quat(n_env, dtype, device)
262
+ else:
263
+ parent_p = positions[parent]
264
+ parent_q = quats[parent]
265
+ rel_pos = self.body_pos[i].to(dtype=dtype, device=device)[:, None].expand(3, n_env)
266
+ rel_quat = self.body_quat[i].to(dtype=dtype, device=device)[:, None].expand(4, n_env)
267
+ base_p = parent_p + _quat_rotate(parent_q, rel_pos)
268
+ base_q = _quat_normalize(_quat_mul(parent_q, rel_quat))
269
+ p_i, q_i = self._apply_joint(i, body, base_p, base_q, q, n_env, dtype, device)
270
+ positions.append(p_i)
271
+ quats.append(q_i)
272
+ return positions, quats
273
+
274
+ def _apply_joint(self, i, body, base_p, base_q, q, n_env, dtype, device):
275
+ """Compose body i's own joint transform onto its attach frame (base_p, base_q).
276
+
277
+ Extracted verbatim from body_poses so the reduced FK (body_poses_subset) shares ONE
278
+ implementation of the joint semantics -- same expressions, same op order, so the full and the
279
+ reduced path agree to float roundoff on every joint type."""
280
+ qa = int(body["qadr"])
281
+ if "joints" in body:
282
+ rel_p = _zero_vec(n_env, dtype, device)
283
+ rel_q = _identity_quat(n_env, dtype, device)
284
+ for k, prim in enumerate(body["joints"]):
285
+ axis = self.joint_axes[i][k].to(dtype=dtype, device=device)
286
+ typ = prim["type"]
287
+ if typ in ("hinge", "revolute"):
288
+ rel_q = _quat_normalize(_quat_mul(rel_q, _quat_axis_angle(axis, q[qa + k])))
289
+ elif typ in ("slide", "prismatic"):
290
+ rel_p = rel_p + _quat_rotate(rel_q, axis[:, None] * q[qa + k][None, :])
291
+ else:
292
+ raise AssertionError(typ)
293
+ return base_p + _quat_rotate(base_q, rel_p), _quat_normalize(_quat_mul(base_q, rel_q))
294
+ joint = body["joint"]
295
+ coupled = body.get("coupled")
296
+ if coupled is not None: # driven ("mimic") joint: angle = poly(q[master_qadr]); mirrors the engine FK
297
+ mq = int(coupled["master_qadr"]); c = coupled["coef"]
298
+ qm = q[mq] # (n_env,) master coord
299
+ theta = c[0] + qm * (c[1] + qm * (c[2] + qm * (c[3] + qm * c[4]))) # Horner: Σ c_k q_m^k
300
+ axis = self.body_axis[i].to(dtype=dtype, device=device)
301
+ if joint in ("hinge", "revolute"):
302
+ return base_p, _quat_normalize(_quat_mul(base_q, _quat_axis_angle(axis, theta)))
303
+ assert joint in ("slide", "prismatic"), joint
304
+ return base_p + _quat_rotate(base_q, axis[:, None] * theta[None, :]), base_q
305
+ if joint == "free":
306
+ # compose the free joint (pos, quat) with the body attach frame (base_p/base_q =
307
+ # parent o pos_tree/quat_tree), matching the engine chain-FK. Using the raw free
308
+ # pos/quat drops quat_tree -> a non-identity root (e.g. myoLeg26's +90deg-about-x
309
+ # y-up->z-up map) is placed wrong. Mirrors viz.dnrec_io.fk_poses.
310
+ return (base_p + _quat_rotate(base_q, q[qa : qa + 3]),
311
+ _quat_normalize(_quat_mul(base_q, q[qa + 3 : qa + 7])))
312
+ if joint == "ball":
313
+ return base_p, _quat_normalize(_quat_mul(base_q, q[qa : qa + 4]))
314
+ if joint in ("hinge", "revolute"):
315
+ axis = self.body_axis[i].to(dtype=dtype, device=device)
316
+ return base_p, _quat_normalize(_quat_mul(base_q, _quat_axis_angle(axis, q[qa])))
317
+ if joint in ("slide", "prismatic"):
318
+ axis = self.body_axis[i].to(dtype=dtype, device=device)
319
+ return base_p + _quat_rotate(base_q, axis[:, None] * q[qa][None, :]), base_q
320
+ assert joint == "fixed", joint
321
+ return base_p, base_q
322
+
323
+ # ---------------------------------------------------------------------------------------------
324
+ # Reduced FK: only the frames that actually move, + welded subtrees folded into composite bodies.
325
+ #
326
+ # body_poses() walks EVERY body in a Python loop; on the full-body models most bodies are WELDED
327
+ # (`fixed`, 0 dof) so their pose is a CONSTANT transform of the nearest moving ancestor and their
328
+ # mass is a CONSTANT contribution to that ancestor's composite inertia. Recomputing them per control
329
+ # step is pure launch overhead: measured (2026-07-27, live SAPO fullbody run) body_poses = 18.3k
330
+ # aten dispatches fwd / 28.7k bwd and the imitation _com another 10.5k -- together ~90% of training
331
+ # wall-clock, with the GPU idle 64% of the time. armless_ball has 27 moving frames out of 156 bodies.
332
+ #
333
+ # The reduced path pre-composes the welded chains ONCE (in f64, at build time) and then evaluates
334
+ # only the moving frames plus whatever fixed bodies a caller explicitly asks for. The COM is the
335
+ # exact same sum, regrouped by composite body -- not an approximation (verified <1e-7 in f32).
336
+ # ---------------------------------------------------------------------------------------------
337
+ @staticmethod
338
+ def _body_is_moving(body) -> bool:
339
+ return ("coupled" in body) or ("joints" in body) or body.get("joint") not in ("fixed", None)
340
+
341
+ def _build_reduced_fk(self):
342
+ nb = len(self.bodies)
343
+ moving = [i for i, b in enumerate(self.bodies) if self._body_is_moving(b)]
344
+ # nearest MOVING ancestor of every body (-1 = welded straight to the world)
345
+ anc = [-1] * nb
346
+ for i in range(nb):
347
+ j = self.parents[i]
348
+ while j >= 0 and not self._body_is_moving(self.bodies[j]):
349
+ j = self.parents[j]
350
+ anc[i] = j
351
+ # constant transform anc(i)-frame -> body i ATTACH frame: compose (pos, quat) of every body on
352
+ # the path (anc(i), i], f64 for accuracy, cast at use.
353
+ const_p, const_q = [None] * nb, [None] * nb
354
+ for i in range(nb):
355
+ chain = []
356
+ j = i
357
+ while j != anc[i]:
358
+ chain.append(j)
359
+ j = self.parents[j]
360
+ p = torch.zeros(3, dtype=torch.float64, device=self.device)
361
+ qq = torch.tensor([1.0, 0.0, 0.0, 0.0], dtype=torch.float64, device=self.device)
362
+ for j in reversed(chain):
363
+ bp = self.body_pos[j].to(torch.float64)
364
+ bq = self.body_quat[j].to(torch.float64)
365
+ p = p + _quat_rotate(qq[:, None], bp[:, None]).squeeze(1)
366
+ qq = _quat_normalize(_quat_mul(qq[:, None], bq[:, None]).squeeze(1))
367
+ const_p[i], const_q[i] = p, qq
368
+ self._fk_moving = moving # topological (dnmodel body order is parent-first)
369
+ self._fk_anc = anc
370
+ self._fk_const_p, self._fk_const_q = const_p, const_q
371
+ # composite mass + COM offset per moving frame (welded descendants folded in). Bodies welded to
372
+ # the world (anc == -1) contribute a CONSTANT world moment.
373
+ mass = [float(b.get("mass", 0.0)) for b in self.bodies]
374
+ com = [torch.tensor(b.get("com", [0.0, 0.0, 0.0]), dtype=torch.float64, device=self.device)
375
+ for b in self.bodies]
376
+ acc_m = {f: 0.0 for f in moving}
377
+ acc_c = {f: torch.zeros(3, dtype=torch.float64, device=self.device) for f in moving}
378
+ world_moment = torch.zeros(3, dtype=torch.float64, device=self.device)
379
+ for i in range(nb):
380
+ if mass[i] <= 0.0:
381
+ continue
382
+ # HOST frame = the frame body i is rigidly fixed to = itself when it moves, else its nearest
383
+ # moving ancestor. const_p/const_q map anc(i)'s POSE frame to i's ATTACH frame, which for a
384
+ # WELDED body IS its pose frame; a MOVING body sits at its own frame (its joint transform is
385
+ # applied at FK time), so its offset is the identity.
386
+ if self._body_is_moving(self.bodies[i]):
387
+ host, c_in_f = i, com[i]
388
+ else:
389
+ host = anc[i]
390
+ c_in_f = const_p[i] + _quat_rotate(const_q[i][:, None], com[i][:, None]).squeeze(1)
391
+ if host < 0:
392
+ world_moment = world_moment + mass[i] * c_in_f
393
+ continue
394
+ acc_m[host] += mass[i]
395
+ acc_c[host] = acc_c[host] + mass[i] * c_in_f
396
+ self._com_terms = [(f, acc_m[f], acc_c[f] / acc_m[f]) for f in moving if acc_m[f] > 0.0]
397
+ self._com_world_moment = world_moment
398
+ # Decided ONCE here: testing the tensor per call was a host sync, and it would break a compiled trace.
399
+ self._com_has_world = bool(float(world_moment.abs().sum()) > 0.0)
400
+ self._mass_tot = sum(mass)
401
+ self._fk_cache = {} # (dtype, n_env) -> broadcast constants, see _fk_consts
402
+
403
+ def _fk_consts(self, dtype, n_env):
404
+ """Per-(dtype, n_env) broadcast views of the FK constants. Built once: casting + unsqueeze +
405
+ expand on every call is ~4 extra dispatches per frame, which is exactly the overhead this path
406
+ exists to remove (n_env is fixed for the lifetime of a training run, so the cache always hits)."""
407
+ key = (dtype, n_env)
408
+ c = self._fk_cache.get(key)
409
+ if c is None:
410
+ cp = [p.to(dtype=dtype)[:, None].expand(3, n_env) for p in self._fk_const_p]
411
+ cq = [p.to(dtype=dtype)[:, None].expand(4, n_env) for p in self._fk_const_q]
412
+ com_m = torch.tensor([t[1] for t in self._com_terms], dtype=dtype, device=self.device)
413
+ com_c = (torch.stack([t[2] for t in self._com_terms]).to(dtype=dtype)[:, :, None]
414
+ if self._com_terms else None) # (F,3,1), broadcasts over n_env
415
+ com_w = self._com_world_moment.to(dtype=dtype)[:, None]
416
+ # contracted forms of the per-body CONSTANTS (welded-chain quat/offset + joint axes)
417
+ qm = [_qmul_right_matrix(p.to(dtype=dtype)) for p in self._fk_const_q]
418
+ qa = [_qrot_form(p.to(dtype=dtype)) for p in self._fk_const_p]
419
+ ax = []
420
+ for i, b in enumerate(self.bodies):
421
+ if self.joint_axes[i] is not None:
422
+ ax.append([(_qmul_right_matrix(torch.cat([torch.zeros(1, dtype=dtype, device=self.device),
423
+ a.to(dtype=dtype)])),
424
+ _qrot_form(a.to(dtype=dtype))) for a in self.joint_axes[i]])
425
+ elif self.body_axis[i] is not None:
426
+ a = self.body_axis[i].to(dtype=dtype)
427
+ ax.append((_qmul_right_matrix(torch.cat([torch.zeros(1, dtype=dtype, device=self.device), a])),
428
+ _qrot_form(a)))
429
+ else:
430
+ ax.append(None)
431
+ c = (cp, cq, com_m[:, None, None], com_c, com_w, qm, qa, ax,
432
+ _QMUL_T.to(device=self.device, dtype=dtype))
433
+ # _QMUL_T is a module-level CPU constant: every contraction helper must place it on the
434
+ # model's device or the first CUDA call dies inside einsum (a CPU-only test cannot see this).
435
+ assert all(t.device.type == self.device.type for t in qm), (qm[0].device, self.device)
436
+ self._fk_cache[key] = c
437
+ return c
438
+
439
+ def _apply_joint_fast(self, i, body, base_p, base_q, q, K):
440
+ """_apply_joint with the constant-folded quaternion contractions (see the module header). Same
441
+ function, ~4x fewer dispatches; test_reduced_fk_parity checks it against _apply_joint."""
442
+ _, _, _, _, _, _, _, ax, T = K
443
+ qa_i = int(body["qadr"])
444
+
445
+ def _spin(qq, axM, theta): # qq (x) (cos(th/2), sin(th/2)*axis), axis folded into axM
446
+ half = 0.5 * theta
447
+ return torch.cos(half).unsqueeze(0) * qq + torch.sin(half).unsqueeze(0) * _cmm(axM, qq)
448
+
449
+ if "joints" in body:
450
+ rel_p = None
451
+ rel_q = None
452
+ for k, prim in enumerate(body["joints"]):
453
+ axM, axA = ax[i][k]
454
+ typ = prim["type"]
455
+ if typ in ("hinge", "revolute"):
456
+ if rel_q is None: # identity (x) spin == spin about the axis alone
457
+ half = 0.5 * q[qa_i + k]
458
+ rel_q = torch.cat([torch.cos(half).unsqueeze(0),
459
+ self.joint_axes[i][k].to(dtype=q.dtype)[:, None]
460
+ * torch.sin(half).unsqueeze(0)], 0)
461
+ else:
462
+ rel_q = _quat_normalize(_spin(rel_q, axM, q[qa_i + k]))
463
+ elif typ in ("slide", "prismatic"):
464
+ step = (self.joint_axes[i][k].to(dtype=q.dtype)[:, None] * q[qa_i + k].unsqueeze(0)
465
+ if rel_q is None else _qrot_const(axA, rel_q) * q[qa_i + k].unsqueeze(0))
466
+ rel_p = step if rel_p is None else rel_p + step
467
+ else:
468
+ raise AssertionError(typ)
469
+ p = base_p if rel_p is None else base_p + _quat_rotate(base_q, rel_p)
470
+ qq = base_q if rel_q is None else _quat_normalize(_qmul_fast(base_q, rel_q, T))
471
+ return p, qq
472
+ joint = body["joint"]
473
+ coupled = body.get("coupled")
474
+ if coupled is not None:
475
+ mq = int(coupled["master_qadr"]); c = coupled["coef"]
476
+ qm_ = q[mq]
477
+ theta = c[0] + qm_ * (c[1] + qm_ * (c[2] + qm_ * (c[3] + qm_ * c[4])))
478
+ axM, axA = ax[i]
479
+ if joint in ("hinge", "revolute"):
480
+ return base_p, _quat_normalize(_spin(base_q, axM, theta))
481
+ assert joint in ("slide", "prismatic"), joint
482
+ return base_p + _qrot_const(axA, base_q) * theta.unsqueeze(0), base_q
483
+ if joint == "free":
484
+ return (base_p + _quat_rotate(base_q, q[qa_i:qa_i + 3]),
485
+ _quat_normalize(_qmul_fast(base_q, q[qa_i + 3:qa_i + 7], T)))
486
+ if joint == "ball":
487
+ return base_p, _quat_normalize(_qmul_fast(base_q, q[qa_i:qa_i + 4], T))
488
+ if joint in ("hinge", "revolute"):
489
+ return base_p, _quat_normalize(_spin(base_q, ax[i][0], q[qa_i]))
490
+ if joint in ("slide", "prismatic"):
491
+ return base_p + _qrot_const(ax[i][1], base_q) * q[qa_i].unsqueeze(0), base_q
492
+ assert joint == "fixed", joint
493
+ return base_p, base_q
494
+
495
+ def body_poses_subset(self, q: torch.Tensor, bodies=(), need_com: bool = False):
496
+ """Reduced FK. Returns `(pos, quat, com)` where pos/quat are DICTS keyed by body index -- the
497
+ requested `bodies` are always present (plus every moving frame that had to be evaluated) -- and
498
+ `com` is the whole-body centre of mass `(3, n_env)` or None when `need_com` is False.
499
+
500
+ Mathematically identical to body_poses()/the per-body COM sum; only the grouping differs, so
501
+ results match to float roundoff (gated by python/tests/test_reduced_fk_parity.py). With
502
+ DN_FK_COMPILE=1 the same function runs compiled (see __init__; gated by
503
+ tools/fk_compile_gate.py)."""
504
+ # Compiled ONLY where it pays: a call whose output enters the backward. The op exists to cut autograd
505
+ # nodes; a no-grad call (reset grounding, calibration, eval) has none, and the reset path calls with a
506
+ # different batch size every time, which recompiled until dynamo's recompile limit killed the run
507
+ # (2026-10-01, fb_..._e2000_fk_s1 at ep1). One training signature -> one compile.
508
+ if not (self._fk_compile and torch.is_grad_enabled() and q.requires_grad):
509
+ return self._body_poses_subset_eager(q, bodies, need_com)
510
+ assert q.dim() == 2, q.shape
511
+ want = tuple(sorted({int(b) for b in bodies}))
512
+ key = (want, bool(need_com), q.dtype, int(q.shape[1]), q.device.type)
513
+ fn = self._fk_compiled.get(key)
514
+ if fn is None:
515
+ self._fk_consts(q.dtype, int(q.shape[1])) # build the constant cache EAGERLY: the trace reads it
516
+ fn = torch.compile(lambda qq: self._body_poses_subset_eager(qq, want, key[1]),
517
+ fullgraph=True, dynamic=False)
518
+ self._fk_compiled[key] = fn
519
+ return fn(q)
520
+
521
+ def _body_poses_subset_eager(self, q: torch.Tensor, bodies=(), need_com: bool = False):
522
+ assert q.dim() == 2, q.shape
523
+ n_env = q.shape[1]
524
+ dtype, device = q.dtype, q.device
525
+ want = {int(b) for b in bodies}
526
+ # which moving frames must be evaluated: every moving ancestor chain of a requested body, plus
527
+ # ALL of them when the COM is needed (the composite sum spans the whole body).
528
+ need_moving = set(self._fk_moving) if need_com else set()
529
+ for b in want:
530
+ j = b if self._body_is_moving(self.bodies[b]) else self._fk_anc[b]
531
+ while j >= 0:
532
+ if j in need_moving:
533
+ break
534
+ need_moving.add(j)
535
+ j = self._fk_anc[j]
536
+ K = self._fk_consts(dtype, n_env)
537
+ cp_all, cq_all, com_m, com_c, com_w, qm_all, qa_all = K[0], K[1], K[2], K[3], K[4], K[5], K[6]
538
+ pos: dict[int, torch.Tensor] = {}
539
+ quat: dict[int, torch.Tensor] = {}
540
+ for f in self._fk_moving: # parent-first order
541
+ if f not in need_moving:
542
+ continue
543
+ a = self._fk_anc[f]
544
+ if a < 0: # welded straight to the world: the constant IS the frame
545
+ base_p, base_q = cp_all[f], cq_all[f]
546
+ else:
547
+ base_p = pos[a] + _qrot_const(qa_all[f], quat[a])
548
+ base_q = _quat_normalize(_qmul_const(qm_all[f], quat[a]))
549
+ pos[f], quat[f] = self._apply_joint_fast(f, self.bodies[f], base_p, base_q, q, K)
550
+ for b in want: # requested WELDED bodies: one constant compose
551
+ if b in pos:
552
+ continue
553
+ a = self._fk_anc[b]
554
+ if a < 0:
555
+ pos[b], quat[b] = cp_all[b], cq_all[b]
556
+ else:
557
+ pos[b] = pos[a] + _qrot_const(qa_all[b], quat[a])
558
+ quat[b] = _quat_normalize(_qmul_const(qm_all[b], quat[a]))
559
+ com = None
560
+ if need_com:
561
+ frames = [t[0] for t in self._com_terms]
562
+ P = torch.stack([pos[f] for f in frames], 0) # (F,3,n)
563
+ Q = torch.stack([quat[f] for f in frames], 0) # (F,4,n)
564
+ com = ((P + _quat_rotate_batched(Q, com_c)) * com_m).sum(0) # mass-weighted, batched over F
565
+ if self._com_has_world:
566
+ com = com + com_w
567
+ com = com / self._mass_tot
568
+ return pos, quat, com
569
+
570
+ # ------------------------------------------------------------------ heading (yaw) frame
571
+ # A locomotion policy should not care WHICH COMPASS DIRECTION it walks in. Measured on the v3 reward,
572
+ # 51% of the error signal was expressed in WORLD axes -- the end-effector offsets, the COM offset, the
573
+ # end-effector velocities and every FK quaternion -- so the reward demanded the clip's absolute heading,
574
+ # and the observation carried the absolute root quaternion on top of that. Both are removed by working
575
+ # in the root's own HEADING frame: the rotation about world z that the body currently faces.
576
+ #
577
+ # Yaw is taken as the ZYX-euler heading, atan2(2(wz+xy), 1-2(y^2+z^2)). That is singular at pitch = +-90
578
+ # deg; a walking pelvis stays far from it (measured |lean_FWD| <= 23 deg even on the falls), and the
579
+ # alternative -- projecting the body x-axis onto the ground plane -- has the same singularity in the same
580
+ # place. Not guarded, but named.
581
+
582
+ @staticmethod
583
+ def yaw_quat(q: torch.Tensor) -> torch.Tensor:
584
+ """The yaw-only quaternion of q (4,n): the heading, with roll and pitch removed."""
585
+ w, x, y, z = q[0], q[1], q[2], q[3]
586
+ half = 0.5 * torch.atan2(2.0 * (w * z + x * y), 1.0 - 2.0 * (y * y + z * z))
587
+ zero = torch.zeros_like(half)
588
+ return torch.stack((torch.cos(half), zero, zero, torch.sin(half)), 0)
589
+
590
+ @classmethod
591
+ def yaw_free_quat(cls, q: torch.Tensor) -> torch.Tensor:
592
+ """conj(yaw(q)) (x) q -- the orientation with the heading divided out, so only roll and pitch remain.
593
+ Two bodies facing different compass directions but tilted identically give the SAME value."""
594
+ yq = cls.yaw_quat(q)
595
+ conj = torch.stack((yq[0], -yq[1], -yq[2], -yq[3]), 0)
596
+ return _quat_mul(conj, q)
597
+
598
+ @classmethod
599
+ def yaw_conj(cls, q_root: torch.Tensor) -> torch.Tensor:
600
+ """conj(yaw(q_root)) -- the rotation taking a world vector INTO q_root's heading frame.
601
+
602
+ Exposed separately so a caller mapping SEVERAL vectors into ONE body's heading frame pays the
603
+ atan2/cos/sin once instead of once per vector. The v3 reward maps five (two feet, the COM, two foot
604
+ velocities) into the root's frame, so four of the five were redundant.
605
+ """
606
+ yq = cls.yaw_quat(q_root)
607
+ return torch.stack((yq[0], -yq[1], -yq[2], -yq[3]), 0)
608
+
609
+ @staticmethod
610
+ def rotate_by_yaw_conj(conj: torch.Tensor, v: torch.Tensor) -> torch.Tensor:
611
+ """Apply a `yaw_conj` result to v (3,n). Split from to_yaw_frame so `conj` can be hoisted."""
612
+ return _quat_rotate(conj, v)
613
+
614
+ @classmethod
615
+ def to_yaw_frame(cls, q_root: torch.Tensor, v: torch.Tensor) -> torch.Tensor:
616
+ """Express the world vector v (3,n) in the heading frame of q_root (4,n)."""
617
+ return cls.rotate_by_yaw_conj(cls.yaw_conj(q_root), v)
618
+
619
+ def body_velocities_from_poses(self, pos, quat, qd: torch.Tensor, bodies):
620
+ """World LINEAR velocity of `bodies`, assembled from the frames body_poses_subset ALREADY evaluated.
621
+
622
+ `v_b = sum_f [ l_f + w_f x (p_b - p_f) ]` over the moving ancestor chain of b -- the jacobian columns
623
+ of the chain, contracted against qd on the spot. Every quantity it needs is in the primal FK output:
624
+
625
+ hinge the world axis is `R_f * axis`, and `R_f` is safe to use even though it already contains this
626
+ joint's own rotation, because rotating an axis about ITSELF is the identity. `pos[f]` is the
627
+ joint origin (a hinge does not translate its frame).
628
+ ball `w_f = R_f * qd[vadr:vadr+3]` -- the rate is in the CHILD frame, which is what R_f maps out
629
+ of; `pos[f]` is again the origin.
630
+ slide pure translation, `R_f * axis * qd` -- no origin needed.
631
+ free `[w_body; v_body]` with S = I6 (core/dyn/articulated.h), both in the child frame, so
632
+ `w_f = R_f * qd[v:v+3]` and `l_f = R_f * qd[v+3:v+6]` about the frame origin `pos[f]`.
633
+
634
+ WHY NOT torch.func.jvp THROUGH THE FK. That is the obvious one-liner and it works (it was implemented
635
+ and gated first), but measured on armless_ball / 64 env / CPU it cost **+320%** on reward()+backward:
636
+ forward-mode doubles the dual arithmetic AND adds a functorch dispatch layer over every op in the FK.
637
+ This path instead reuses the primal and adds ~6 ops per frame in TWO chains, so it is a rounding error
638
+ against the FK it borrows from. Same value: gated against a central difference of the FK along the
639
+ same tangent.
640
+
641
+ `qd` is the engine's velocity vector, NOT a q-space tangent -- no chart map is involved here, which is
642
+ the other reason this is cheaper.
643
+ """
644
+ n_env = qd.shape[1]
645
+ out = {}
646
+ for b in bodies:
647
+ b = int(b)
648
+ p_b = pos[b]
649
+ v = torch.zeros_like(p_b)
650
+ f = b if self._body_is_moving(self.bodies[b]) else self._fk_anc[b]
651
+ while f >= 0:
652
+ body = self.bodies[f]
653
+ assert "coupled" not in body, (
654
+ f"body {f} on the chain of {b} is a COUPLED mimic joint: its rate is c'(q_master)*qd_master, "
655
+ "not a dof of its own, and this assembly would silently drop it")
656
+ assert self.joint_axes[f] is None, (
657
+ f"body {f} on the chain of {b} is a composite joint STACK: its sub-joints have "
658
+ "intermediate frames that the reduced FK does not materialise, so their origins are "
659
+ "unavailable here")
660
+ jt = body["joint"]
661
+ va = int(body["vadr"])
662
+ R = quat[f]
663
+ if jt in ("free", "freejoint"):
664
+ w = _quat_rotate(R, qd[va:va + 3])
665
+ v = v + _quat_rotate(R, qd[va + 3:va + 6]) + torch.cross(w, p_b - pos[f], dim=0)
666
+ elif jt == "ball":
667
+ w = _quat_rotate(R, qd[va:va + 3])
668
+ v = v + torch.cross(w, p_b - pos[f], dim=0)
669
+ elif jt in ("hinge", "revolute"):
670
+ ax = self.body_axis[f].to(dtype=p_b.dtype)[:, None].expand(3, n_env)
671
+ v = v + torch.cross(_quat_rotate(R, ax) * qd[va], p_b - pos[f], dim=0)
672
+ elif jt in ("slide", "prismatic"):
673
+ ax = self.body_axis[f].to(dtype=p_b.dtype)[:, None].expand(3, n_env)
674
+ v = v + _quat_rotate(R, ax) * qd[va]
675
+ else:
676
+ raise AssertionError((f, jt))
677
+ f = self._fk_anc[f]
678
+ out[b] = v
679
+ return out
680
+
681
+ def body_twists_from_poses(self, pos, quat, q: torch.Tensor, qd: torch.Tensor, bodies):
682
+ """World LINEAR and ANGULAR velocity `(v_b, w_b)` of `bodies` (see _body_twists_from_poses_eager). With
683
+ DN_TWIST_COMPILE=1 a call whose outputs enter the backward runs compiled, once per call signature; any
684
+ other call (no grad, eval, reset) stays eager, as body_poses_subset does."""
685
+ if not (self._tw_compile and torch.is_grad_enabled() and (q.requires_grad or qd.requires_grad)):
686
+ return self._body_twists_from_poses_eager(pos, quat, q, qd, bodies)
687
+ want = tuple(int(b) for b in bodies)
688
+ frames = tuple(sorted(int(k) for k in (pos.keys() if isinstance(pos, dict) else range(len(pos)))))
689
+ key = (want, frames, q.dtype, int(q.shape[1]), q.device.type)
690
+ fn = self._tw_compiled.get(key)
691
+ if fn is None:
692
+ fn = torch.compile(lambda P, Q, qq, qqd: self._body_twists_from_poses_eager(P, Q, qq, qqd, want),
693
+ fullgraph=True, dynamic=False)
694
+ self._tw_compiled[key] = fn
695
+ return fn(pos, quat, q, qd)
696
+
697
+ def _body_twists_from_poses_eager(self, pos, quat, q: torch.Tensor, qd: torch.Tensor, bodies):
698
+ """World LINEAR and ANGULAR velocity `(v_b, w_b)` of `bodies`, from the frames body_poses_subset evaluated.
699
+
700
+ body_velocities_from_poses plus two things it refuses: the angular velocity, and COUPLED ("mimic")
701
+ joints on the chain. A coupled joint's angle is `theta = sum_k c_k q_m^k` of its master (see the FK), so
702
+ its rate is `theta' = (c_1 + 2 c_2 q_m + 3 c_3 q_m^2 + 4 c_4 q_m^3) * qd[master_vadr]`, and it then
703
+ contributes exactly like an independent hinge / slide with that rate. MuscleMimic's site velocities need
704
+ this on the full body, whose spine levels and shoulder girdle are coupled to their masters.
705
+
706
+ `w_b` is the sum of the chain's joint angular velocities (world frame); hinge / ball / free conventions are
707
+ body_velocities_from_poses'. Composite joint stacks are still refused for the same reason.
708
+
709
+ SHARED, not per body: each moving frame's twist at its own origin is built ONCE from its moving ancestor's,
710
+ `v_f = v_a + w_a x (p_f - p_a) + l_f`, `w_f = w_a + w_f(joint)`, in topological order, and a requested body reads
711
+ its frame's twist (shifted to its own origin when it is welded to that frame). The same sum as walking every
712
+ body's chain separately (which re-walked the shared spine and pelvis for each of 17 sites: ~10x the reward's
713
+ dispatches), only regrouped.
714
+ """
715
+ n_env = qd.shape[1]
716
+ want = [int(b) for b in bodies]
717
+ frame_of = {b: (b if self._body_is_moving(self.bodies[b]) else self._fk_anc[b]) for b in want}
718
+ frames = set()
719
+ for f in frame_of.values():
720
+ while f >= 0:
721
+ frames.add(f)
722
+ f = self._fk_anc[f]
723
+ tw = {}
724
+ for f in sorted(frames): # topological: a moving ancestor always has the lower index
725
+ body = self.bodies[f]
726
+ assert self.joint_axes[f] is None, (
727
+ f"body {f} is a composite joint STACK: its sub-joints have intermediate frames that the reduced FK "
728
+ "does not materialise, so their origins are unavailable here")
729
+ a = self._fk_anc[f]
730
+ if a >= 0:
731
+ v_a, w_a = tw[a]
732
+ v = v_a + torch.cross(w_a, pos[f] - pos[a], dim=0)
733
+ w = w_a
734
+ else:
735
+ v = torch.zeros_like(pos[f])
736
+ w = torch.zeros_like(pos[f])
737
+ jt = body["joint"]
738
+ R = quat[f]
739
+ coupled = body.get("coupled")
740
+ if coupled is not None:
741
+ c = coupled["coef"]
742
+ qm = q[int(coupled["master_qadr"])]
743
+ rate = (c[1] + qm * (2.0 * c[2] + qm * (3.0 * c[3] + qm * 4.0 * c[4]))) * qd[int(coupled["master_vadr"])]
744
+ else:
745
+ rate = None
746
+ if jt in ("free", "freejoint"):
747
+ va = int(body["vadr"])
748
+ w = w + _quat_rotate(R, qd[va:va + 3])
749
+ v = v + _quat_rotate(R, qd[va + 3:va + 6])
750
+ elif jt == "ball":
751
+ va = int(body["vadr"])
752
+ w = w + _quat_rotate(R, qd[va:va + 3])
753
+ elif jt in ("hinge", "revolute"):
754
+ ax = self.body_axis[f].to(dtype=pos[f].dtype)[:, None].expand(3, n_env)
755
+ w = w + _quat_rotate(R, ax) * (qd[int(body["vadr"])] if rate is None else rate)
756
+ elif jt in ("slide", "prismatic"):
757
+ ax = self.body_axis[f].to(dtype=pos[f].dtype)[:, None].expand(3, n_env)
758
+ v = v + _quat_rotate(R, ax) * (qd[int(body["vadr"])] if rate is None else rate)
759
+ else:
760
+ raise AssertionError((f, jt))
761
+ tw[f] = (v, w)
762
+ out = {}
763
+ for b in want:
764
+ f = frame_of[b]
765
+ if f < 0: # welded straight to the world
766
+ out[b] = (torch.zeros_like(pos[b]), torch.zeros_like(pos[b]))
767
+ continue
768
+ v, w = tw[f]
769
+ out[b] = (v if f == b else v + torch.cross(w, pos[b] - pos[f], dim=0), w)
770
+ return out
771
+
772
+ def contact_penetration(self, q: torch.Tensor) -> torch.Tensor:
773
+ """Per-env maximum ground penetration over contact spheres."""
774
+ if not self.contact_geoms:
775
+ return torch.zeros(q.shape[1], dtype=q.dtype, device=q.device)
776
+ positions, quats = self.body_poses(q)
777
+ pen = torch.zeros(q.shape[1], dtype=q.dtype, device=q.device)
778
+ for body, center, radius in zip(self.contact_body, self.contact_center, self.contact_radius):
779
+ c = center.to(dtype=q.dtype, device=q.device)[:, None].expand(3, q.shape[1])
780
+ world_center = positions[body] + _quat_rotate(quats[body], c)
781
+ n = self.ground_normal
782
+ gap = (n[0] * world_center[0] + n[1] * world_center[1] + n[2] * world_center[2]
783
+ - float(radius)) # == world_center[2] on flat ground
784
+ pen = torch.maximum(pen, (-gap).clamp_min(0.0))
785
+ return pen
786
+
787
+ def joint_limit_penetration(self, q: torch.Tensor) -> torch.Tensor:
788
+ """Per-env maximum violation of passive joint ranges, in q units."""
789
+ pen, _idx, _side, _value = self.joint_limit_detail(q)
790
+ return pen
791
+
792
+ def joint_limit_detail(
793
+ self, q: torch.Tensor
794
+ ) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
795
+ """Per-env maximum joint-limit violation plus the responsible limit spec.
796
+
797
+ Returns `(pen, spec_idx, side, q_value)`, where side is -1 for lower-limit
798
+ violation, +1 for upper-limit violation, and 0 when no limit is violated.
799
+ """
800
+ n_env = q.shape[1]
801
+ if not self.limit_specs:
802
+ z = torch.zeros(n_env, dtype=q.dtype, device=q.device)
803
+ zi = torch.full((n_env,), -1, dtype=torch.long, device=q.device)
804
+ return z, zi, z, z
805
+ per_limit = []
806
+ per_side = []
807
+ per_value = []
808
+ for spec in self.limit_specs:
809
+ v = q[int(spec["qadr"])]
810
+ lo_pen = (float(spec["lo"]) - v).clamp_min(0.0)
811
+ hi_pen = (v - float(spec["hi"])).clamp_min(0.0)
812
+ use_hi = hi_pen >= lo_pen
813
+ per_limit.append(torch.maximum(lo_pen, hi_pen))
814
+ per_side.append(torch.where(use_hi, torch.ones_like(v), -torch.ones_like(v)))
815
+ per_value.append(v)
816
+ pens = torch.stack(per_limit, dim=0)
817
+ sides = torch.stack(per_side, dim=0)
818
+ values = torch.stack(per_value, dim=0)
819
+ pen, idx = pens.max(dim=0)
820
+ env_ids = torch.arange(n_env, device=q.device)
821
+ side = torch.where(pen > 0.0, sides[idx, env_ids], torch.zeros_like(pen))
822
+ value = values[idx, env_ids]
823
+ return pen, idx, side, value
824
+
825
+ @torch.no_grad()
826
+ def metrics(self, q: torch.Tensor) -> dict[str, float]:
827
+ contact_pen = self.contact_penetration(q)
828
+ joint_pen = self.joint_limit_penetration(q)
829
+ return {
830
+ "contact_pen_max": float(contact_pen.max().detach()),
831
+ "contact_pen_mean": float(contact_pen.mean().detach()),
832
+ "joint_limit_pen_max": float(joint_pen.max().detach()),
833
+ "joint_limit_pen_mean": float(joint_pen.mean().detach()),
834
+ }