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,452 @@
1
+ """Unitree G1 one-clip tracking on the D16 soft law (line 23, docs/training/campaigns/g1/seconds.md; the design's G1 trainer port).
2
+
3
+ Physics is the production law (models/derived/unitree_g1_soft_law.json) in MuJoCo's native layout, batch-first:
4
+ qpos [n, 36] = root position, root quaternion (w x y z), the 29 joints; qvel [n, 35] = root linear velocity (world), root angular
5
+ velocity (body), the 29 joint rates; warm [n, 35] the solver's warm start; ctrl [n, 29] the position actuators' setpoints in the
6
+ law's ACTUATOR order (LawMap.ctrl permutes from the joint order). The law's joint order is the dnmodel's actuator order (asserted).
7
+ Backends share one signature (tools/d16/soft_capi.py Soft.control_step_batch):
8
+ CpuLaw the f64 CPU law (soft_capi), for the Mac's tests; values only
9
+ GpuLaw the production GPU extension (tools/d16_binding/soft_engine.py's ext), with one output / tape / foot-friction slot per
10
+ window step, so that step k's adjoint reads step k's own buffers (the reading of the extension, 11-10: the adjoint reads only
11
+ what it is passed, except the foot friction, which SoftEngine keeps global). Host-side only: no kernel is touched.
12
+ The env (G1SoftTrack) is the same for both arms:
13
+ action residual PD: setpoint = q_ref(t + 1) + half_range * a, clamped to the joint range (InstantMimic's
14
+ _apply_action_ref_kernel, with the next reference frame as NablaMimic's residual recipe)
15
+ reward InstantMimic's body-state power sum (envs/tracking/reward_kernels.py, base.yaml weights): E = 100 e_pos + 5 e_rot +
16
+ 0.1 e_lin + 0.1 e_ang, each a mean over the tracked bodies and 3 components of the squared world-frame error (rotation:
17
+ the axis-angle of the quaternion difference), r = 1 / (1 + E). Deviation (labelled): their simulated linear velocity is
18
+ MuJoCo's cvel (at the root subtree's COM); here both sim and reference use the body origin's world velocity
19
+ terminate BeyondMimic's G1 terms (mjlab 15ebce88 tracking_env_cfg.py / config/g1/env_cfgs.py): anchor (torso_link) height
20
+ error > 0.25 m, anchor projected-gravity z error > 0.8, any end effector's height error > 0.25 m; plus, in training
21
+ only and when enabled, InstantMimic's early termination (reward < 0.15 for 4 consecutive steps)
22
+ observe obs_phc below: InstantMimic's feature set (snu_imitation/observation_runtime.py, future_observation_kernels.py
23
+ phc_v6: joint state; the bodies' heading-frame position, 6D rotation, linear and angular velocity; per future body
24
+ the 24 features diff pos / diff rot 6D / diff lin vel / diff ang vel / local ref pos / local ref rot 6D; the previous
25
+ action). Representation differences (labelled): joint angles raw (theirs 6D), body positions root-relative with the root
26
+ height apart (theirs relative to the root's ground point), velocities unscaled (theirs x 0.1; the standardiser absorbs
27
+ a scale), the 14 tracked bodies
28
+ reset the reference state at a frame, masked (torch.where; no host sync), warm start zeroed (mj_resetData)
29
+ """
30
+ from __future__ import annotations
31
+
32
+ import json
33
+ import pathlib
34
+
35
+ import numpy as np
36
+ import torch
37
+
38
+ from diffneusim._paths import ROOT as ROOT # (3a) the repo root
39
+ LAW = ROOT / "models" / "derived" / "unitree_g1_soft_law.json"
40
+ DNMODEL = ROOT / "models" / "unitree_g1.dnmodel"
41
+ NQ, NV, NU = 36, 35, 29
42
+ CONTROL_DT = 0.02
43
+ TRACKED = ("pelvis", "left_hip_roll_link", "left_knee_link", "left_ankle_roll_link", "right_hip_roll_link", "right_knee_link",
44
+ "right_ankle_roll_link", "torso_link", "left_shoulder_roll_link", "left_elbow_link", "left_wrist_yaw_link",
45
+ "right_shoulder_roll_link", "right_elbow_link", "right_wrist_yaw_link") # mjlab's G1 motion body_names
46
+ ANCHOR = "torso_link"
47
+ EE = ("left_ankle_roll_link", "right_ankle_roll_link", "left_wrist_yaw_link", "right_wrist_yaw_link")
48
+ TERM_ANCHOR_Z, TERM_ANCHOR_ORI, TERM_EE_Z = 0.25, 0.8, 0.25
49
+ REW_W = dict(pos=100.0, rot=5.0, lin=0.1, ang=0.1) # InstantMimic humanoid/imitation/base.yaml reward.tracking.weights
50
+ ET_REWARD, ET_STEPS = 0.15, 4 # its termination.early (type reward)
51
+
52
+
53
+ def _load_json_c(path):
54
+ t = pathlib.Path(path).read_text()
55
+ return json.loads("\n".join(l for l in t[t.index("{"):].splitlines() if not l.lstrip().startswith("//")))
56
+
57
+
58
+ # ---------------------------------------------------------------------------------------------- quaternions (w x y z), batch-last
59
+ def qmul(a, b):
60
+ aw, ax, ay, az = a.unbind(-1)
61
+ bw, bx, by, bz = b.unbind(-1)
62
+ return torch.stack([aw * bw - ax * bx - ay * by - az * bz, aw * bx + ax * bw + ay * bz - az * by,
63
+ aw * by - ax * bz + ay * bw + az * bx, aw * bz + ax * by - ay * bx + az * bw], -1)
64
+
65
+
66
+ def qconj(q):
67
+ # no host constant: a tensor built from host data is a host-to-device copy, which CUDA graph capture forbids (W1's G4, 11-10)
68
+ return torch.cat([q[..., :1], -q[..., 1:]], -1)
69
+
70
+
71
+ def qrot(q, v):
72
+ u, w = q[..., 1:], q[..., :1]
73
+ t = 2.0 * torch.cross(u, v, dim=-1)
74
+ return v + w * t + torch.cross(u, t, dim=-1)
75
+
76
+
77
+ def qrot_inv(q, v):
78
+ return qrot(qconj(q), v)
79
+
80
+
81
+ def quat_axis_angle(q, eps=1e-8):
82
+ """The rotation vector of unit quaternions (shortest rotation), differentiable at 0."""
83
+ q = torch.where(q[..., :1] < 0, -q, q)
84
+ s = q[..., 1:].norm(dim=-1, keepdim=True)
85
+ ang = 2.0 * torch.atan2(s, q[..., :1])
86
+ scale = torch.where(s > eps, ang / s.clamp_min(eps), 2.0 + 0.0 * s)
87
+ return q[..., 1:] * scale
88
+
89
+
90
+ def quat_mat6(q):
91
+ """The first two columns of the rotation matrix, [..., 6]."""
92
+ o = torch.ones_like(q[..., :1]) # the unit axes on the device (no host constant: capturable)
93
+ z = torch.zeros_like(o)
94
+ ex = qrot(q, torch.cat([o, z, z], -1))
95
+ ey = qrot(q, torch.cat([z, o, z], -1))
96
+ return torch.cat([ex, ey], -1)
97
+
98
+
99
+ def yaw_quat(q):
100
+ """The heading of q as a rotation about world z: the yaw of its x axis, atan2(R10, R00) (PHC's calc_heading, mjlab's yaw_quat);
101
+ undefined when the x axis is vertical."""
102
+ w, x, y, z = q.unbind(-1)
103
+ yaw = torch.atan2(2.0 * (w * z + x * y), 1.0 - 2.0 * (y * y + z * z))
104
+ zero = torch.zeros_like(w)
105
+ return torch.stack([torch.cos(0.5 * yaw), zero, zero, torch.sin(0.5 * yaw)], -1)
106
+
107
+
108
+ # ---------------------------------------------------------------------------------------------- the law's layout
109
+ class LawMap:
110
+ def __init__(self, law_path=LAW, dnmodel_path=DNMODEL, device="cpu"):
111
+ L = json.loads(pathlib.Path(law_path).read_text())
112
+ jm = _load_json_c(dnmodel_path)
113
+ self.L = L
114
+ assert L["nq"] == NQ and L["nv"] == NV and len(L["actuators"]) == NU
115
+ self.joints = [j["name"] for j in L["joints"]]
116
+ assert all(j["dof"] == 6 + i and j["qadr"] == 7 + i for i, j in enumerate(L["joints"])), "joint i at qpos 7+i / qvel 6+i"
117
+ assert self.joints == [a["joint"] for a in jm["actuators"]], "the law's joint order is not the dnmodel's actuator order"
118
+ act_of_dof = {a["dof"]: a["index"] for a in L["actuators"]}
119
+ assert sorted(act_of_dof.values()) == list(range(NU)) and sorted(act_of_dof) == list(range(6, 6 + NU))
120
+ joint_of_act = [None] * NU
121
+ for d, k in act_of_dof.items():
122
+ joint_of_act[k] = d - 6
123
+ self.joint_of_act = torch.tensor(joint_of_act, dtype=torch.long, device=device) # ctrl[:, k] = sp[:, joint_of_act[k]]
124
+ self.act_of_joint = torch.tensor([act_of_dof[6 + i] for i in range(NU)], dtype=torch.long, device=device)
125
+ rng = torch.tensor([j["range"] for j in L["joints"]], dtype=torch.float64, device=device)
126
+ assert all(j["limited"] for j in L["joints"])
127
+ self.lo, self.hi = rng[:, 0], rng[:, 1]
128
+ self.half_range = 0.5 * (self.hi - self.lo)
129
+ self.body = {b["name"].removeprefix("robot/"): i for i, b in enumerate(L["bodies"])}
130
+ self.nb = len(L["bodies"])
131
+ assert len(L["train_foot_friction"]) == 1, L["train_foot_friction"]
132
+ self.train_foot_friction = float(L["train_foot_friction"][0])
133
+
134
+ def ids(self, names):
135
+ return [self.body[n] for n in names]
136
+
137
+ def ctrl(self, sp):
138
+ """[n, 29] joint order -> [n, 29] the law's actuator order (a gather: differentiable)."""
139
+ return sp.index_select(1, self.joint_of_act)
140
+
141
+ def to_joint_order(self, u_act):
142
+ return u_act.index_select(1, self.act_of_joint)
143
+
144
+
145
+ # ---------------------------------------------------------------------------------------------- the reference
146
+ class Motion:
147
+ """A 50 Hz motion file of tools/g1_lafan1_convert.py's format (mjlab's keys; bodies in MuJoCo order without the world, which is
148
+ the dnmodel's body order) mapped onto the law's body indices."""
149
+
150
+ def __init__(self, npz_path, lawmap, device="cpu", dtype=torch.float64, dnmodel_path=DNMODEL):
151
+ d = np.load(npz_path, allow_pickle=False)
152
+ assert int(d["fps"][0]) == 50, d["fps"]
153
+ jm = _load_json_c(dnmodel_path)
154
+ jnames = [b["name"] for b in jm["bodies"]]
155
+ T, nbj = d["body_pos_w"].shape[:2]
156
+ assert nbj == len(jnames), (nbj, len(jnames))
157
+ idx = [lawmap.body[n] for n in jnames]
158
+ self.T = T
159
+ t = lambda a: torch.as_tensor(np.asarray(a, np.float64), dtype=dtype, device=device) # noqa: E731
160
+ self.joint_pos, self.joint_vel = t(d["joint_pos"]), t(d["joint_vel"])
161
+ assert self.joint_pos.shape == (T, NU)
162
+ full = lambda a, w: torch.zeros(T, lawmap.nb, w, dtype=dtype, device=device).index_copy_(1, torch.tensor(idx, device=device), t(a)) # noqa: E731
163
+ self.bpos, self.bquat = full(d["body_pos_w"], 3), full(d["body_quat_w"], 4)
164
+ self.bvel, self.bang = full(d["body_lin_vel_w"], 3), full(d["body_ang_vel_w"], 3)
165
+ self.bquat[:, : min(idx)] = torch.tensor([1.0, 0, 0, 0], dtype=dtype, device=device) # world / terrain rows: identity
166
+ self.pelvis = lawmap.body["pelvis"]
167
+ assert self.pelvis == 2
168
+
169
+ def state(self, f):
170
+ """The reference's law state at frames f [n] (long): qpos [n, 36], qvel [n, 35] (root angular velocity in the body frame)."""
171
+ p, q = self.bpos[f, self.pelvis], self.bquat[f, self.pelvis]
172
+ v, w = self.bvel[f, self.pelvis], self.bang[f, self.pelvis]
173
+ qpos = torch.cat([p, q, self.joint_pos[f]], -1)
174
+ qvel = torch.cat([v, qrot_inv(q, w), self.joint_vel[f]], -1)
175
+ return qpos, qvel
176
+
177
+
178
+ # ---------------------------------------------------------------------------------------------- backends
179
+ class CpuLaw:
180
+ """The f64 CPU law (soft_capi), values only; the Mac's reference backend for the env's tests."""
181
+
182
+ def __init__(self, bodies, law_path=None):
183
+ # (3a) was: sys.path.insert(0, str(ROOT / "tools" / "d16"))
184
+ from diffneusim.engine import soft_capi # noqa: E402
185
+ soft_capi.build()
186
+ self.soft = soft_capi.Soft(law_path) if law_path else soft_capi.Soft()
187
+ self.bodies = np.asarray(bodies, np.int32)
188
+ self.anchor_body = [i for i, b in enumerate(self.soft.L["bodies"]) if b["name"].removeprefix("robot/") == ANCHOR]
189
+ assert len(self.anchor_body) == 1, self.anchor_body
190
+ self.anchor_body = self.anchor_body[0]
191
+ self.anchor_ipos_offset = None
192
+
193
+ def set_anchor_ipos_offset(self, off):
194
+ """COMDR (tools/g1_seconds/COMDR_DESIGN.md): the anchor body's (ANCHOR, torso_link) ipos += off[i] for world i of every later
195
+ step, set once after construction; off [n, 3] (m) in any float dtype / device, or None: nominal. Zeros go through the offset
196
+ path (the macro-on-at-zero gate). Mass, inertia, iquat and the invweight0-derived constants stay nominal."""
197
+ if off is None:
198
+ self.soft.set_anchor_ipos_offset(0, None)
199
+ self.anchor_ipos_offset = None
200
+ return
201
+ assert off.dim() == 2 and off.shape[1] == 3, tuple(off.shape)
202
+ self.soft.set_anchor_ipos_offset(self.anchor_body, off.detach().cpu().double().numpy())
203
+ self.anchor_ipos_offset = off.detach().clone()
204
+
205
+ def step(self, slot, qpos, qvel, warm, ctrl, foot):
206
+ o = self.soft.control_step_batch(qpos.detach().cpu().double().numpy(), qvel.detach().cpu().double().numpy(),
207
+ warm.detach().cpu().double().numpy(), ctrl.detach().cpu().double().numpy(),
208
+ foot.detach().cpu().double().numpy(), bodies=self.bodies)
209
+ dev, dt = qpos.device, qpos.dtype
210
+ return {k: torch.as_tensor(o[k], dtype=dt, device=dev) for k in ("qpos", "qvel", "warm", "xpos", "xquat", "xvel", "xangvel")}
211
+
212
+ def frames(self, qpos, qvel):
213
+ o = self.soft.body_frames(qpos.detach().cpu().double().numpy(), qvel.detach().cpu().double().numpy(), self.bodies)
214
+ return {k: torch.as_tensor(o[k], dtype=qpos.dtype, device=qpos.device) for k in o}
215
+
216
+
217
+ class GpuLaw:
218
+ """The production GPU extension with per-slot buffers (one slot per window step; slots=1 for values-only rollouts). Every buffer
219
+ is allocated here once, so step() and adjoint() only launch (graph-capturable). Outputs are views of slot buffers: a caller that
220
+ keeps them past the slot's next use clones them."""
221
+
222
+ def __init__(self, n, bodies, slots=1, tape=False, device="cuda", com_dr=False):
223
+ # (3a) was: sys.path.insert(0, str(ROOT / "tools" / "d16_binding"))
224
+ from diffneusim.engine import soft_engine as SE # noqa: E402
225
+ self.SE = SE
226
+ self.com_dr = bool(com_dr) # COMDR (tools/g1_seconds/COMDR_DESIGN.md): the deck-only macro build
227
+ self.ext, self.soft = SE.load_ext(True, comdr=self.com_dr)
228
+ self.n, self.slots, self.taped = int(n), int(slots), bool(tape)
229
+ K = int(self.ext.tail()[0])
230
+ cc = tuple(torch.cuda.get_device_capability(torch.device(device)))
231
+ self.parts = SE.TA if (n > K and cc not in SE.ROWS_ARCHS) else SE.ROWS # SoftEngine's production dispatch
232
+ f = lambda *s: torch.zeros(*s, dtype=torch.float32, device=device) # noqa: E731
233
+ i = lambda *s, dt=torch.int32: torch.zeros(*s, dtype=dt, device=device) # noqa: E731
234
+ hw, tw = int(self.ext.hand_words()), int(self.ext.tape_words())
235
+ self.bodies = torch.as_tensor(np.asarray(bodies, np.int32), device=device)
236
+ nbt = len(self.bodies)
237
+ self.w = dict(hand=f(n, hw), nefc=i(n), a_adv=f(n, NV), qfrc_c=f(0), LH=f(0), LQ=f(0), zone=i(0), niter=i(n), kflags=i(n),
238
+ nls=i(n), nfact=i(n), cycles=i(n, dt=torch.int64), flags=i(n), stats=i(n, SE.NSUB, 6), order=i(n), nbig=i(1))
239
+ S = self.slots
240
+ self.o = dict(oq=f(S, n, NQ), ov=f(S, n, NV), ow=f(S, n, NV), sq=f(n, NQ), sv=f(n, NV), sw=f(n, NV),
241
+ xpos=f(S, n, nbt, 3), xquat=f(S, n, nbt, 4), xvel=f(S, n, nbt, 3), xangvel=f(S, n, nbt, 3))
242
+ self.tape = f(S, n, SE.NSUB, tw) if tape else f(0)
243
+ self.foot = torch.zeros(S, n, dtype=torch.float64, device=device)
244
+ self.adj = dict(q_bar=f(n, NV), v_bar=f(n, NV), u_bar=f(n, NU), aflags=i(n)) if tape else None
245
+ self.empty = f(0)
246
+ # the fix (c), 11-11: the adjoint's per-world aflags (bit 0 kShellBadRecord: some substep's tape record overflowed, its VJP
247
+ # the identity of the forward's hold; bit 8 kRowsNoContact) accumulated ON THE DEVICE after every adjoint call (static tensors:
248
+ # capture-safe); read_aflags() returns and zeroes them, one host read per update, outside the clock
249
+ self.aflag_bad = torch.zeros((), dtype=torch.long, device=device)
250
+ self.aflag_or = torch.zeros((), dtype=torch.int32, device=device)
251
+ ab = [i for i, b in enumerate(self.soft.L["bodies"]) if b["name"].removeprefix("robot/") == ANCHOR]
252
+ assert len(ab) == 1, ab
253
+ self.anchor_body = ab[0]
254
+ self.anchor_ipos_offset = None
255
+ # the worlds' anchor CoM offsets [n, 3], one static tensor (written in place: capture-safe), passed to every step and adjoint
256
+ self.ipo = f(n, 3) if self.com_dr else None
257
+
258
+ def set_anchor_ipos_offset(self, off):
259
+ """COMDR: the anchor body's (ANCHOR) ipos += off[i] for world i of every later step and adjoint, set once after
260
+ construction; off [n, 3] (m), or None: nominal. A law built without com_dr=True refuses a nonzero offset."""
261
+ if off is None:
262
+ if self.com_dr:
263
+ self.ipo.zero_()
264
+ self.anchor_ipos_offset = None
265
+ return
266
+ assert off.dim() == 2 and tuple(off.shape) == (self.n, 3), tuple(off.shape)
267
+ if not self.com_dr:
268
+ assert not bool((off != 0).any()), "a nonzero anchor CoM offset on a law built without com_dr=True (the COMDR build)"
269
+ self.anchor_ipos_offset = off.detach().clone()
270
+ return
271
+ self.ipo.copy_(off.detach().to(self.ipo.dtype))
272
+ self.anchor_ipos_offset = off.detach().clone()
273
+
274
+ def step(self, slot, qpos, qvel, warm, ctrl, foot):
275
+ o, w = self.o, self.w
276
+ tape = self.tape[slot] if self.taped else self.empty
277
+ self.ext.control_step(qpos, qvel, warm, ctrl, foot, o["oq"][slot], o["ov"][slot], o["ow"][slot], o["sq"], o["sv"], o["sw"],
278
+ w["hand"], w["nefc"], w["a_adv"], w["qfrc_c"], w["LH"], w["LQ"], w["zone"], w["niter"], w["kflags"],
279
+ w["nls"], w["nfact"], w["cycles"], w["flags"], w["stats"], self.bodies, o["xpos"][slot],
280
+ o["xquat"][slot], o["xvel"][slot], o["xangvel"][slot], w["order"], w["nbig"], tape, self.SE.NSUB,
281
+ self.parts, *((self.ipo, self.anchor_body) if self.com_dr else ()))
282
+ if self.taped:
283
+ self.foot[slot].copy_(foot) # the adjoint reads the forward's friction in f64
284
+ return dict(qpos=o["oq"][slot], qvel=o["ov"][slot], warm=o["ow"][slot], xpos=o["xpos"][slot], xquat=o["xquat"][slot],
285
+ xvel=o["xvel"][slot], xangvel=o["xangvel"][slot])
286
+
287
+ def adjoint(self, slot, wq, wv, xpos_bar=None, xrot_bar=None, vb_bar=None, wb_bar=None):
288
+ """Step `slot`'s VJP: wq, wv [n, 35] (the output q's cotangent in its tangent), the output frames' cotangents [n, 32, 3]
289
+ (world frame, every law body). Returns views of shared buffers (q_bar [n, 35] tangent, v_bar, u_bar [n, 29] actuator
290
+ order, aflags): clone before the next adjoint."""
291
+ assert self.taped, "GpuLaw(tape=True) first"
292
+ a, e = self.adj, self.empty
293
+ self.ext.adjoint(self.tape[slot], self.o["oq"][slot], self.o["ov"][slot], wq, wv, self.foot[slot],
294
+ e if xpos_bar is None else xpos_bar, e if xrot_bar is None else xrot_bar, e if vb_bar is None else vb_bar,
295
+ e if wb_bar is None else wb_bar, a["q_bar"], a["v_bar"], a["u_bar"], a["aflags"], e, self.SE.NSUB,
296
+ *((self.ipo, self.anchor_body) if self.com_dr else ()))
297
+ return a
298
+
299
+ def frames(self, qpos, qvel):
300
+ """The tracked bodies' frames and world velocities at given states (no step), into buffers of their own."""
301
+ if not hasattr(self, "_fr"):
302
+ f = lambda *s: torch.zeros(*s, dtype=torch.float32, device=qpos.device) # noqa: E731
303
+ nbt = len(self.bodies)
304
+ self._fr = dict(xpos=f(self.n, nbt, 3), xquat=f(self.n, nbt, 4), xvel=f(self.n, nbt, 3), xangvel=f(self.n, nbt, 3))
305
+ r = self._fr
306
+ self.ext.frames(qpos, qvel, self.bodies, r["xpos"], r["xquat"], r["xvel"], r["xangvel"])
307
+ return dict(r)
308
+
309
+ def note_aflags(self):
310
+ """After an adjoint call: the worlds with kShellBadRecord counted and every aflags bit OR-ed, in place on the device."""
311
+ af = self.adj["aflags"]
312
+ self.aflag_bad += ((af & 1) != 0).sum()
313
+ bits = torch.stack([((af >> b) & 1).amax() << b for b in range(16)]).sum().to(self.aflag_or.dtype)
314
+ self.aflag_or.copy_(self.aflag_or | bits)
315
+
316
+ def read_aflags(self):
317
+ """(world-steps with kShellBadRecord, the OR of the aflags bits) since the last read; a host read, then both zeroed."""
318
+ v = (int(self.aflag_bad), int(self.aflag_or))
319
+ self.aflag_bad.zero_()
320
+ self.aflag_or.zero_()
321
+ return v
322
+
323
+ def flags(self):
324
+ """The OR of every world's flag word since the last zero_flags (a host sync: read once per iteration)."""
325
+ return int(np.bitwise_or.reduce(self.w["flags"].cpu().numpy()))
326
+
327
+ def zero_flags(self):
328
+ self.w["flags"].zero_()
329
+
330
+
331
+ # ---------------------------------------------------------------------------------------------- the task
332
+ def obs_phc(lm, tracked, xpos, xquat, xvel, xang, qpos, qvel, a_prev, ref):
333
+ """PHC-style observation in the sim root's heading frame H (yaw of the pelvis):
334
+ self: root height; tracked bodies' positions relative to the root, 6D rotations, linear and angular velocities (all in H);
335
+ joint positions and velocities
336
+ task: the next reference frame's tracked bodies: positions relative to the sim root, position errors, 6D of the reference
337
+ rotations and of the rotation errors, linear and angular velocity errors (all in H)
338
+ the previous action"""
339
+ root_p, root_q = xpos[:, :1], xquat[:, :1] # tracked[0] is the pelvis
340
+ H = yaw_quat(root_q).expand_as(xquat)
341
+ rel = lambda v: qrot_inv(H, v) # noqa: E731
342
+ n = xpos.shape[0]
343
+ rp, rq, rv, rw = ref
344
+ self_obs = [qpos[:, 2:3], rel(xpos - root_p).reshape(n, -1), quat_mat6(qmul(qconj(H), xquat)).reshape(n, -1),
345
+ rel(xvel).reshape(n, -1), rel(xang).reshape(n, -1), qpos[:, 7:], qvel[:, 6:]]
346
+ task_obs = [rel(rp - root_p).reshape(n, -1), rel(rp - xpos).reshape(n, -1), quat_mat6(qmul(qconj(H), rq)).reshape(n, -1),
347
+ quat_mat6(qmul(qconj(H), qmul(qmul(rq, qconj(xquat)), H))).reshape(n, -1), rel(rv - xvel).reshape(n, -1),
348
+ rel(rw - xang).reshape(n, -1)]
349
+ return torch.cat(self_obs + task_obs + [a_prev], -1)
350
+
351
+
352
+ class G1SoftTrack:
353
+ """One clip, n worlds. State lives here; the arms drive step() (values) or their own differentiable wrapper over the same parts."""
354
+
355
+ def __init__(self, backend, motion, lawmap, n, foot_friction=None, early_termination=True, device="cpu", dtype=torch.float64):
356
+ self.be, self.m, self.lm, self.n = backend, motion, lawmap, int(n)
357
+ self.dev, self.dt = device, dtype
358
+ self.tr = lawmap.ids(TRACKED)
359
+ assert list(np.asarray(backend.bodies.cpu() if torch.is_tensor(backend.bodies) else backend.bodies)) == self.tr, \
360
+ "the backend's frame bodies must be TRACKED in order"
361
+ self.i_anchor, self.i_ee = TRACKED.index(ANCHOR), [TRACKED.index(e) for e in EE]
362
+ # index and constant tensors on the device: a Python list index or a host constant inside step() is a host-to-device
363
+ # copy, which CUDA graph capture forbids (W1's G4 failed on it, 11-10)
364
+ self.tr_t = torch.tensor(self.tr, dtype=torch.long, device=device)
365
+ self.i_ee_t = torch.tensor(self.i_ee, dtype=torch.long, device=device)
366
+ self.g_down = torch.tensor([0.0, 0.0, -1.0], dtype=dtype, device=device)
367
+ self.early = bool(early_termination)
368
+ # in the engine's dtype: the GPU forward takes its friction in f32 (GpuLaw keeps the adjoint's f64 copy per slot)
369
+ self.foot = torch.full((n,), lawmap.train_foot_friction if foot_friction is None else float(foot_friction), dtype=dtype,
370
+ device=device)
371
+ z = lambda *s, dt=dtype: torch.zeros(*s, dtype=dt, device=device) # noqa: E731
372
+ self.qpos, self.qvel, self.warm = z(n, NQ), z(n, NV), z(n, NV)
373
+ self.t = torch.zeros(n, dtype=torch.long, device=device)
374
+ self.a_prev = z(n, NU)
375
+ self.et_timer = torch.zeros(n, dtype=torch.long, device=device)
376
+ self.half = lawmap.half_range.to(device=device, dtype=dtype)
377
+ self.lo, self.hi = lawmap.lo.to(device=device, dtype=dtype), lawmap.hi.to(device=device, dtype=dtype)
378
+ self.frames = None
379
+
380
+ # -- reference at frames f
381
+ def ref(self, f):
382
+ tr = self.tr_t
383
+ return (self.m.bpos[f][:, tr], self.m.bquat[f][:, tr], self.m.bvel[f][:, tr], self.m.bang[f][:, tr])
384
+
385
+ def reset(self, mask, frames, q_noise=None, qd_noise=None):
386
+ """Worlds under `mask` [n] bool start at the reference state of `frames` [n] (+ joint noise); others are untouched."""
387
+ qp, qv = self.m.state(frames)
388
+ if q_noise is not None:
389
+ qp = torch.cat([qp[:, :7], qp[:, 7:] + q_noise], -1)
390
+ if qd_noise is not None:
391
+ qv = torch.cat([qv[:, :6], qv[:, 6:] + qd_noise], -1)
392
+ mk = mask.view(-1, 1)
393
+ self.qpos = torch.where(mk, qp.to(self.dt), self.qpos)
394
+ self.qvel = torch.where(mk, qv.to(self.dt), self.qvel)
395
+ self.warm = torch.where(mk, torch.zeros_like(self.warm), self.warm)
396
+ self.a_prev = torch.where(mk, torch.zeros_like(self.a_prev), self.a_prev)
397
+ self.t = torch.where(mask, frames, self.t)
398
+ self.et_timer = torch.where(mask, torch.zeros_like(self.et_timer), self.et_timer)
399
+ self.frames = None
400
+
401
+ def setpoint(self, a):
402
+ """Residual PD: q_ref(t + 1) + half_range * a, clamped to the joint range."""
403
+ t1 = (self.t + 1).clamp_max(self.m.T - 1)
404
+ return torch.minimum(torch.maximum(self.m.joint_pos[t1].to(self.dt) + self.half * a, self.lo), self.hi)
405
+
406
+ def reward(self, fr, f):
407
+ rp, rq, rv, rw = self.ref(f)
408
+ nb3 = 3.0 * len(self.tr)
409
+ e_pos = (fr["xpos"] - rp).square().sum((1, 2)) / nb3
410
+ e_rot = quat_axis_angle(qmul(fr["xquat"], qconj(rq))).square().sum((1, 2)) / nb3
411
+ e_lin = (fr["xvel"] - rv).square().sum((1, 2)) / nb3
412
+ e_ang = (fr["xangvel"] - rw).square().sum((1, 2)) / nb3
413
+ E = REW_W["pos"] * e_pos + REW_W["rot"] * e_rot + REW_W["lin"] * e_lin + REW_W["ang"] * e_ang
414
+ return (1.0 / (1.0 + E)).clamp_min(1e-6), dict(e_pos=e_pos, e_rot=e_rot, e_lin=e_lin, e_ang=e_ang)
415
+
416
+ def fails(self, fr, f):
417
+ """BeyondMimic's G1 terminations at frames f: (anchor height, anchor orientation, end-effector height) masks [n]."""
418
+ rp, rq, _, _ = self.ref(f)
419
+ ia = self.i_anchor
420
+ g = self.g_down.to(fr["xpos"].dtype)
421
+ az = (fr["xpos"][:, ia, 2] - rp[:, ia, 2]).abs() > TERM_ANCHOR_Z
422
+ gs, gr = qrot_inv(fr["xquat"][:, ia], g.expand(self.n, 3)), qrot_inv(rq[:, ia], g.expand(self.n, 3))
423
+ ao = (gr[:, 2] - gs[:, 2]).abs() > TERM_ANCHOR_ORI
424
+ ee = (fr["xpos"][:, self.i_ee_t, 2] - rp[:, self.i_ee_t, 2]).abs().gt(TERM_EE_Z).any(1)
425
+ return az, ao, ee
426
+
427
+ def step(self, a, slot=0):
428
+ """One control step under action a [n, 29] (joint order, values only). Returns (obs-ready frames, reward, terminated,
429
+ time_out, info); the state advances to t + 1. Worlds stay where they are: the caller resets under a mask."""
430
+ ctrl = self.lm.ctrl(self.setpoint(a))
431
+ o = self.be.step(slot, self.qpos, self.qvel, self.warm, ctrl.to(self.qpos.dtype), self.foot)
432
+ self.t = (self.t + 1).clamp_max(self.m.T - 1)
433
+ fr = {k: o[k] for k in ("xpos", "xquat", "xvel", "xangvel")}
434
+ r, terms = self.reward(fr, self.t)
435
+ az, ao, ee = self.fails(fr, self.t)
436
+ term = az | ao | ee
437
+ if self.early:
438
+ self.et_timer = torch.where(r < ET_REWARD, self.et_timer + 1, torch.zeros_like(self.et_timer))
439
+ term = term | (self.et_timer >= ET_STEPS)
440
+ time_out = self.t >= self.m.T - 1
441
+ nonfinite = ~torch.isfinite(o["qpos"]).all(1) | ~torch.isfinite(o["qvel"]).all(1)
442
+ # copies, not the backend's slot buffers: a state that aliased them would be the next step's input AND output buffer
443
+ self.qpos, self.qvel, self.warm = o["qpos"].clone(), o["qvel"].clone(), o["warm"].clone()
444
+ self.a_prev = a
445
+ self.frames = fr
446
+ return fr, r, term | nonfinite, time_out, dict(anchor_z=az, anchor_ori=ao, ee_z=ee, nonfinite=nonfinite, **terms)
447
+
448
+ def observe(self):
449
+ fr = self.frames if self.frames is not None else self.be.frames(self.qpos, self.qvel)
450
+ t1 = (self.t + 1).clamp_max(self.m.T - 1)
451
+ return obs_phc(self.lm, self.tr, fr["xpos"], fr["xquat"], fr["xvel"], fr["xangvel"], self.qpos, self.qvel, self.a_prev,
452
+ self.ref(t1))
@@ -0,0 +1,145 @@
1
+ """Arm B's differentiable G1 control step (line 23): one torch.autograd.Function over g1_soft_env's backends.
2
+
3
+ Forward: the law's control step (values, and on the GPU the step's own tape slot). Backward: the step's VJP with the cotangents of
4
+ the next state AND of the tracked bodies' frames, so a reward computed on the engine's frames needs no FK of its own.
5
+
6
+ Conventions (tools/d16/soft_capi.py; core/soft/adj/out_adj.h; the reading of the extension, 11-10):
7
+ state tangent [root world translation 3, root body-frame rotation d 3, joints 29]: dquat = 0.5 quat (x) (0, d)
8
+ raw qpos cotangent g -> tangent: g_d = 0.5 Im(conj(quat) (x) g) (the transpose of that map)
9
+ tangent cotangent -> raw: g = 2 quat (x) (0, g_d) (zero along quat: no radial component)
10
+ frame rotation the adjoint's xrot_bar is the cotangent of a world-frame rotation theta: dq_b = 0.5 (0, theta) (x) q_b, so a raw
11
+ quaternion cotangent g maps to g_theta = 0.5 Im(g (x) conj(q_b))
12
+ ctrl the law's actuator order (g1_soft_env.LawMap.ctrl gathers it from the joint order, autograd carries the rest)
13
+ constants the warm start and the foot friction (no gradient), as the binding's adjoint
14
+ Backends: GpuLaw (production, per-slot tapes) and CpuJacLaw (the f64 CPU law's full step Jacobian from its batched JVP, small n:
15
+ the reference for the tests and for the GPU gate).
16
+ """
17
+ from __future__ import annotations
18
+
19
+ import numpy as np
20
+ import torch
21
+
22
+ from . import g1_soft_env as G
23
+
24
+
25
+ def _qm(a, b):
26
+ return G.qmul(a, b)
27
+
28
+
29
+ def quat_cot_raw_to_tangent(q, g):
30
+ """[n, 4] quaternion and its raw cotangent -> the body-frame rotation's cotangent [n, 3]."""
31
+ return 0.5 * _qm(G.qconj(q), g)[..., 1:]
32
+
33
+
34
+ def quat_cot_tangent_to_raw(q, gd):
35
+ z = torch.zeros_like(gd[..., :1])
36
+ return 2.0 * _qm(q, torch.cat([z, gd], -1))
37
+
38
+
39
+ def frame_quat_cot_to_theta(q, g):
40
+ """Raw cotangents of world-frame body quaternions [..., 4] -> world rotation cotangents [..., 3]."""
41
+ return 0.5 * _qm(g, G.qconj(q))[..., 1:]
42
+
43
+
44
+ def qpos_cot_to_tangent(qpos, g):
45
+ """Raw qpos cotangent [n, 36] -> tangent cotangent [n, 35]."""
46
+ return torch.cat([g[:, :3], quat_cot_raw_to_tangent(qpos[:, 3:7], g[:, 3:7]), g[:, 7:]], -1)
47
+
48
+
49
+ def tangent_cot_to_qpos(qpos, gt):
50
+ """Tangent cotangent [n, 35] -> raw qpos cotangent [n, 36] (zero along the root quaternion)."""
51
+ return torch.cat([gt[:, :3], quat_cot_tangent_to_raw(qpos[:, 3:7], gt[:, 3:6]), gt[:, 6:]], -1)
52
+
53
+
54
+ class CpuJacLaw:
55
+ """The f64 CPU law with each step's full Jacobian (99 input directions: the state tangent, the velocities, the actuators;
56
+ outputs: the next state's tangent at the output qpos, its velocities, and the tracked frames with raw quaternions), built from
57
+ the batched JVP, 4 directions per call. For tests and the GPU gate at small n only."""
58
+
59
+ def __init__(self, bodies, slots=1):
60
+ self.cpu = G.CpuLaw(bodies)
61
+ self.soft, self.bodies = self.cpu.soft, self.cpu.bodies
62
+ self.J = [None] * slots
63
+
64
+ def set_anchor_ipos_offset(self, off):
65
+ """COMDR: CpuLaw.set_anchor_ipos_offset on the shared CPU model (the JVP batch reads it as the step does)"""
66
+ self.cpu.set_anchor_ipos_offset(off)
67
+
68
+ @property
69
+ def anchor_ipos_offset(self):
70
+ return self.cpu.anchor_ipos_offset
71
+
72
+ def step(self, slot, qpos, qvel, warm, ctrl, foot):
73
+ S = self.soft
74
+ q, v, w, c = (x.detach().cpu().double().numpy() for x in (qpos, qvel, warm, ctrl))
75
+ f = foot.detach().cpu().double().numpy()
76
+ n, nv, nu, nb = q.shape[0], G.NV, G.NU, len(self.bodies)
77
+ D = 2 * nv + nu
78
+ eye = np.eye(D)
79
+ cols = []
80
+ for k in range(0, D, 4):
81
+ d = eye[k:k + 4]
82
+ nd = d.shape[0]
83
+ vq = np.broadcast_to(d[:, :nv], (n, nd, nv)).copy()
84
+ vv = np.broadcast_to(d[:, nv:2 * nv], (n, nd, nv)).copy()
85
+ vu = np.broadcast_to(d[:, 2 * nv:], (n, nd, nu)).copy()
86
+ o = S.control_step_jvp_batch(q, v, w, c, vq, vv, vu, f, bodies=self.bodies)
87
+ dq_t = np.stack([S.qpos_raw_to_tangent(o["qpos"][i], o["dq"][i]) for i in range(n)]) # [n, nd, 35]
88
+ cols.append(np.concatenate([dq_t, o["dv"], o["dxpos"].reshape(n, nd, -1), o["dxquat"].reshape(n, nd, -1),
89
+ o["dxvel"].reshape(n, nd, -1), o["dxangvel"].reshape(n, nd, -1)], -1))
90
+ last = o
91
+ self.J[slot] = np.concatenate(cols, 1) # [n, D in, outputs]
92
+ self.nb = nb
93
+ dev, dt = qpos.device, qpos.dtype
94
+ return {k: torch.as_tensor(last[k], dtype=dt, device=dev) for k in ("qpos", "qvel", "warm", "xpos", "xquat", "xvel", "xangvel")}
95
+
96
+ def frames(self, qpos, qvel):
97
+ return self.cpu.frames(qpos, qvel)
98
+
99
+ def vjp(self, slot, qpos_out, wq, wv, gxpos, gxquat_raw, gxvel, gxang, xquat_out):
100
+ n = wq.shape[0]
101
+ g = torch.cat([wq, wv, gxpos.reshape(n, -1), gxquat_raw.reshape(n, -1), gxvel.reshape(n, -1), gxang.reshape(n, -1)], -1)
102
+ Jt = torch.as_tensor(self.J[slot], dtype=torch.float64)
103
+ r = torch.einsum("nio,no->ni", Jt, g.detach().cpu().double()).to(wq)
104
+ nv = G.NV
105
+ return r[:, :nv], r[:, nv:2 * nv], r[:, 2 * nv:]
106
+
107
+
108
+ def gpu_vjp(law, slot, qpos_out, wq, wv, gxpos, gxquat_raw, gxvel, gxang, xquat_out):
109
+ """GpuLaw's adjoint with the frame cotangents scattered onto every law body (world frame) and the rotation converted."""
110
+ n, nb = wq.shape[0], law.ext_nb if hasattr(law, "ext_nb") else 32
111
+ idx = law.bodies.long()
112
+ full = lambda x: torch.zeros(n, nb, 3, dtype=x.dtype, device=x.device).index_copy_(1, idx, x) # noqa: E731
113
+ a = law.adjoint(slot, wq.contiguous(), wv.contiguous(), full(gxpos).contiguous(),
114
+ full(frame_quat_cot_to_theta(xquat_out, gxquat_raw)).contiguous(), full(gxvel).contiguous(),
115
+ full(gxang).contiguous())
116
+ law.note_aflags() # the fix (c): the overflowed-record count, on the device
117
+ return a["q_bar"].clone(), a["v_bar"].clone(), a["u_bar"].clone()
118
+
119
+
120
+ class StepFn(torch.autograd.Function):
121
+ """(qpos [n, 36], qvel [n, 35], ctrl [n, 29] actuator order) -> (qpos', qvel', warm', xpos, xquat, xvel, xangvel)."""
122
+
123
+ @staticmethod
124
+ def forward(ctx, qpos, qvel, ctrl, law, slot, warm, foot):
125
+ o = law.step(slot, qpos.detach(), qvel.detach(), warm.detach(), ctrl.detach(), foot)
126
+ outs = tuple(o[k].clone() for k in ("qpos", "qvel", "warm", "xpos", "xquat", "xvel", "xangvel"))
127
+ ctx.law, ctx.slot = law, slot
128
+ ctx.save_for_backward(qpos.detach(), outs[0], outs[4])
129
+ ctx.mark_non_differentiable(outs[2])
130
+ return outs
131
+
132
+ @staticmethod
133
+ def backward(ctx, gq, gv, gw, gxp, gxq, gxv, gxa):
134
+ q_in, q_out, xq_out = ctx.saved_tensors
135
+ law = ctx.law
136
+ wq = qpos_cot_to_tangent(q_out, gq)
137
+ if isinstance(law, CpuJacLaw):
138
+ qb, vb, ub = law.vjp(ctx.slot, q_out, wq, gv, gxp, gxq, gxv, gxa, xq_out)
139
+ else:
140
+ qb, vb, ub = gpu_vjp(law, ctx.slot, q_out, wq, gv, gxp, gxq, gxv, gxa, xq_out)
141
+ return tangent_cot_to_qpos(q_in, qb), vb, ub, None, None, None, None
142
+
143
+
144
+ def step(law, slot, qpos, qvel, ctrl, warm, foot):
145
+ return StepFn.apply(qpos, qvel, ctrl, law, slot, warm, foot)