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,551 @@
1
+ """Arm A3 (tools/g1_seconds/PREREG_A3.md): our first-order trainer on InstantMimic's BeyondMimic side kick, through the D16 G1
2
+ engine's adjoint. The env is line 23's BMTrack in its differentiable mode (diffneusim/rl/g1_bm_env.py; the contract is
3
+ docs/training/campaigns/g1/a2-env-interface.md plus `differentiable=True, horizon=H`, `make_static`, `begin_window` / `end_window`); the task, reward,
4
+ terminations, resets, DR and observations are InstantMimic's, unchanged from A2.
5
+
6
+ The algorithm is g1_sapo_soft.SapoG1's (G1Sapo transcribed with the knobs), with what this env needs:
7
+ - two observations: the actor reads their 160-number actor observation, the double critic their 286-number critic observation,
8
+ each with its own running normaliser, frozen for the window as in SapoVec;
9
+ - the time-out bootstrap reads V(terminal_critic), the critic observation of the state reached BEFORE the env's internal reset
10
+ (BMTrack returns the fresh episode's observation for a done world); a terminated world bootstraps 0, as theirs and ours;
11
+ - the action: SAPO's squashed u in [-1, 1] maps to their raw action a = A u, with A from the model: every joint position from
12
+ their default pose plus a full-effort margin, A_j = (max(hi_j - q0_j, q0_j - lo_j) + effort_j / kp_j) / scale_j (the rule of
13
+ g1_tracking.G1Tracking; scale = their 0.25 effort / kp, so the margin term is 4 for every joint);
14
+ - the actor's head init of g1_tracking.G1MlpActor (LONG13's G1 actor): mean weights x 0.01 and bias 0, so the untrained mean
15
+ action is their default pose; log-std weights x 0.01 and bias at the target entropy's per-dim sigma;
16
+ - the EMA shadow exactly as tools/e0speed/learn/train14.py builds it: from the actor before its first step, then after every
17
+ actor step decay d = min(0.999, (1 + n) / (10 + n)) with n = 0, 1, 2, ... (SapoG1 starts its n at 1); evaluation only, with
18
+ the raw policy's normaliser;
19
+ - counted per update (the review's addition to the prereg): the action-gradient rows that are non-finite and those the per-env
20
+ median clip scales down, the rows, and the BPTT windows (one per actor update);
21
+ - overflow-as-done (the docs/design/overflow-as-done.md, the review's rulings 11-11): the env owns the rule (BMTrack(overflow_done=True)
22
+ truncates an overflowed world at that step, masks a termination judged on its held state, resets it at once, and gives the held
23
+ state's terminal observation), so the time-out bootstrap above takes it unchanged. The loop reads o["overflow"] (always present,
24
+ all false with the rule off) and counts per update the overflowed world-steps ("overflow") and those the env did NOT hand over as
25
+ truncated & ~terminated ("ovf_bad", the contract), on the device; iteration() asserts ovf_bad == 0 after the window, before the
26
+ actor step, so a broken contract raises instead of silently bootstrapping 0. With no overflow both counts are 0 and every float
27
+ of the update is unchanged.
28
+
29
+ CUDA-graph capture (the design brief, 11-11: the eager 2.93 s per update is launch-bound; line 23 owns the env / StepFn side). One
30
+ update = _window() (the H-step forward, loss.backward() through the engine's adjoint, then the end state written back) + _rest() (the
31
+ actor's clip and step, the EMA, the temperature step, the targets, the critic minibatches). capture() records _window() as one CUDA
32
+ graph; iteration() then replays it and runs the same eager _rest(), so the optimisers, the lr schedule, the EMA rule and the non-finite
33
+ raise are the eager code in both modes. What makes _window() capture-safe (and is the eager code too, so eager == captured):
34
+ - its start observation and the frozen per-window normalisers live in static buffers, copied in place (no deepcopy);
35
+ - the critic's parameters take no gradient inside the window (the actor's gradient is unchanged; the critic trains in _rest);
36
+ - no host read and no Python-side state change inside it (counters move to iteration());
37
+ - the env's state is line 23's static state S: begin_window(S) at the start, end_window(S) as the last op, after the backward.
38
+ """
39
+ from __future__ import annotations
40
+
41
+ import copy
42
+ import math
43
+ import time
44
+
45
+ import torch
46
+ import torch.nn as nn
47
+ from torch.nn.utils.clip_grad import clip_grad_norm_
48
+
49
+ from .g1_sapo_soft import CFG as CFG_B, GradCounter, lr_linear
50
+ from .nets_shac import ActorSquashedMLP, EnsembleCritic, RunningMeanStd
51
+
52
+ # the knobs as SapoG1 carries them (RECIPES["e0"] with A1's critic), with A3's window and κ registered in PREREG_A3.md
53
+ CFG = dict(CFG_B, H=64, decay_iters=3000)
54
+ CFG.pop("reset_noise") # BMTrack applies their reset perturbation itself
55
+
56
+
57
+ def action_bound(bm):
58
+ """A_j in their action units (see the module docstring), from the env's own model fields, in the action's joint order."""
59
+ q0, scale, kp, effort = bm.q_default, bm.action_scale, bm.kp, bm.effort
60
+ lo, hi = bm.joint_range[:, 0], bm.joint_range[:, 1]
61
+ assert bool((hi > q0).all() and (q0 > lo).all()), "the default pose lies inside the hard joint range"
62
+ assert bool((scale > 0).all() and (kp > 0).all() and (effort > 0).all())
63
+ return (torch.maximum(hi - q0, q0 - lo) + effort / kp) / scale
64
+
65
+
66
+ class SapoBM:
67
+ def __init__(self, bm, cfg=CFG, seed=0):
68
+ """bm: a BMTrack built with differentiable=True and horizon >= cfg["H"] (GPU law with a tape, or the CPU Jacobian law)."""
69
+ torch.manual_seed(seed)
70
+ self.bm, self.cfg = bm, dict(cfg)
71
+ self.dev, self.N, self.H = bm.dev, bm.n, int(cfg["H"])
72
+ self.gen = torch.Generator(device=self.dev).manual_seed(seed)
73
+ self.obs_dim, self.cobs_dim, self.act_dim = bm.actor_obs_dim, bm.critic_obs_dim, bm.act_dim
74
+ self.A = action_bound(bm).to(device=self.dev, dtype=bm.dt)
75
+ # A3's diagnostic knobs (11-11; every default leaves the gated ops unchanged): a fixed action box, the target entropy from an
76
+ # action noise in action units (LONG13's "noise" target, g1_tracking.G1Sapo), a fixed temperature, a reward scale
77
+ if cfg.get("action_box") is not None:
78
+ self.A = torch.full_like(self.A, float(cfg["action_box"]))
79
+ self.reward_scale = float(cfg.get("reward_scale", 1.0))
80
+ self.alpha_fixed = cfg.get("alpha_fixed")
81
+ if cfg.get("target_entropy", "per_dim") == "noise": # sigma_u = action_noise / A per joint (SuperMimic Table A.5's 0.1)
82
+ sig_t = (float(cfg.get("action_noise", 0.1)) / self.A).float()
83
+ self.target_entropy = float((0.5 * torch.log(2 * math.pi * math.e * sig_t ** 2)).sum())
84
+ sig = None
85
+ else:
86
+ assert cfg.get("target_entropy", "per_dim") == "per_dim", cfg.get("target_entropy")
87
+ self.target_entropy = float(cfg["target_entropy_per_dim"] * self.act_dim)
88
+ sig = math.exp(cfg["target_entropy_per_dim"] - 0.5 * math.log(2 * math.pi * math.e))
89
+ self._abs_H = abs(self.target_entropy)
90
+ self.actor = ActorSquashedMLP(self.obs_dim, self.act_dim, units=tuple(cfg["actor_units"]), activation="silu", device=self.dev)
91
+ with torch.no_grad(): # g1_tracking.G1MlpActor's head init
92
+ self.actor.mu.weight.mul_(0.01); self.actor.mu.bias.zero_()
93
+ self.actor.logstd.weight.mul_(0.01)
94
+ if sig is None:
95
+ self.actor.logstd.bias.copy_(torch.log(sig_t).to(self.actor.logstd.bias))
96
+ else:
97
+ self.actor.logstd.bias.fill_(math.log(sig))
98
+ self.critic = EnsembleCritic(self.cobs_dim, units=tuple(cfg["critic_units"]), activation="silu", device=self.dev, n_critics=2)
99
+ self.actor_opt = torch.optim.AdamW(self.actor.parameters(), lr=cfg["actor_lr"], betas=(0.7, 0.95))
100
+ self.critic_opt = torch.optim.AdamW(self.critic.parameters(), lr=cfg["critic_lr"], betas=(0.7, 0.95))
101
+ self.log_alpha = nn.Parameter(torch.tensor(math.log(self.alpha_fixed if self.alpha_fixed is not None else cfg["init_alpha"]),
102
+ device=self.dev))
103
+ self.alpha_opt = torch.optim.AdamW([self.log_alpha], lr=cfg["alpha_lr"], betas=(0.7, 0.95))
104
+ self.obs_rms = RunningMeanStd(shape=(self.obs_dim,), device=self.dev)
105
+ self.cobs_rms = RunningMeanStd(shape=(self.cobs_dim,), device=self.dev)
106
+ self.ema, self.n_ema = None, 0 # built at the first actor step
107
+ H, N = self.H, self.N
108
+ z = lambda *s: torch.zeros(*s, device=self.dev) # noqa: E731
109
+ self.cobs_buf, self.rew_buf, self.done_mask = z(H, N, self.cobs_dim), z(H, N), z(H, N)
110
+ self.next_values, self.ent_buf, self.target_values = z(H, N), z(H, N), z(H, N)
111
+ self.grads = GradCounter(cfg["action_grad_clip"], self.dev)
112
+ self.it = 0
113
+ self.windows = 0
114
+ self._obs_s = None # the window's start observation (actor, critic), static, allocated at the first reset
115
+ self._o_frz = RunningMeanStd(shape=(self.obs_dim,), device=self.dev) # the frozen per-window normalisers, static
116
+ self._c_frz = RunningMeanStd(shape=(self.cobs_dim,), device=self.dev)
117
+ self._graph, self._cap = None, None # the captured window and its static outputs (loss, stats)
118
+ self._ptrs = None # the addresses the captured window binds (asserted before each replay)
119
+ self.segments = int(cfg.get("segments", 1)) # the window's autograd / CUDA-graph segments (the review's fallback for the driver fault)
120
+ assert self.H % self.segments == 0, (self.H, self.segments)
121
+ self._W = None
122
+ self._S = None # the env's static window state, made at the first reset
123
+
124
+ def _ent_norm(self, ent):
125
+ return (ent - self.target_entropy) / (2.0 * self._abs_H)
126
+
127
+ def _start_window(self):
128
+ """The first call resets every world (their reset_all) and allocates the static start observation."""
129
+ if self._obs_s is None:
130
+ o = self.bm.reset_all()
131
+ self._obs_s = (o["actor"].detach().clone(), o["critic"].detach().clone())
132
+ self._S = self.bm.make_static() # line 23: the env's static window state (begin_window / end_window)
133
+
134
+ @staticmethod
135
+ def _freeze(src, dst):
136
+ dst.mean.copy_(src.mean); dst.var.copy_(src.var); dst._count.copy_(src._count)
137
+
138
+ def _win_begin(self):
139
+ """The window's start: the frozen normalisers, the env bound to its static state S, the start observation, the critic without
140
+ parameter gradients, the accumulators. Returns the carry C (everything the steps read and update)."""
141
+ N = self.N
142
+ alpha = self.log_alpha.exp().detach()
143
+ self._freeze(self.obs_rms, self._o_frz); self._freeze(self.cobs_rms, self._c_frz)
144
+ self.bm.begin_window(self._S)
145
+ obs, cobs = self._obs_s
146
+ for q in self.critic.parameters(): # the critic trains in _rest(): no parameter gradient from the actor's loss
147
+ q.requires_grad_(False)
148
+ self.obs_rms.update(obs.float()); self.cobs_rms.update(cobs.float())
149
+ return dict(alpha=alpha, obs=obs, cobs=cobs, rew_acc=torch.zeros(N, device=self.dev), disc=torch.ones(N, device=self.dev),
150
+ st={**{k: torch.zeros((), device=self.dev) for k in ("rew", "done", "terminated", "timeout")},
151
+ **{k: torch.zeros((), dtype=torch.int64, device=self.dev) for k in ("overflow", "ovf_bad")}})
152
+
153
+ def _win_steps(self, C, i0, i1):
154
+ """Steps i0 .. i1 - 1 of the window on the carry C; returns their summed (undivided) loss terms."""
155
+ H, cfg, bm = self.H, self.cfg, self.bm
156
+ o_rms, c_rms, alpha = self._o_frz, self._c_frz, C["alpha"]
157
+ obs, cobs, rew_acc, disc, st = C["obs"], C["cobs"], C["rew_acc"], C["disc"], C["st"]
158
+ loss = torch.zeros((), device=self.dev)
159
+ for i in range(i0, i1):
160
+ self.cobs_buf[i] = c_rms.normalize(cobs.float()).detach()
161
+ dist = self.actor.distribution(o_rms.normalize(obs.float()))
162
+ u = dist.rsample()
163
+ u.register_hook(self.grads)
164
+ ent = dist.entropy().sum(-1)
165
+ o = bm.step(self.A * u.to(bm.dt))
166
+ obs, cobs = o["actor"], o["critic"]
167
+ r = o["reward"].float()
168
+ r_env = r
169
+ if self.reward_scale != 1.0: # the return and the critic's targets see K r; the stats keep the env's r
170
+ r = r * self.reward_scale
171
+ term, trunc, ovf = o["terminated"], o["truncated"], o["overflow"]
172
+ done = term | trunc
173
+ boot = trunc & ~term # the time-out (and an env-truncated overflow): bootstrap from the state reached
174
+ self.obs_rms.update(obs.detach().float()); self.cobs_rms.update(cobs.detach().float())
175
+ v_min, v_avg = self.critic(c_rms.normalize(cobs.float()), return_type="min_and_avg")
176
+ b_min, b_avg = self.critic(c_rms.normalize(o["terminal_critic"].float()), return_type="min_and_avg")
177
+ nv_avg = torch.where(done, torch.where(boot, b_avg.squeeze(-1), torch.zeros_like(r)), v_avg.squeeze(-1))
178
+ nv_min = torch.where(done, torch.where(boot, b_min.squeeze(-1), torch.zeros_like(r)), v_min.squeeze(-1))
179
+ rew_acc = rew_acc + disc * (r + alpha * self._ent_norm(ent))
180
+ if i < H - 1:
181
+ loss = loss + ((-rew_acc - cfg["gamma"] * disc * nv_avg) * done.float()).sum()
182
+ else:
183
+ loss = loss + (-rew_acc - cfg["gamma"] * disc * nv_avg).sum()
184
+ disc = torch.where(done, torch.ones_like(disc), disc * cfg["gamma"])
185
+ rew_acc = torch.where(done, torch.zeros_like(rew_acc), rew_acc)
186
+ with torch.no_grad():
187
+ self.rew_buf[i] = r.detach()
188
+ self.done_mask[i] = done.float() if i < H - 1 else torch.ones_like(r)
189
+ self.next_values[i] = nv_min.detach()
190
+ self.ent_buf[i] = ent.detach()
191
+ st["rew"] += r_env.detach().mean() / H
192
+ st["done"] += done.float().mean() / H
193
+ st["terminated"] += term.float().mean() / H
194
+ st["timeout"] += boot.float().mean() / H # every bootstrapped world, env-truncated overflows included
195
+ st["overflow"] += ovf.sum()
196
+ st["ovf_bad"] += (ovf & ~boot).sum() # the env's contract: an overflowed world is truncated & ~terminated
197
+ C.update(obs=obs, cobs=cobs, rew_acc=rew_acc, disc=disc)
198
+ return loss
199
+
200
+ def _win_end(self, C):
201
+ """After the backward: the critic trains again, the start observation buffers and line 23's end_window(S) take the end state."""
202
+ for q in self.critic.parameters():
203
+ q.requires_grad_(True)
204
+ self._obs_s[0].copy_(C["obs"].detach()); self._obs_s[1].copy_(C["cobs"].detach())
205
+ self.bm.end_window(self._S)
206
+
207
+ def _cut(self, C):
208
+ """A segment boundary (cfg["segments"] > 1): every carried tensor that holds gradient (the env's state and frames, the trainer's
209
+ observations and return accumulator) becomes a fresh leaf, so each segment has its own autograd graph; returns (out, leaf) pairs,
210
+ the backward's link from the next segment to this one."""
211
+ bm, pairs = self.bm, []
212
+
213
+ def leaf(x):
214
+ y = x.detach().requires_grad_(True)
215
+ pairs.append((x, y))
216
+ return y
217
+ for k in bm.STATE:
218
+ x = getattr(bm, k)
219
+ if torch.is_tensor(x) and x.requires_grad:
220
+ setattr(bm, k, leaf(x))
221
+ if bm.frames is not None:
222
+ bm.frames = {k: leaf(x) if x.requires_grad else x for k, x in bm.frames.items()}
223
+ for k in ("obs", "cobs", "rew_acc"):
224
+ if C[k].requires_grad:
225
+ C[k] = leaf(C[k])
226
+ return pairs
227
+
228
+ def _seg_forward(self, k):
229
+ """Segment k's forward (k = 0 begins the window); the last segment also sums the window's loss for the stats."""
230
+ H, N, m = self.H, self.N, self.segments
231
+ K = H // m
232
+ if k == 0:
233
+ self._W = dict(C=self._win_begin(), seg=[], cuts=[])
234
+ else:
235
+ self._W["cuts"].append(self._cut(self._W["C"]))
236
+ self._W["seg"].append(self._win_steps(self._W["C"], k * K, (k + 1) * K) / (H * N))
237
+ if k == m - 1:
238
+ tot = self._W["seg"][0].detach()
239
+ for s_ in self._W["seg"][1:]:
240
+ tot = tot + s_.detach()
241
+ self._W["loss"] = tot
242
+
243
+ def _seg_backward(self, k):
244
+ """Segment k's backward: its own loss share plus, through the cut after it, the gradient its outputs received from segment k + 1;
245
+ the actor's parameters accumulate across segments. Segment 0's backward ends the window."""
246
+ tensors, grads = [self._W["seg"][k]], [torch.ones_like(self._W["seg"][k])]
247
+ if k < self.segments - 1:
248
+ for out, lf in self._W["cuts"][k]:
249
+ if lf.grad is not None:
250
+ tensors.append(out); grads.append(lf.grad)
251
+ torch.autograd.backward(tensors, grad_tensors=grads)
252
+ if k == 0:
253
+ self._win_end(self._W["C"])
254
+
255
+ def _window(self):
256
+ """One update's captured part: the H-step forward through the env, the backward, then the window's end state written back
257
+ (after the backward). One segment (the default) is one autograd graph and one CUDA graph; m segments cut the window into m
258
+ autograd graphs (and 2m CUDA graphs when captured), the same gradient up to the summation order at the cuts. Returns (loss, stats)."""
259
+ if self.segments == 1:
260
+ C = self._win_begin()
261
+ loss = self._win_steps(C, 0, self.H) / (self.H * self.N)
262
+ loss.backward()
263
+ self._win_end(C)
264
+ return loss.detach(), C["st"]
265
+ for k in range(self.segments):
266
+ self._seg_forward(k)
267
+ for k in reversed(range(self.segments)):
268
+ self._seg_backward(k)
269
+ return self._W["loss"], self._W["C"]["st"]
270
+
271
+ @torch.no_grad()
272
+ def targets(self):
273
+ alpha, lam_c, g = self.log_alpha.exp(), self.cfg["lam"], self.cfg["gamma"]
274
+ Ai = torch.zeros(self.N, device=self.dev)
275
+ Bi = torch.zeros(self.N, device=self.dev)
276
+ lam = torch.ones(self.N, device=self.dev)
277
+ ent = self._ent_norm(self.ent_buf)
278
+ for i in reversed(range(self.H)):
279
+ lam = lam * lam_c * (1.0 - self.done_mask[i]) + self.done_mask[i]
280
+ rew = self.rew_buf[i] + alpha * ent[i]
281
+ Ai = (1.0 - self.done_mask[i]) * (lam_c * g * Ai + g * self.next_values[i] + (1.0 - lam) / (1.0 - lam_c) * rew)
282
+ Bi = g * (self.next_values[i] * self.done_mask[i] + Bi * (1.0 - self.done_mask[i])) + rew
283
+ self.target_values[i] = (1.0 - lam_c) * Ai + lam * Bi
284
+
285
+ def train_critic(self):
286
+ x, y = self.cobs_buf.reshape(-1, self.cobs_dim), self.target_values.reshape(-1)
287
+ n = x.shape[0]
288
+ bs = n // self.cfg["critic_minibatches"]
289
+ tot = torch.zeros((), device=self.dev)
290
+ for _ in range(self.cfg["critic_iterations"]):
291
+ perm = torch.randperm(n, generator=self.gen, device=self.dev)
292
+ for s in range(0, n - bs + 1, bs):
293
+ idx = perm[s:s + bs]
294
+ self.critic_opt.zero_grad()
295
+ l = ((self.critic(x[idx], return_type="all").squeeze(-1) - y[idx][None]) ** 2).mean()
296
+ l.backward()
297
+ clip_grad_norm_(self.critic.parameters(), self.cfg["critic_clip"])
298
+ self.critic_opt.step()
299
+ tot += l.detach()
300
+ return tot / (self.cfg["critic_iterations"] * self.cfg["critic_minibatches"])
301
+
302
+ def update_alpha(self):
303
+ loss = (self.log_alpha.exp() * self._abs_H * (self.ent_buf - self.target_entropy)).mean()
304
+ self.alpha_opt.zero_grad()
305
+ loss.backward()
306
+ clip_grad_norm_([self.log_alpha], 0.5)
307
+ self.alpha_opt.step()
308
+
309
+ def _actor_step(self):
310
+ if self.cfg["ema"] and self.ema is None: # E0: the shadow starts from the actor before its first step
311
+ self.ema = copy.deepcopy(self.actor)
312
+ for p in self.ema.parameters():
313
+ p.requires_grad_(False)
314
+ self.actor_opt.step()
315
+ if self.ema is not None:
316
+ d = min(0.999, (1 + self.n_ema) / (10 + self.n_ema))
317
+ with torch.no_grad():
318
+ for pe, pa in zip(self.ema.parameters(), self.actor.parameters()):
319
+ pe.mul_(d).add_(pa.detach(), alpha=1.0 - d)
320
+ self.n_ema += 1
321
+
322
+ def _rest(self):
323
+ """The eager part of an update, the same code in both modes: the actor's clip, the non-finite raise, the step and the EMA, the
324
+ temperature, the targets, the critic."""
325
+ cfg = self.cfg
326
+ gn = clip_grad_norm_(self.actor.parameters(), cfg["actor_clip"])
327
+ if not torch.isfinite(gn):
328
+ raise ValueError(f"non-finite actor grad norm at iteration {self.it}: {self.grads.read_and_zero()}")
329
+ self._actor_step()
330
+ if self.alpha_fixed is None:
331
+ self.update_alpha()
332
+ self.targets()
333
+ return gn, self.train_critic()
334
+
335
+ def iteration(self):
336
+ cfg = self.cfg
337
+ for o, v in ((self.actor_opt, lr_linear(self.it, cfg["actor_lr"], cfg["decay_iters"])),
338
+ (self.critic_opt, lr_linear(self.it, cfg["critic_lr"], cfg["decay_iters"]))):
339
+ for g in o.param_groups:
340
+ g["lr"] = v
341
+ sync = torch.cuda.synchronize if str(self.dev).startswith("cuda") else (lambda: None)
342
+ sync(); t0 = time.clock_gettime(time.CLOCK_MONOTONIC_RAW)
343
+ if self._graph is None:
344
+ self._start_window()
345
+ self.actor_opt.zero_grad()
346
+ loss, st = self._window()
347
+ else: # the captured window: its gradients land in the actor's static .grad
348
+ assert self._graph_ptrs() == self._ptrs, "a tensor the captured window reads or writes was reassigned since capture()"
349
+ for g in self._graph:
350
+ g.replay()
351
+ loss, st = self._cap
352
+ self.windows += 1
353
+ sync(); t1 = time.clock_gettime(time.CLOCK_MONOTONIC_RAW)
354
+ bad = int(st["ovf_bad"]) # overflow-as-done's contract, checked before the actor step (one scalar read)
355
+ assert bad == 0, (f"overflow contract broken at iteration {self.it}: {bad} of {int(st['overflow'])} overflowed world-steps not "
356
+ "truncated & ~terminated by the env (docs/design/overflow-as-done.md)")
357
+ gn, vloss = self._rest()
358
+ sync(); t2 = time.clock_gettime(time.CLOCK_MONOTONIC_RAW)
359
+ self.it += 1
360
+ out = {k: float(v) if v.is_floating_point() else int(v) for k, v in st.items()} # the host reads, after the window (replay)
361
+ out.update(t_window=t1 - t0, t_rest=t2 - t1, loss=float(loss), gn=float(gn), vloss=float(vloss),
362
+ alpha=float(self.log_alpha.detach().exp()), ent=float(self.ent_buf.mean()), windows=1,
363
+ captured=self._graph is not None, lr=lr_linear(self.it - 1, cfg["actor_lr"], cfg["decay_iters"]),
364
+ **self.grads.read_and_zero())
365
+ return out
366
+
367
+ def capture(self, warmup=2):
368
+ """Record _window() as one CUDA graph (after at least one eager update: the start observation and the EMA exist). The env's
369
+ static state S comes from the first eager update (_start_window: S = bm.make_static(); every window begin_window(S) /
370
+ end_window(S)). The warm-ups run the window on a side stream, under CUDA's sync-debug "error" mode, and are undone: the agent's and the env's state and the RNG are restored before the capture, and again after it, so the
371
+ first replay continues exactly where the last eager update left off."""
372
+ assert str(self.dev).startswith("cuda") and self._graph is None and self._obs_s is not None and self.ema is not None
373
+ snap = self.snapshot_all()
374
+ s = torch.cuda.Stream()
375
+ s.wait_stream(torch.cuda.current_stream())
376
+ with torch.cuda.stream(s):
377
+ torch.cuda.set_sync_debug_mode("error") # any host sync inside the window raises here, with its stack trace
378
+ for _ in range(warmup):
379
+ self.actor_opt.zero_grad(set_to_none=True)
380
+ self._window()
381
+ torch.cuda.set_sync_debug_mode("default")
382
+ torch.cuda.current_stream().wait_stream(s)
383
+ torch.cuda.synchronize()
384
+
385
+ def undo():
386
+ self.restore_all(snap)
387
+ self.grads.read_and_zero()
388
+ undo()
389
+ self.actor_opt.zero_grad(set_to_none=True) # the backward allocates the actor's .grad in the graph's pool (static)
390
+ if self.segments == 1:
391
+ g = torch.cuda.CUDAGraph()
392
+ with torch.cuda.graph(g):
393
+ cap = self._window()
394
+ graphs = [g]
395
+ else: # 2m graphs in one pool: the forwards in order, then the backwards in reverse
396
+ pool = torch.cuda.graph_pool_handle()
397
+ fw = [torch.cuda.CUDAGraph() for _ in range(self.segments)]
398
+ bw = [torch.cuda.CUDAGraph() for _ in range(self.segments)]
399
+ for k in range(self.segments):
400
+ with torch.cuda.graph(fw[k], pool=pool):
401
+ self._seg_forward(k)
402
+ for k in reversed(range(self.segments)):
403
+ with torch.cuda.graph(bw[k], pool=pool):
404
+ self._seg_backward(k)
405
+ graphs = fw + bw[::-1] # the replay order
406
+ cap = (self._W["loss"], self._W["C"]["st"])
407
+ torch.cuda.synchronize()
408
+ undo()
409
+ self._graph, self._cap = graphs, cap
410
+ self._ptrs = self._graph_ptrs()
411
+
412
+ def _graph_ptrs(self):
413
+ """The addresses the captured window reads or writes (asserted before every replay, as sapo_capture.py does): the actor's
414
+ parameters and its static .grad, the critic, log_alpha, the four normalisers, the start observation, the env's S and sampler,
415
+ the H x N buffers, the gradient counters."""
416
+ ts = [*self.actor.parameters(), *(q.grad for q in self.actor.parameters()), *self.critic.parameters(), self.log_alpha]
417
+ for r in (self.obs_rms, self.cobs_rms, self._o_frz, self._c_frz):
418
+ ts += [r.mean, r.var, r._count]
419
+ ts += [*self._obs_s, *self._S.values(), self.bm.sampler.bin_failed_count, self.bm.sampler.current_bin_failed]
420
+ ts += [self.cobs_buf, self.rew_buf, self.done_mask, self.next_values, self.ent_buf, self.target_values]
421
+ ts += [self.grads.nonfinite, self.grads.clipped, self.grads.rows]
422
+ ts += [self.bm.be.aflag_bad, self.bm.be.aflag_or] # the fix (c): the law's device-side adjoint flag counters
423
+ return [None if x is None else x.data_ptr() for x in ts]
424
+
425
+ # ------------------------------------------------------------------ evaluation and checkpoints
426
+ def eval_actor(self, which="ema"):
427
+ assert which in ("ema", "raw"), which
428
+ return self.ema if (which == "ema" and self.ema is not None) else self.actor
429
+
430
+ @torch.no_grad()
431
+ def act_mean(self, actor_obs_raw, which="ema"):
432
+ """g1_bm_eval's `act_mean`: the mean action in their raw units on the env's raw actor observation, normalised by the raw
433
+ policy's normaliser (E0: the EMA shadow keeps it)."""
434
+ a = self.eval_actor(which)
435
+ u = torch.tanh(a.mu(a.feature_net(self.obs_rms.normalize(actor_obs_raw.float()))))
436
+ return self.A * u.to(self.A.dtype)
437
+
438
+ def checkpoint(self):
439
+ """The checkpoint payload (arm_a3 saves it under the key "snapshot"; load_policy reads it)."""
440
+ rms = lambda r: dict(mean=r.mean.clone(), var=r.var.clone(), count=r.count) # noqa: E731
441
+ sd = lambda m: {k: v.detach().clone() for k, v in m.state_dict().items()} # noqa: E731
442
+ return dict(actor=sd(self.actor), actor_ema=sd(self.ema) if self.ema is not None else None, critic=sd(self.critic),
443
+ actor_opt=self.actor_opt.state_dict(), critic_opt=self.critic_opt.state_dict(),
444
+ alpha_opt=self.alpha_opt.state_dict(), log_alpha=self.log_alpha.detach().clone(), obs_rms=rms(self.obs_rms),
445
+ cobs_rms=rms(self.cobs_rms), it=self.it, n_ema=self.n_ema, windows=self.windows, A=self.A.clone(),
446
+ cfg=dict(self.cfg))
447
+
448
+ def state_full(self, bufs=True):
449
+ """Every mutable agent tensor, cloned (the capture's undo and line 23's / the gate's eager-vs-captured comparison). bufs=False
450
+ leaves out the H x N buffers, which every update rewrites before reading (arm_a3's resume state)."""
451
+ c = lambda x: x.detach().clone() # noqa: E731
452
+ sd = lambda m: {k: c(v) for k, v in m.state_dict().items()} # noqa: E731
453
+ rms = lambda r: (c(r.mean), c(r.var), c(r._count)) # noqa: E731
454
+ return dict(actor=sd(self.actor), critic=sd(self.critic), ema=sd(self.ema) if self.ema is not None else None,
455
+ actor_opt=copy.deepcopy(self.actor_opt.state_dict()), critic_opt=copy.deepcopy(self.critic_opt.state_dict()),
456
+ alpha_opt=copy.deepcopy(self.alpha_opt.state_dict()), log_alpha=c(self.log_alpha),
457
+ obs_rms=rms(self.obs_rms), cobs_rms=rms(self.cobs_rms), obs_s=tuple(c(x) for x in self._obs_s),
458
+ bufs=[c(b) for b in (self.cobs_buf, self.rew_buf, self.done_mask, self.next_values, self.ent_buf, self.target_values)]
459
+ if bufs else None,
460
+ gen=self.gen.get_state(), it=self.it, windows=self.windows, n_ema=self.n_ema)
461
+
462
+ def load_full(self, s):
463
+ """state_full()'s inverse, IN PLACE wherever a captured graph reads the tensor (parameters, normalisers, buffers, the start
464
+ observation); the optimisers (eager only) load their state dicts."""
465
+ with torch.no_grad():
466
+ for m, k in ((self.actor, "actor"), (self.critic, "critic")):
467
+ for n_, v in m.state_dict().items():
468
+ v.copy_(s[k][n_])
469
+ if s["ema"] is not None:
470
+ if self.ema is None: # a fresh agent (arm_a3 --resume): the shadow is built, then loaded
471
+ self.ema = copy.deepcopy(self.actor)
472
+ for q in self.ema.parameters():
473
+ q.requires_grad_(False)
474
+ for n_, v in self.ema.state_dict().items():
475
+ v.copy_(s["ema"][n_])
476
+ self.log_alpha.copy_(s["log_alpha"])
477
+ for r, k in ((self.obs_rms, "obs_rms"), (self.cobs_rms, "cobs_rms")):
478
+ r.mean.copy_(s[k][0]); r.var.copy_(s[k][1]); r._count.copy_(s[k][2])
479
+ for x, y in zip(self._obs_s, s["obs_s"]):
480
+ x.copy_(y)
481
+ if s["bufs"] is not None:
482
+ for b, y in zip((self.cobs_buf, self.rew_buf, self.done_mask, self.next_values, self.ent_buf, self.target_values),
483
+ s["bufs"]):
484
+ b.copy_(y)
485
+ # a deep copy: load_state_dict keeps the given state tensors when dtype and device match, so later steps would mutate the snapshot
486
+ self.actor_opt.load_state_dict(copy.deepcopy(s["actor_opt"])); self.critic_opt.load_state_dict(copy.deepcopy(s["critic_opt"]))
487
+ self.alpha_opt.load_state_dict(copy.deepcopy(s["alpha_opt"]))
488
+ self.gen.set_state(s["gen"])
489
+ self.it, self.windows, self.n_ema = s["it"], s["windows"], s["n_ema"]
490
+
491
+ def snapshot_all(self, bufs=True):
492
+ """The whole update's state: every agent tensor (state_full), the env's static window state S and its sampler, the RNGs. The
493
+ capture's undo and the eager-vs-captured gate (from one snapshot) both use it."""
494
+ bm = self.bm
495
+ c = lambda x: x.detach().clone() # noqa: E731
496
+ return dict(agent=self.state_full(bufs=bufs), S={k: c(v) for k, v in self._S.items()},
497
+ sampler=(c(bm.sampler.bin_failed_count), c(bm.sampler.current_bin_failed)), initial_reset_done=bm.initial_reset_done,
498
+ rng_cpu=torch.get_rng_state(), rng_cuda=torch.cuda.get_rng_state() if str(self.dev).startswith("cuda") else None)
499
+
500
+ def restore_all(self, s):
501
+ """snapshot_all()'s inverse, in place (S and the sampler are what the captured window reads)."""
502
+ bm = self.bm
503
+ self.load_full(s["agent"])
504
+ with torch.no_grad():
505
+ for k, v in self._S.items():
506
+ v.copy_(s["S"][k])
507
+ bm.sampler.bin_failed_count.copy_(s["sampler"][0]); bm.sampler.current_bin_failed.copy_(s["sampler"][1])
508
+ bm.initial_reset_done = s["initial_reset_done"]
509
+ bm.begin_window(self._S) # the env's attributes back on S (the next window starts there anyway)
510
+ torch.set_rng_state(s["rng_cpu"])
511
+ if s["rng_cuda"] is not None:
512
+ torch.cuda.set_rng_state(s["rng_cuda"])
513
+
514
+ # line 23's gate names (a3_capture_gate.py): the whole-state snapshot, its in-place restore, and every tensor an update touches
515
+ def snapshot(self):
516
+ return self.snapshot_all()
517
+
518
+ def restore(self, snap):
519
+ self.restore_all(snap)
520
+
521
+ def tensors(self):
522
+ """name -> tensor of everything an update reads or writes on the agent's side (the gate compares these bitwise)."""
523
+ out = {}
524
+ for pre, m in (("actor", self.actor), ("critic", self.critic), ("ema", self.ema)):
525
+ if m is not None:
526
+ out.update({f"{pre}.{k}": v for k, v in m.state_dict().items()})
527
+ for pre, opt in (("actor_opt", self.actor_opt), ("critic_opt", self.critic_opt), ("alpha_opt", self.alpha_opt)):
528
+ names = {id(q): f"p{i}" for i, q in enumerate(q for g in opt.param_groups for q in g["params"])}
529
+ for q, st in opt.state.items():
530
+ out.update({f"{pre}.{names[id(q)]}.{k}": v for k, v in st.items() if torch.is_tensor(v)})
531
+ out["log_alpha"] = self.log_alpha
532
+ for pre, r in (("obs_rms", self.obs_rms), ("cobs_rms", self.cobs_rms), ("o_frz", self._o_frz), ("c_frz", self._c_frz)):
533
+ out.update({f"{pre}.mean": r.mean, f"{pre}.var": r.var, f"{pre}.count": r._count})
534
+ if self._obs_s is not None:
535
+ out["obs_s.actor"], out["obs_s.critic"] = self._obs_s
536
+ for k in ("cobs_buf", "rew_buf", "done_mask", "next_values", "ent_buf", "target_values"):
537
+ out[k] = getattr(self, k)
538
+ for k in ("nonfinite", "clipped", "rows"):
539
+ out[f"grads.{k}"] = getattr(self.grads, k)
540
+ return out
541
+
542
+ def load_policy(self, snap):
543
+ """The evaluation part of a snapshot (actor, its EMA shadow, the actor normaliser, A); asserts the same action bound."""
544
+ assert torch.equal(snap["A"].to(self.A.device, self.A.dtype), self.A), "the snapshot's action bound differs from this env's"
545
+ self.actor.load_state_dict(snap["actor"])
546
+ if snap["actor_ema"] is not None:
547
+ if self.ema is None:
548
+ self.ema = copy.deepcopy(self.actor)
549
+ self.ema.load_state_dict(snap["actor_ema"])
550
+ self.obs_rms.mean.copy_(snap["obs_rms"]["mean"]); self.obs_rms.var.copy_(snap["obs_rms"]["var"])
551
+ self.obs_rms._count.fill_(snap["obs_rms"]["count"]) # in place (the count setter swaps the tensor)