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,572 @@
1
+ """A2 (tools/g1_seconds/PREREG_A2.md): InstantMimic's BeyondMimic side-kick task on our engine. The task terms are InstantMimic's own
2
+ code, the vendored third_party/instantmimic_947430ee/.../reference.py, called unchanged on our engine's states; this module is the
3
+ plumbing (docs/training/campaigns/g1/a2-env-interface.md, a2-beyondmimic-spec.md):
4
+ state the law's qpos / qvel / warm per world; frames of all 30 robot bodies (the 14 tracked ones are a subset)
5
+ action their default-pose targets: default + a * 0.25 effort / kp - encoder bias, policy order = our joint order
6
+ obs their assemble_actor_observation (160, with their uniform noise) / assemble_critic_observation (286); the IMU is the
7
+ pelvis site imu_in_pelvis (mjlab g1.xml:69, no site rotation): velocimeter = R_p^T (v_p + w x R_p r), gyro = R_p^T w
8
+ reward their compute_reward; the self_collision term reads a STRICTER substitute (the review, the design's no-advantage rule): any
9
+ penetration of a robot-robot pair among the law's 469 (capsules and spheres, from the frames) counts as all 4 substeps
10
+ over their 10 N threshold
11
+ dones their compute_terminations (anchor height, anchor orientation, end-effector height) or a non-finite state; 500-step time-out
12
+ reset their perturb_reference_state with their ranges; start frames by their adaptive sampler (failure_bins, EMA, overwrite
13
+ semantics, sampling_probabilities) or "start"; the step order is theirs (direct_rl_env.step + _reset_idx every step:
14
+ time + 1, the motion-end rewrite, the target realignment from the pre-physics anchor, the EMA, then the pushes)
15
+ DR (ship) foot friction U(0.3, 1.2) per world, encoder bias U(+-0.01) per joint, pushes every U(1, 3) s; the torso CoM draw is
16
+ ABSENT unless com_dr (labelled "favours us" wherever an A2 / A3 ship run without it is reported); com_dr draws theirs
17
+ once per world from a dedicated generator and hands it to the law (law.set_anchor_ipos_offset, the engine piece)
18
+ A3 (differentiable=True, horizon=H; the review / the design brief 11-10: our side trains with SAPO through the engine's gradient): the step is
19
+ g1_soft_grad.StepFn on tape slot t (t = steps since detach_state(), t < H), so the action, the next state and the 30 bodies' frames
20
+ carry gradient into their observation and reward functions unchanged. Pushes are additive on qvel (v + dv, in the graph); the DR draws
21
+ and the observation noise are constants; reset worlds take a constant reference state by torch.where (cut, as SAPO's windows); the
22
+ frame refresh gives every world the FK frames' values, exactly as A2's full refresh, and the worlds not rewritten carry the step's own
23
+ frames' gradient through a zero-valued straight-through term (fk + (x - x.detach())), so the forward is A2's bit for bit even where the
24
+ device's step frames and its FK differ in the last bit (the A3 gate's A1 failed on 11-11 with the step's frames used as values). The
25
+ self-contact substitute and the terminations are piecewise constant (no gradient)."""
26
+ from __future__ import annotations
27
+
28
+ import pathlib
29
+ import re
30
+ import sys
31
+
32
+ import torch
33
+
34
+ from . import g1_soft_env as G
35
+ from . import g1_soft_grad as D
36
+
37
+ V = pathlib.Path(__file__).resolve().parents[1] / "third_party" / "instantmimic_947430ee"
38
+ if str(V) not in sys.path:
39
+ sys.path.insert(0, str(V))
40
+ from instantmimic.envs.unitree_g1.tasks.beyondmimic_tracking import reference as R # noqa: E402
41
+ from instantmimic.motion import quaternion as Q # noqa: E402
42
+
43
+ ROBOT_BODIES = tuple(range(2, 32)) # the law's robot bodies (0 world, 1 terrain)
44
+ IMU_SITE = (0.04525, 0.0, -0.08339) # mjlab 15ebce88 g1.xml:69, in the pelvis frame
45
+ KNEES_BENT = {r".*_hip_pitch_joint": -0.312, r".*_knee_joint": 0.669, r".*_ankle_pitch_joint": -0.363, r".*_elbow_joint": 0.6,
46
+ r"left_shoulder_roll_joint": 0.2, r"left_shoulder_pitch_joint": 0.2, r"right_shoulder_roll_joint": -0.2,
47
+ r"right_shoulder_pitch_joint": 0.2} # mjlab g1_constants.py:198-211
48
+ RESET = dict(position=((-0.05, 0.05), (-0.05, 0.05), (-0.01, 0.01)), euler=((-0.1, 0.1), (-0.1, 0.1), (-0.2, 0.2)),
49
+ velocity=((-0.5, 0.5), (-0.5, 0.5), (-0.2, 0.2), (-0.52, 0.52), (-0.52, 0.52), (-0.78, 0.78)), joint=(-0.1, 0.1))
50
+ OBS_NOISE = dict(anchor_position=0.25, anchor_orientation=0.05, base_linear_velocity=0.5, base_angular_velocity=0.2,
51
+ joint_position=0.01, joint_velocity=0.5) # constants.py:114-121
52
+ PUSH_INTERVAL, PUSH_VEL = (1.0, 3.0), RESET["velocity"] # base.yaml push ranges = the reset velocity ranges
53
+ COM_RANGE = ((-0.025, 0.025), (-0.05, 0.05), (-0.05, 0.05)) # base.yaml:68-71 torso_com_offset_range (x, y, z), m
54
+ SAMPLER = dict(uniform_ratio=0.1, kernel_size=1, adaptive_lambda=0.8, alpha=0.001)
55
+
56
+
57
+ def _u(shape, lo, hi, device, dtype):
58
+ return lo + (hi - lo) * torch.rand(shape, device=device, dtype=dtype)
59
+
60
+
61
+ def _ranges(rs, n, device, dtype):
62
+ return torch.cat([_u((n, 1), lo, hi, device, dtype) for lo, hi in rs], -1)
63
+
64
+
65
+ def _seg_dist(p1, q1, p2, q2, eps=1e-12):
66
+ """Closest distance between segments [p1, q1] and [p2, q2] (batched; a degenerate segment is a point)."""
67
+ d1, d2, r = q1 - p1, q2 - p2, p1 - p2
68
+ a, e, f = (d1 * d1).sum(-1), (d2 * d2).sum(-1), (d2 * r).sum(-1)
69
+ c, b = (d1 * r).sum(-1), (d1 * d2).sum(-1)
70
+ den = a * e - b * b
71
+ s = torch.where(den > eps, ((b * f - c * e) / den.clamp_min(eps)).clamp(0.0, 1.0), torch.zeros_like(a))
72
+ t = torch.where(e > eps, (b * s + f) / e.clamp_min(eps), torch.zeros_like(a))
73
+ s = torch.where(t < 0.0, torch.where(a > eps, (-c / a.clamp_min(eps)).clamp(0.0, 1.0), torch.zeros_like(a)), s)
74
+ s = torch.where(t > 1.0, torch.where(a > eps, ((b - c) / a.clamp_min(eps)).clamp(0.0, 1.0), torch.zeros_like(a)), s)
75
+ t = t.clamp(0.0, 1.0)
76
+ return ((p1 + d1 * s[..., None]) - (p2 + d2 * t[..., None])).norm(dim=-1)
77
+
78
+
79
+ class BMTrack:
80
+ actor_obs_dim, critic_obs_dim, act_dim = R.ACTOR_OBSERVATION_DIM, R.CRITIC_OBSERVATION_DIM, R.ACTION_DIM
81
+ step_duration = 0.02
82
+ benchmark_end_effector_indices = tuple(G.TRACKED.index(e) for e in G.EE)
83
+
84
+ def __init__(self, backend, motion, lawmap, n, *, ship, device, dtype, seed, obs_noise=True, reset_noise=True, pushes=None,
85
+ sampling="adaptive", episode_steps=500, differentiable=False, horizon=1, overflow_done=False, com_dr=False, com_scale=1.0,
86
+ residual=False, compile=False, audit=False, plain_eager=False):
87
+ assert sampling in ("adaptive", "start"), sampling
88
+ # the compiled path (the unification, the review / the design brief 11-11: one env, the speed-up in the shared path): compile=True
89
+ # runs THIS step with its post-engine half as one torch.compile region on an RNG draw tape (g1_bm_fused.compile_env). The tape
90
+ # state lives here, before any draw (the constructor's own draws pass through _rand with no tape).
91
+ self._tape, self._ti, self._rec, self._spec, self._specs, self._post_c = None, 0, None, None, {}, None
92
+ assert not (plain_eager and not compile), "plain_eager is the compiled path's eager middle arm (compile=True)"
93
+ self.plain_eager = bool(plain_eager)
94
+ self.compiled = bool(compile) and not self.plain_eager # torch.compile in use (plain_eager: the plain modules, run eagerly)
95
+ self._compile_path = bool(compile)
96
+ # overflow-as-done (the docs/design/overflow-as-done.md, the review's ruling 11-11): a world whose engine step overflowed (the row cap,
97
+ # kFlagOverflow 1, or an L2 capacity, kFlagHandOverflow 256) is TRUNCATED at that step, never terminated, and reset at once; its
98
+ # terminal observation is the held state's. Default off: every existing caller is unchanged. Their scorer's success is
99
+ # truncated & ~terminated, so an overflow would score as a success: a scorer env (sampling "start") must keep it off.
100
+ assert not (overflow_done and sampling == "start"), "overflow_done in a scorer env (sampling 'start') would score overflows as successes"
101
+ self.overflow_done = bool(overflow_done)
102
+ # R-G1 (the review / the design brief, 11-11): residual actions, A1c's design (NablaMimic's recipe). The PD target is the reference joint pose
103
+ # of the frame this step's reward compares against (their pre-step command frame, self.time) + the action x THEIR action scale
104
+ # - the encoder bias: their default_relative_action_targets with the default pose replaced by that reference pose, so the
105
+ # learners' flags (action box, scale) carry over and residual is the only change. Under G1SoftTrack's alignment (its reward
106
+ # compares against the advanced frame) the same frame is A1c's q_ref(t + 1). Off by default; one place: _engine_step, which the
107
+ # compiled path shares (the unification). A subclass with its own step (other code) would bypass it, so it is refused.
108
+ self.residual = bool(residual)
109
+ assert not (self.residual and getattr(type(self).step, "__code__", None) is not BMTrack.step.__code__), \
110
+ f"{type(self).__name__} has its own step: the residual option lives in BMTrack.step / _engine_step"
111
+ self.differentiable, self.horizon, self.slot = bool(differentiable), int(horizon), 0
112
+ assert self.horizon >= 1 and (self.differentiable or self.horizon == 1), (differentiable, horizon)
113
+ if self.differentiable:
114
+ assert isinstance(backend, D.CpuJacLaw) or getattr(backend, "taped", False), "A3 needs CpuJacLaw or GpuLaw(tape=True)"
115
+ assert (len(backend.J) if isinstance(backend, D.CpuJacLaw) else backend.slots) >= self.horizon, "fewer slots than H"
116
+ assert tuple(int(b) for b in (backend.bodies.tolist() if torch.is_tensor(backend.bodies) else backend.bodies)) == ROBOT_BODIES
117
+ torch.manual_seed(int(seed))
118
+ self.be, self.m, self.lm, self.n, self.dev, self.dt = backend, motion, lawmap, int(n), device, dtype
119
+ self.ship, self.obs_noise, self.reset_noise = bool(ship), bool(obs_noise), bool(reset_noise)
120
+ self.pushes = self.ship if pushes is None else bool(pushes)
121
+ self.sampling, self.episode_steps, self.T = sampling, int(episode_steps), int(motion.T)
122
+ # the engine's flag word per world, OR-ed over every substep and step since read_overflow() (the env zeroes the engine's word
123
+ # after each step), and the overflowed world-steps: static device tensors (in STATE: snapshot, restore, capture)
124
+ self.ovf_or_w = torch.zeros(self.n, dtype=torch.int32, device=device)
125
+ self.ovf_world_steps = torch.zeros((), dtype=torch.int64, device=device)
126
+ self._zero_fl = torch.zeros(self.n, dtype=torch.int32, device=device) # the CPU laws' flag word (they have none)
127
+ self._inj = None # _inject_flags: OR-ed into the next step's word
128
+ self.last_overflow_worlds = (0, 0)
129
+ f = lambda x: torch.as_tensor(x, dtype=dtype, device=device) # noqa: E731
130
+ L = lawmap.L
131
+ self.tr_law = torch.tensor(lawmap.ids(G.TRACKED), dtype=torch.long, device=device) # motion rows (law body ids)
132
+ self.tr_fr = self.tr_law - ROBOT_BODIES[0] # rows of the frames buffers
133
+ self.ia = G.TRACKED.index(G.ANCHOR)
134
+ self.ee = torch.tensor(self.benchmark_end_effector_indices, dtype=torch.long, device=device)
135
+ self.pelvis_fr = lawmap.body["pelvis"] - ROBOT_BODIES[0]
136
+ assert G.TRACKED[0] == "pelvis"
137
+ # their default pose, action scale and soft limits, in the policy (= our joint) order
138
+ self.q_default = f([next((v for pat, v in KNEES_BENT.items() if re.fullmatch(pat, j)), 0.0) for j in lawmap.joints])
139
+ act = {a["dof"]: a for a in L["actuators"]}
140
+ self.action_scale = f([0.25 * act[6 + i]["forcerange"][1] / act[6 + i]["kp"] for i in range(G.NU)])
141
+ self.kp = f([act[6 + i]["kp"] for i in range(G.NU)]) # the trainer's action range (A3) reads these
142
+ self.effort = f([act[6 + i]["forcerange"][1] for i in range(G.NU)])
143
+ assert all(act[6 + i]["forcelimited"] and act[6 + i]["forcerange"][0] == -act[6 + i]["forcerange"][1] for i in range(G.NU))
144
+ lo, hi = lawmap.lo.to(device=device, dtype=dtype), lawmap.hi.to(device=device, dtype=dtype)
145
+ self.joint_range = torch.stack([lo, hi], -1) # the hard limits [29, 2] (soft_lo / hi: 0.9)
146
+ c, e = 0.5 * (lo + hi), hi - lo
147
+ self.soft_lo, self.soft_hi = c - 0.45 * e, c + 0.45 * e
148
+ self.imu = f(IMU_SITE).expand(self.n, 3)
149
+ self.zero_qd = torch.zeros(self.n, G.NU, dtype=dtype, device=device)
150
+ self.down = f([0.0, 0.0, -1.0]).expand(self.n, 3)
151
+ # the self-contact substitute: the law's robot-robot pairs over capsules (type 3) and spheres (type 2)
152
+ geoms = {g["id"]: g for g in L["geoms"]}
153
+ pairs = [(p["g1"], p["g2"]) for p in L["pairs"] if geoms[p["g1"]]["body"] >= 2 and geoms[p["g2"]]["body"] >= 2]
154
+ assert len(pairs) == 469 and all(geoms[i]["type"] in (2, 3) for pr in pairs for i in pr), len(pairs)
155
+ gid = sorted({i for pr in pairs for i in pr})
156
+ col = {g: k for k, g in enumerate(gid)}
157
+ self.g_body = torch.tensor([geoms[g]["body"] - ROBOT_BODIES[0] for g in gid], dtype=torch.long, device=device)
158
+ self.g_pos = f([geoms[g]["pos"] for g in gid])
159
+ self.g_axis = Q.quat_rotate(f([geoms[g]["quat"] for g in gid]), f([[0.0, 0.0, 1.0]] * len(gid)))
160
+ self.g_half = f([geoms[g]["size"][1] if geoms[g]["type"] == 3 else 0.0 for g in gid])
161
+ self.g_rad = f([geoms[g]["size"][0] for g in gid])
162
+ self.pair_a = torch.tensor([col[a] for a, _ in pairs], dtype=torch.long, device=device)
163
+ self.pair_b = torch.tensor([col[b] for _, b in pairs], dtype=torch.long, device=device)
164
+ # DR, drawn once at construction (ship), as their env does
165
+ if self.ship:
166
+ self.foot = self._uni((self.n,), 0.3, 1.2)
167
+ self.encoder_bias = self._uni((self.n, G.NU), -0.01, 0.01)
168
+ else:
169
+ self.foot = torch.full((self.n,), float(lawmap.train_foot_friction), dtype=dtype, device=device)
170
+ self.encoder_bias = torch.zeros(self.n, G.NU, dtype=dtype, device=device)
171
+ self.push_timer = self._uni((self.n,), *PUSH_INTERVAL)
172
+ # InstantMimic's torso CoM draw (the review, 11-11; base.yaml:68-71 torso_com_offset_range; their _apply_startup_randomization,
173
+ # beyondmimic_tracking_env.py:370-399): body_ipos[torso_link] += (U(-0.025, 0.025), U(-0.05, 0.05), U(-0.05, 0.05)) m per world,
174
+ # ONCE at construction (as their friction and encoder bias; ours too), mass, inertia and iquat unchanged. Opt-in (com_dr) and
175
+ # drawn from a DEDICATED generator seeded with the env's seed, so the global stream, and so every other draw of the run, is a
176
+ # com_dr-off run's. The law applies it in its step, frames, tape and adjoint (the per-world anchor ipos, deck-only).
177
+ self.com_dr, self.com_offset = bool(com_dr), None
178
+ if self.com_dr:
179
+ assert self.ship, "the torso CoM draw is part of the ship DR"
180
+ g = torch.Generator(device="cpu").manual_seed(int(seed))
181
+ off = torch.stack([lo + (hi - lo) * torch.rand(self.n, generator=g, dtype=torch.float64) for lo, hi in COM_RANGE], -1)
182
+ off = off * float(com_scale) # a gate's knob only: 0 must reproduce a com_dr-off run bitwise
183
+ self.com_offset = off.to(device, dtype)
184
+ assert callable(getattr(backend, "set_anchor_ipos_offset", None)), "this law takes no per-world anchor CoM offset"
185
+ backend.set_anchor_ipos_offset(self.com_offset)
186
+ z = lambda *s: torch.zeros(*s, dtype=dtype, device=device) # noqa: E731
187
+ self.qpos, self.qvel, self.warm = z(self.n, G.NQ), z(self.n, G.NV), z(self.n, G.NV)
188
+ self.time = torch.zeros(self.n, dtype=torch.long, device=device)
189
+ self.length = torch.zeros(self.n, dtype=torch.long, device=device)
190
+ self.action, self.prev_action = z(self.n, G.NU), z(self.n, G.NU)
191
+ self.target_pos, self.target_quat = z(self.n, len(G.TRACKED), 3), z(self.n, len(G.TRACKED), 4)
192
+ self.reset_terminated = torch.zeros(self.n, dtype=torch.bool, device=device)
193
+ self.sampler = R.AdaptiveSamplerState.create(motion_frame_count=self.T, sampling_fps=1.0 / self.step_duration,
194
+ device=device, dtype=dtype)
195
+ self.bin_ids = torch.arange(self.sampler.bin_count, device=device)
196
+ self.frames = None
197
+ self.initial_reset_done = False
198
+ if self._compile_path:
199
+ from . import g1_bm_fused as F
200
+ F.compile_env(self, audit=audit)
201
+
202
+ # ------------------------------------------------------------------ the one random source, and the draw tape of the compiled path
203
+ def _rand(self, shape):
204
+ """EVERY random draw of the env goes through here, in a fixed order per step. No tape (the eager step): torch.rand on the
205
+ default generator (and the shape recorded while _record_spec records). A tape (the compiled step, g1_bm_fused): the next
206
+ pre-drawn tensor, its shape checked against the recorded draw sequence (a static check at trace time)."""
207
+ tape = self._tape
208
+ if tape is not None:
209
+ shape = tuple(int(x) for x in shape) if isinstance(shape, (tuple, list)) else (int(shape),)
210
+ i = self._ti
211
+ assert i < len(tape) and self._spec[i] == shape, ("the tape does not match the step's draws", i, shape, self._spec)
212
+ self._ti = i + 1
213
+ return tape[i]
214
+ r = torch.rand(shape, device=self.dev, dtype=self.dt)
215
+ if self._rec is not None:
216
+ self._rec.append(tuple(int(x) for x in shape) if isinstance(shape, (tuple, list)) else (int(shape),))
217
+ return r
218
+
219
+ def _uni(self, shape, lo, hi):
220
+ return lo + (hi - lo) * self._rand(shape)
221
+
222
+ def _ranges(self, rs):
223
+ return torch.cat([self._uni((self.n, 1), lo, hi) for lo, hi in rs], -1)
224
+
225
+ # ------------------------------------------------------------------ reference and frames
226
+ def _ref(self, k):
227
+ tr = self.tr_law
228
+ return self.m.bpos[k][:, tr], self.m.bquat[k][:, tr], self.m.bvel[k][:, tr], self.m.bang[k][:, tr]
229
+
230
+ def _fk(self, qpos, qvel):
231
+ """the backend's FK of a state (frames dict); the compiled path replaces it by an opaque custom op over the same call"""
232
+ return self.be.frames(qpos, qvel)
233
+
234
+ def _refresh_frames(self, mask=None):
235
+ fk = self._fk(self.qpos.detach(), self.qvel.detach())
236
+ if not self.differentiable or self.frames is None or mask is None:
237
+ self.frames = {k: v.clone() for k, v in fk.items()}
238
+ return
239
+ # A3: every world takes the FK frames' VALUES, as A2's full refresh (fk + (x - x) is fk exactly), and the worlds not rewritten
240
+ # carry the gradient of the step's own frames (the same function of the state: the step returns its output state's FK), so the
241
+ # forward is A2's bit for bit whatever the device's step frames round to; the rewritten worlds take fk as a constant (the cut)
242
+ mk = mask.view(-1, 1, 1)
243
+ self.frames = {k: torch.where(mk, fk[k], fk[k] + (self.frames[k] - self.frames[k].detach())) for k in fk}
244
+
245
+ def _tracked(self):
246
+ fr = self.frames
247
+ return {k: fr[k][:, self.tr_fr] for k in ("xpos", "xquat", "xvel", "xangvel")}
248
+
249
+ # ------------------------------------------------------------------ reset path (theirs)
250
+ def _sample_frames(self, mask):
251
+ if self.sampling == "start":
252
+ self.time = torch.where(mask, torch.zeros_like(self.time), self.time)
253
+ return
254
+ # capture-safe (no host sync): their overwrite of the failure counts as a fixed-size one-hot sum under a device-side "any",
255
+ # their probabilities without the host constant (kernel_size 1: the conv is the identity; tested equal to theirs), and the
256
+ # bin drawn by inverting the CDF, as their Warp hot path does (ok.py:627-688), instead of torch.multinomial: the same law,
257
+ # a different stream
258
+ B = self.sampler.bin_count
259
+ failed = self.reset_terminated & mask
260
+ hit = R.failure_bins(self.time, self.T, B)[:, None] == self.bin_ids[None] # one-hot without F.one_hot's host check
261
+ counts = (hit & failed[:, None]).sum(0).to(self.dt)
262
+ self.sampler.current_bin_failed.copy_(torch.where(failed.any(), counts, self.sampler.current_bin_failed))
263
+ p = self.sampling_probabilities()
264
+ cdf = torch.cumsum(p, 0)
265
+ u = self._rand((self.n,)) * cdf[-1]
266
+ bins = torch.searchsorted(cdf, u, right=True).clamp_max(B - 1)
267
+ within = self._rand((self.n,))
268
+ frames = ((bins + within) / self.sampler.bin_count * (self.T - 1)).to(torch.long)
269
+ self.time = torch.where(mask, frames, self.time)
270
+
271
+ def sampling_probabilities(self):
272
+ """Their sampling_probabilities at kernel_size 1 (the kernel is [lambda ** 0] = [1], so the conv is the identity), with no host
273
+ constant: (failed + uniform_ratio / B) normalised."""
274
+ assert SAMPLER["kernel_size"] == 1
275
+ q = self.sampler.bin_failed_count + SAMPLER["uniform_ratio"] / float(self.sampler.bin_count)
276
+ return q / q.sum()
277
+
278
+ def _write_reference_state(self, mask):
279
+ k, pel = self.time, self.m.pelvis
280
+ z3 = lambda: torch.zeros(self.n, 3, dtype=self.dt, device=self.dev) # noqa: E731
281
+ on = self.reset_noise
282
+ st = R.perturb_reference_state(
283
+ reference_root_position=self.m.bpos[k, pel], reference_root_quaternion=self.m.bquat[k, pel],
284
+ reference_root_linear_velocity=self.m.bvel[k, pel], reference_root_angular_velocity=self.m.bang[k, pel],
285
+ reference_joint_position=self.m.joint_pos[k], reference_joint_velocity=self.m.joint_vel[k],
286
+ position_delta=self._ranges(RESET["position"]) if on else z3(),
287
+ euler_delta=self._ranges(RESET["euler"]) if on else z3(),
288
+ root_velocity_delta=self._ranges(RESET["velocity"]) if on else torch.cat([z3(), z3()], -1),
289
+ joint_position_delta=self._uni((self.n, G.NU), *RESET["joint"]) if on else self.zero_qd,
290
+ joint_lower=self.soft_lo, joint_upper=self.soft_hi)
291
+ qp = torch.cat([st.root_position, st.root_quaternion, st.joint_position], -1)
292
+ qv = torch.cat([st.root_linear_velocity_world, st.root_angular_velocity_body, st.joint_velocity], -1)
293
+ mk = mask.view(-1, 1)
294
+ self.qpos = torch.where(mk, qp, self.qpos)
295
+ self.qvel = torch.where(mk, qv, self.qvel)
296
+ self.warm = torch.where(mk, torch.zeros_like(self.warm), self.warm)
297
+
298
+ def _update_command(self):
299
+ self.time = self.time + 1
300
+ end = self.time >= self.T # the motion-end rewrite: no episode end, actions kept (masked, every
301
+ self._sample_frames(end) # step: capture-safe, the same result as a branch on end.any())
302
+ self._write_reference_state(end)
303
+ self._refresh_frames(end)
304
+ rp, rq, _, _ = self._ref(self.time)
305
+ tf = self._tracked()
306
+ self.target_pos, self.target_quat = R.motion_relative_to_robot_anchor(
307
+ robot_anchor_position=tf["xpos"][:, self.ia], robot_anchor_quaternion=tf["xquat"][:, self.ia],
308
+ reference_anchor_position=rp[:, self.ia], reference_anchor_quaternion=rq[:, self.ia],
309
+ reference_body_position=rp, reference_body_quaternion=rq)
310
+ if self.sampling == "adaptive":
311
+ self.sampler.bin_failed_count.copy_(R.update_failure_ema(self.sampler.bin_failed_count, self.sampler.current_bin_failed,
312
+ alpha=SAMPLER["alpha"]))
313
+ self.sampler.current_bin_failed.zero_()
314
+
315
+ def _apply_pushes(self):
316
+ self.push_timer = self.push_timer - self.step_duration
317
+ fire = self.push_timer < 1e-6
318
+ self.push_timer = torch.where(fire, self._uni((self.n,), *PUSH_INTERVAL), self.push_timer)
319
+ dv = self._ranges(PUSH_VEL)
320
+ q = self.qpos[:, 3:7]
321
+ lin = self.qvel[:, :3] + dv[:, :3]
322
+ ang_body = Q.quat_rotate_inverse(q, Q.quat_rotate(q, self.qvel[:, 3:6]) + dv[:, 3:])
323
+ mk = fire.view(-1, 1)
324
+ self.qvel = torch.cat([torch.where(mk, lin, self.qvel[:, :3]), torch.where(mk, ang_body, self.qvel[:, 3:6]), self.qvel[:, 6:]], -1)
325
+
326
+ def _reset_worlds(self, mask):
327
+ self._sample_frames(mask)
328
+ self._write_reference_state(mask)
329
+ mk = mask.view(-1, 1)
330
+ self.action = torch.where(mk, torch.zeros_like(self.action), self.action)
331
+ self.prev_action = torch.where(mk, torch.zeros_like(self.prev_action), self.prev_action)
332
+ self.length = torch.where(mask, torch.zeros_like(self.length), self.length)
333
+ self._refresh_frames(mask)
334
+
335
+ # ------------------------------------------------------------------ observations (their assemble_* functions)
336
+ def _imu(self, tf):
337
+ q, v, w = tf["xquat"][:, 0], tf["xvel"][:, 0], tf["xangvel"][:, 0]
338
+ v_site = v + torch.cross(w, Q.quat_rotate(q, self.imu), dim=-1)
339
+ return Q.quat_rotate_inverse(q, v_site), Q.quat_rotate_inverse(q, w)
340
+
341
+ def _observe(self):
342
+ k = self.time
343
+ rp, rq, _, _ = self._ref(k)
344
+ tf = self._tracked()
345
+ pa, qa = tf["xpos"][:, self.ia], tf["xquat"][:, self.ia]
346
+ command = torch.cat([self.m.joint_pos[k], self.m.joint_vel[k]], -1)
347
+ anchor_pos = Q.quat_rotate_inverse(qa, rp[:, self.ia] - pa)
348
+ anchor_ori = Q.quat_to_matrix(Q.quat_mul(Q.quat_inverse(qa), rq[:, self.ia]))[..., :2].reshape(self.n, 6)
349
+ lin, ang = self._imu(tf)
350
+ qj, qdj = self.qpos[:, 7:], self.qvel[:, 6:]
351
+ noise = None
352
+ if self.obs_noise:
353
+ u = lambda w, h: self._uni((self.n, w), -h, h) # noqa: E731
354
+ noise = R.ObservationNoise(anchor_position=u(3, OBS_NOISE["anchor_position"]), anchor_orientation=u(6, OBS_NOISE["anchor_orientation"]),
355
+ base_linear_velocity=u(3, OBS_NOISE["base_linear_velocity"]),
356
+ base_angular_velocity=u(3, OBS_NOISE["base_angular_velocity"]),
357
+ joint_position=u(G.NU, OBS_NOISE["joint_position"]), joint_velocity=u(G.NU, OBS_NOISE["joint_velocity"]))
358
+ actor = R.assemble_actor_observation(command=command, anchor_position=anchor_pos, anchor_orientation=anchor_ori,
359
+ base_linear_velocity=lin, base_angular_velocity=ang, joint_position=qj + self.encoder_bias,
360
+ default_joint_position=self.q_default.expand(self.n, G.NU), joint_velocity=qdj,
361
+ default_joint_velocity=self.zero_qd, action=self.action, noise=noise)
362
+ qa_e = qa[:, None].expand_as(tf["xquat"])
363
+ body_pos = Q.quat_rotate_inverse(qa_e, tf["xpos"] - pa[:, None]).reshape(self.n, -1)
364
+ body_ori = Q.quat_to_matrix(Q.quat_mul(Q.quat_inverse(qa_e), tf["xquat"]))[..., :2].reshape(self.n, -1)
365
+ critic = R.assemble_critic_observation(command=command, anchor_position=anchor_pos, anchor_orientation=anchor_ori,
366
+ body_position=body_pos, body_orientation=body_ori, base_linear_velocity=lin,
367
+ base_angular_velocity=ang, joint_position=qj,
368
+ default_joint_position=self.q_default.expand(self.n, G.NU), joint_velocity=qdj,
369
+ default_joint_velocity=self.zero_qd, action=self.action)
370
+ return dict(actor=actor, critic=critic)
371
+
372
+ # ------------------------------------------------------------------ the self-contact substitute
373
+ def self_contact(self):
374
+ """[n] bool: any robot-robot pair (the law's 469) penetrating at the current frames."""
375
+ fr = self.frames
376
+ p = fr["xpos"][:, self.g_body]
377
+ q = fr["xquat"][:, self.g_body]
378
+ c = p + Q.quat_rotate(q, self.g_pos.expand_as(p))
379
+ ax = Q.quat_rotate(q, self.g_axis.expand_as(p)) * self.g_half[None, :, None]
380
+ lo, hi = c - ax, c + ax
381
+ d = _seg_dist(lo[:, self.pair_a], hi[:, self.pair_a], lo[:, self.pair_b], hi[:, self.pair_b])
382
+ return (d - self.g_rad[self.pair_a] - self.g_rad[self.pair_b] < 0.0).any(-1)
383
+
384
+ # ------------------------------------------------------------------ the interface
385
+ def reset_all(self):
386
+ allw = torch.ones(self.n, dtype=torch.bool, device=self.dev)
387
+ self.reset_terminated.zero_()
388
+ self.time = torch.zeros_like(self.time)
389
+ self._reset_worlds(allw)
390
+ self._update_command()
391
+ self.initial_reset_done = True
392
+ return self._observe()
393
+
394
+ def step(self, action):
395
+ """One control step: _engine_step (the action, the engine and its flag word; always eager) then _post (the task code). With
396
+ compile=True the post half runs as one torch.compile region on the step's RNG draw tape (g1_bm_fused.post_compiled); every env
397
+ path (eager, compiled, a subclass) is this one step."""
398
+ args = self._engine_step(action)
399
+ if self._post_c is None:
400
+ return self._post(*args)
401
+ from . import g1_bm_fused as F
402
+ return F.post_compiled(self, args)
403
+
404
+ def _engine_step(self, action):
405
+ assert action.shape == (self.n, G.NU), action.shape
406
+ self.prev_action, self.action = self.action, action.to(self.dt)
407
+ base = self.m.joint_pos[self.time].to(self.dt) if self.residual else self.q_default
408
+ target = R.default_relative_action_targets(self.action, self.action_scale, base, self.encoder_bias)
409
+ if self.differentiable:
410
+ assert self.slot < self.horizon, ("detach_state() at each window start", self.slot, self.horizon)
411
+ qp, qv, wm, xp, xq, xv, xa = D.step(self.be, self.slot, self.qpos, self.qvel, self.lm.ctrl(target).to(self.qpos.dtype),
412
+ self.warm, self.foot)
413
+ self.slot += 1
414
+ else:
415
+ o = self.be.step(0, self.qpos, self.qvel, self.warm, self.lm.ctrl(target).to(self.qpos.dtype), self.foot)
416
+ qp, qv, wm = o["qpos"].clone(), o["qvel"].clone(), o["warm"].clone()
417
+ xp, xq, xv, xa = (o[k].clone() for k in ("xpos", "xquat", "xvel", "xangvel"))
418
+ # overflow-as-done: the flag read, accumulate and zero, eager (it mutates the static accumulators, zeroes the engine's word and
419
+ # consumes a one-shot injection); its mask enters the post half as an input
420
+ overflow = self._read_step_flags()
421
+ return qp, qv, wm, xp, xq, xv, xa, overflow
422
+
423
+ def _post(self, qp, qv, wm, xp, xq, xv, xa, overflow, tape=None):
424
+ """the step from the engine's outputs on; tape: the compiled step's pre-drawn randoms (None: the draws inline)"""
425
+ self._tape, self._ti = tape, 0
426
+ self.qpos, self.qvel, self.warm = qp, qv, wm
427
+ self.frames = dict(xpos=xp, xquat=xq, xvel=xv, xangvel=xa)
428
+ self.length = self.length + 1
429
+ k = self.time
430
+ rp, rq, rv, rw = self._ref(k)
431
+ tf = self._tracked()
432
+ g_r = Q.quat_rotate_inverse(tf["xquat"][:, self.ia], self.down)[:, 2]
433
+ g_t = Q.quat_rotate_inverse(rq[:, self.ia], self.down)[:, 2]
434
+ term = R.compute_terminations(elapsed_steps=self.length, max_episode_steps=self.episode_steps,
435
+ robot_anchor_height=tf["xpos"][:, self.ia, 2], target_anchor_height=rp[:, self.ia, 2],
436
+ robot_projected_gravity_z=g_r, target_projected_gravity_z=g_t,
437
+ robot_end_effector_height=tf["xpos"][:, self.ee, 2], target_end_effector_height=rp[:, self.ee, 2])
438
+ nonfinite = ~torch.isfinite(self.qpos).all(1) | ~torch.isfinite(self.qvel).all(1)
439
+ # an overflowed world (overflow_done on): truncated, and a termination judged on the held state is masked (an overflow artifact);
440
+ # a non-finite state stays terminated. With the rule off, `overflow` is all false and both lines are the old ones, bitwise.
441
+ terminated = (term.terminated & ~overflow) | nonfinite
442
+ truncated = term.timeout | overflow # RAW, as theirs: the agent bootstraps on it, their scorer takes success = truncated & ~terminated
443
+ with torch.no_grad():
444
+ sc = self.self_contact() # a bool: piecewise constant, no gradient (the same values either way)
445
+ hist = torch.zeros(self.n, 4, 3, dtype=self.dt, device=self.dev)
446
+ hist[..., 0] = torch.where(sc, 11.0, 0.0).to(self.dt)[:, None] # every substep over their 10 N: the strictest count
447
+ rew = R.compute_reward(robot_anchor_position=tf["xpos"][:, self.ia], target_anchor_position=rp[:, self.ia],
448
+ robot_anchor_quaternion=tf["xquat"][:, self.ia], target_anchor_quaternion=rq[:, self.ia],
449
+ robot_body_position=tf["xpos"], target_body_position=self.target_pos,
450
+ robot_body_quaternion=tf["xquat"], target_body_quaternion=self.target_quat,
451
+ robot_body_linear_velocity=tf["xvel"], target_body_linear_velocity=rv,
452
+ robot_body_angular_velocity=tf["xangvel"], target_body_angular_velocity=rw,
453
+ action=self.action, previous_action=self.prev_action, joint_position=self.qpos[:, 7:],
454
+ soft_joint_lower=self.soft_lo, soft_joint_upper=self.soft_hi, self_collision_force_history=hist,
455
+ step_duration=self.step_duration)
456
+ terminal = self._observe()
457
+ done = terminated | truncated
458
+ self.reset_terminated = terminated
459
+ self._reset_worlds(done) # masked, every step (capture-safe)
460
+ self._update_command()
461
+ if self.pushes and self.initial_reset_done:
462
+ self._apply_pushes() # qvel only; like theirs (no forward after the push) the IMU observation reads the pre-push frames
463
+ obs = self._observe()
464
+ info = {f"r_{k}": v.detach() for k, v in rew.raw.items()}
465
+ info["self_contact"] = sc
466
+ return dict(obs, reward=rew.total, terminated=terminated, truncated=truncated, terminal_actor=terminal["actor"],
467
+ terminal_critic=terminal["critic"], overflow=overflow, info=info)
468
+
469
+ def _read_step_flags(self):
470
+ """This step's engine flag word (GpuLaw: w["flags"], OR-ed over the step's substeps; the CPU laws have none, so zeros) with any
471
+ injected bits, accumulated into ovf_or_w / ovf_world_steps, then the engine's word zeroed. Returns the step's overflow mask
472
+ (kFlagOverflow | kFlagHandOverflow), AND-ed with overflow_done. Device ops only (capture-safe; _inject_flags is eager-only)."""
473
+ w = getattr(self.be, "w", None)
474
+ eng = w["flags"] if isinstance(w, dict) and "flags" in w else None
475
+ fl = self._zero_fl if eng is None else eng
476
+ if self._inj is not None:
477
+ fl = fl | self._inj
478
+ self._inj = None
479
+ ovf = (fl & 0x101) != 0
480
+ self.ovf_or_w |= fl
481
+ self.ovf_world_steps += ovf.sum()
482
+ if eng is not None:
483
+ eng.zero_()
484
+ return ovf & self.overflow_done
485
+
486
+ def _inject_flags(self, t):
487
+ """A test hook (the gates N0 / N2): int32 [n] bits OR-ed into the NEXT step's flag word, then dropped. Eager only: a captured
488
+ window bakes the Python branch at capture time."""
489
+ assert t.dtype == torch.int32 and t.shape == (self.n,), (t.dtype, t.shape)
490
+ self._inj = t.to(self.dev)
491
+
492
+ @torch.no_grad()
493
+ def read_overflow(self):
494
+ """(the OR of every flag bit, the overflowed world-steps) since the last read, then both zeroed: one host read per update,
495
+ outside the clock. Also sets last_overflow_worlds = (worlds with kFlagOverflow, worlds with kFlagHandOverflow) in that span."""
496
+ w = self.ovf_or_w
497
+ orv = 0
498
+ for x in w.unique().tolist():
499
+ orv |= int(x)
500
+ self.last_overflow_worlds = (int(((w & 1) != 0).sum()), int(((w & 256) != 0).sum()))
501
+ cnt = int(self.ovf_world_steps)
502
+ w.zero_()
503
+ self.ovf_world_steps.zero_()
504
+ return orv, cnt
505
+
506
+ def detach_state(self):
507
+ """A3: the window start. Every state tensor leaves the graph and the tape slots restart at 0."""
508
+ assert self.differentiable
509
+ for k in ("qpos", "qvel", "warm", "action", "prev_action", "target_pos", "target_quat"):
510
+ setattr(self, k, getattr(self, k).detach())
511
+ if self.frames is not None:
512
+ self.frames = {k: v.detach() for k, v in self.frames.items()}
513
+ self.slot = 0
514
+
515
+ # ------------------------------------------------------------------ snapshot / restore (the agent's bitwise replay)
516
+ STATE = ("qpos", "qvel", "warm", "time", "length", "action", "prev_action", "target_pos", "target_quat", "reset_terminated",
517
+ "push_timer", "foot", "encoder_bias", "ovf_or_w", "ovf_world_steps")
518
+
519
+ def snapshot(self):
520
+ snap = {k: getattr(self, k).clone() for k in self.STATE}
521
+ snap["frames"] = {k: v.clone() for k, v in self.frames.items()} if self.frames is not None else None
522
+ snap["sampler"] = (self.sampler.bin_failed_count.clone(), self.sampler.current_bin_failed.clone())
523
+ snap["initial_reset_done"] = self.initial_reset_done
524
+ return snap
525
+
526
+ def make_static(self):
527
+ """Static copies of every mutable state tensor (the CUDA graphs read and write these addresses); detached in A3's mode."""
528
+ S = {k: getattr(self, k).detach().clone() for k in self.STATE}
529
+ S.update({f"frames.{k}": v.detach().clone() for k, v in self.frames.items()})
530
+ return S
531
+
532
+ def bind_static(self, S):
533
+ for k in self.STATE:
534
+ setattr(self, k, S[k])
535
+ self.frames = {k[7:]: v for k, v in S.items() if k.startswith("frames.")}
536
+
537
+ def copy_into(self, S):
538
+ with torch.no_grad(): # A3: the values only (the static tensors never join the graph)
539
+ for k in self.STATE:
540
+ S[k].copy_(getattr(self, k).detach())
541
+ for k, v in self.frames.items():
542
+ S[f"frames.{k}"].copy_(v.detach())
543
+
544
+ def begin_window(self, S):
545
+ """A3's window start in its capture form (the same call in eager, so eager == captured): the state is read from the static
546
+ tensors S (no grad: the cut) and the tape slots restart at 0."""
547
+ assert self.differentiable
548
+ self.bind_static(S)
549
+ self.slot = 0
550
+
551
+ def end_window(self, S):
552
+ """A3's window end: the window's end state written into S (values only), the last op of a captured update."""
553
+ assert self.differentiable
554
+ self.copy_into(S)
555
+
556
+ def restore(self, snap):
557
+ for k in self.STATE:
558
+ setattr(self, k, snap[k].clone())
559
+ self.frames = {k: v.clone() for k, v in snap["frames"].items()} if snap["frames"] is not None else None
560
+ self.sampler.bin_failed_count.copy_(snap["sampler"][0])
561
+ self.sampler.current_bin_failed.copy_(snap["sampler"][1])
562
+ self.initial_reset_done = snap["initial_reset_done"]
563
+
564
+ # ------------------------------------------------------------------ the evaluate protocol's hooks
565
+ def snapshot_benchmark_reference(self):
566
+ rp, _, _, _ = self._ref(self.time)
567
+ return dict(body_position_world=rp.clone(), body_position_relative_world=self.target_pos.clone(),
568
+ body_quaternion_relative_world=self.target_quat.clone(), joint_velocity=self.m.joint_vel[self.time].clone())
569
+
570
+ def get_benchmark_robot_state(self):
571
+ tf = self._tracked()
572
+ return dict(body_position_world=tf["xpos"], body_quaternion_world=tf["xquat"], joint_velocity=self.qvel[:, 6:])