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,622 @@
1
+ """Arm A2's PPO: InstantMimic's side_kick_hpo training rules for the G1 BeyondMimic side kick (a2-beyondmimic-spec.md, section
2
+ "PPO as configured by side_kick_hpo"), driving the A2 env (a2-env-interface.md, g1_bm_env.BMTrack).
3
+
4
+ Every rule is cited to InstantMimic 947430ee. IM = ~/data/oneclip/lit/repos/instantmimic_src; C = IM/config/unitree_g1/beyondmimic;
5
+ S = IM/src/instantmimic. The config chain is side_kick_hpo -> side_kick -> side_kick_reference -> base; only base and hpo set
6
+ agent / models keys (side_kick.yaml:1-21 and side_kick_reference.yaml:1-7 set env, experiment and runtime only).
7
+
8
+ Configuration (C/base.yaml:84-133 overridden by C/side_kick_hpo.yaml:7-36):
9
+ rollouts 16 (hpo:20), epochs 3 (hpo:25), mini_batches 4 (base:113), shuffle per_update (base:118), gamma 0.99 (base:107),
10
+ GAE lambda 0.82 (hpo:26), ratio clip 0.175 (hpo:28), value clip 0.2 with clip_predicted_values and mode max (base:115-117),
11
+ value scale 1.0 (base:121), entropy 0.015 (hpo:27), grad-norm clip 50 (hpo:24) per actor / critic group (the env flag,
12
+ S/envs/unitree_g1/tasks/beyondmimic_tracking/beyondmimic_tracking_env.py:109-112, read by S/rl/factory.py:105-119),
13
+ lr 1.37e-4 in [1e-5, 4e-4] (hpo:21-23), KL-adaptive with threshold 0.01, factor 1.5, per_minibatch (base:128-132),
14
+ analytic KL (base:133), time-limit bootstrap (base:108), RslRlEmpiricalNormalization on states, no value preprocessor
15
+ (base:110-111), rsl_rl init (base:119), separate MLPs (base:85), ELU, no normalisation, actor 512-256-128, critic 640-320-160
16
+ (hpo:30-36), sigma a direct parameter (std: parameter, parameterization: scalar), initial log std 0, log-std bounds
17
+ +-13.8155 = log(1e-6), log(1e6) with clamp, no action transform (base:91-97); runtime precision float32 (side_kick.yaml:21).
18
+ Optimiser muon with momentum 0.95, nesterov, match_rms_adamw, ns 5, eps 1e-7, weight decay 3e-5 and the AdamW companion
19
+ betas (0.9, 0.999), eps 2e-5, weight decay 3e-5 (hpo:8-19, lowered by S/rl/build_specs.py:331-366).
20
+
21
+ Rules, in the order an iteration runs them:
22
+ - Observations: the agent input is [actor 160 | critic 286] (S/rl/runtime.py:84-104); the actor MLP reads [:160], the critic
23
+ [160:446] (S/rl/models/actor_critic.py:368-378).
24
+ - Normaliser: RSL-RL empirical moments over the 446 inputs, (x - mean) / (std + 0.01), no clip
25
+ (S/rl/normalization.py:223-319). It is updated once per env step with that step's post-step observation buf.obs[k+1]
26
+ (S/train/rollout.py:762-778), which for a done world is its fresh episode's first observation. Neither the reset
27
+ observation that seeds the run (S/train/runtime.py:858-862) nor any terminal observation updates it.
28
+ - Act (S/rl/ppo/agent.py:1639-1680; S/rl/models/actor_critic.py:1086-1129): normalise the current raw observation with the
29
+ current moments, keep that normalised input for the update (policy-input snapshot, normalization.py:240-243 and
30
+ agent.py:3511-3533), a = mean + sigma * eps, value from the critic.
31
+ - Step order after env.step (S/train/rollout.py:776-782): dones = terminated | truncated; the normaliser update with the new
32
+ observation; then the time-out bootstrap V(terminal critic obs), normalised with the moments that include this step's update
33
+ (rollout.py:862-920, agent.py:3351-3361, 1742-1780), kept only where the time-out mask is set (agent.py:3340-3349).
34
+ - End of the rollout phase (IM: the start of its update, agent.py:3363-3404; nothing changes in between and no random number
35
+ is drawn, so the arithmetic is the same and the rollout graph ends with the advantages): last value from buf.obs[R];
36
+ rewards + gamma * bootstrap values; GAE and one advantage normalisation over the whole rollout,
37
+ (A - mean) / (std(correction 1) + 1e-8), returns = A_raw + V (agent.py:250-313).
38
+ - Update (agent.py:4643-4676, 4630-4637, 4223-4402):
39
+ old log sigma snapshot (agent.py:3834-3845); one permutation per update (agent.py:3581-3594, 3645-3650); the shuffled views (agent.py:3652-3705); the old log-probabilities and old means recomputed through the update path per
40
+ minibatch before any step, so an unchanged policy starts at ratio 1 and KL 0 (agent.py:3108-3163);
41
+ then 3 epochs x 4 minibatches of: evaluate (actor_critic.py:754-806, distributions.py:19-73), analytic KL(old || new)
42
+ (agent.py:106-121, 3847-3874), the loss terms (S/learning/losses.py:33-71), the KL learning-rate rule BEFORE this
43
+ minibatch's step (agent.py:3281-3285, tensor branch 1871-1930), zero_grad, backward of policy + value + entropy
44
+ (agent.py:3291-3301), the per-group grad-norm clip (agent.py:3305, 2921-2951, groups actor_critic.py:395-420), Muon then AdamW
45
+ (S/rl/optimizers.py:734-747).
46
+ - Muon on exactly the parameters S/rl/optimizers.py:23-24, 53-63, 79-93 selects (here actor_trunk.{2,4}.weight and
47
+ trunk.{2,4}.weight), AdamW on every other trainable parameter including sigma (one group, decay_vector_parameters default
48
+ True, optimizers.py:129-146, 149-158, 228-307). Optimiser state is materialised at construction without a step
49
+ (agent.py:2709-2808).
50
+ - Network init: built on the CPU in float32 in IM's registration order, then the CPU RNG state taken at entry is restored and
51
+ the Linear layers re-initialised in RSL-RL order actor_trunk, policy_head, trunk, value_head (actor_critic.py:81-83,
52
+ 199-232, 274-297, 313-328); then moved to the env's device and dtype.
53
+ - Network matmuls run with TF32 ("high") on CUDA (S/utils/network_precision.py:69-85, agent.py:1470-1474, 1655-1658,
54
+ 1721-1757, 4639-4641); the env step stays IEEE.
55
+
56
+ Deviations, each numerically neutral or forced:
57
+ 1. Random streams: action noise from torch.randn and the permutation from argsort(torch.rand) (their randperm: the same law), both on the default generator of the
58
+ device. IM draws noise with a counter-based Warp kernel on CUDA (agent.py:1433-1467) and the permutation from a captured
59
+ generator (agent.py:3596-3616). Same distributions, different streams.
60
+ 2. Muon's Newton-Schulz runs eager (IM torch.compile's it on CUDA, optimizers.py:396-425): same math, possibly other rounding.
61
+ g1_ppo.CapturableMuon ports IM's single-tensor path; IM batches equal-shaped matrices (optimizers.py:544-577), so the four
62
+ Muon matrices are asserted to have distinct shapes (they do).
63
+ 3. One lr tensor shared by Muon and AdamW, updated once per minibatch. IM keeps two tensors (optimizers.py:255-274) and applies
64
+ the same rule to each group (agent.py:1871-1930), so the two always hold the same value.
65
+ 4. IM casts the update-path tensors and the loss inputs to float32 (agent.py:3217-3223, 3251-3254). These casts are no-ops in
66
+ float32 training and are left out, so f64 CPU tests stay f64. The analytic KL keeps IM's float32 cast (it only feeds the
67
+ float32 lr rule).
68
+ 5. On the CPU (tests only) torch refuses a capturable AdamW, so it holds a float lr refreshed from the lr tensor before each of
69
+ its steps (a host read of a CPU tensor) and reads its own step counter on the host. On CUDA AdamW is capturable and reads
70
+ the device lr tensor (IM's update_cuda_graph path).
71
+ 6. The TF32 scope is entered on CUDA only. IM's setter is process-wide, but it has no effect for float64 or CPU tensors.
72
+ 7. IM's action_mean_scale (ones) and action_log_std_scale (zeros) buffers are left out: x * 1 and x + 0 are exact. They change
73
+ only through an ActionScaleSnapshot, which the direct G1 control does not provide (S/envs/direct_rl_env.py:3580-3587).
74
+ 8. The act-time log-probability and mean are not stored: IM's recompute overwrites both before any use (agent.py:3108-3163).
75
+ 9. The time-out mask is the env's `truncated`, which g1_bm_env sends RAW as IM's (reference.py:385, optimized_kernels.py:555/590
76
+ via rollout.py:965-975): a world that also terminated on its time-out step is bootstrapped too.
77
+ 10. snapshot() / restore() use env.snapshot() / env.restore(snap); capture() uses env.make_static() / bind_static(S) /
78
+ copy_into(S).
79
+
80
+ The captured iteration (capture(), as g1_ppo.PPO.capture): after one eager iteration, the env's state is moved to static tensors,
81
+ everything is snapshot, `warmup` iterations run on a side stream, the snapshot is restored in place, then the rollout (+ GAE) is
82
+ captured as one CUDA graph and the update as a second in the first's pool; iteration() then replays them. The agent's own state is
83
+ allocated once and only written in place, so its addresses are static without copies. Random draws use the default CUDA generator,
84
+ whose philox offset a graph replay advances as the eager ops do.
85
+
86
+ Host synchronisation in iteration(), eager or captured: a device synchronize after each phase for the phase clocks (outside the
87
+ graphs) and the one read of the stats vector after the phases. Nothing inside the phases reads a device value on the host: the KL
88
+ lr rule, the normaliser, the advantage normalisation and the grad clip are device arithmetic without Python branches on tensors
89
+ (on the CPU, see 5).
90
+ """
91
+ from __future__ import annotations
92
+
93
+ import contextlib
94
+ import math
95
+
96
+ import torch
97
+ import torch.nn as nn
98
+ import torch.nn.functional as F
99
+
100
+ from .g1_ppo import CapturableMuon, raw_now
101
+
102
+ BM_CFG = dict(
103
+ rollouts=16, epochs=3, minibatches=4, gamma=0.99, lam=0.82, ratio_clip=0.175, value_clip=0.2, value_scale=1.0, entropy=0.015,
104
+ grad_clip=50.0, lr=0.000137, lr_bounds=(1.0e-5, 4.0e-4), kl_threshold=0.01, kl_factor=1.5, actor_layers=(512, 256, 128),
105
+ critic_layers=(640, 320, 160), initial_log_std=0.0, log_std_bounds=(-13.815510557964274, 13.815510557964274), norm_eps=1.0e-2,
106
+ adv_eps=1e-08, muon=dict(momentum=0.95, nesterov=True, ns_steps=5, eps=1.0e-7, weight_decay=3.0e-5, adjust_lr_fn="match_rms_adamw"),
107
+ adamw=dict(betas=(0.9, 0.999), eps=2.0e-5, weight_decay=3.0e-5, amsgrad=False))
108
+
109
+ LOG_2PI_HALF = 0.5 * math.log(2.0 * math.pi) # S/rl/models/distributions.py:13-15
110
+ NORMAL_ENTROPY_CONST = LOG_2PI_HALF + 0.5
111
+
112
+
113
+ # ----------------------------------------------------------------------------------------------------------- pure rules
114
+
115
+
116
+ def ppo_loss_terms(new_log_probs, old_log_probs, predicted_values, old_values, returns, advantages, entropy, cfg):
117
+ """S/learning/losses.py:33-71 with clip_predicted_values=True and value_loss_clip_mode="max": the policy loss clips the log
118
+ ratio at log(1 +- clip) by the sign of the advantage before exponentiating; the value loss is the max of the unclipped and the
119
+ clipped squared errors; the entropy loss is -scale * mean(per-sample entropy). Returns (policy, value, entropy, clip fraction)."""
120
+ log_ratio = new_log_probs - old_log_probs
121
+ ratio = log_ratio.detach().exp()
122
+ clip_fraction = ((ratio - 1.0).abs() > cfg["ratio_clip"]).float().mean()
123
+ log_upper = math.log1p(cfg["ratio_clip"])
124
+ log_lower = math.log1p(-cfg["ratio_clip"])
125
+ objective_log_ratio = torch.where(advantages >= 0.0, log_ratio.clamp(max=log_upper), log_ratio.clamp(min=log_lower))
126
+ policy_loss = -(advantages * objective_log_ratio.exp()).mean()
127
+ clipped_values = old_values + (predicted_values - old_values).clamp(-cfg["value_clip"], cfg["value_clip"])
128
+ clipped_error = F.mse_loss(returns, clipped_values, reduction="none")
129
+ unclipped_error = F.mse_loss(returns, predicted_values, reduction="none")
130
+ value_loss = cfg["value_scale"] * torch.maximum(unclipped_error, clipped_error).mean()
131
+ entropy_loss = -cfg["entropy"] * entropy.mean()
132
+ return policy_loss, value_loss, entropy_loss, clip_fraction
133
+
134
+
135
+ def diagonal_gaussian_kl_mean(old_mean, old_log_std, new_mean, new_log_std):
136
+ """S/rl/ppo/agent.py:106-121 verbatim: KL(old || new) of diagonal Gaussians in float32, summed over dimensions, batch mean."""
137
+ old_mean = old_mean.float()
138
+ new_mean = new_mean.float()
139
+ old_log_std = old_log_std.float().expand_as(old_mean)
140
+ new_log_std = new_log_std.float().expand_as(new_mean)
141
+ log_std_delta = new_log_std - old_log_std
142
+ old_to_new_var_ratio = torch.exp(2.0 * (old_log_std - new_log_std))
143
+ mean_delta_term = (old_mean - new_mean).square() * torch.exp(-2.0 * new_log_std)
144
+ kl_per_dim = log_std_delta + 0.5 * (old_to_new_var_ratio + mean_delta_term) - 0.5
145
+ return kl_per_dim.sum(dim=-1, keepdim=True).mean()
146
+
147
+
148
+ def lr_schedule_constants(cfg, device):
149
+ """The schedule's device scalars in the lr dtype float32 (agent.py:1823-1869): kl_high = 2 threshold, kl_low = threshold / 2."""
150
+ th = cfg["kl_threshold"]
151
+ vals = dict(kl_high=th * 2.0, kl_low=th / 2.0, factor=cfg["kl_factor"], min_lr=cfg["lr_bounds"][0], max_lr=cfg["lr_bounds"][1])
152
+ return {k: torch.zeros((), device=device, dtype=torch.float32).fill_(float(v)) for k, v in vals.items()}
153
+
154
+
155
+ @torch.no_grad()
156
+ def kl_adaptive_lr_(lr_t, kl, c):
157
+ """agent.py:1911-1930, the per_minibatch tensor branch: lr / factor (floored) if KL > kl_high, lr * factor (capped) if
158
+ 0 < KL < kl_low, else unchanged. In place on the 0-dim lr tensor; no host read."""
159
+ kl = kl.to(device=lr_t.device, dtype=lr_t.dtype)
160
+ decreased = torch.maximum(lr_t / c["factor"], c["min_lr"])
161
+ increased = torch.minimum(lr_t * c["factor"], c["max_lr"])
162
+ increase_condition = (kl < c["kl_low"]) & (kl > 0.0)
163
+ lr_t.copy_(torch.where(kl > c["kl_high"], decreased, torch.where(increase_condition, increased, lr_t)))
164
+
165
+
166
+ @torch.no_grad()
167
+ def gae_(rewards, values, dones, last_values, advantages, returns, gamma, lam, adv_eps):
168
+ """agent.py:291-313 (the torch path; the CUDA Warp kernel agent.py:124-151 computes the same formula). Tensors [R, n, 1];
169
+ writes the raw returns and the normalised advantages in place."""
170
+ R = rewards.shape[0]
171
+ advantage = torch.zeros_like(last_values)
172
+ for i in reversed(range(R)):
173
+ next_values = values[i + 1] if i < R - 1 else last_values
174
+ advantage = rewards[i] - values[i] + gamma * (1.0 - dones[i]) * (next_values + lam * advantage)
175
+ advantages[i].copy_(advantage)
176
+ returns.copy_(advantages + values)
177
+ advantages.sub_(advantages.mean()).div_(advantages.std(correction=1 if advantages.numel() > 1 else 0) + adv_eps)
178
+
179
+
180
+ @torch.no_grad()
181
+ def clip_group_grad_norm_(parameters, max_norm, device):
182
+ """agent.py:2936-2951: one group's L2 norm accumulated parameter by parameter, scaled by min(max_norm / (norm + 1e-6), 1)."""
183
+ grads = [p.grad for p in parameters if p.grad is not None]
184
+ total_norm_sq = torch.zeros((), device=device)
185
+ for grad in grads:
186
+ total_norm_sq = total_norm_sq + torch.sum(grad * grad)
187
+ total_norm = torch.sqrt(total_norm_sq)
188
+ clip_coef = torch.clamp(max_norm / (total_norm + 1e-06), max=1.0)
189
+ for grad in grads:
190
+ grad.mul_(clip_coef)
191
+ return total_norm
192
+
193
+
194
+ def _trunk_module_index(name):
195
+ parts = name.split(".")
196
+ if not parts or parts[-1] != "weight":
197
+ return None
198
+ for index, part in enumerate(parts[:-1]):
199
+ if (part == "trunk" or part.endswith("_trunk")) and index + 1 < len(parts) - 1 and parts[index + 1].isdigit():
200
+ return int(parts[index + 1])
201
+ return None
202
+
203
+
204
+ def is_muon_hidden_layer_param(name, param):
205
+ """S/rl/optimizers.py:23-24, 53-63, 79-93: a trainable 2-D matrix with both sides > 1, not in a *head, at a trunk index > 0
206
+ (the residual-block rule of optimizers.py:66-76 cannot match these MLP names)."""
207
+ if not (param.requires_grad and param.ndim == 2 and min(param.shape) > 1):
208
+ return False
209
+ parts = name.split(".")
210
+ if len(parts) >= 2 and parts[-2].endswith("head"):
211
+ return False
212
+ idx = _trunk_module_index(name)
213
+ return idx is not None and idx > 0
214
+
215
+
216
+ # ----------------------------------------------------------------------------------------------------------- modules
217
+
218
+
219
+ class EmpiricalNorm(nn.Module):
220
+ """S/rl/normalization.py:223-319 (RslRlEmpiricalNormalization, epsilon 1e-2), in the env's dtype (IM: float32). The rate is
221
+ the integer count ratio, which true division makes a default-dtype (float32) scalar, as in IM."""
222
+
223
+ def __init__(self, dim, device, dtype, eps):
224
+ super().__init__()
225
+ self.eps = float(eps)
226
+ self.register_buffer("running_mean", torch.zeros(dim, device=device, dtype=dtype))
227
+ self.register_buffer("running_variance", torch.ones(dim, device=device, dtype=dtype))
228
+ self.register_buffer("running_std", torch.ones(dim, device=device, dtype=dtype))
229
+ self.register_buffer("current_count", torch.zeros((), device=device, dtype=torch.long))
230
+
231
+ @torch.no_grad()
232
+ def update(self, x):
233
+ assert x.dim() == 2 and x.shape[1] == self.running_mean.shape[0], x.shape
234
+ count_x = x.shape[0]
235
+ self.current_count.add_(count_x)
236
+ rate = count_x / self.current_count
237
+ input_var = torch.var(x, dim=0, unbiased=False)
238
+ input_mean = torch.mean(x, dim=0)
239
+ delta_mean = input_mean - self.running_mean
240
+ self.running_mean.add_(rate * delta_mean)
241
+ self.running_variance.add_(rate * (input_var - self.running_variance + delta_mean * (input_mean - self.running_mean)))
242
+ self.running_std.copy_(torch.sqrt(self.running_variance))
243
+
244
+ def forward(self, x, cols=slice(None)):
245
+ """Normalise x, whose features are columns `cols` of the 446 (elementwise, so a slice equals slicing the full output)."""
246
+ return (x - self.running_mean[cols]) / (self.running_std[cols] + self.eps)
247
+
248
+
249
+ def _mlp(in_dim, layers):
250
+ """S/rl/models/actor_critic_shared.py:83-120 (mlp, no norm): Linear, ELU per hidden layer."""
251
+ mods, d = [], int(in_dim)
252
+ for h in layers:
253
+ mods += [nn.Linear(d, int(h)), nn.ELU()]
254
+ d = int(h)
255
+ return nn.Sequential(*mods)
256
+
257
+
258
+ class BMActorCritic(nn.Module):
259
+ """IM's ActorCritic as side_kick_hpo builds it (separate, asymmetric, std parameter in scalar parameterization, rsl_rl init),
260
+ with IM's module names so its optimiser split and gradient groups apply unchanged."""
261
+
262
+ def __init__(self, actor_obs_dim, critic_obs_dim, act_dim, cfg):
263
+ super().__init__()
264
+ self.actor_obs_dim, self.critic_obs_dim, self.act_dim = int(actor_obs_dim), int(critic_obs_dim), int(act_dim)
265
+ self.min_log_std, self.max_log_std = (float(v) for v in cfg["log_std_bounds"])
266
+ rng = torch.get_rng_state() # actor_critic.py:81-83
267
+ self.trunk = _mlp(self.critic_obs_dim, cfg["critic_layers"]) # registration order: actor_critic.py:199-232
268
+ self.actor_trunk = _mlp(self.actor_obs_dim, cfg["actor_layers"])
269
+ self.value_head = nn.Linear(int(cfg["critic_layers"][-1]), 1)
270
+ self.policy_head = nn.Linear(int(cfg["actor_layers"][-1]), self.act_dim)
271
+ self.log_std = nn.Parameter(torch.full((self.act_dim,), math.exp(float(cfg["initial_log_std"])))) # holds sigma (289-297)
272
+ assert all(p.device.type == "cpu" and p.dtype == torch.float32 for p in self.parameters())
273
+ torch.set_rng_state(rng) # RSL-RL order: actor_critic.py:313-328
274
+ for m in self.actor_trunk.modules():
275
+ if isinstance(m, nn.Linear):
276
+ m.reset_parameters()
277
+ self.policy_head.reset_parameters()
278
+ for m in self.trunk.modules():
279
+ if isinstance(m, nn.Linear):
280
+ m.reset_parameters()
281
+ self.value_head.reset_parameters()
282
+
283
+ def physical_log_std(self):
284
+ """actor_critic.py:511-522: log(clamp(sigma, e^min, e^max))."""
285
+ return torch.log(self.log_std.clamp(min=math.exp(self.min_log_std), max=math.exp(self.max_log_std)))
286
+
287
+ def actor_mean(self, obs_actor):
288
+ return self.policy_head(self.actor_trunk(obs_actor))
289
+
290
+ def value(self, obs_critic):
291
+ return self.value_head(self.trunk(obs_critic))
292
+
293
+ def _split(self, obs):
294
+ a, c = self.actor_obs_dim, self.critic_obs_dim
295
+ return obs[..., :a], obs[..., a:a + c]
296
+
297
+ def act(self, obs, eps):
298
+ """actor_critic.py:1086-1129 without the log-probability (see deviation 8): a = mean + sigma eps, and the value."""
299
+ oa, oc = self._split(obs)
300
+ mean = self.actor_mean(oa)
301
+ std = self.physical_log_std().expand_as(mean).exp()
302
+ return torch.addcmul(mean, std, eps), self.value(oc)
303
+
304
+ def evaluate(self, obs, actions):
305
+ """actor_critic.py:754-806 with distributions.py:19-59, 70-73: log-probability, value, entropy (each [B, 1]), mean, log std."""
306
+ oa, oc = self._split(obs)
307
+ mean = self.actor_mean(oa)
308
+ log_std = self.physical_log_std().expand_as(mean)
309
+ std = log_std.exp()
310
+ noise = (actions - mean) / std
311
+ log_prob = torch.sum(-0.5 * noise.square() - log_std - LOG_2PI_HALF, dim=-1, keepdim=True)
312
+ entropy = torch.sum(log_std + NORMAL_ENTROPY_CONST, dim=-1, keepdim=True)
313
+ return log_prob, self.value(oc), entropy, mean, log_std
314
+
315
+ def ppo_parameter_groups(self):
316
+ """actor_critic.py:395-420: actor = sigma + actor_trunk.* + policy_head.*, critic = trunk.* + value_head.*, in
317
+ named_parameters order."""
318
+ actor, critic = [], []
319
+ for name, p in self.named_parameters():
320
+ if p is self.log_std or name.startswith(("actor_trunk.", "policy_head.")):
321
+ actor.append(p)
322
+ else:
323
+ assert name.startswith(("trunk.", "value_head.")), name
324
+ critic.append(p)
325
+ return actor, critic
326
+
327
+
328
+ def make_bm_optimisers(model, cfg, lr_t):
329
+ """Hybrid Muon + AdamW (S/rl/optimizers.py:228-307, 676-747) with one shared 0-dim float32 lr tensor (deviation 3); the state
330
+ materialised without a step as IM does before capture (agent.py:2709-2808)."""
331
+ named = list(model.named_parameters())
332
+ muon = [p for n, p in named if is_muon_hidden_layer_param(n, p)]
333
+ rest = [p for n, p in named if p.requires_grad and not is_muon_hidden_layer_param(n, p)]
334
+ assert len({tuple(p.shape) for p in muon}) == len(muon), "IM batches equal shapes (optimizers.py:544-577); our port does not"
335
+ mu = CapturableMuon(muon, lr=lr_t, **cfg["muon"])
336
+ cuda = lr_t.device.type == "cuda"
337
+ ad = torch.optim.AdamW(rest, lr=lr_t if cuda else float(lr_t), capturable=cuda, **cfg["adamw"])
338
+ with torch.no_grad():
339
+ for p in muon:
340
+ mu.state[p]["momentum_buffer"] = torch.zeros_like(p)
341
+ for p in rest:
342
+ st = ad.state[p]
343
+ st["step"] = torch.zeros((), dtype=torch.float32, device=p.device if cuda else "cpu")
344
+ st["exp_avg"] = torch.zeros_like(p)
345
+ st["exp_avg_sq"] = torch.zeros_like(p)
346
+ return mu, ad
347
+
348
+
349
+ def network_matmul_precision(device):
350
+ """S/utils/network_precision.py:69-85: TF32 ("high") float32 matmuls while a network runs; CUDA only (deviation 6)."""
351
+ if device.type != "cuda":
352
+ return contextlib.nullcontext()
353
+ return _tf32_scope()
354
+
355
+
356
+ @contextlib.contextmanager
357
+ def _tf32_scope():
358
+ prev = torch.get_float32_matmul_precision()
359
+ torch.set_float32_matmul_precision("high")
360
+ yield
361
+ torch.set_float32_matmul_precision(prev)
362
+
363
+
364
+ # ----------------------------------------------------------------------------------------------------------- the agent
365
+
366
+
367
+ class BMPPO:
368
+ STAT_NAMES = ("kl", "lr", "policy_loss", "value_loss", "entropy_loss", "clip_fraction", "std", "reward", "term_rate",
369
+ "trunc_rate")
370
+ _M_POLICY, _M_VALUE, _M_ENTROPY, _M_KL, _M_CLIP = range(5)
371
+
372
+ def __init__(self, env, cfg=BM_CFG, seed=0):
373
+ self.env, self.cfg = env, dict(cfg)
374
+ cfg = self.cfg
375
+ self.dev, self.dt, n = torch.device(env.dev), env.dt, int(env.n)
376
+ self.na, self.nc, self.A = int(env.actor_obs_dim), int(env.critic_obs_dim), int(env.act_dim)
377
+ self.D = self.na + self.nc
378
+ R, E, M = cfg["rollouts"], cfg["epochs"], cfg["minibatches"]
379
+ self.N = R * n
380
+ assert self.N % M == 0, (self.N, M) # agent.py:67-80
381
+ self.mb = self.N // M
382
+ torch.manual_seed(seed)
383
+ self.model = BMActorCritic(self.na, self.nc, self.A, cfg).to(device=self.dev, dtype=self.dt)
384
+ self.lr_t = torch.tensor(float(cfg["lr"]), device=self.dev, dtype=torch.float32)
385
+ self.lr_c = lr_schedule_constants(cfg, self.dev)
386
+ self.muon, self.adamw = make_bm_optimisers(self.model, cfg, self.lr_t)
387
+ self.actor_params, self.critic_params = self.model.ppo_parameter_groups()
388
+ self.norm = EmpiricalNorm(self.D, self.dev, self.dt, cfg["norm_eps"])
389
+ z = lambda *s: torch.zeros(*s, device=self.dev, dtype=self.dt) # noqa: E731
390
+ self.buf = dict(obs=z(R, n, self.D), act=z(R, n, self.A), val=z(R, n, 1), rew=z(R, n, 1), done=z(R, n, 1),
391
+ tv=z(R, n, 1), term=z(R, n, 1), trunc=z(R, n, 1), adv=z(R, n, 1), ret=z(R, n, 1), last_v=z(n, 1))
392
+ self.ws = dict(obs=z(self.N, self.D), act=z(self.N, self.A), val=z(self.N, 1), ret=z(self.N, 1), adv=z(self.N, 1),
393
+ old_logp=z(self.N, 1), old_mean=z(self.N, self.A))
394
+ self.perm = torch.arange(self.N, device=self.dev, dtype=torch.int32)
395
+ self.metrics = torch.zeros(E * M, 5, device=self.dev, dtype=torch.float32)
396
+ self.stat_t = torch.zeros(len(self.STAT_NAMES), device=self.dev, dtype=torch.float32)
397
+ out = env.reset_all()
398
+ self.obs = torch.cat([out["actor"], out["critic"]], -1) # raw; it seeds buf.obs[0] (runtime.py:858-862)
399
+ assert self.obs.shape == (n, self.D) and self.obs.dtype == self.dt, (self.obs.shape, self.obs.dtype)
400
+ self.it = 0
401
+ self.stats = {}
402
+ self.S, self.graphs = None, None # set by capture()
403
+
404
+ # -------------------------------------------------------------------------------------------------- rollout
405
+
406
+ def _check(self, out):
407
+ n = self.env.n
408
+ for k, w in (("actor", self.na), ("critic", self.nc), ("terminal_actor", self.na), ("terminal_critic", self.nc)):
409
+ assert out[k].shape == (n, w) and out[k].dtype == self.dt, (k, out[k].shape, out[k].dtype)
410
+ assert out["reward"].shape == (n,) and out["reward"].dtype == self.dt, (out["reward"].shape, out["reward"].dtype)
411
+ for k in ("terminated", "truncated"):
412
+ assert out[k].shape == (n,) and out[k].dtype == torch.bool, (k, out[k].shape, out[k].dtype)
413
+
414
+ @torch.no_grad()
415
+ def rollout(self):
416
+ """R env steps in IM's order (rollout.py:762-785), then the update's preamble that reads no learning state: the last value,
417
+ the rewards with the time-out bootstrap and GAE (agent.py:3363-3404, 250-313). IM runs that preamble at the start of its
418
+ update; nothing changes between the two points and it draws no random numbers, so ending the rollout with it is the same
419
+ arithmetic and lets the rollout graph end with the advantages (as g1_ppo's rollout graph does)."""
420
+ cfg, b, env = self.cfg, self.buf, self.env
421
+ for k in range(cfg["rollouts"]):
422
+ b["obs"][k].copy_(self.norm(self.obs)) # the policy-input snapshot
423
+ eps = torch.randn(env.n, self.A, device=self.dev, dtype=self.dt)
424
+ with network_matmul_precision(self.dev):
425
+ a, v = self.model.act(b["obs"][k], eps)
426
+ b["act"][k].copy_(a)
427
+ b["val"][k].copy_(v)
428
+ out = env.step(a)
429
+ self._check(out)
430
+ term, trunc = out["terminated"], out["truncated"]
431
+ b["rew"][k, :, 0].copy_(out["reward"])
432
+ b["done"][k, :, 0].copy_(term | trunc) # reset_buf = terminated | time-out
433
+ b["term"][k, :, 0].copy_(term)
434
+ b["trunc"][k, :, 0].copy_(trunc)
435
+ self.obs.copy_(torch.cat([out["actor"], out["critic"]], -1))
436
+ self.norm.update(self.obs) # rollout.py:778
437
+ with network_matmul_precision(self.dev): # rollout.py:862-920 after the update
438
+ tv = self.model.value(self.norm(out["terminal_critic"], slice(self.na, self.D)))
439
+ b["tv"][k].copy_(tv.masked_fill(~trunc.view(-1, 1), 0.0)) # agent.py:3340-3349
440
+ with network_matmul_precision(self.dev): # the last value: buf.obs[R] (agent.py:3392-3394)
441
+ b["last_v"].copy_(self.model.value(self.norm(self.obs[:, self.na:], slice(self.na, self.D))))
442
+ rewards = b["rew"].add(b["tv"], alpha=cfg["gamma"]) # agent.py:3363-3382
443
+ gae_(rewards, b["val"], b["done"], b["last_v"], b["adv"], b["ret"], cfg["gamma"], cfg["lam"], cfg["adv_eps"])
444
+
445
+ # -------------------------------------------------------------------------------------------------- update
446
+
447
+ def update(self):
448
+ cfg, b, ws, mb = self.cfg, self.buf, self.ws, self.mb
449
+ with network_matmul_precision(self.dev):
450
+ with torch.no_grad():
451
+ old_log_std = self.model.physical_log_std().detach().view(1, -1) # agent.py:3834-3845, 4647
452
+ # their randperm (agent.py:3581-3594, 4634) as argsort(rand): the same uniform permutation law, a different stream;
453
+ # argsort(rand) is the form arm A's capture gate passed bitwise (W2b C1), randperm under capture is unverified
454
+ self.perm.copy_(torch.argsort(torch.rand(self.N, device=self.dev)))
455
+ for key, src in (("obs", b["obs"]), ("act", b["act"]), ("val", b["val"]), ("ret", b["ret"]), ("adv", b["adv"])):
456
+ torch.index_select(src.reshape(self.N, -1), 0, self.perm, out=ws[key]) # agent.py:3652-3705
457
+ for j in range(cfg["minibatches"]): # agent.py:3108-3163
458
+ s = slice(j * mb, (j + 1) * mb)
459
+ logp, _, _, mean, _ = self.model.evaluate(ws["obs"][s], ws["act"][s])
460
+ ws["old_logp"][s].copy_(logp)
461
+ ws["old_mean"][s].copy_(mean)
462
+ for e in range(cfg["epochs"]):
463
+ for j in range(cfg["minibatches"]):
464
+ self._minibatch(slice(j * mb, (j + 1) * mb), old_log_std, self.metrics[e * cfg["minibatches"] + j])
465
+ with torch.no_grad():
466
+ m = self.metrics.mean(0)
467
+ std = self.model.physical_log_std().exp().mean()
468
+ self.stat_t.copy_(torch.stack([m[self._M_KL], self.lr_t, m[self._M_POLICY], m[self._M_VALUE], m[self._M_ENTROPY],
469
+ m[self._M_CLIP], std.float(), b["rew"].mean().float(), b["term"].mean().float(),
470
+ b["trunc"].mean().float()]))
471
+
472
+ def _minibatch(self, s, old_log_std, out_metrics):
473
+ """agent.py:3165-3328."""
474
+ cfg, ws = self.cfg, self.ws
475
+ logp, value, entropy, mean, log_std = self.model.evaluate(ws["obs"][s], ws["act"][s])
476
+ with torch.no_grad():
477
+ kl = diagonal_gaussian_kl_mean(ws["old_mean"][s], old_log_std, mean.detach(), log_std.detach())
478
+ pol, val, ent, clip_frac = ppo_loss_terms(logp, ws["old_logp"][s], value, ws["val"][s], ws["ret"][s], ws["adv"][s], entropy,
479
+ cfg)
480
+ kl_adaptive_lr_(self.lr_t, kl, self.lr_c) # before this minibatch's step, on the device
481
+ self.muon.zero_grad(set_to_none=True)
482
+ self.adamw.zero_grad(set_to_none=True)
483
+ (pol + val + ent).backward()
484
+ clip_group_grad_norm_(self.actor_params, cfg["grad_clip"], self.dev)
485
+ clip_group_grad_norm_(self.critic_params, cfg["grad_clip"], self.dev)
486
+ self.muon.step()
487
+ self._adamw_step()
488
+ with torch.no_grad():
489
+ out_metrics.copy_(torch.stack([pol.detach().float(), val.detach().float(), ent.detach().float(), kl, clip_frac]))
490
+
491
+ def _adamw_step(self):
492
+ """On CUDA AdamW is capturable and reads the device lr tensor. On the CPU (tests) torch refuses a capturable AdamW: it holds a
493
+ float lr, refreshed here from the lr tensor (deviation 5), and torch reads its step counter on the host."""
494
+ if self.dev.type != "cuda":
495
+ for g in self.adamw.param_groups:
496
+ g["lr"] = float(self.lr_t)
497
+ self.adamw.step()
498
+
499
+ # -------------------------------------------------------------------------------------------------- driver
500
+
501
+ def _sync(self):
502
+ if self.dev.type == "cuda":
503
+ torch.cuda.synchronize(self.dev)
504
+
505
+ def iteration(self):
506
+ """One iteration (the captured one after capture()); phases timed on CLOCK_MONOTONIC_RAW after a device sync."""
507
+ if self.graphs is not None:
508
+ return self.iteration_captured()
509
+ self._sync(); t0 = raw_now()
510
+ self.rollout()
511
+ self._sync(); t1 = raw_now()
512
+ self.update()
513
+ self._sync(); t2 = raw_now()
514
+ self.it += 1
515
+ self.stats = dict(zip(self.STAT_NAMES, self.stat_t.tolist()), t_rollout=t1 - t0, t_update=t2 - t1)
516
+ return self.stats
517
+
518
+ @torch.no_grad()
519
+ def act_mean(self, actor_obs_raw):
520
+ """The policy mean for scoring: the actor columns of the normaliser (no update), then the actor (agent.py:3551-3555)."""
521
+ assert actor_obs_raw.shape[-1] == self.na and actor_obs_raw.dtype == self.dt, (actor_obs_raw.shape, actor_obs_raw.dtype)
522
+ with network_matmul_precision(self.dev):
523
+ return self.model.actor_mean(self.norm(actor_obs_raw, slice(0, self.na)))
524
+
525
+ # -------------------------------------------------------------------------------------------------- the captured iteration
526
+
527
+ def _make_static(self):
528
+ """The env's mutable state at static addresses through its make_static / bind_static API (g1_ppo's ENV_STATE pattern). The
529
+ agent's own state (model, optimiser state, normaliser, rollout buffers with the current observations and adv / ret,
530
+ workspace, permutation, lr, metrics, stats) is allocated once and only written in place, so it is static already."""
531
+ self.S = self.env.make_static()
532
+ self.env.bind_static(self.S)
533
+
534
+ def _rollout_body(self):
535
+ self.env.bind_static(self.S)
536
+ self.rollout()
537
+ self.env.copy_into(self.S)
538
+
539
+ def _update_body(self):
540
+ self.update()
541
+
542
+ def capture(self, warmup=2):
543
+ """Capture the rollout (+ GAE) and the update as two CUDA graphs, the second in the first's pool (as g1_ppo.PPO.capture).
544
+ Needs one eager iteration first. The warm-up iterations run on a side stream and mutate the state, so everything is
545
+ snapshot before them and restored in place after: the first replay is exactly the next iteration."""
546
+ assert self.dev.type == "cuda" and self.it >= 1 and self.graphs is None
547
+ self._make_static()
548
+ snap = self.snapshot()
549
+ side = torch.cuda.Stream(self.dev)
550
+ side.wait_stream(torch.cuda.current_stream(self.dev))
551
+ with torch.cuda.stream(side):
552
+ for _ in range(warmup):
553
+ self._rollout_body()
554
+ self._update_body()
555
+ torch.cuda.current_stream(self.dev).wait_stream(side)
556
+ torch.cuda.synchronize(self.dev)
557
+ self.restore(snap)
558
+ self.muon.zero_grad(set_to_none=True)
559
+ self.adamw.zero_grad(set_to_none=True)
560
+ torch.cuda.synchronize(self.dev)
561
+ g_roll, g_upd = torch.cuda.CUDAGraph(), torch.cuda.CUDAGraph()
562
+ with torch.cuda.graph(g_roll):
563
+ self._rollout_body()
564
+ with torch.cuda.graph(g_upd, pool=g_roll.pool()):
565
+ self._update_body()
566
+ self.env.bind_static(self.S) # eager reads see the static tensors
567
+ self.graphs = (g_roll, g_upd)
568
+
569
+ def iteration_captured(self):
570
+ """The two replays, each timed after a device sync (outside the graphs); the stats read from the static vector after."""
571
+ g_roll, g_upd = self.graphs
572
+ self._sync(); t0 = raw_now()
573
+ g_roll.replay()
574
+ self._sync(); t1 = raw_now()
575
+ g_upd.replay()
576
+ self._sync(); t2 = raw_now()
577
+ self.it += 1
578
+ self.stats = dict(zip(self.STAT_NAMES, self.stat_t.tolist()), t_rollout=t1 - t0, t_update=t2 - t1)
579
+ return self.stats
580
+
581
+ # -------------------------------------------------------------------------------------------------- snapshots
582
+
583
+ def _tensors(self):
584
+ """Every tensor an iteration reads or writes, by name (restored in place, so the captured addresses hold)."""
585
+ d = {f"model.{k}": v for k, v in self.model.state_dict(keep_vars=True).items()}
586
+ for oname, o in (("muon", self.muon), ("adamw", self.adamw)):
587
+ for gi, g in enumerate(o.param_groups):
588
+ for pi, p in enumerate(g["params"]):
589
+ for k, v in o.state[p].items():
590
+ assert torch.is_tensor(v), (oname, k)
591
+ d[f"{oname}.{gi}.{pi}.{k}"] = v
592
+ d.update({f"norm.{k}": v for k, v in self.norm.state_dict(keep_vars=True).items()})
593
+ d.update({f"buf.{k}": v for k, v in self.buf.items()})
594
+ d.update({f"ws.{k}": v for k, v in self.ws.items()})
595
+ d.update(lr_t=self.lr_t, perm=self.perm, metrics=self.metrics, stat_t=self.stat_t, obs=self.obs)
596
+ return d
597
+
598
+ def snapshot(self):
599
+ snap = {k: v.detach().clone() for k, v in self._tensors().items()}
600
+ snap["env"] = self.env.snapshot()
601
+ snap["rng_cpu"] = torch.get_rng_state()
602
+ if self.dev.type == "cuda":
603
+ snap["rng_cuda"] = torch.cuda.get_rng_state(self.dev)
604
+ snap["it"] = self.it
605
+ return snap
606
+
607
+ @torch.no_grad()
608
+ def restore(self, snap):
609
+ """In place: the agent's tensors by copy; the env by its restore, then, once static state exists, copied into the static
610
+ tensors and rebound (as g1_ppo.restore with S), so the captured graphs keep reading the same addresses."""
611
+ cur = self._tensors()
612
+ assert cur.keys() == {k for k in snap if k not in ("env", "rng_cpu", "rng_cuda", "it")}, "state keys changed"
613
+ for k, v in cur.items():
614
+ v.data.copy_(snap[k])
615
+ self.env.restore(snap["env"])
616
+ if self.S is not None:
617
+ self.env.copy_into(self.S)
618
+ self.env.bind_static(self.S)
619
+ torch.set_rng_state(snap["rng_cpu"])
620
+ if self.dev.type == "cuda":
621
+ torch.cuda.set_rng_state(snap["rng_cuda"], self.dev)
622
+ self.it = snap["it"]