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,599 @@
1
+ """SHAC networks ported from DiffRL (Xu et al. 2022) -- a faithful mirror, not a reinvention.
2
+
3
+ ActorStochasticMLP (learned per-action logstd = the EXPLORATION our prior deterministic actor
4
+ lacked), CriticMLP, and RunningMeanStd (obs normalization). Hidden layers are Linear + elu +
5
+ LayerNorm; the actor's reparameterized rsample() keeps actions differentiable so the SHAC policy
6
+ gradient flows through the differentiable sim. The CRITIC linears use orthogonal init (gain
7
+ sqrt(2), bias 0); the ACTOR uses PyTorch default init -- matching DiffRL, whose ActorStochasticMLP
8
+ DEFINES an orthogonal init_ but never applies it to its Linears (only the critic + the deterministic
9
+ actor do). [An earlier commit wrongly made the actor orthogonal "to match DiffRL"; this reverts it.]
10
+
11
+ Reference: physics-review/DiffRL/models/{actor,critic}.py + utils/running_mean_std.py.
12
+ """
13
+ import math
14
+
15
+ import numpy as np
16
+ import torch
17
+ import torch.distributions as D
18
+ import torch.nn as nn
19
+ import torch.nn.functional as F
20
+ from torch.distributions.normal import Normal
21
+
22
+ _ACT = {"elu": nn.ELU, "relu": nn.ReLU, "tanh": nn.Tanh, "silu": nn.SiLU}
23
+
24
+
25
+ class _LatticeDist:
26
+ """State-independent Lattice exploration (Chiappa et al. 2023, arXiv:2305.20065) as a LOW-RANK
27
+ Gaussian N(mu, Sigma), Sigma = diag(sa^2) + W diag(sx^2) W^T, WITHOUT ever forming or factorizing
28
+ the dense (A,A) covariance. Every Gaussian quantity (log_prob / entropy / KL) is routed through
29
+ the (H,H) Woodbury capacitance C = diag(1/sx^2) + W^T diag(1/sa^2) W, where H = latent width << A
30
+ (416 vs ~512 at full body). Cost/memory are O(A*H + H^3) instead of the dense O(A^3), and there is
31
+ no per-step (A,A) Cholesky (the dense version's full-body OOM / 298-steps/s wall). Sigma is shared
32
+ across the batch (state-independent), so C is factorized ONCE per distribution. A tiny jitter is
33
+ folded into sa^2 for PSD stability (mirrors the old dense _lattice_cov). Shapes: mu (B,A); sa (A,);
34
+ sx (H,); W (A,H) = the policy's final linear (its emergent actuator synergies)."""
35
+
36
+ _JITTER = 1e-6
37
+
38
+ def __init__(self, mu, sa, sx, W):
39
+ self.loc = mu # (B,A) mean
40
+ self.sa = sa # (A,) action-space std
41
+ self.sx = sx # (H,) latent std
42
+ self.W = W # (A,H) mean-layer weight (synergy basis)
43
+ self.A = int(W.shape[0])
44
+ self.H = int(W.shape[1])
45
+ self._sa2 = sa * sa + self._JITTER # (A,) effective diagonal variance
46
+ self._sx2 = sx * sx # (H,)
47
+ self._ea = None # last-drawn action noise (B,A)
48
+ self._ex = None # last-drawn latent noise (B,H)
49
+ self._cache = None # (Lc, logdetSigma), shared covariance
50
+
51
+ @property
52
+ def mean(self):
53
+ return self.loc
54
+
55
+ def _capacitance(self):
56
+ """C = diag(1/sx^2) + W^T diag(1/sa^2) W (H,H), its lower Cholesky Lc, and log|Sigma| via the
57
+ matrix-determinant lemma (log|D| + log|Lambda| + log|C|). Shared cov => computed once, cached."""
58
+ if self._cache is None:
59
+ C = torch.diag(1.0 / self._sx2) + self.W.t() @ (self.W / self._sa2[:, None]) # (H,H)
60
+ Lc = torch.linalg.cholesky(C)
61
+ logdet = (self._sa2.log().sum() + self._sx2.log().sum()
62
+ + 2.0 * torch.diagonal(Lc).log().sum())
63
+ self._cache = (Lc, logdet)
64
+ return self._cache
65
+
66
+ def rsample(self):
67
+ a, _, _ = self.rsample_with_noise()
68
+ return a
69
+
70
+ def rsample_with_noise(self):
71
+ """Reparameterized draw a = mu + sa*ea + (sx*ex) W^T, ea~N(0,I_A), ex~N(0,I_H). NO Cholesky.
72
+ Returns (a, ea, ex) and stashes (ea,ex) so a caller can cache the exact noise realization for
73
+ the pathwise sample-reuse surrogate."""
74
+ mu = self.loc
75
+ ea = torch.randn_like(mu) # (B,A)
76
+ ex = torch.randn(mu.shape[0], self.H, dtype=mu.dtype, device=mu.device) # (B,H)
77
+ a = mu + self.sa * ea + (self.sx * ex) @ self.W.t()
78
+ self._ea, self._ex = ea, ex
79
+ return a, ea, ex
80
+
81
+ def log_prob(self, a):
82
+ """log N(a; mu, Sigma) via Woodbury; NEVER forms (A,A). r = a-mu (B,A)."""
83
+ Lc, logdet = self._capacitance()
84
+ r = a - self.loc # (B,A)
85
+ t = self.W.t() @ (r / self._sa2).t() # (H,B) = W^T D^-1 r
86
+ v = torch.cholesky_solve(t, Lc) # (H,B) = C^-1 t
87
+ maha = (r * r / self._sa2).sum(-1) - (t * v).sum(0) # (B,) r^T Sigma^-1 r
88
+ return -0.5 * (maha + logdet + self.A * math.log(2.0 * math.pi)) # (B,)
89
+
90
+ def entropy(self):
91
+ _, logdet = self._capacitance()
92
+ return 0.5 * (self.A * (1.0 + math.log(2.0 * math.pi)) + logdet) # scalar (shared cov)
93
+
94
+ def kl_old_new(self, old, mu_o):
95
+ """KL( N(mu_o, So) || self ): OLD (behavior) dist vs this NEW dist. `old` is a detached
96
+ _LatticeDist holding (sa_o, sx_o, W_o); mu_o (B,A) is the cached behavior mean. All work is
97
+ (H,H)/(H,A); NEVER an (A,A) tensor. Differentiable in the new dist; old detached.
98
+ KL = 0.5[ tr(Sn^-1 So) + (mu_n-mu_o)^T Sn^-1 (mu_n-mu_o) - A + log|Sn| - log|So| ]."""
99
+ Lcn, logdet_n = self._capacitance()
100
+ _, logdet_o = old._capacitance()
101
+ san2, Wn = self._sa2, self.W
102
+ sao2, sxo2, Wo = old._sa2, old._sx2, old.W
103
+ # quadratic term via the Woodbury Mahalanobis of the NEW dist at r = mu_n - mu_o
104
+ r = self.loc - mu_o # (B,A)
105
+ t = Wn.t() @ (r / san2).t() # (H,B)
106
+ v = torch.cholesky_solve(t, Lcn)
107
+ quad = (r * r / san2).sum(-1) - (t * v).sum(0) # (B,)
108
+ # tr(Sn^-1 Do) with Sn^-1 = Dn^-1 - Dn^-1 Wn Cn^-1 Wn^T Dn^-1
109
+ Y = torch.cholesky_solve(Wn.t(), Lcn) # (H,A) = Cn^-1 Wn^T
110
+ diag_WCW = (Wn * Y.t()).sum(1) # (A,) diag(Wn Cn^-1 Wn^T)
111
+ term_Do = (sao2 * (1.0 / san2 - diag_WCW / (san2 * san2))).sum() # scalar
112
+ # tr(Sn^-1 Wo Lambda_o Wo^T) = sum sxo^2 * diag(Wo^T Sn^-1 Wo)
113
+ P = Wo.t() @ (Wo / san2[:, None]) # (H,H) = Wo^T Dn^-1 Wo
114
+ Q = Wn.t() @ (Wo / san2[:, None]) # (H,H) = Wn^T Dn^-1 Wo
115
+ WoSnInvWo = P - Q.t() @ torch.cholesky_solve(Q, Lcn) # (H,H) = Wo^T Sn^-1 Wo
116
+ term_Wo = (sxo2 * torch.diagonal(WoSnInvWo)).sum() # scalar
117
+ tr = term_Do + term_Wo
118
+ return 0.5 * (tr + quad - self.A + logdet_n - logdet_o) # (B,)
119
+
120
+
121
+ def _mlp(dims, activation, orthogonal, plain_last=True):
122
+ # dims = [in, h1, ..., out]; hidden layers get activation + LayerNorm (DiffRL structure).
123
+ # plain_last=True (default): the final linear is bare (no act/LayerNorm) -- the ShacVec/RpoVec
124
+ # convention (mu_net / critic head), byte-identical. plain_last=False: EVERY linear (incl. the last)
125
+ # gets act+LayerNorm -- used for SAPO's ActorSquashedMLP shared feature trunk, whose units[-1] output
126
+ # feeds the mu/logstd heads with activation+norm already applied (mirrors mineral MLP plain_last=False).
127
+ act = _ACT[activation]
128
+ mods = []
129
+ for i in range(len(dims) - 1):
130
+ lin = nn.Linear(dims[i], dims[i + 1])
131
+ if orthogonal:
132
+ nn.init.orthogonal_(lin.weight, np.sqrt(2))
133
+ nn.init.constant_(lin.bias, 0.0)
134
+ mods.append(lin)
135
+ if i < len(dims) - 2 or not plain_last:
136
+ mods.append(act())
137
+ mods.append(nn.LayerNorm(dims[i + 1]))
138
+ return nn.Sequential(*mods)
139
+
140
+
141
+ class ActorStochasticMLP(nn.Module):
142
+ def __init__(self, obs_dim, act_dim, units=(128, 64, 32), activation="elu",
143
+ logstd_init=-1.0, device="cuda", out_bias=None, lattice=False, lattice_alpha=1.0):
144
+ super().__init__()
145
+ self.mu_net = _mlp([obs_dim, *units, act_dim], activation, orthogonal=False).to(device) # DiffRL stochastic actor = PyTorch default init
146
+ # Relaxed-start init (DiffRL small-action-init idea): tiny last-layer weights + a bias so the
147
+ # UNTRAINED policy outputs a near-constant baseline action. For the myoLeg muscle env where
148
+ # u = 0.5*(tanh(a)+1) in [0,1], out_bias=-1.5 -> u ~ 0.05 (muscles RELAXED) instead of the
149
+ # default-init ~0.5 (co-contraction -> stiff legs from the very first step). None = default init.
150
+ if out_bias is not None:
151
+ last = [m for m in self.mu_net if isinstance(m, nn.Linear)][-1]
152
+ nn.init.uniform_(last.weight, -1e-3, 1e-3)
153
+ nn.init.constant_(last.bias, float(out_bias))
154
+ self.obs_dim, self.act_dim = obs_dim, act_dim
155
+ # Lattice exploration (Chiappa et al. 2023, arXiv:2305.20065; default OFF => diagonal Gaussian,
156
+ # byte-identical). ON: correlated action noise induced by the final linear layer W (= the policy's
157
+ # own emergent actuator synergies, NO external data). Non-state-dependent variant (their
158
+ # LatticeNoiseDistribution): Sigma = W diag(S_x^2) W^T + diag(S_a^2). logstd = [S_a (act_dim); S_x
159
+ # (latent_dim)]; S_x is offset by ln(alpha) so alpha scales latent vs action noise (alpha=0-like =>
160
+ # diagonal). mu_net[:-1] = feature net -> latent x; mu_net[-1] = W (the mean layer).
161
+ self.lattice = bool(lattice)
162
+ self._latent_dim = int(units[-1])
163
+ if self.lattice:
164
+ ls = torch.empty(act_dim + self._latent_dim, dtype=torch.float32, device=device)
165
+ ls[:act_dim] = logstd_init
166
+ ls[act_dim:] = logstd_init + float(np.log(max(lattice_alpha, 1e-8)))
167
+ self.logstd = nn.Parameter(ls)
168
+ else:
169
+ self.logstd = nn.Parameter(torch.ones(act_dim, dtype=torch.float32, device=device) * logstd_init)
170
+
171
+ def _lattice_dist(self, obs):
172
+ """Low-rank Lattice distribution N(mu, diag(S_a^2) + W diag(S_x^2) W^T). W = the final linear
173
+ (the emergent synergy basis); mu = W x + b for latent x = feature net(obs). Returns a
174
+ _LatticeDist that does all Gaussian math via the (H,H) Woodbury capacitance -- NO dense (A,A)
175
+ covariance is ever formed or factorized (the dense variant's full-body OOM / throughput wall)."""
176
+ x = self.mu_net[:-1](obs) # feature net -> latent (batch, H)
177
+ mu = self.mu_net[-1](x) # mean (batch, A)
178
+ std = self.logstd.exp()
179
+ sa = std[: self.act_dim] # (A,) action std
180
+ sx = std[self.act_dim :] # (H,) latent std
181
+ return _LatticeDist(mu, sa, sx, self.mu_net[-1].weight)
182
+
183
+ def forward(self, obs, deterministic=False):
184
+ if self.lattice:
185
+ dist = self._lattice_dist(obs)
186
+ return dist.mean if deterministic else dist.rsample() # rsample = reparameterized
187
+ mu = self.mu_net(obs)
188
+ if deterministic:
189
+ return mu
190
+ return Normal(mu, self.logstd.exp()).rsample() # reparameterized -> grad flows to mu, logstd
191
+
192
+ def distribution(self, obs):
193
+ """Pre-tanh action distribution. PPO/RPO need log_prob/entropy/KL over the raw action a;
194
+ the env is fed tanh(a) (GpuMyoLegVecEnv maps [-1,1] -> activation), and -- matching DiffRL/
195
+ ShacVec -- no tanh Jacobian correction is applied, so SHAC/PPO/RPO share one action interface.
196
+ SHAC itself keeps using forward(); this is additive. Lattice => low-rank _LatticeDist."""
197
+ if self.lattice:
198
+ return self._lattice_dist(obs)
199
+ return Normal(self.mu_net(obs), self.logstd.exp())
200
+
201
+
202
+ class TanhTransform(D.Transform):
203
+ """tanh bijector for the SquashedNormal (SAPO). A faithful port of mineral/nets/distributions.py:
204
+ the numerically stable log-abs-det-Jacobian 2*(log2 - x - softplus(-2x)) = log(1 - tanh(x)^2), and
205
+ cache_size=1 so log_prob(rsample()) reuses the pre-tanh x (never atanh(+-1) -> inf)."""
206
+
207
+ domain = D.constraints.real
208
+ codomain = D.constraints.interval(-1.0, 1.0)
209
+ sign = +1
210
+
211
+ def __init__(self, cache_size=1):
212
+ super().__init__(cache_size=cache_size)
213
+
214
+ @staticmethod
215
+ def atanh(x):
216
+ return 0.5 * (x.log1p() - (-x).log1p())
217
+
218
+ def __eq__(self, other):
219
+ return isinstance(other, TanhTransform)
220
+
221
+ def _call(self, x):
222
+ return x.tanh()
223
+
224
+ def _inverse(self, y):
225
+ return self.atanh(y)
226
+
227
+ def log_abs_det_jacobian(self, x, y):
228
+ return 2.0 * (math.log(2.0) - x - F.softplus(-2.0 * x))
229
+
230
+
231
+ class SquashedNormal(D.TransformedDistribution):
232
+ """Normal(mu, std) pushed through tanh (SAPO action distribution; mineral distributions.py). rsample()
233
+ is reparameterized AND already in (-1,1); log_prob includes the tanh Jacobian correction (via the
234
+ TransformedDistribution machinery); entropy() is the single-sample Monte-Carlo estimate
235
+ -log_prob(rsample()) INCLUDING that Jacobian (matches the reference: draw N=1, per-dim, sum elsewhere)."""
236
+
237
+ def __init__(self, loc, scale, validate_args=False):
238
+ self.loc = loc
239
+ self.scale = scale
240
+ self.base_dist = D.Normal(loc, scale, validate_args=validate_args)
241
+ super().__init__(self.base_dist, [TanhTransform()], validate_args=validate_args)
242
+
243
+ @property
244
+ def mean(self):
245
+ mu = self.loc
246
+ for tr in self.transforms:
247
+ mu = tr(mu)
248
+ return mu
249
+
250
+ def entropy(self, N=1):
251
+ # empirical entropy of the squashed law: E[-log p(a)] via a single reparameterized draw.
252
+ # Returns (batch, act_dim); the caller sums over the action dimension.
253
+ x = self.rsample((N,))
254
+ log_p = self.log_prob(x)
255
+ return -log_p.mean(axis=0)
256
+
257
+ def rsample_eps(self, eps):
258
+ """rsample() with its standard-normal draw passed in (the eager action noise, CAPTURE_PLAN.md P2): Normal.rsample's
259
+ `loc + eps * scale`, then the transforms, the same operations in the same order, so it is bitwise to rsample() given the
260
+ same eps. eps: (B, A) for an action, (N, B, A) for N draws."""
261
+ x = self.loc + eps * self.scale
262
+ for transform in self.transforms:
263
+ x = transform(x)
264
+ return x
265
+
266
+ def entropy_eps(self, eps):
267
+ """entropy() with its draw passed in: eps (N, B, A)"""
268
+ x = self.rsample_eps(eps)
269
+ log_p = self.log_prob(x)
270
+ return -log_p.mean(axis=0)
271
+
272
+
273
+ class PhaseGate(nn.Module):
274
+ """DeepLoco's phase-gated input (biped3d_llc_actor_net.prototxt / _critic_net.prototxt, 518f502): the observation carries
275
+ K one-hot phase-bin slots (`bin_idx`); every other input is multiplied by each bin and the K products are concatenated,
276
+ bin-major (slice0 -> tile_phase{k} x data_char_task -> Eltwise PROD -> bilin_state Concat), so the first layer has one weight
277
+ block per phase bin. The bins themselves are not passed on. No parameters (its index buffers are not saved), so a
278
+ checkpoint's keys are those of the ungated net with a wider first layer."""
279
+
280
+ def __init__(self, obs_dim, bin_idx, device="cuda"):
281
+ super().__init__()
282
+ bins = [int(i) for i in bin_idx]
283
+ assert len(bins) >= 2 and len(set(bins)) == len(bins) and all(0 <= i < obs_dim for i in bins), (bins, obs_dim)
284
+ rest = [i for i in range(obs_dim) if i not in set(bins)]
285
+ self.register_buffer("bins", torch.tensor(bins, dtype=torch.long, device=device), persistent=False)
286
+ self.register_buffer("rest", torch.tensor(rest, dtype=torch.long, device=device), persistent=False)
287
+ self.in_dim, self.out_dim = obs_dim, len(bins) * len(rest)
288
+
289
+ def forward(self, obs):
290
+ assert obs.shape[-1] == self.in_dim, (obs.shape, self.in_dim)
291
+ b, r = obs[..., self.bins], obs[..., self.rest]
292
+ return (b[..., :, None] * r[..., None, :]).reshape(*obs.shape[:-1], self.out_dim)
293
+
294
+
295
+ class ActorSquashedMLP(nn.Module):
296
+ """State-dependent squashed-Normal actor for SAPO (Soft Analytic Policy Optimization, Xing et al.
297
+ ICLR 2025, arXiv:2412.12089). A shared feature trunk (obs -> units, Linear+act+LayerNorm on EVERY
298
+ layer) then TWO heads: mu = Linear(units[-1], act_dim) and logstd = Linear(units[-1], act_dim).
299
+ distribution(obs) = SquashedNormal(mu, exp(clamp(logstd, -5, 2))), whose rsample() is ALREADY in
300
+ [-1,1] -- SapoVec feeds it to the env directly (identity _env_action; NO second tanh).
301
+
302
+ forward() returns the PRE-tanh action (deterministic -> mu; stochastic -> Normal(mu,std).rsample()),
303
+ matching the ActorStochasticMLP convention so the eval harness's torch.tanh(algo.act(...)) squashes it
304
+ exactly (tanh(mu) = the SquashedNormal mean). Mirrors mineral models.Actor(fixed_sigma=False,
305
+ dist=squashed_normal). out_bias is kept (relaxed-muscle init of the mu head, as in ActorStochasticMLP)."""
306
+
307
+ LOGSTD_MIN, LOGSTD_MAX = -5.0, 2.0
308
+
309
+ def __init__(self, obs_dim, act_dim, units=(128, 64, 32), activation="silu",
310
+ device="cuda", out_bias=None, phase_bins=None):
311
+ super().__init__()
312
+ # phase_bins: the observation's one-hot phase-bin slots for DeepLoco's gated input (PhaseGate); None = ungated
313
+ self.gate = PhaseGate(obs_dim, phase_bins, device) if phase_bins is not None else None
314
+ # shared feature trunk: plain_last=False -> units[-1] output already has act+LayerNorm applied
315
+ # (the representation the mu/logstd heads read). DiffRL/our idiom: Linear -> act -> LayerNorm.
316
+ in_dim = self.gate.out_dim if self.gate is not None else obs_dim
317
+ self.feature_net = _mlp([in_dim, *units], activation, orthogonal=False, plain_last=False).to(device)
318
+ self.mu = nn.Linear(units[-1], act_dim).to(device)
319
+ self.logstd = nn.Linear(units[-1], act_dim).to(device)
320
+ # Relaxed-start init of the MEAN head (same idea as ActorStochasticMLP.out_bias): tiny last-layer
321
+ # weights + a constant bias so the untrained squashed mean ~ tanh(out_bias). For the myoLeg muscle
322
+ # env (u = 0.5*(a+1)), out_bias=-1.5 -> mean action ~ -0.905 -> u ~ 0.047 (muscles RELAXED). None =
323
+ # default init. The logstd head keeps default init (state-dependent exploration is learned).
324
+ if out_bias is not None:
325
+ nn.init.uniform_(self.mu.weight, -1e-3, 1e-3)
326
+ if np.ndim(out_bias) == 0:
327
+ nn.init.constant_(self.mu.bias, float(out_bias))
328
+ else: # per-action (DN_OUT_BIAS_FILE): one value per muscle
329
+ ob = torch.as_tensor(np.asarray(out_bias, dtype=np.float32), device=self.mu.bias.device)
330
+ assert ob.shape == self.mu.bias.shape, (ob.shape, self.mu.bias.shape)
331
+ with torch.no_grad():
332
+ self.mu.bias.copy_(ob)
333
+ self.obs_dim, self.act_dim = obs_dim, act_dim
334
+
335
+ def distribution(self, obs):
336
+ x = self.feature_net(self.gate(obs) if self.gate is not None else obs)
337
+ logstd = torch.clamp(self.logstd(x), self.LOGSTD_MIN, self.LOGSTD_MAX)
338
+ return SquashedNormal(self.mu(x), logstd.exp())
339
+
340
+ def forward(self, obs, deterministic=False):
341
+ # PRE-tanh action (the ActorStochasticMLP convention: callers / the env apply the squash).
342
+ x = self.feature_net(self.gate(obs) if self.gate is not None else obs)
343
+ mu = self.mu(x)
344
+ if deterministic:
345
+ return mu
346
+ logstd = torch.clamp(self.logstd(x), self.LOGSTD_MIN, self.LOGSTD_MAX)
347
+ return Normal(mu, logstd.exp()).rsample()
348
+
349
+
350
+ class _ConcatMLP(nn.Module):
351
+ """ControlVAE's encoder MLP (ControlVAECore/Model/modules.py `Encoder`): the input `x` is concatenated to the
352
+ input of EVERY layer, the first one also takes the condition `c`: h = act(L0([x, c])), h = act(Lk([x, h])),
353
+ out = Lout([x, h]). No normalisation layers, PyTorch default init (as there)."""
354
+
355
+ def __init__(self, x_dim, c_dim, units, out_dim, activation):
356
+ super().__init__()
357
+ assert len(units) >= 1, units
358
+ dims_in = [x_dim + c_dim] + [x_dim + u for u in units[:-1]]
359
+ self.hidden = nn.ModuleList([nn.Linear(i, o) for i, o in zip(dims_in, units)])
360
+ self.out = nn.Linear(x_dim + units[-1], out_dim)
361
+ self.act = _ACT[activation]()
362
+
363
+ def forward(self, x, c=None):
364
+ h = x if c is None else torch.cat([x, c], dim=-1)
365
+ h = self.act(self.hidden[0](h))
366
+ for lin in self.hidden[1:]:
367
+ h = self.act(lin(torch.cat([x, h], dim=-1)))
368
+ return self.out(torch.cat([x, h], dim=-1))
369
+
370
+
371
+ class LatentSkillEncoder(nn.Module):
372
+ """The latent skill model's prior and posterior (ControlVAE, Yao et al. 2022, arXiv:2210.06063 Sec. 3.4.1;
373
+ MuscleVAE, Feng et al. 2023, arXiv:2312.07340 App. B):
374
+
375
+ prior p(z | s) = N(mu_p(s), sigma^2 I)
376
+ posterior q(z | s, s~') = N(mu_p(s) + mu_q(s, s~'), sigma^2 I) s~' = the next reference frame
377
+
378
+ sigma_p = sigma_q = 0.3 and the posterior mean is the prior mean plus a trainable OFFSET, so the KL has the closed
379
+ form KL(q || p) = ||mu_q||^2 / (2 sigma^2) (ControlVAE's SimpleLearnablePriorEncoder.kl_loss, summed over z).
380
+ mu_p and mu_q are _ConcatMLPs (ELU): the prior concatenates s to the input of each layer, the posterior s~'
381
+ (with s also in its first layer), as the paper's "we concatenate the input of each layer of the prior and
382
+ posterior networks with s_t and s_{t+1}". Hidden layers default to the papers' "two 512-unit hidden layers";
383
+ the released ControlVAE code builds three from its `hidden_layer_num: 2` (one first layer + two), which
384
+ `units` reproduces as (512, 512, 512).
385
+
386
+ z is drawn with the reparameterisation trick, so a return differentiated through the simulator reaches both
387
+ mu_p and mu_q through z; the KL reaches mu_q only (it does not depend on mu_p)."""
388
+
389
+ def __init__(self, obs_dim, ref_dim, latent_dim=64, units=(512, 512), sigma=0.3, activation="elu",
390
+ device="cuda"):
391
+ super().__init__()
392
+ assert latent_dim > 0 and sigma > 0.0, (latent_dim, sigma)
393
+ self.obs_dim, self.ref_dim, self.latent_dim, self.sigma = int(obs_dim), int(ref_dim), int(latent_dim), float(sigma)
394
+ self.prior = _ConcatMLP(obs_dim, 0, units, latent_dim, activation).to(device)
395
+ self.posterior = _ConcatMLP(ref_dim, obs_dim, units, latent_dim, activation).to(device)
396
+
397
+ def prior_mean(self, obs):
398
+ return self.prior(obs)
399
+
400
+ def posterior_mean(self, obs, ref):
401
+ return self.prior(obs) + self.posterior(ref, obs)
402
+
403
+ def kl(self, mu_q):
404
+ """KL(q || p) per env, (N,): ||mu_q||^2 / (2 sigma^2), the closed form for two Gaussians of equal sigma."""
405
+ return (mu_q * mu_q).sum(-1) / (2.0 * self.sigma * self.sigma)
406
+
407
+ def sample_posterior(self, obs, ref):
408
+ """z ~ q(z | s, s~') by reparameterisation, and the per-env KL(q || p). Returns (z (N,Z), kl (N,))."""
409
+ mu_p = self.prior(obs)
410
+ mu_q = self.posterior(ref, obs)
411
+ z = mu_p + mu_q + self.sigma * torch.randn_like(mu_p)
412
+ return z, self.kl(mu_q)
413
+
414
+ def sample_prior(self, obs):
415
+ """z ~ p(z | s), the generation mode (no reference)."""
416
+ mu_p = self.prior(obs)
417
+ return mu_p + self.sigma * torch.randn_like(mu_p)
418
+
419
+
420
+ class ActorSquashedLatentMLP(nn.Module):
421
+ """The latent skill model's DECODER pi(a | s, z) as a SAPO actor: ActorSquashedMLP with z concatenated to the input
422
+ of every layer, the mean and logstd heads included. It never sees the reference, only s and z, which is what makes z
423
+ the skill code.
424
+
425
+ DEVIATION from the papers, stated: ControlVAE / MuscleVAE decode with a mixture of experts (6 experts x 3 x 512 ELU,
426
+ a 2 x 64 gating network, z concatenated to the input of each expert layer and that input layer-normalised, a fixed
427
+ sigma_pi = 0.05). Phase 1 keeps this project's SAPO actor (Linear -> act -> LayerNorm on each layer, the state-
428
+ dependent squashed Normal, SAPO's entropy and temperature) and takes over only the papers' "z at every layer"."""
429
+
430
+ LOGSTD_MIN, LOGSTD_MAX = ActorSquashedMLP.LOGSTD_MIN, ActorSquashedMLP.LOGSTD_MAX
431
+
432
+ def __init__(self, obs_dim, latent_dim, act_dim, units=(128, 64, 32), activation="silu", device="cuda",
433
+ out_bias=None):
434
+ super().__init__()
435
+ act = _ACT[activation]
436
+ dims_in = [obs_dim] + list(units[:-1])
437
+ self.layers = nn.ModuleList([nn.Linear(i + latent_dim, o) for i, o in zip(dims_in, units)]).to(device)
438
+ self.acts = nn.ModuleList([act() for _ in units]).to(device)
439
+ self.norms = nn.ModuleList([nn.LayerNorm(o) for o in units]).to(device)
440
+ self.mu = nn.Linear(units[-1] + latent_dim, act_dim).to(device)
441
+ self.logstd = nn.Linear(units[-1] + latent_dim, act_dim).to(device)
442
+ if out_bias is not None: # the relaxed-start mean head, as ActorSquashedMLP
443
+ nn.init.uniform_(self.mu.weight, -1e-3, 1e-3)
444
+ if np.ndim(out_bias) == 0:
445
+ nn.init.constant_(self.mu.bias, float(out_bias))
446
+ else:
447
+ ob = torch.as_tensor(np.asarray(out_bias, dtype=np.float32), device=self.mu.bias.device)
448
+ assert ob.shape == self.mu.bias.shape, (ob.shape, self.mu.bias.shape)
449
+ with torch.no_grad():
450
+ self.mu.bias.copy_(ob)
451
+ self.obs_dim, self.latent_dim, self.act_dim = obs_dim, latent_dim, act_dim
452
+
453
+ def features(self, obs, z):
454
+ h = obs
455
+ for lin, a, ln in zip(self.layers, self.acts, self.norms):
456
+ h = ln(a(lin(torch.cat([h, z], dim=-1))))
457
+ return torch.cat([h, z], dim=-1)
458
+
459
+ def distribution(self, obs, z):
460
+ x = self.features(obs, z)
461
+ logstd = torch.clamp(self.logstd(x), self.LOGSTD_MIN, self.LOGSTD_MAX)
462
+ return SquashedNormal(self.mu(x), logstd.exp())
463
+
464
+ def forward(self, obs, z, deterministic=False):
465
+ # PRE-tanh action, the ActorSquashedMLP convention
466
+ x = self.features(obs, z)
467
+ mu = self.mu(x)
468
+ if deterministic:
469
+ return mu
470
+ logstd = torch.clamp(self.logstd(x), self.LOGSTD_MIN, self.LOGSTD_MAX)
471
+ return Normal(mu, logstd.exp()).rsample()
472
+
473
+
474
+ class LatentTaskPolicy(nn.Module):
475
+ """The latent skill model's TASK policy offset mu_g(s, g) (MuscleVAE App. B.3 eq. 43, ControlVAE Sec. 4.2 eq. 21): the
476
+ high-level policy is N(mu_p(s) + mu_g(s, g), sigma_g^2 I) over z, an OFFSET on the frozen state prior's mean. An MLP
477
+ on [s, g] with three 256-unit ELU hidden layers (MuscleVAE's text; ControlVAE's released build_mlp(obs + 3, latent,
478
+ 3, 256, 'ELU'): Linear and ELU only, no normalisation layers, PyTorch default init).
479
+
480
+ DEVIATION, stated: the output layer starts at ~0 (weights uniform +-1e-3, bias 0), so the untrained task policy is
481
+ the prior itself (the P2 generation mode) instead of a random offset on it."""
482
+
483
+ def __init__(self, obs_dim, task_dim, latent_dim, units=(256, 256, 256), activation="elu", device="cuda"):
484
+ super().__init__()
485
+ assert len(units) >= 1, units
486
+ act = _ACT[activation]
487
+ dims = [obs_dim + task_dim, *units]
488
+ mods = []
489
+ for i, o in zip(dims[:-1], dims[1:]):
490
+ mods += [nn.Linear(i, o), act()]
491
+ self.hidden = nn.Sequential(*mods).to(device)
492
+ self.out = nn.Linear(units[-1], latent_dim).to(device)
493
+ nn.init.uniform_(self.out.weight, -1e-3, 1e-3)
494
+ nn.init.zeros_(self.out.bias)
495
+ self.obs_dim, self.task_dim, self.latent_dim = int(obs_dim), int(task_dim), int(latent_dim)
496
+
497
+ def forward(self, obs, task):
498
+ return self.out(self.hidden(torch.cat([obs, task], dim=-1)))
499
+
500
+
501
+ class CriticMLP(nn.Module):
502
+ def __init__(self, obs_dim, units=(64, 64), activation="elu", device="cuda"):
503
+ super().__init__()
504
+ self.critic = _mlp([obs_dim, *units, 1], activation, orthogonal=True).to(device)
505
+
506
+ def forward(self, obs):
507
+ return self.critic(obs)
508
+
509
+
510
+ class EnsembleCritic(nn.Module):
511
+ """n independent value heads (SAPO uses n=2). forward(obs, return_type): 'min' -> elementwise min
512
+ over the ensemble, 'avg' -> mean, 'min_and_avg' -> (min, avg), 'all' -> per-critic values stacked
513
+ (n_critics, batch, 1). Each head is a CriticMLP (orthogonal init). SAPO bootstraps the ACTOR return
514
+ with 'avg' and the CRITIC target with 'min' (clipped-double-Q, no target network). Mirrors mineral
515
+ models.EnsembleCritic (non-vmap path)."""
516
+
517
+ def __init__(self, obs_dim, units=(64, 64), activation="silu", device="cuda", n_critics=2, phase_bins=None):
518
+ super().__init__()
519
+ self.n_critics = int(n_critics)
520
+ # DeepLoco gates its critic's input by the phase bins too (biped3d_llc_critic_net.prototxt); None = ungated
521
+ self.gate = PhaseGate(obs_dim, phase_bins, device) if phase_bins is not None else None
522
+ in_dim = self.gate.out_dim if self.gate is not None else obs_dim
523
+ self.critics = nn.ModuleList(
524
+ [_mlp([in_dim, *units, 1], activation, orthogonal=True).to(device) for _ in range(self.n_critics)])
525
+
526
+ def forward(self, obs, return_type="min"):
527
+ if self.gate is not None:
528
+ obs = self.gate(obs)
529
+ vs = torch.stack([c(obs) for c in self.critics]) # (n_critics, batch, 1)
530
+ if return_type == "all":
531
+ return vs
532
+ if return_type == "min":
533
+ return torch.min(vs, dim=0).values
534
+ if return_type == "avg":
535
+ return torch.mean(vs, dim=0)
536
+ if return_type == "min_and_avg":
537
+ return torch.min(vs, dim=0).values, torch.mean(vs, dim=0)
538
+ raise ValueError(return_type)
539
+
540
+
541
+ class RunningMeanStd:
542
+ """Parallel-variance running normalizer (DiffRL utils/running_mean_std.py). Not an nn.Module
543
+ -- holds running mean/var buffers updated under no_grad during the rollout."""
544
+
545
+ def __init__(self, shape, device="cuda", epsilon=1e-4):
546
+ self.mean = torch.zeros(shape, dtype=torch.float32, device=device)
547
+ self.var = torch.ones(shape, dtype=torch.float32, device=device)
548
+ # the count lives on the device (CAPTURE_PLAN.md P2 (ii)): a Python float would be baked into a captured update. f64,
549
+ # as the Python float it replaces; `count` reads and sets it as a float (checkpoints, loads), never per step
550
+ self._count = torch.tensor(float(epsilon), dtype=torch.float64, device=device)
551
+ # (shape,) bool: slots passed through unnormalized (DeepLoco's eOffsetScaleTypeFixed, its phase bins); None = every slot
552
+ # normalized. Set from the env by the algorithm, never saved: the env that rebuilds the algorithm sets it again.
553
+ self.fixed = None
554
+
555
+ @property
556
+ def count(self):
557
+ return float(self._count) # a host read: checkpoints and logs only
558
+
559
+ @count.setter
560
+ def count(self, v):
561
+ self._count = torch.as_tensor(v, dtype=torch.float64, device=self.mean.device).clone()
562
+
563
+ @torch.no_grad()
564
+ def update(self, arr): # arr [batch, *shape]
565
+ # in place, with the count on the device. Bitwise to the Python-float form it replaces: there, every `tensor op
566
+ # scalar` cast the double scalar to f32 inside the kernel, and a division by a CPU scalar ran as a multiplication by
567
+ # its f32 reciprocal (verified on the 4090: this form bitwise over 300 updates at counts 1e-4, 3.3e7, 1.7e9; a true
568
+ # division by the f32 tensor is not)
569
+ bmean = arr.mean(dim=0)
570
+ bvar = arr.var(dim=0, unbiased=False)
571
+ bcount = arr.shape[0]
572
+ delta = bmean - self.mean
573
+ if self.mean.device.type != "cuda": # off the GPU, the original Python-float arithmetic exactly (verified on CUDA only)
574
+ count = float(self._count)
575
+ tot = count + bcount
576
+ self.mean.copy_(self.mean + delta * bcount / tot)
577
+ m2 = self.var * count + bvar * bcount + delta ** 2 * count * bcount / tot
578
+ self.var.copy_(m2 / tot)
579
+ self._count.fill_(tot)
580
+ return
581
+ tot = self._count + bcount # bcount stays a Python int (static per shape; no host-to-device copy)
582
+ c32 = self._count.float()
583
+ inv = 1.0 / tot.float()
584
+ self.mean.copy_(self.mean + delta * bcount * inv)
585
+ m_a = self.var * c32
586
+ m_b = bvar * bcount
587
+ m2 = m_a + m_b + delta ** 2 * c32 * bcount * inv
588
+ self.var.copy_(m2 * inv)
589
+ self._count.copy_(tot)
590
+
591
+ def normalize(self, arr):
592
+ out = (arr - self.mean) / torch.sqrt(self.var + 1e-5)
593
+ if self.fixed is not None:
594
+ out = torch.where(self.fixed, arr, out)
595
+ return out
596
+
597
+ def state_dict(self):
598
+ # copies: update() now writes in place, so a state_dict held for later must not follow the live buffers
599
+ return {"mean": self.mean.clone(), "var": self.var.clone(), "count": self.count}