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,248 @@
1
+ """Dimension-grouped, authority-weighted, online-adaptive imitation reward (GitHub #44).
2
+
3
+ WHAT IS WRONG WITH THE v1 REWARD. `r = sum_i w_i*exp(-a_i*e_i)` over 7 hand-tuned terms fails three ways:
4
+
5
+ 1. Raw-sum saturation. `exp(-a*sum_j e_j)` grows its exponent with DOF count, so a term calibrated on a
6
+ small model dies on a big one. Measured DELIVERY RATE `f = exp(-a*e)` -- the fraction of a term's
7
+ nominal weight actually paid: velocity delivered 1.1% on myoLeg26 (nv=18, e_vel 45) and 0.01% on
8
+ armless_ball (nv=23, e_vel 239). The term was not weak on full-body, it was OFF.
9
+ 2. A fixed `a` prices every joint on the same absolute rad^2 scale, but the reference's own motion spans
10
+ 89x across dofs. A 0.1 rad error is 42% of the lumbar's travel and 8% of the knee's, priced the same.
11
+ 3. Every `a` needs re-tuning per model, per clip and per training stage.
12
+
13
+ THE STRUCTURE. Errors are grouped by PHYSICAL DIMENSION -- quantities with different units must never
14
+ share an exponent, which is what made the v1 cross-term comparisons meaningless (rad^2 vs m^2):
15
+
16
+ E_g = sum_j c_j * (e_j / s_j) with sum_j c_j = 1, sum_j s_j = 1
17
+ r = sum_g W_g * exp(-alpha_g * E_g) - effort
18
+
19
+ c_j AUTHORITY, static, measured once at init: A_j = sqrt(J_foot,j^2 + lam*J_com,j^2) where
20
+ J = d|contact point or COM|/dq_j. It answers "how much does this dof move the things that decide
21
+ whether the model stays up", and it spans 105x on full-body (knee 0.316 vs axial_rotation 0.003
22
+ m/rad), which is exactly the ordering an equal-weighted pose term destroys. FK-OUTPUT components
23
+ (end-effector positions, COM_xy, height) are not dofs and take c = 1.
24
+
25
+ s_j SCALE, adapts online, shape only. `s_j ~ EMA(e_j)` normalized to sum 1, so it NORMALIZES rather
26
+ than prioritizes: each `e_j/s_j` becomes O(1) and no component dominates the group by unit scale
27
+ alone. With that in place the composition converges to c_j exactly -- which is the point. Capped to
28
+ a bounded spread so a component the reference PINS (an artifact, not data) cannot be crushed or
29
+ blown up without limit.
30
+
31
+ alpha_g = 1 / EMA_slow(E_g). The EMA is SLOW on purpose. An INSTANTANEOUS alpha = 1/E pins
32
+ `exp(-alpha*E)` at e^-1 forever and reports no progress -- rejected. A slow EMA leaves alpha
33
+ quasi-static inside its window, so real improvement shows up as real reward, while over long
34
+ horizons alpha re-scales and the term can never saturate the way a fixed alpha does.
35
+
36
+ W_g uniform. A 0.40/0.25/0.20/0.15 split was proposed and NOT adopted; uniform is the agreed start.
37
+
38
+ Off by default (`DN_IM_V2=0`) -- v1 stays byte-identical.
39
+ """
40
+ import math
41
+
42
+ import torch
43
+
44
+ GROUPS = ("ang", "pos", "angvel", "linvel") # fixed order: every per-group vector indexes by this
45
+
46
+
47
+ def _contact_points(monitor, feet):
48
+ """[(body, local_center)] for EVERY ground-contact sphere in the model, else the EE body origins.
49
+
50
+ Two corrections live here, both found by reading the numbers the first versions produced:
51
+
52
+ ORIGIN -> CONTACT POINT. Rotating the ankle barely translates the calcn's ORIGIN, it rotates it, so
53
+ measuring origins reported the ankle at 0.0065 against the lumbar's 0.0176 -- the joint that produces
54
+ push-off ranked BELOW trunk bending. At the contact spheres, ~0.1-0.2 m out from the joint, the ankle
55
+ gets the leverage it actually has.
56
+
57
+ EE BODIES -> ALL CONTACT GEOMS. Restricting to the DECLARED end-effectors (`morph.feet`, the calcanei)
58
+ silently dropped every sphere on the toes, and the MTP moves nothing else -- so the toe joint measured
59
+ 1.26e-05 m/rad and landed on the authority floor. "Authority" means leverage over the points that
60
+ decide whether the model stays up; that is the whole contact set, not the subset the reward happens to
61
+ name as end-effectors.
62
+ """
63
+ jm = getattr(monitor, "jm", None)
64
+ geoms = (jm or {}).get("contact", {}).get("geoms", [])
65
+ out = [(int(g["body"]), [float(x) for x in g["center"]]) for g in geoms]
66
+ return out or [(int(b), [0.0, 0.0, 0.0]) for b in feet]
67
+
68
+
69
+ def _fd_authority(monitor, morph, ref_q, layout, *, lam=1.0, n_frames=8, eps=1e-3):
70
+ """Per-OWNING-BODY authority A_b, by central finite difference on the reference frames.
71
+
72
+ Central FD rather than autograd because it needs no graph through the 156-body FK and this runs once.
73
+ Per owning BODY, not per q index, so a Ball joint's 4 q-dims and 3 v-dims share one number -- there is
74
+ no clean 1:1 q<->v map for a quaternion dof, and authority is a property of the joint anyway.
75
+
76
+ `lam` weights the COM channel against the contact-point channel. Returns {body_idx: A}, unnormalized.
77
+ """
78
+ from diffneusim.model.monitor import _quat_rotate
79
+ dev = ref_q.device
80
+ T = ref_q.shape[0]
81
+ frames = torch.linspace(0, T - 1, min(n_frames, T), device=dev).long().unique()
82
+ q0 = ref_q[frames].t().contiguous() # (nq, F)
83
+ F = q0.shape[1]
84
+ feet = list(morph.feet)
85
+ cps = _contact_points(monitor, feet)
86
+ cp_body = sorted({b for b, _c in cps})
87
+ cp_local = {}
88
+ for b, c in cps:
89
+ cp_local.setdefault(b, []).append(torch.tensor(c, dtype=ref_q.dtype, device=dev))
90
+ cols, tags = [], []
91
+ for (bi, qadr, _vadr, wq, _wv) in layout:
92
+ for k in range(wq):
93
+ for sgn in (+1.0, -1.0):
94
+ qp = q0.clone()
95
+ qp[qadr + k] = qp[qadr + k] + sgn * eps
96
+ cols.append(qp)
97
+ tags.append((bi, k, sgn))
98
+ if not cols:
99
+ return {}
100
+ big = torch.cat([q0] + cols, dim=1) # (nq, F*(1+2*sum wq))
101
+ with torch.no_grad():
102
+ pos, quat, com = monitor.body_poses_subset(big, cp_body, True)
103
+
104
+ def points(sl):
105
+ """World positions of every tracked contact point, for one column slice. (n_pt, 3, F)"""
106
+ out = []
107
+ for b in cp_body:
108
+ p, qq = pos[b][:, sl], quat[b][:, sl]
109
+ for c in cp_local[b]:
110
+ out.append(p + _quat_rotate(qq, c[:, None].expand(3, p.shape[1])))
111
+ return torch.stack(out, 0)
112
+
113
+ A = {}
114
+ for i in range(0, len(tags), 2):
115
+ bi, _k, _s = tags[i]
116
+ sp = slice(F * (1 + i), F * (2 + i))
117
+ sm = slice(F * (2 + i), F * (3 + i))
118
+ d_pt = (points(sp) - points(sm)) / (2.0 * eps) # (n_pt,3,F)
119
+ d_com = (com[:, sp] - com[:, sm]) / (2.0 * eps) # (3,F)
120
+ # magnitude per frame, then AMAX over contact points (the binding one) and MEAN over frames
121
+ jf = float(d_pt.norm(dim=1).amax(0).mean())
122
+ jc = float(d_com.norm(dim=0).mean())
123
+ A[bi] = max(A.get(bi, 0.0), math.sqrt(jf * jf + lam * jc * jc)) # multi-dof joint: strongest axis
124
+ return A
125
+
126
+
127
+ class GroupedAdaptiveReward:
128
+ """Holds the group layout, the static authority `c`, and the adaptive `s`/`alpha` state.
129
+
130
+ Every buffer lives on-device and every update is a tensor op: no `.item()`, so nothing here inserts a
131
+ GPU sync into the training loop (the measured cost of a sync in this codebase dwarfs the arithmetic).
132
+ """
133
+
134
+ def __init__(self, *, comp_names, comp_c, device, dtype=torch.float32,
135
+ s_beta=None, a_beta=None, s_spread=None, w=None, beta=None):
136
+ """`comp_names[g]` = list of component names for group g; `comp_c[g]` = matching authority list."""
137
+ self.device, self.dtype = device, dtype
138
+ self.names = {g: list(comp_names.get(g, [])) for g in GROUPS}
139
+ self.active = [g for g in GROUPS if self.names[g]]
140
+ assert self.active, "IM_V2 needs at least one non-empty group"
141
+ self.S_BETA = 0.01 if s_beta is None else s_beta
142
+ self.A_BETA = 0.001 if a_beta is None else a_beta
143
+ # SPREAD, not a per-component bound: max(s)/min(s) <= S_SPREAD. 1.25 was judged too tight to do
144
+ # anything (the reference's own variance spans 89x), 4 was floated and then withdrawn, so this is
145
+ # the one parameter of the design that is NOT settled -- it is a knob, and the default is the
146
+ # withdrawn figure kept only as a starting point. Re-decide it with an A/B, do not trust it.
147
+ self.S_SPREAD = 4.0 if s_spread is None else s_spread
148
+ # Soft-max aggregation temperature. 0 (default) = the authority-weighted mean = byte-identical to
149
+ # the pre-beta behaviour, so this is a continuous knob over the current design rather than a
150
+ # replacement of it. See group_error for why the failure-attention goes here and not into s_j.
151
+ self.BETA = 0.0 if beta is None else beta
152
+ assert self.BETA >= 0.0, f"soft-max temperature must be >= 0 (0 = mean), got {self.BETA}"
153
+ assert self.S_SPREAD >= 1.0, f"spread cap must be >= 1 (1 = frozen uniform s), got {self.S_SPREAD}"
154
+ assert 0.0 < self.S_BETA <= 1.0 and 0.0 < self.A_BETA <= 1.0, (self.S_BETA, self.A_BETA)
155
+ assert self.A_BETA <= self.S_BETA, (
156
+ f"alpha must adapt SLOWER than s (a_beta {self.A_BETA} > s_beta {self.S_BETA}): a fast alpha "
157
+ "pins exp(-alpha*E) at e^-1 and the reward stops reporting progress -- see the module docstring")
158
+ self.c, self.s_ema, self.s, self.E_ema = {}, {}, {}, {}
159
+ for g in self.active:
160
+ cv = torch.tensor(comp_c[g], dtype=dtype, device=device)
161
+ assert cv.numel() == len(self.names[g]) and bool((cv > 0).all()), (g, cv)
162
+ self.c[g] = cv / cv.sum() # sum_j c_j = 1
163
+ k = cv.numel()
164
+ self.s_ema[g] = torch.full((k,), 1.0 / k, dtype=dtype, device=device)
165
+ self.s[g] = self.s_ema[g].clone() # sum_j s_j = 1
166
+ self.E_ema[g] = torch.ones((), dtype=dtype, device=device)
167
+ # W_g uniform over the ACTIVE groups, summing to 1 (see docstring: the weighted split is deferred)
168
+ if w is None:
169
+ self.W = {g: 1.0 / len(self.active) for g in self.active}
170
+ else:
171
+ tot = sum(w[g] for g in self.active)
172
+ self.W = {g: w[g] / tot for g in self.active}
173
+ self._steps = 0
174
+
175
+ def alpha(self, g):
176
+ """alpha_g = 1 / EMA_slow(E_g), clamped away from 0 so a perfectly-tracked group cannot divide by 0."""
177
+ return 1.0 / self.E_ema[g].clamp_min(1e-6)
178
+
179
+ def group_error(self, g, e):
180
+ """E_g over the group's components e (k, n). Differentiable in e; c/s are constants this step.
181
+
182
+ BETA = 0 (default): the authority-weighted mean, `sum_j c_j * x_j` with `x_j = e_j/s_j`.
183
+
184
+ BETA > 0: a SOFT-MAX over the same x, `log(sum_j c_j exp(beta*x_hat_j))/beta`, which attends to
185
+ whichever component is currently worst instead of averaging it away.
186
+
187
+ WHY THIS AND NOT AN ADAPTIVE WEIGHT. c_j and 1/s_j multiply the same x_j, so `c_j/s_j` is ONE
188
+ number per component: adapting both is spending one degree of freedom twice, and "prioritise the
189
+ failing component" cannot be bought by inverting s_j. Measured on a two-component example -- knee
190
+ (typical error 30, currently 30, i.e. FINE) and subtalar (typical 2, currently 8, i.e. 4x worse
191
+ than its own norm) -- `s ~ 1/EMA(e)` hands the KNEE 98.6% of the group against the subtalar's 1.4%,
192
+ because it cannot tell "large natural scale" from "failing". That is exactly the confound s_j was
193
+ introduced to remove. The soft-max reads the already-normalised x, so s_j keeps doing the units job
194
+ (what counts as normal for this component) while the aggregation does the selection (which
195
+ component is abnormal right now) -- and the selection needs no stored per-component parameter.
196
+
197
+ THE EXPONENT IS TAKEN ON x/mean(x), NOT x. With sum(s) = 1, x_j is O(k) rather than O(1) (a
198
+ normally-tracking component in the 17-component `ang` group sits near 17), so a raw `beta*x` would
199
+ saturate to a hard max at beta ~ 0.5 and be unusable. Dividing by the group's own mean makes beta
200
+ mean the same thing on every group and every model -- the same reason IM_AP_NORM/IM_AV_NORM exist
201
+ ("an unreadable alpha is one nobody recomputes on a model change").
202
+
203
+ RISK, on record: v1 added IM_POSE_DECOUPLE precisely because one bad joint could kill the whole
204
+ pose term. A soft-max moves back toward that, and beta is the dial. Start small.
205
+ """
206
+ assert e.shape[0] == self.c[g].numel(), (g, e.shape, self.c[g].numel())
207
+ x = e / self.s[g][:, None]
208
+ b = self.BETA
209
+ if b <= 0.0:
210
+ return (self.c[g][:, None] * x).sum(0)
211
+ xh = x / x.mean(dim=0, keepdim=True).clamp_min(1e-9) # group-size- and model-independent beta
212
+ # log-sum-exp with the max subtracted: the exponent reaches beta*max(xh), which is small by
213
+ # construction, but the shift costs nothing and keeps this safe if beta is pushed hard.
214
+ z = b * xh
215
+ m = z.amax(dim=0, keepdim=True)
216
+ lse = m + (self.c[g][:, None] * (z - m).exp()).sum(0, keepdim=True).clamp_min(1e-30).log()
217
+ return (lse.squeeze(0) / b) * x.mean(dim=0) # undo the x/mean scaling -> E_g in x units
218
+
219
+ def observe(self, per_group_e, per_group_E):
220
+ """Advance the EMAs from DETACHED errors already computed this step. Call once per reward().
221
+
222
+ `s` tracks the typical per-component error so that e/s is O(1); `E_ema` tracks the group error so
223
+ alpha can re-scale. Both are pure tensor ops on tiny vectors -- this is the "rides along with the
224
+ rollout update" requirement, not a separate diagnostic pass.
225
+ """
226
+ self._steps += 1
227
+ for g in self.active:
228
+ e = per_group_e[g]
229
+ self.s_ema[g] = (1.0 - self.S_BETA) * self.s_ema[g] + self.S_BETA * e.mean(dim=1)
230
+ v = self.s_ema[g].clamp_min(1e-12)
231
+ v = v / v.sum()
232
+ # bound the spread about the geometric mean, then renormalize to sum 1
233
+ r = math.sqrt(self.S_SPREAD)
234
+ gm = v.log().mean().exp()
235
+ v = v.clamp(gm / r, gm * r)
236
+ self.s[g] = v / v.sum()
237
+ self.E_ema[g] = (1.0 - self.A_BETA) * self.E_ema[g] + self.A_BETA * per_group_E[g].mean()
238
+
239
+ def state(self):
240
+ """Small dict for run logging / checkpointing (host-side: only call outside the hot loop)."""
241
+ return {"steps": self._steps,
242
+ "beta": self.BETA,
243
+ "W": dict(self.W),
244
+ "alpha": {g: float(self.alpha(g)) for g in self.active},
245
+ "E_ema": {g: float(self.E_ema[g]) for g in self.active},
246
+ "s": {g: [float(x) for x in self.s[g]] for g in self.active},
247
+ "c": {g: [float(x) for x in self.c[g]] for g in self.active},
248
+ "names": {g: self.names[g] for g in self.active}}
@@ -0,0 +1,349 @@
1
+ """Imitation reward v3: jacobian-mapped joint error, ABSOLUTE exponents, split value/gradient.
2
+
3
+ Read `docs/training/concepts/imitation-reward.md` first -- it carries the measurements that produced this design and
4
+ the list of alternatives that were tried and rejected with numbers. This module is the implementation; the
5
+ document is the argument.
6
+
7
+ v3 exists BESIDE v2 (`DN_IM_V2`), which is kept as the baseline: v2 produced the best full-body result
8
+ on record (fb_v9_imv2 ep3600 -- 5/5 starts x 1000 steps, 14.288 m, std 0.038 m) and must stay reproducible.
9
+
10
+ WHAT CHANGES FROM v2, and why each
11
+
12
+ 1. A JOINT ERROR IS MEASURED IN METRES, not in normalized rad^2.
13
+ v2 formed `c_j * e_j / s_j`, whose units are (m/rad)*rad^2/rad^2 = m/rad -- not a physical quantity --
14
+ and whose statistical normalization INVERTED the physical ordering: measured on armless_ball, the knee
15
+ ranks 10-11th of 11 by 1/var and 1st-2nd by jacobian (mean rank disagreement 4.5/11). v3 uses
16
+ `A_j^2 * e_j`, units (m/rad)^2 * rad^2 = m^2: the squared displacement of the contact points / COM that
17
+ this joint's error causes WITH THE OTHER JOINTS HELD FIXED. Same unit for every joint, so NO per-joint
18
+ statistical yardstick is needed -- no reference variance, no adaptive s_j. The held-fixed clause is not a
19
+ caveat to skip: the sum is the DIAGONAL of the quadratic form and overstates the true displacement by
20
+ 9.66x on ep3600, which is why `joint` and `task` are separate groups (see GROUPS below).
21
+
22
+ 2. THE EXPONENT IS ABSOLUTE.
23
+ v2's `alpha_g = 1/EMA_slow(E_g)` makes `alpha*E == 1` at its fixed point, so `exp(-alpha*E)` sits at
24
+ e^-1 = 0.3679 no matter how well the policy tracks -- measured at all four groups on ep3600/4080/4560/6000
25
+ of fb_v9_imv2. The level then carries no information and "is it tracking well, or is the coefficient
26
+ small?" becomes unanswerable. Anchoring alpha to the MEAN also cuts off the tail: the failing start at
27
+ ep4560 sat at 18-39x the mean error, where both the term and its gradient are 0.0000x the surviving
28
+ population's -- a rollout that is falling gets no pull-back at all. An absolute alpha is a TOLERANCE, which
29
+ is only possible because (1) put every joint in metres.
30
+
31
+ CORRECTED 2026-08-04: this used to say a tolerance "reads the same on every model and clip". It does not.
32
+ The reference's own scale varies 1.74-1.86x (position groups) and 2.56-3.09x (velocity groups) across the
33
+ 18 CMU walk clips, so a raw absolute alpha is a per-clip constant. What restores clip-invariance is
34
+ dividing alpha by the clip's own reference scale (see _ANCHOR_SCALE) -- a STATIC, policy-independent
35
+ quantity, not the adaptation deleted in (2).
36
+
37
+ 3. VALUE AND GRADIENT TAKE DIFFERENT PATHS (restored from v1's IM_TRACK / IM_TORSO_ST / IM_CART_W).
38
+ A single coefficient cannot both report progress and supply gradient: too small and `dr/de` vanishes, too
39
+ large and `exp` saturates on both flanks. So the critic gets the bounded `exp` VALUE and the actor gets a
40
+ linear (or huber) gradient that does not die far from the reference. This also removes the joint-vs-joint
41
+ contest: on the linear path `dr/de_j = -W_g * A_j^2` is a constant BUDGET, and no component's gradient can
42
+ be taken by whichever one happens to be worst (that stealing is a property of exp/softmax coupling).
43
+
44
+ WHAT IS KEPT FROM v2: dimension grouping, authority measured by central-FD FK sweep (`_fd_authority`), and
45
+ FK-OUTPUT components as separate entries. The FK outputs matter more here than in v2: mapping joint error
46
+ through the jacobian makes any configuration that puts the contact points and COM in the right place FREE,
47
+ so posture and style have to be carried by something else. `sapo_fb_svd20` is the cautionary case -- it
48
+ walked 12.65 m with the trunk pitching 99.2 deg p2p against the reference's 9.7 (feet right, body folded).
49
+ The torso/foot orientation components are that something else. NOT YET VALIDATED.
50
+
51
+ GROUPS. Because (1) changes units, the grouping is not v2's. The split is JOINT-SPACE vs TASK-SPACE:
52
+
53
+ joint m^2 jacobian-mapped joint POSITION error (scalar dofs + quaternion blocks)
54
+ task m^2 MEASURED end-effector positions + COM_xy + root height
55
+ ang rad^2 FK-OUTPUT orientations (torso, feet) -- posture/style, no jacobian mapping
56
+ jointvel (m/s)^2 jacobian-mapped joint RATE error
57
+ taskvel (m/s)^2 MEASURED end-effector velocities (root-relative)
58
+ rootvel (m/s)^2 the ROOT's own linear velocity, body frame (fwd, lat, vert)
59
+ angvel (rad/s)^2 root angular velocity
60
+
61
+ A quaternion joint (the free base, the Ball hips) is mapped by the same per-body A and lands in `joint`; its
62
+ error is a squared geodesic angle, so `A^2 * theta^2` is again m^2.
63
+
64
+ WHY joint AND task are separate groups even though both are m^2. `sum_j A_j^2 e_j` is the DIAGONAL of the
65
+ quadratic form -- it drops the cross terms, so it cannot be gamed by two joints cancelling each other, but it
66
+ also OVERSTATES the displacement whenever they partly do (measured 9.66x on ep3600: the parts sum to 0.324 m^2
67
+ against a true whole of 0.0335 m^2). That conservatism is deliberate and is kept. But when the two live in ONE
68
+ group their errors ADD, so the 9.66x-inflated proxy buries the directly measured quantity it is a proxy FOR:
69
+ the task components were 9.4% of the old `pos`. Separating them gives each its own exponent, so the measured
70
+ end-effector error is read at its own scale instead of as a tenth of an inflated surrogate.
71
+
72
+ `jointvel` / `taskvel` is the SAME split one time derivative up: `sum_j A_j^2 (dq_j)^2` is the diagonal form of
73
+ the end-effector velocity error, and `|| J(q) qdot - v_ref ||^2` is that form without the approximation. The
74
+ task velocity is obtained by forward-mode AD through the same reduced FK (one extra FK-equivalent pass), not by
75
+ differencing positions across control steps.
76
+
77
+ REFERENCE VELOCITY ALIGNMENT (measured 2026-08-04, myoleg26 07_01). `ref_qd` in the retarget artifacts is a
78
+ FORWARD difference of `ref_q`: fitting `qd[t]` against a central difference centred at t+s gives cos 0.9134 /
79
+ 0.9553 / 0.9872 / **0.9979** / 0.9872 for s = -1, -0.5, 0, +0.5, +1 on the hinge dofs (an identity map, so no
80
+ convention is involved). So `ref_qd[t]` is the velocity at t+0.5 -- half a frame late, 6.5% in norm. `taskvel`
81
+ does NOT reproduce that: its reference is a cyclic CENTRAL difference of the precomputed reference EE
82
+ positions, aligned at t with O(dt^2) error. The two velocity groups therefore have slightly different
83
+ reference alignment, with `taskvel` the correct one; fixing `ref_qd` is a retargeter change, tracked separately.
84
+ """
85
+ import os
86
+
87
+ import torch
88
+
89
+ from diffneusim.rl.imitation_reward_v2 import _fd_authority # same FD sweep; see its docstring
90
+
91
+ GROUPS = ("joint", "task", "ang", "jointvel", "taskvel", "rootvel", "angvel")
92
+
93
+ # Absolute exponents. CALIBRATED AGAINST A MEASURED POLICY, not reasoned from a tolerance.
94
+ #
95
+ # My first attempt set these from a per-component tolerance ("a 3 cm contact-point error costs e^-1" ->
96
+ # alpha_pos = 1/0.03^2 = 1111) and it was wrong by two orders of magnitude, because E_g is a SUM over the
97
+ # group's components, not a single error. Measured on the best full-body policy on record (fb_v9_imv2
98
+ # ep3600, 5/5 starts x 1000 steps, 14.288 m):
99
+ #
100
+ # group E_g alpha=1111/44.4/11.1/0.25 alpha*E exp(-alpha*E)
101
+ # pos 0.35758 397.3 0.0000
102
+ # ang 0.22413 9.95 0.0000
103
+ # linvel 45.2164 501.9 0.0000
104
+ # angvel 1.46876 0.37 0.6927
105
+ #
106
+ # Three of four groups delivered EXACTLY ZERO to the best policy we have -- i.e. I reproduced v1's
107
+ # DOF-count saturation while writing the document that criticises it. The defaults are 1/E_g of that policy,
108
+ # so it lands at exp(-1) = 0.368 per group and there is real signal in both directions: a better policy
109
+ # climbs toward 1, a worse one falls with a live gradient (the huber path keeps dr/dE bounded away from 0).
110
+ #
111
+ # WHAT alpha = 1/E_cal DOES AND DOES NOT EQUALIZE. It equalizes the response to an equal RELATIVE
112
+ # degradation: at the calibration point dr_g = -W_g * alpha_g * dE_g = -W_g * (dE_g / E_cal_g), so +10% on
113
+ # any group's own error costs the same 0.025 of reward. It does NOT equalize `alpha_g * w_j`, and it must
114
+ # not be expected to: those carry the group's unit (1/m^2 for `joint`/`task`, 1/rad^2 for `ang`,
115
+ # 1/(m/s)^2 for the velocity groups), so comparing them across groups divides incommensurable quantities.
116
+ # An earlier note in this file read alpha_linvel*w = 0.055 against alpha_pos*w = 9.85 and called `linvel`
117
+ # "178x too weak"; that ratio has units of (m/s)^2/m^2 and means nothing. Removed.
118
+ #
119
+ # THIS ANCHORS THE SCALE TO ONE POLICY ON ONE MODEL. It is a starting point, not a law. Re-measure when the
120
+ # model, the reference or the component set changes -- and re-measure by running a known-good policy and
121
+ # reading E_g (`tools/im_v3_calibrate.py`), not by reasoning about tolerances.
122
+ #
123
+ # MEASURED 2026-08-04 on an RTX 3080 Ti laptop GPU by tools/im_v3_calibrate.py against fb_v9_imv2 ep3600 (armless_ball, ref
124
+ # 07_01_loop_fullbody, eval eplen 1000, 3 starts, 3000 step-samples). The rollout reproduced the baseline --
125
+ # 3/3 starts x 1000 steps at 14.237 / 14.253 / 14.284 m against the recorded 14.288 -- so these are the group
126
+ # errors of the best policy on record, on the model it was trained on.
127
+ #
128
+ # group mean E p50 p90 alpha=1/mean the PLACEHOLDER it replaced
129
+ # joint 0.50932 0.32764 1.1488 1.9634 3.0860 (derived, 1.6x too large)
130
+ # task 0.061579 0.042094 0.13853 16.239 29.7500 (derived, 1.8x too large)
131
+ # ang 0.35623 0.22140 0.87126 2.8072 4.4617
132
+ # jointvel 60.899 36.774 152.41 0.016421 0.0221
133
+ # taskvel 5.0317 3.0668 12.242 0.19874 0.0221 (12x too SMALL -- see below)
134
+ # angvel 1.6949 1.1489 3.9916 0.59001 0.6808
135
+ #
136
+ # WHAT THE MEASUREMENT CAUGHT, and why it was not optional. At the inherited alpha, `taskvel` would have sat
137
+ # at exp(-0.0221 * 5.03) = **0.895** of its maximum 1.0 -- pinned against the ceiling, delivering almost no
138
+ # signal in either direction. The end-effector velocity term would have been effectively inert, and the run
139
+ # would have reported "task velocity does not help" about a term that never fired.
140
+ #
141
+ # THE EARLIER "E_g" NUMBERS ABOVE ARE MEDIANS, NOT MEANS. `ang` p50 here is 0.22140 against the 0.22413
142
+ # recorded as its mean, and `joint`+`task` p50 is 0.36973 against the 0.35758 recorded for `pos` -- agreement
143
+ # to ~1%, while the actual MEANS are 1.55x higher. The E_g distributions are right-skewed (p90/p50 ~ 3.5), so
144
+ # the distinction changes the anchor: on the median, the mean state would sit at exp(-1.55) = 0.21 with little
145
+ # room above it. Anchored on the mean, as below, the median state sits at exp(-0.64) = 0.53 and p90 at
146
+ # exp(-2.26) = 0.10 -- live signal in both directions, which is the point.
147
+ #
148
+ # (One earlier prediction does survive: removing the root linear block from the velocity group DOES lower it.
149
+ # Like-for-like on medians, `jointvel` is 36.8 against the old `linvel` 45.2.)
150
+ #
151
+ # RE-MEASURE when the model, the reference or the component set changes, by running a known-good policy
152
+ # through the calibrator -- never by reasoning about tolerances, which already produced alpha_pos = 1111 and
153
+ # three groups delivering exactly zero.
154
+ _DEFAULT_ALPHA = {"joint": 1.9634, "task": 16.239, "ang": 2.8072,
155
+ "jointvel": 0.016421, "taskvel": 0.20714, "rootvel": 4.9003, "angvel": 0.59001}
156
+ # Provenance of each default, surfaced in the banner and in state() so a run's own config is readable from
157
+ # its log. "measured" = read off a real policy; anything else is a placeholder.
158
+ # taskvel/rootvel are the two halves of the ONE measured taskvel group, split by their measured
159
+ # contributions (4.8276 and 0.20407 of 5.0317), so their exponents are exact rather than guessed -- but they
160
+ # were not read off a policy AS SEPARATE GROUPS, hence "derived" rather than "measured".
161
+ _ALPHA_STATUS = {g: "measured" for g in GROUPS}
162
+ _ALPHA_STATUS["taskvel"] = _ALPHA_STATUS["rootvel"] = "derived"
163
+
164
+ # CLIP NORMALIZATION. The exponents above were measured on 07_01 alone, and an earlier version of this
165
+ # docstring claimed an absolute alpha "reads the same on every model and clip". MEASURED 2026-08-04, that is
166
+ # FALSE. The reference's own natural scale per group, over the 18 CMU walk clips with a full-body loop
167
+ # reference (forward speed 0.92-1.84 m/s), computed from the reference data alone (no policy, so no
168
+ # self-reference):
169
+ #
170
+ # group min max max/min CV
171
+ # joint 0.7642 1.327 1.74 0.153
172
+ # task 0.1090 0.2026 1.86 0.148
173
+ # ang 0.3923 0.6882 1.75 0.150
174
+ # jointvel 32.44 82.90 2.56 0.238
175
+ # taskvel 4.347 13.44 3.09 0.288
176
+ # angvel 0.4514 1.330 2.95 0.291
177
+ #
178
+ # The velocity groups scale with roughly the square of gait speed, which is why they spread most. Applying
179
+ # 07_01's alpha_taskvel to 08_08 (1.838 m/s) would put alpha*E at 3.09x its calibration value, i.e.
180
+ # exp(-3.09) = 0.045 -- the saturation failure v3 exists to avoid, reappearing from a change of CLIP.
181
+ #
182
+ # So alpha is divided by the clip's own scale relative to 07_01's. This is NOT the adaptation that was
183
+ # deleted: the scale is a property of the REFERENCE, computed once at init, policy-independent, auditable, and
184
+ # printed in the banner. It is the same category as the static feasibility check that this document prefers
185
+ # over an adaptive s_j. On 07_01 every factor is 1.0 by construction, so the current calibration is unchanged.
186
+ #
187
+ # `DN_IM_V3_CLIP_NORM=0` disables it (for an A/B, or to reproduce a run made before this existed).
188
+ _ANCHOR_SCALE = {"joint": 0.9961, "task": 0.1494, "ang": 0.5753,
189
+ "jointvel": 59.1438, "taskvel": 6.8139, "rootvel": 2.2395, "angvel": 1.0476} # 07_01_loop_fullbody, armless_ball
190
+ # The calibration's own units: armless_ball (MyoTorso spine) on 07_01. It is retired; its successor lane (lumbar spine
191
+ # as its source distributes it, decisions/0025) on 07_01 retargeted onto that spine reads every group within 2e-4 of
192
+ # these except "ang", 1.24% smaller (0.56825), so its clip factor there is 1.0124 and alpha * S keeps the calibration.
193
+
194
+
195
+ class JacobianAbsoluteReward:
196
+ """v3 aggregator. Holds the per-component jacobian weights and the absolute exponents.
197
+
198
+ Deliberately stateless across steps: nothing here adapts, so there is no EMA, no fixed point, and no
199
+ way for the reward to become a function of its own history. That is the property v2 lost.
200
+ """
201
+
202
+ def __init__(self, *, comp_names, comp_w, device, dtype=torch.float32, alpha=None, track=None,
203
+ huber_delta=None, clip_scale=None):
204
+ """`comp_w[g][j]` is the multiplier that converts component j's raw error into the group's unit:
205
+ `A_j^2` for a mapped joint, 1.0 for an FK output that is already in that unit."""
206
+ self.device, self.dtype = device, dtype
207
+ self.names = {g: list(comp_names.get(g, [])) for g in GROUPS}
208
+ self.active = [g for g in GROUPS if self.names[g]]
209
+ assert self.active, "IM_V3 needs at least one non-empty group"
210
+ self.w = {}
211
+ for g in self.active:
212
+ v = torch.tensor(comp_w[g], dtype=dtype, device=device)
213
+ assert v.numel() == len(self.names[g]) and bool((v >= 0).all()), (g, v)
214
+ self.w[g] = v
215
+ self.alpha = dict(_DEFAULT_ALPHA)
216
+ self.alpha_src = dict(_ALPHA_STATUS)
217
+ for g in GROUPS: # per-group override, e.g. DN_IM_V3_ALPHA_JOINT
218
+ env = os.environ.get(f"DN_IM_V3_ALPHA_{g.upper()}")
219
+ if env is not None:
220
+ self.alpha[g] = float(env); self.alpha_src[g] = "env"
221
+ if alpha:
222
+ self.alpha.update(alpha)
223
+ for g in alpha:
224
+ self.alpha_src[g] = "arg"
225
+ # CLIP NORMALIZATION (see _ANCHOR_SCALE): alpha_g <- alpha_g * S_g(07_01) / S_g(this clip). Applied
226
+ # AFTER the env/arg overrides, so an explicitly set exponent is also expressed in 07_01 units and a
227
+ # value copied from one run's config means the same thing on another clip. Static: the scale comes from
228
+ # the reference, not from the policy.
229
+ # `clip_scale` is ONE dict for a single clip, or a LIST of dicts (one per clip) for a corpus. In the
230
+ # multi-clip case alpha becomes a per-clip VECTOR and the reward indexes it by each env's clip: the
231
+ # scales vary 1.74-3.09x across the corpus, so one pooled exponent would saturate the fast clips and
232
+ # under-drive the slow ones -- exactly what the normalization exists to prevent.
233
+ self.CLIP_NORM = True
234
+ per_clip = isinstance(clip_scale, (list, tuple))
235
+ scales = list(clip_scale) if per_clip else ([clip_scale] if clip_scale else [])
236
+ self.n_clips = max(1, len(scales))
237
+ self.clip_scale = scales[0] if scales else {}
238
+ self.alpha_base = dict(self.alpha)
239
+ self.clip_factor = {g: 1.0 for g in GROUPS}
240
+ self.alpha_vec = None
241
+ if scales:
242
+ fac = {g: [] for g in self.active}
243
+ for sc in scales:
244
+ for g in self.active:
245
+ v = sc.get(g)
246
+ assert v is not None and v > 0.0, (
247
+ f"clip scale for group {g} is {v}: it divides alpha, so a zero or a missing entry "
248
+ "would silently blow up or drop the group")
249
+ fac[g].append(_ANCHOR_SCALE[g] / v)
250
+ for g in self.active:
251
+ self.clip_factor[g] = float(sum(fac[g]) / len(fac[g])) # reported; the mean over clips
252
+ self.alpha[g] = self.alpha_base[g] * fac[g][0] # scalar path == clip 0
253
+ self.alpha_src[g] = self.alpha_src[g] + "+clipnorm"
254
+ if len(scales) > 1:
255
+ self.alpha_vec = {g: torch.tensor([self.alpha_base[g] * f for f in fac[g]],
256
+ dtype=dtype, device=device) for g in self.active}
257
+ for g in self.active:
258
+ assert self.alpha[g] > 0.0, (g, self.alpha[g])
259
+ # groups still on a placeholder exponent -- the caller prints these so no run can quietly rest on them
260
+ self.alpha_provisional = tuple(g for g in self.active
261
+ if self.alpha_src[g].split("+")[0] in ("derived", "inherited"))
262
+ # W_g uniform over ACTIVE groups, summing to 1 (as v2; the weighted split was proposed, not adopted)
263
+ self.W = {g: 1.0 / len(self.active) for g in self.active}
264
+ # GRADIENT PATH. "exp" reproduces a plain single-path exp reward (no split) and is NOT the default:
265
+ # the whole point of v3 is that one path cannot do both jobs. huber is the default because it is
266
+ # linear far from the reference (never vanishing) and quadratic near it (so the optimum is not a
267
+ # kink). delta is in units of alpha*E, i.e. dimensionless.
268
+ self.TRACK = (track or "huber").lower()
269
+ assert self.TRACK in ("huber", "mse", "exp"), self.TRACK
270
+ self.DELTA = 1.0 if huber_delta is None \
271
+ else huber_delta
272
+ assert self.DELTA > 0.0, self.DELTA
273
+
274
+ def group_error(self, g, e):
275
+ """E_g = sum_j w_j * e_j for e (k, n) -- already a physical quantity, so a plain sum.
276
+
277
+ No c_j/s_j: `w_j = A_j^2` carries both the physical weighting and the unit conversion, so there is
278
+ one number per component instead of v2's two on the same multiplicative axis.
279
+ """
280
+ assert e.shape[0] == self.w[g].numel(), (g, e.shape, self.w[g].numel())
281
+ return (self.w[g][:, None] * e).sum(0)
282
+
283
+ def alpha_of(self, g, clip_id=None):
284
+ """The exponent for group g -- a scalar, or a per-env vector gathered by clip when a corpus is
285
+ loaded. Keeping it a scalar in the single-clip case preserves that path exactly."""
286
+ if self.alpha_vec is None or clip_id is None:
287
+ return self.alpha[g]
288
+ return self.alpha_vec[g][clip_id]
289
+
290
+ def group_reward(self, g, E, clip_id=None):
291
+ """W_g * exp(-alpha_g * E_g), with the ACTOR's gradient rerouted unless TRACK == 'exp'.
292
+
293
+ `val.detach() + grad - grad.detach()` is the straight-through form already used by v1's IM_TRACK /
294
+ IM_TORSO_ST / IM_CART_W / IM_WLAT: the returned VALUE is the bounded exp (so the critic, the GAE
295
+ bootstrap and every logged return stay on the same scale), while d/dE follows the surrogate.
296
+
297
+ The value is exact only to float32: the cancellation adds and subtracts a surrogate that GROWS with
298
+ the error against a value that SHRINKS, so it costs a couple of mantissa digits at large error
299
+ (measured 4.9e-6 relative at alpha*E = 4.4, i.e. ~1e-8 absolute on an O(1) reward). Harmless for the
300
+ critic; worth knowing before chasing a tiny value/return mismatch as a bug.
301
+ """
302
+ a = self.alpha_of(g, clip_id)
303
+ val = self.W[g] * torch.exp(-a * E)
304
+ if self.TRACK == "exp":
305
+ return val
306
+ x = a * E # dimensionless
307
+ if self.TRACK == "mse":
308
+ loss = x # d(reward)/dE = -W*a, constant
309
+ else:
310
+ d = self.DELTA # huber: quadratic near 0, linear past delta
311
+ loss = torch.where(x < d, 0.5 * x * x / d, x - 0.5 * d)
312
+ g_path = -self.W[g] * loss
313
+ return val.detach() + g_path - g_path.detach()
314
+
315
+ def state(self):
316
+ """Host-side summary for run logging. Static by construction -- logged once is enough, but it is
317
+ emitted per logged epoch anyway so a run's own config is readable from its log alone."""
318
+ return {"track": self.TRACK, "huber_delta": self.DELTA,
319
+ "W": dict(self.W),
320
+ "alpha": {g: float(self.alpha[g]) for g in self.active},
321
+ "alpha_base": {g: float(self.alpha_base[g]) for g in self.active},
322
+ "alpha_src": {g: self.alpha_src[g] for g in self.active},
323
+ "alpha_provisional": list(self.alpha_provisional),
324
+ "clip_norm": self.CLIP_NORM,
325
+ "clip_scale": {g: float(self.clip_scale[g]) for g in self.active if g in self.clip_scale},
326
+ "clip_factor": {g: float(self.clip_factor[g]) for g in self.active},
327
+ "w": {g: [float(x) for x in self.w[g]] for g in self.active},
328
+ "names": {g: self.names[g] for g in self.active}}
329
+
330
+
331
+ def build_component_weights(authority, layout, jm, *, q_index_of, floor_frac=0.0):
332
+ """`A_b` per owning body -> `A_j^2` per mapped joint component.
333
+
334
+ `floor_frac` exists only so a dof with ~zero measured authority is not multiplied by exactly 0 (which
335
+ would delete it from the group). It defaults to 0: unlike v2's authority floor, v3 has no normalization
336
+ that a zero would break, and a joint that genuinely does not move the contact points SHOULD contribute
337
+ nothing to a metres-based error.
338
+ """
339
+ amax = max(authority.values()) if authority else 1.0
340
+ floor = floor_frac * amax
341
+ body_of = {}
342
+ for (bi, qadr, _vadr, wq, _wv) in layout:
343
+ for k in range(wq):
344
+ body_of[qadr + k] = bi
345
+ out = []
346
+ for qi in q_index_of:
347
+ a = max(authority.get(body_of.get(qi, -1), 0.0), floor)
348
+ out.append(a * a)
349
+ return out