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,395 @@
1
+ """Arm A (line 23, docs/training/campaigns/g1/seconds.md): InstantMimic's seconds-level PPO recipe on the G1 env of g1_soft_env.
2
+
3
+ Every setting is InstantMimic's humanoid imitation base (config/humanoid/imitation/base.yaml at 947430ee, the HPO-derived base its
4
+ five motions share), with its code as the reference for the update rules:
5
+ model one shared MLP trunk obs -> 384 -> 384 -> 192 (SiLU) with a mean head (29) and a value head (1); a state-independent
6
+ log-std parameter, initial -2, clamped to [-20, 2]; actions unsquashed (action_transform none)
7
+ data 2,048 worlds x 6 control steps per iteration; running standardisers on observations and on values (RunningStandardScaler)
8
+ returns GAE, gamma 0.95, lambda 0.95; time-limit bootstrap (a time-out adds gamma V(s') to its reward)
9
+ update 5 epochs x 4 minibatches, shuffled per update; clipped surrogate (ratio clip 0.2); value loss scale 4.5 with the
10
+ predicted value clamped to old +- 0.2 (value_loss_clip_mode clamp); entropy 1e-3; grad-norm clip 1.0
11
+ lr 1e-3, KL-adaptive per epoch (rl/ppo/agent.py _update_lr_tensor_kernel): kl > 2 x 0.1 -> lr / 1.5, kl < 0.5 x 0.1 -> lr x 1.5,
12
+ within [1e-6, 1e-2]; the sampled KL estimator ((ratio - 1) - log ratio)
13
+ optimiser Muon (InstantMimic's CapturableMuon, single-tensor path; Nesterov, momentum 0.95, 5 Newton-Schulz steps in bf16,
14
+ match_rms_adamw, weight decay 3e-5, eps 2e-5; one device lr shared with AdamW)
15
+ on the trunk's hidden matrices (not the first layer, not the heads: rl/optimizers.py _is_muon_hidden_layer_param);
16
+ AdamW (0.9, 0.999), eps 2e-5, weight decay 3e-5 on the rest
17
+ episodes random start frame and joint noise N(0, 0.02) at every reset (reset.random_start, motion_noise_std); early
18
+ termination as the env's (BeyondMimic's G1 terms + reward < 0.15 for 4 steps); adaptive sampling off (its base)
19
+ Scoring: g1_soft_eval (shared by every arm). Labelled deviations: the observation is g1_soft_env.obs_phc (PHC-style), the observer standardiser updates once per iteration on the
20
+ rollout batch, and the clock is ours (CLOCK_MONOTONIC_RAW around the training iterations; the benchmark and the first, compiling
21
+ iteration's time excluded, its learning kept).
22
+ """
23
+ from __future__ import annotations
24
+
25
+ import math
26
+ import time
27
+
28
+ import torch
29
+ import torch.nn as nn
30
+
31
+ from . import g1_soft_env as G
32
+
33
+ CFG = dict(n_env=2048, rollouts=6, gamma=0.95, lam=0.95, epochs=5, minibatches=4, ratio_clip=0.2, value_clip=0.2, value_scale=4.5,
34
+ entropy=1e-3, grad_clip=1.0, lr=1e-3, lr_bounds=(1e-6, 1e-2), kl_threshold=0.1, kl_factor=1.5, layers=(384, 384, 192),
35
+ log_std_init=-2.0, log_std_bounds=(-20.0, 2.0), muon=dict(momentum=0.95, nesterov=True, ns_steps=5, eps=2e-5,
36
+ weight_decay=3e-5, adjust_lr_fn="match_rms_adamw"), adamw=dict(betas=(0.9, 0.999), eps=2e-5, weight_decay=3e-5),
37
+ reset_noise=0.02)
38
+
39
+
40
+ class RunningStd(nn.Module):
41
+ """skrl's RunningStandardScaler: running mean / variance (parallel update), clip 5, eps 1e-8."""
42
+
43
+ def __init__(self, dim, device, clip=5.0, eps=1e-8):
44
+ super().__init__()
45
+ self.register_buffer("mean", torch.zeros(dim, device=device))
46
+ self.register_buffer("var", torch.ones(dim, device=device))
47
+ self.register_buffer("count", torch.ones((), device=device))
48
+ self.clip, self.eps = clip, eps
49
+
50
+ @torch.no_grad()
51
+ def update(self, x):
52
+ x = x.reshape(-1, self.mean.shape[0])
53
+ bm, bv, bc = x.mean(0), x.var(0, unbiased=False), x.shape[0]
54
+ d = bm - self.mean
55
+ tot = self.count + bc
56
+ self.mean += d * bc / tot
57
+ self.var.copy_((self.var * self.count + bv * bc + d.square() * self.count * bc / tot) / tot)
58
+ self.count.copy_(tot)
59
+
60
+ def forward(self, x, inverse=False):
61
+ if inverse:
62
+ return x * torch.sqrt(self.var + self.eps) + self.mean
63
+ return ((x - self.mean) / torch.sqrt(self.var + self.eps)).clamp(-self.clip, self.clip)
64
+
65
+
66
+ class SharedActorCritic(nn.Module):
67
+ def __init__(self, obs_dim, act_dim, cfg, device):
68
+ super().__init__()
69
+ dims = (obs_dim,) + tuple(cfg["layers"])
70
+ self.trunk = nn.Sequential(*[m for i in range(len(dims) - 1) for m in (nn.Linear(dims[i], dims[i + 1]), nn.SiLU())])
71
+ self.mean_head = nn.Linear(dims[-1], act_dim)
72
+ self.value_head = nn.Linear(dims[-1], 1)
73
+ self.log_std = nn.Parameter(torch.full((act_dim,), float(cfg["log_std_init"])))
74
+ self.lo, self.hi = cfg["log_std_bounds"]
75
+ self.to(device)
76
+
77
+ def forward(self, obs):
78
+ h = self.trunk(obs)
79
+ return self.mean_head(h), self.log_std.clamp(self.lo, self.hi).expand(obs.shape[0], -1), self.value_head(h).squeeze(-1)
80
+
81
+
82
+ NS_COEFFICIENTS = (3.4445, -4.7750, 2.0315)
83
+
84
+
85
+ def newton_schulz_bf16(grad, steps, eps, coeff=NS_COEFFICIENTS):
86
+ """InstantMimic's _muon_zero_power_via_newton_schulz (= torch.optim.Muon's), in bfloat16, eager (theirs is torch.compile'd on
87
+ CUDA: the same math, possibly other rounding)."""
88
+ a, b, c = coeff
89
+ x = grad.bfloat16()
90
+ if grad.shape[0] > grad.shape[1]:
91
+ x = x.T
92
+ x = x / x.norm().clamp(min=eps)
93
+ for _ in range(steps):
94
+ gram = x @ x.T
95
+ gram_update = torch.addmm(gram, gram, gram, beta=b, alpha=c)
96
+ x = torch.addmm(x, gram_update, x, beta=a)
97
+ if grad.shape[0] > grad.shape[1]:
98
+ x = x.T
99
+ return x
100
+
101
+
102
+ class CapturableMuon(torch.optim.Optimizer):
103
+ """InstantMimic's CapturableMuon (rl/optimizers.py at 947430ee), its single-tensor path: a 0-dim device learning rate (no host
104
+ read, so the update can be captured), decoupled decay 1 - lr wd, Nesterov momentum by lerp, Newton-Schulz, the
105
+ match_rms_adamw scale 0.2 sqrt(max(rows, cols))."""
106
+
107
+ def __init__(self, params, lr, weight_decay, momentum, nesterov, ns_steps, eps, adjust_lr_fn):
108
+ assert adjust_lr_fn == "match_rms_adamw" and torch.is_tensor(lr) and lr.dim() == 0
109
+ super().__init__(params, dict(lr=lr, weight_decay=float(weight_decay), momentum=float(momentum), nesterov=bool(nesterov),
110
+ ns_steps=int(ns_steps), eps=float(eps)))
111
+ for g in self.param_groups:
112
+ assert all(p.ndim == 2 for p in g["params"])
113
+
114
+ @torch.no_grad()
115
+ def step(self):
116
+ for g in self.param_groups:
117
+ lr, mom = g["lr"], g["momentum"]
118
+ decay = 1.0 - lr * g["weight_decay"]
119
+ for p in g["params"]:
120
+ if p.grad is None:
121
+ continue
122
+ st = self.state[p]
123
+ if "momentum_buffer" not in st:
124
+ st["momentum_buffer"] = torch.zeros_like(p.grad, memory_format=torch.preserve_format)
125
+ buf = st["momentum_buffer"]
126
+ buf.lerp_(p.grad, 1.0 - mom)
127
+ upd = p.grad.lerp(buf, mom) if g["nesterov"] else buf
128
+ upd = newton_schulz_bf16(upd, g["ns_steps"], g["eps"])
129
+ adj = lr * (0.2 * math.sqrt(max(p.shape[0], p.shape[1])))
130
+ p.mul_(decay)
131
+ p.add_(upd * (-adj))
132
+
133
+
134
+ def make_optimisers(model, cfg, lr_t):
135
+ """Muon on the trunk's hidden matrices (Linear index > 0), AdamW on everything else, both reading the one 0-dim lr tensor
136
+ lr_t (AdamW capturable on CUDA, as InstantMimic's update_cuda_graph path)."""
137
+ lins = [m for m in model.trunk if isinstance(m, nn.Linear)]
138
+ muon = [l.weight for l in lins[1:]]
139
+ ids = {id(p) for p in muon}
140
+ rest = [p for p in model.parameters() if id(p) not in ids]
141
+ mu = CapturableMuon(muon, lr=lr_t, **cfg["muon"])
142
+ cuda = lr_t.device.type == "cuda"
143
+ ad = torch.optim.AdamW(rest, lr=lr_t if cuda else float(lr_t), capturable=cuda, **cfg["adamw"])
144
+ return [mu, ad]
145
+
146
+
147
+ def gaussian_logp(a, mean, log_std):
148
+ return (-0.5 * ((a - mean) / log_std.exp()).square() - log_std - 0.5 * math.log(2 * math.pi)).sum(-1)
149
+
150
+
151
+ class PPO:
152
+ def __init__(self, env, cfg=CFG, seed=0):
153
+ torch.manual_seed(seed)
154
+ self.env, self.cfg = env, dict(cfg)
155
+ self.dev, n, R = env.dev, env.n, cfg["rollouts"]
156
+ # every draw from the default generator of the device (seeded above): a CUDA graph replays its philox stream, so the
157
+ # eager and the captured iteration draw the same numbers (W2b)
158
+ self.gen = None
159
+ env.reset(torch.ones(n, dtype=torch.bool, device=self.dev), self._starts(n))
160
+ obs = env.observe().float()
161
+ self.obs_dim = obs.shape[1]
162
+ self.model = SharedActorCritic(self.obs_dim, G.NU, cfg, self.dev)
163
+ self.lr_t = torch.tensor(float(cfg["lr"]), device=self.dev) # the device lr: the KL rule updates it without a host read
164
+ self.opts = make_optimisers(self.model, cfg, self.lr_t)
165
+ self.obs_rms = RunningStd(self.obs_dim, self.dev)
166
+ self.val_rms = RunningStd(1, self.dev)
167
+ z = lambda *s: torch.zeros(*s, device=self.dev) # noqa: E731
168
+ self.buf = dict(obs=z(R, n, self.obs_dim), act=z(R, n, G.NU), logp=z(R, n), val=z(R, n), rew=z(R, n), term=z(R, n),
169
+ tout=z(R, n))
170
+ self.obs = obs
171
+ self.it = 0
172
+ self.stats = {}
173
+
174
+ def _starts(self, k):
175
+ return torch.randint(0, self.env.m.T - 1, (k,), generator=self.gen, device=self.dev)
176
+
177
+ @torch.no_grad()
178
+ def rollout(self):
179
+ env, b, n = self.env, self.buf, self.env.n
180
+ self.obs_rms.update(self.obs)
181
+ for k in range(self.cfg["rollouts"]):
182
+ o = self.obs_rms(self.obs)
183
+ mean, log_std, v = self.model(o)
184
+ a = mean + log_std.exp() * torch.randn(mean.shape, generator=self.gen, device=self.dev)
185
+ b["obs"][k], b["act"][k], b["logp"][k] = o, a, gaussian_logp(a, mean, log_std)
186
+ b["val"][k] = self.val_rms(v.unsqueeze(-1), inverse=True).squeeze(-1)
187
+ fr, r, term, tout, info = env.step(a.to(env.dt))
188
+ b["rew"][k], b["term"][k], b["tout"][k] = r.float(), term.float(), (tout & ~term).float()
189
+ done = term | tout
190
+ if self.cfg["reset_noise"] > 0:
191
+ noise = self.cfg["reset_noise"] * torch.randn(n, G.NU, generator=self.gen, device=self.dev).to(env.dt)
192
+ else:
193
+ noise = None
194
+ nxt_obs = env.observe().float()
195
+ # the time-out bootstrap needs V at the state the episode reached, before the reset replaces it
196
+ _, _, v_next = self.model(self.obs_rms(nxt_obs))
197
+ b["rew"][k] += self.cfg["gamma"] * self.val_rms(v_next.unsqueeze(-1), inverse=True).squeeze(-1) * b["tout"][k]
198
+ env.reset(done, self._starts(n), q_noise=noise)
199
+ self.obs = torch.where(done.view(-1, 1), env.observe().float(), nxt_obs)
200
+ _, _, v_last = self.model(self.obs_rms(self.obs))
201
+ return self.val_rms(v_last.unsqueeze(-1), inverse=True).squeeze(-1)
202
+
203
+ @torch.no_grad()
204
+ def gae(self, v_last):
205
+ b, g, lam = self.buf, self.cfg["gamma"], self.cfg["lam"]
206
+ adv = torch.zeros_like(b["rew"])
207
+ last = torch.zeros_like(v_last)
208
+ for k in reversed(range(self.cfg["rollouts"])):
209
+ nv = v_last if k == self.cfg["rollouts"] - 1 else b["val"][k + 1]
210
+ nd = 1.0 - torch.maximum(b["term"][k], b["tout"][k]) # no bootstrap across an episode end (a time-out is in rew)
211
+ delta = b["rew"][k] + g * nv * nd - b["val"][k]
212
+ last = delta + g * lam * nd * last
213
+ adv[k] = last
214
+ ret = adv + b["val"]
215
+ return adv, ret
216
+
217
+ def update(self, adv, ret):
218
+ cfg, b = self.cfg, self.buf
219
+ self.val_rms.update(ret.reshape(-1, 1))
220
+ N = adv.numel()
221
+ flat = {k: v.reshape(N, *v.shape[2:]) for k, v in b.items()}
222
+ adv_f, ret_n = adv.reshape(N), self.val_rms(ret.reshape(N, 1)).squeeze(-1)
223
+ old_v_n = self.val_rms(flat["val"].reshape(N, 1)).squeeze(-1)
224
+ mb = N // cfg["minibatches"]
225
+ kls = []
226
+ for ep in range(cfg["epochs"]):
227
+ perm = torch.argsort(torch.rand(N, generator=self.gen, device=self.dev)) # capturable, unlike a host-sized randperm
228
+ ep_kl = []
229
+ for j in range(cfg["minibatches"]):
230
+ i = perm[j * mb:(j + 1) * mb]
231
+ mean, log_std, v = self.model(flat["obs"][i])
232
+ logp = gaussian_logp(flat["act"][i], mean, log_std)
233
+ log_ratio = logp - flat["logp"][i]
234
+ ratio = log_ratio.exp()
235
+ with torch.no_grad():
236
+ ep_kl.append(((ratio - 1) - log_ratio).mean())
237
+ a = adv_f[i]
238
+ pol = -torch.min(a * ratio, a * ratio.clamp(1 - cfg["ratio_clip"], 1 + cfg["ratio_clip"])).mean()
239
+ v_c = old_v_n[i] + (v - old_v_n[i]).clamp(-cfg["value_clip"], cfg["value_clip"])
240
+ val = (ret_n[i] - v_c).square().mean()
241
+ ent = (log_std + 0.5 * math.log(2 * math.pi * math.e)).sum(-1).mean()
242
+ loss = pol + cfg["value_scale"] * val - cfg["entropy"] * ent
243
+ for o in self.opts:
244
+ o.zero_grad(set_to_none=True)
245
+ loss.backward()
246
+ nn.utils.clip_grad_norm_(self.model.parameters(), cfg["grad_clip"])
247
+ for o in self.opts:
248
+ o.step()
249
+ kl = torch.stack(ep_kl).mean()
250
+ kls.append(kl)
251
+ lo, hi = cfg["lr_bounds"]
252
+ th, fac = cfg["kl_threshold"], cfg["kl_factor"]
253
+ new = torch.where(kl > 2.0 * th, (self.lr_t / fac).clamp_min(lo),
254
+ torch.where(kl < 0.5 * th, (self.lr_t * fac).clamp_max(hi), self.lr_t))
255
+ self.lr_t.copy_(new)
256
+ if self.lr_t.device.type != "cuda": # the CPU AdamW holds a float lr (tests only)
257
+ for gr in self.opts[1].param_groups:
258
+ gr["lr"] = float(self.lr_t)
259
+ # the iteration's stats as one device vector (a captured update cannot read them on the host)
260
+ self.stat_t = torch.stack([torch.stack(kls).mean(), self.lr_t, pol.detach(), val.detach(), self.model.log_std.detach().mean(),
261
+ self.buf["rew"].mean(), self.buf["term"].mean()])
262
+
263
+ STAT_NAMES = ("kl", "lr", "policy_loss", "value_loss", "log_std", "reward", "term_rate")
264
+
265
+ def _sync(self):
266
+ if str(self.dev).startswith("cuda"):
267
+ torch.cuda.synchronize()
268
+
269
+ def _read_stats(self):
270
+ return dict(zip(self.STAT_NAMES, self.stat_t.tolist()))
271
+
272
+ def iteration(self):
273
+ """One eager iteration; its phases are timed on CLOCK_MONOTONIC_RAW with a device sync after each (t_rollout, t_update)."""
274
+ if getattr(self, "graphs", None) is not None:
275
+ return self.iteration_captured()
276
+ self._sync(); t0 = raw_now()
277
+ v_last = self.rollout()
278
+ self._sync(); t1 = raw_now()
279
+ adv, ret = self.gae(v_last)
280
+ self.update(adv, ret)
281
+ self._sync(); t2 = raw_now()
282
+ self.it += 1
283
+ self.stats = dict(self._read_stats(), t_rollout=t1 - t0, t_update=t2 - t1)
284
+ return self.stats
285
+
286
+ # ------------------------------------------------------------------------------------------ W2b: the captured iteration
287
+ ENV_STATE = ("qpos", "qvel", "warm", "t", "a_prev", "et_timer")
288
+
289
+ def _tensors(self):
290
+ """Every tensor an iteration reads or writes, by name (for snapshots: restored in place, so captured addresses hold)."""
291
+ d = {f"model.{k}": v for k, v in self.model.state_dict(keep_vars=True).items()}
292
+ for oi, o in enumerate(self.opts):
293
+ for pi, (p, st) in enumerate(o.state.items()):
294
+ for k, v in st.items():
295
+ if torch.is_tensor(v):
296
+ d[f"opt{oi}.{pi}.{k}"] = v
297
+ for k, v in self.buf.items():
298
+ d[f"buf.{k}"] = v
299
+ for name, rms in (("obs_rms", self.obs_rms), ("val_rms", self.val_rms)):
300
+ for k, v in rms.state_dict().items():
301
+ d[f"{name}.{k}"] = getattr(rms, k)
302
+ d["lr_t"] = self.lr_t
303
+ return d
304
+
305
+ def snapshot(self):
306
+ snap = {k: v.detach().clone() for k, v in self._tensors().items()}
307
+ snap.update({f"env.{k}": getattr(self.env, k).clone() for k in self.ENV_STATE})
308
+ snap["obs"] = self.obs.clone()
309
+ snap["rng"] = torch.cuda.get_rng_state() if self.dev.startswith("cuda") else torch.get_rng_state()
310
+ snap["it"] = self.it
311
+ return snap
312
+
313
+ @torch.no_grad()
314
+ def restore(self, snap):
315
+ for k, v in self._tensors().items():
316
+ v.data.copy_(snap[k])
317
+ for k in self.ENV_STATE:
318
+ cur = getattr(self.env, k)
319
+ if getattr(self, "S", None) is not None:
320
+ self.S[k].copy_(snap[f"env.{k}"]); setattr(self.env, k, self.S[k])
321
+ else:
322
+ setattr(self.env, k, snap[f"env.{k}"].clone())
323
+ if getattr(self, "S", None) is not None:
324
+ self.S["obs"].copy_(snap["obs"]); self.obs = self.S["obs"]
325
+ else:
326
+ self.obs = snap["obs"].clone()
327
+ self.env.frames = None
328
+ if self.lr_t.device.type != "cuda": # the CPU AdamW keeps its lr as a float (tests only)
329
+ for gr in self.opts[1].param_groups:
330
+ gr["lr"] = float(self.lr_t)
331
+ (torch.cuda.set_rng_state if self.dev.startswith("cuda") else torch.set_rng_state)(snap["rng"])
332
+ self.it = snap["it"]
333
+
334
+ def _bind_static(self):
335
+ for k in self.ENV_STATE:
336
+ setattr(self.env, k, self.S[k])
337
+ self.obs = self.S["obs"]
338
+ self.env.frames = None
339
+
340
+ def _rollout_body(self):
341
+ self._bind_static()
342
+ v_last = self.rollout()
343
+ adv, ret = self.gae(v_last)
344
+ for k in self.ENV_STATE:
345
+ self.S[k].copy_(getattr(self.env, k))
346
+ self.S["obs"].copy_(self.obs)
347
+ self.S["adv"].copy_(adv); self.S["ret"].copy_(ret)
348
+
349
+ def _update_body(self):
350
+ self.update(self.S["adv"], self.S["ret"])
351
+ self.S["stat"].copy_(self.stat_t)
352
+
353
+ def capture(self, warmup=2):
354
+ """Capture the rollout (+ GAE) and the update as two CUDA graphs. Needs one eager iteration first (the optimisers' state).
355
+ The warm-up runs on a side stream mutate the state, so everything is snapshot before and restored in place after them:
356
+ the first replay is exactly the next iteration."""
357
+ assert self.dev.startswith("cuda") and self.it >= 1
358
+ R, n = self.cfg["rollouts"], self.env.n
359
+ self.S = {k: getattr(self.env, k).clone() for k in self.ENV_STATE}
360
+ self.S.update(obs=self.obs.clone(), adv=torch.zeros(R, n, device=self.dev), ret=torch.zeros(R, n, device=self.dev),
361
+ stat=torch.zeros(len(self.STAT_NAMES), device=self.dev))
362
+ snap = self.snapshot()
363
+ side = torch.cuda.Stream()
364
+ side.wait_stream(torch.cuda.current_stream())
365
+ with torch.cuda.stream(side):
366
+ for _ in range(warmup):
367
+ self._rollout_body(); self._update_body()
368
+ torch.cuda.current_stream().wait_stream(side)
369
+ torch.cuda.synchronize()
370
+ self.restore(snap)
371
+ for o in self.opts:
372
+ o.zero_grad(set_to_none=True)
373
+ torch.cuda.synchronize()
374
+ g_roll, g_upd = torch.cuda.CUDAGraph(), torch.cuda.CUDAGraph()
375
+ with torch.cuda.graph(g_roll):
376
+ self._rollout_body()
377
+ with torch.cuda.graph(g_upd, pool=g_roll.pool()):
378
+ self._update_body()
379
+ self._bind_static()
380
+ self.graphs = (g_roll, g_upd)
381
+
382
+ def iteration_captured(self):
383
+ g_roll, g_upd = self.graphs
384
+ self._sync(); t0 = raw_now()
385
+ g_roll.replay()
386
+ self._sync(); t1 = raw_now()
387
+ g_upd.replay()
388
+ self._sync(); t2 = raw_now()
389
+ self.it += 1
390
+ self.stats = dict(zip(self.STAT_NAMES, self.S["stat"].tolist()), t_rollout=t1 - t0, t_update=t2 - t1)
391
+ return self.stats
392
+
393
+
394
+ def raw_now():
395
+ return time.clock_gettime(time.CLOCK_MONOTONIC_RAW)
@@ -0,0 +1,240 @@
1
+ """Arm B (line 23, docs/training/campaigns/g1/seconds.md): our exact-gradient SAPO with residual PD actions on the G1 env of
2
+ g1_soft_env, through the engine's adjoint (g1_soft_grad.StepFn).
3
+
4
+ The algorithm is g1_tracking.G1Sapo's, transcribed (rollout_loss / targets / train_critic / update_alpha / iteration):
5
+ entropy-augmented BPTT return over an H-step window, the double critic (average for the actor's bootstrap, minimum for the
6
+ critic's target), td-lambda targets, the temperature's dual step. The knobs are the (RECIPES["e0"] and
7
+ docs/logs/env/fb_e0_mm_kit_sapo_s1.env.sh, with A1's critic): actor ActorSquashedMLP 1024-1024-512, critic EnsembleCritic 2 x
8
+ 512-512 SiLU, AdamW (0.7, 0.95) actor 2e-3 / critic 5e-4 linear to 1e-5 over `decay_iters`, temperature AdamW 5e-3 from 0.1,
9
+ target entropy -0.5 per dim, actor and critic grad-norm clips 0.5, the per-env action-gradient clip at 2 x the median
10
+ (non-finite rows propagate and raise, as G1Sapo's), gamma 0.99, lambda 0.95, H 32, 4 critic iterations x 4 minibatches, the EMA
11
+ actor for evaluation (the LEARN_EMA decay min(0.999, (1 + n) / (10 + n))).
12
+ The env is arm A's (same observation, reward, terminations, residual map): the squashed action u in [-1, 1] is g1_soft_env's a, so
13
+ the setpoint is q_ref(t + 1) + half_range * u. Counted per window (the plan's guard on the unbounded self-pair derivatives, 11-10):
14
+ the envs whose action-gradient row is non-finite, and those the median clip scales down.
15
+ """
16
+ from __future__ import annotations
17
+
18
+ import copy
19
+ import math
20
+
21
+ import torch
22
+ import torch.nn as nn
23
+ from torch.nn.utils.clip_grad import clip_grad_norm_
24
+
25
+ from . import g1_soft_env as G
26
+ from . import g1_soft_grad as D
27
+ from .nets_shac import ActorSquashedMLP, EnsembleCritic, RunningMeanStd
28
+
29
+ CFG = dict(n_env=1024, H=32, gamma=0.99, lam=0.95, actor_lr=2e-3, critic_lr=5e-4, alpha_lr=5e-3, init_alpha=0.1,
30
+ target_entropy_per_dim=-0.5, actor_units=(1024, 1024, 512), critic_units=(512, 512), actor_clip=0.5, critic_clip=0.5,
31
+ action_grad_clip=2.0, critic_iterations=4, critic_minibatches=4, decay_iters=3000, reset_noise=0.02, ema=True)
32
+
33
+
34
+ class GradCounter:
35
+ """The per-env action-gradient clip of E0 (shac_vec._clip_grad_per_env, as g1_tracking.clip_grad_per_env: no zeroing), with
36
+ counts: non-finite rows and rows scaled down, accumulated over a window on the device (no host sync)."""
37
+
38
+ def __init__(self, factor, device):
39
+ self.factor = factor
40
+ self.nonfinite = torch.zeros((), device=device)
41
+ self.clipped = torch.zeros((), device=device)
42
+ self.rows = torch.zeros((), device=device)
43
+
44
+ def __call__(self, g):
45
+ n = g.norm(dim=-1, keepdim=True)
46
+ fin = torch.isfinite(n)
47
+ med = torch.where(fin, n, torch.full_like(n, float("nan"))).nanmedian()
48
+ cap = self.factor * med
49
+ scale = torch.where(n > cap, cap / n, torch.ones_like(n))
50
+ self.nonfinite += (~fin).sum()
51
+ self.clipped += ((n > cap) & fin).sum()
52
+ self.rows += n.numel()
53
+ return g * scale
54
+
55
+ def read_and_zero(self):
56
+ out = dict(grad_nonfinite=float(self.nonfinite), grad_clipped=float(self.clipped), grad_rows=float(self.rows))
57
+ for t in (self.nonfinite, self.clipped, self.rows):
58
+ t.zero_()
59
+ return out
60
+
61
+
62
+ def lr_linear(it, lr, decay):
63
+ return lr + (1e-5 - lr) * min(it / decay, 1.0)
64
+
65
+
66
+ class SapoG1:
67
+ def __init__(self, env, law, cfg=CFG, seed=0):
68
+ """env: a g1_soft_env.G1SoftTrack whose backend is `law` (GpuLaw with slots >= H and tape=True, or CpuJacLaw)."""
69
+ torch.manual_seed(seed)
70
+ self.env, self.law, self.cfg = env, law, dict(cfg)
71
+ self.dev, self.N, self.H = env.dev, env.n, cfg["H"]
72
+ self.gen = torch.Generator(device=self.dev).manual_seed(seed)
73
+ env.reset(torch.ones(self.N, dtype=torch.bool, device=self.dev), self._starts(self.N))
74
+ obs = env.observe().float()
75
+ self.obs_dim = obs.shape[1]
76
+ self.actor = ActorSquashedMLP(self.obs_dim, G.NU, units=tuple(cfg["actor_units"]), activation="silu", device=self.dev)
77
+ self.critic = EnsembleCritic(self.obs_dim, units=tuple(cfg["critic_units"]), activation="silu", device=self.dev, n_critics=2)
78
+ self.actor_opt = torch.optim.AdamW(self.actor.parameters(), lr=cfg["actor_lr"], betas=(0.7, 0.95))
79
+ self.critic_opt = torch.optim.AdamW(self.critic.parameters(), lr=cfg["critic_lr"], betas=(0.7, 0.95))
80
+ self.log_alpha = nn.Parameter(torch.tensor(math.log(cfg["init_alpha"]), device=self.dev))
81
+ self.alpha_opt = torch.optim.AdamW([self.log_alpha], lr=cfg["alpha_lr"], betas=(0.7, 0.95))
82
+ self.target_entropy = float(cfg["target_entropy_per_dim"] * G.NU)
83
+ self._abs_H = abs(self.target_entropy)
84
+ self.obs_rms = RunningMeanStd(shape=(self.obs_dim,), device=self.dev)
85
+ self.ema = copy.deepcopy(self.actor) if cfg["ema"] else None
86
+ self.n_ema = 0
87
+ H, N = self.H, self.N
88
+ z = lambda *s: torch.zeros(*s, device=self.dev) # noqa: E731
89
+ self.cobs_buf, self.rew_buf, self.done_mask = z(H, N, self.obs_dim), z(H, N), z(H, N)
90
+ self.next_values, self.ent_buf, self.target_values = z(H, N), z(H, N), z(H, N)
91
+ self.grads = GradCounter(cfg["action_grad_clip"], self.dev)
92
+ self.it = 0
93
+
94
+ def _starts(self, k):
95
+ return torch.randint(0, self.env.m.T - 1, (k,), generator=self.gen, device=self.dev)
96
+
97
+ def _ent_norm(self, ent):
98
+ return (ent - self.target_entropy) / (2.0 * self._abs_H)
99
+
100
+ def _diff_step(self, k, u):
101
+ """One differentiable control step of the env under the squashed action u: the engine through StepFn on tape slot k, then
102
+ the reward, terminations and observation on the step's own frames (all differentiable but the masks)."""
103
+ e = self.env
104
+ ctrl = e.lm.ctrl(e.setpoint(u.to(e.dt))).contiguous()
105
+ q1, v1, w1, xp, xq, xv, xa = D.step(self.law, k, e.qpos, e.qvel, ctrl, e.warm.detach(), e.foot)
106
+ e.t = (e.t + 1).clamp_max(e.m.T - 1)
107
+ fr = dict(xpos=xp, xquat=xq, xvel=xv, xangvel=xa)
108
+ r, _ = e.reward(fr, e.t)
109
+ az, ao, ee = e.fails({k_: v.detach() for k_, v in fr.items()}, e.t)
110
+ term = az | ao | ee
111
+ if e.early:
112
+ e.et_timer = torch.where(r.detach() < G.ET_REWARD, e.et_timer + 1, torch.zeros_like(e.et_timer))
113
+ term = term | (e.et_timer >= G.ET_STEPS)
114
+ nonfinite = ~torch.isfinite(q1.detach()).all(1) | ~torch.isfinite(v1.detach()).all(1)
115
+ tout = e.t >= e.m.T - 1
116
+ ue = u.to(e.dt)
117
+ e.qpos, e.qvel, e.warm, e.a_prev, e.frames = q1, v1, w1, ue, fr
118
+ obs = G.obs_phc(e.lm, e.tr, xp, xq, xv, xa, q1, v1, ue, e.ref((e.t + 1).clamp_max(e.m.T - 1)))
119
+ return obs.float(), r.float(), term | nonfinite, tout, nonfinite
120
+
121
+ def rollout_loss(self):
122
+ H, N, cfg, e = self.H, self.N, self.cfg, self.env
123
+ alpha = self.log_alpha.exp().detach()
124
+ o_rms = copy.deepcopy(self.obs_rms)
125
+ e.qpos, e.qvel = e.qpos.detach(), e.qvel.detach() # the window starts from the carried state, detached
126
+ e.a_prev = e.a_prev.detach()
127
+ e.frames = None
128
+ obs = e.observe().float()
129
+ self.obs_rms.update(obs)
130
+ rew_acc = torch.zeros(N, device=self.dev)
131
+ disc = torch.ones(N, device=self.dev)
132
+ loss = torch.zeros((), device=self.dev)
133
+ stats = dict(rew=0.0, done=0.0)
134
+ for i in range(H):
135
+ self.cobs_buf[i] = o_rms.normalize(obs).detach()
136
+ dist = self.actor.distribution(o_rms.normalize(obs))
137
+ u = dist.rsample()
138
+ u.register_hook(self.grads)
139
+ ent = dist.entropy().sum(-1)
140
+ obs, r, term, tout, nonfin = self._diff_step(i, u)
141
+ done = term | tout
142
+ self.obs_rms.update(obs.detach())
143
+ v_min, v_avg = self.critic(o_rms.normalize(obs), return_type="min_and_avg")
144
+ boot = tout & ~term # the clip's end: bootstrap from the state reached
145
+ nv_avg = torch.where(done, torch.where(boot, v_avg.squeeze(-1), torch.zeros_like(r)), v_avg.squeeze(-1))
146
+ nv_min = torch.where(done, torch.where(boot, v_min.squeeze(-1), torch.zeros_like(r)), v_min.squeeze(-1))
147
+ rew_acc = rew_acc + disc * (r + alpha * self._ent_norm(ent))
148
+ if i < H - 1:
149
+ loss = loss + ((-rew_acc - cfg["gamma"] * disc * nv_avg) * done.float()).sum()
150
+ else:
151
+ loss = loss + (-rew_acc - cfg["gamma"] * disc * nv_avg).sum()
152
+ disc = torch.where(done, torch.ones_like(disc), disc * cfg["gamma"])
153
+ rew_acc = torch.where(done, torch.zeros_like(rew_acc), rew_acc)
154
+ with torch.no_grad():
155
+ self.rew_buf[i] = r.detach()
156
+ self.done_mask[i] = done.float() if i < H - 1 else torch.ones_like(r)
157
+ self.next_values[i] = nv_min.detach()
158
+ self.ent_buf[i] = ent.detach()
159
+ stats["rew"] += r.detach().mean() / H
160
+ stats["done"] += done.float().mean() / H
161
+ if bool(done.any()): # one host read per step (eager); worlds restart detached
162
+ noise = cfg["reset_noise"] * torch.randn(N, G.NU, generator=self.gen, device=self.dev).to(e.dt)
163
+ e.qpos, e.qvel = torch.where(done.view(-1, 1), e.qpos.detach(), e.qpos), torch.where(done.view(-1, 1), e.qvel.detach(), e.qvel)
164
+ e.reset(done, self._starts(N), q_noise=noise)
165
+ obs = torch.where(done.view(-1, 1), e.observe().float(), obs)
166
+ return loss / (H * N), {k: float(v) for k, v in stats.items()}
167
+
168
+ @torch.no_grad()
169
+ def targets(self):
170
+ alpha, lam_c, g = self.log_alpha.exp(), self.cfg["lam"], self.cfg["gamma"]
171
+ Ai = torch.zeros(self.N, device=self.dev)
172
+ Bi = torch.zeros(self.N, device=self.dev)
173
+ lam = torch.ones(self.N, device=self.dev)
174
+ ent = self._ent_norm(self.ent_buf)
175
+ for i in reversed(range(self.H)):
176
+ lam = lam * lam_c * (1.0 - self.done_mask[i]) + self.done_mask[i]
177
+ rew = self.rew_buf[i] + alpha * ent[i]
178
+ Ai = (1.0 - self.done_mask[i]) * (lam_c * g * Ai + g * self.next_values[i] + (1.0 - lam) / (1.0 - lam_c) * rew)
179
+ Bi = g * (self.next_values[i] * self.done_mask[i] + Bi * (1.0 - self.done_mask[i])) + rew
180
+ self.target_values[i] = (1.0 - lam_c) * Ai + lam * Bi
181
+
182
+ def train_critic(self):
183
+ x, y = self.cobs_buf.reshape(-1, self.obs_dim), self.target_values.reshape(-1)
184
+ n = x.shape[0]
185
+ bs = n // self.cfg["critic_minibatches"]
186
+ tot = torch.zeros((), device=self.dev)
187
+ for _ in range(self.cfg["critic_iterations"]):
188
+ perm = torch.randperm(n, generator=self.gen, device=self.dev)
189
+ for s in range(0, n - bs + 1, bs):
190
+ idx = perm[s:s + bs]
191
+ self.critic_opt.zero_grad()
192
+ l = ((self.critic(x[idx], return_type="all").squeeze(-1) - y[idx][None]) ** 2).mean()
193
+ l.backward()
194
+ clip_grad_norm_(self.critic.parameters(), self.cfg["critic_clip"])
195
+ self.critic_opt.step()
196
+ tot += l.detach()
197
+ return float(tot) / (self.cfg["critic_iterations"] * self.cfg["critic_minibatches"])
198
+
199
+ def update_alpha(self):
200
+ loss = (self.log_alpha.exp() * self._abs_H * (self.ent_buf - self.target_entropy)).mean()
201
+ self.alpha_opt.zero_grad()
202
+ loss.backward()
203
+ clip_grad_norm_([self.log_alpha], 0.5)
204
+ self.alpha_opt.step()
205
+
206
+ def iteration(self):
207
+ cfg = self.cfg
208
+ for o, v in ((self.actor_opt, lr_linear(self.it, cfg["actor_lr"], cfg["decay_iters"])),
209
+ (self.critic_opt, lr_linear(self.it, cfg["critic_lr"], cfg["decay_iters"]))):
210
+ for g in o.param_groups:
211
+ g["lr"] = v
212
+ sync = torch.cuda.synchronize if str(self.dev).startswith("cuda") else (lambda: None)
213
+ clock = lambda: __import__("time").clock_gettime(__import__("time").CLOCK_MONOTONIC_RAW) # noqa: E731
214
+ sync(); t0 = clock()
215
+ self.actor_opt.zero_grad()
216
+ loss, stats = self.rollout_loss()
217
+ sync(); t1 = clock()
218
+ loss.backward()
219
+ sync(); t2 = clock()
220
+ gn = clip_grad_norm_(self.actor.parameters(), cfg["actor_clip"])
221
+ if not torch.isfinite(gn):
222
+ raise ValueError(f"non-finite actor grad norm at iteration {self.it}: {self.grads.read_and_zero()}")
223
+ self.actor_opt.step()
224
+ if self.ema is not None:
225
+ self.n_ema += 1
226
+ d = min(0.999, (1 + self.n_ema) / (10 + self.n_ema))
227
+ with torch.no_grad():
228
+ for pe, pa in zip(self.ema.parameters(), self.actor.parameters()):
229
+ pe.mul_(d).add_(pa, alpha=1 - d)
230
+ self.update_alpha()
231
+ self.targets()
232
+ vloss = self.train_critic()
233
+ sync(); t3 = clock()
234
+ self.it += 1
235
+ stats.update(t_rollout=t1 - t0, t_backward=t2 - t1, t_rest=t3 - t2)
236
+ return dict(stats, loss=float(loss.detach()), gn=float(gn), vloss=vloss, alpha=float(self.log_alpha.detach().exp()),
237
+ ent=float(self.ent_buf.mean()), **self.grads.read_and_zero())
238
+
239
+ def eval_actor(self):
240
+ return self.ema if self.ema is not None else self.actor