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,686 @@
1
+ """Shared .dnrec writer + engine forward-kinematics for the renderers (humanoid + full-body).
2
+
3
+ The .dnrec binary: MAGIC ``b"JPLY"``, ``uint32`` version + ``uint32`` header length, a JSON header
4
+ (scene / dt / bodies / channel layout), then the float32 frame blocks. ``fk_poses`` walks a dnmodel
5
+ body tree (free / ball / hinge / slide joints) to world poses; ``write_dnrec`` packs the per-frame
6
+ channels (pose, qvel, optional mtu_poly / activation / contact) into the binary the viewer reads.
7
+
8
+ Torch-free on purpose: a renderer can build geometry + poses without importing the GPU bridge.
9
+ """
10
+ import json
11
+ import math
12
+ import struct
13
+
14
+ import os
15
+ import numpy as np
16
+
17
+ MAGIC = b"JPLY"
18
+
19
+
20
+
21
+ # The record format's extensions: .dnrec, and .jplay, its earlier name (the same format and magic: the paper's stored records).
22
+ # The body format likewise: .dnmodel, and .jmodel.
23
+ RECORD_SUFFIXES = (".dnrec", ".jplay")
24
+ MODEL_SUFFIXES = (".dnmodel", ".jmodel")
25
+
26
+
27
+ def is_record(path):
28
+ return str(path).lower().endswith(RECORD_SUFFIXES)
29
+
30
+
31
+ def muscle_l_opt(mu):
32
+ """`optimal_fiber_length` for one muscle dict, whichever spelling the .dnmodel uses.
33
+
34
+ A muscle declares its scalars EITHER as MuJoCo's positional `gainprm`
35
+ [F_max, l_opt, l_slack, v_max, W, C, N, K, E_REF] OR with the source's own names -- OpenSim's and
36
+ Hyfydy's (decisions/0020). The C++ loader handles both; python consumers that re-read the raw JSON
37
+ did not, and every one of them reached for `mu["gainprm"][1]`. A converted Hyfydy/OpenSim model has
38
+ no `gainprm` at all, so that read is a KeyError -- which is how the H1622 smoke test failed.
39
+
40
+ Use this instead of indexing `gainprm`. Same value, both spellings, one place to fix.
41
+ """
42
+ if "gainprm" in mu:
43
+ return float(mu["gainprm"][1])
44
+ v = mu.get("optimal_fiber_length")
45
+ assert v is not None, (
46
+ f"muscle {mu.get('name', '?')!r} declares neither `gainprm` nor `optimal_fiber_length`; "
47
+ "a .dnmodel muscle must carry one of the two forms (decisions/0020)")
48
+ return float(v)
49
+
50
+
51
+ def muscle_f_max(mu):
52
+ """`max_isometric_force` for one muscle dict, whichever spelling the .dnmodel uses.
53
+
54
+ Same two forms as muscle_l_opt: MuJoCo's positional `gainprm[0]` or the source's own name
55
+ (decisions/0020). The render path needs it for PCSA = Fmax/sigma_max, and it was the LAST
56
+ positional read left after the l_opt sweep -- which only looked for `[1]`, so every converted model
57
+ still died with KeyError: 'gainprm' when the viewer tried to draw its muscles.
58
+ """
59
+ if "gainprm" in mu:
60
+ return float(mu["gainprm"][0])
61
+ v = mu.get("max_isometric_force")
62
+ assert v is not None, (
63
+ f"muscle {mu.get('name', '?')!r} declares neither `gainprm` nor `max_isometric_force`")
64
+ return float(v)
65
+
66
+
67
+ def muscle_f_maxes(jm):
68
+ """`max_isometric_force` for every muscle, in file order."""
69
+ return [muscle_f_max(mu) for mu in jm["muscles"]]
70
+
71
+
72
+ def muscle_l_opts(jm):
73
+ """`optimal_fiber_length` for every muscle, in file order."""
74
+ return [muscle_l_opt(mu) for mu in jm["muscles"]]
75
+
76
+ def _dnmodel_module():
77
+ """diffneusim.model.dnmodel: the one .dnmodel reader, torch-free"""
78
+ from diffneusim.model import dnmodel
79
+ return dnmodel
80
+
81
+
82
+ def load_dnmodel(path):
83
+ """Parse a `.dnmodel` (JSON + comments) into a dict: diffneusim.model.read_model, the one reader."""
84
+ return _JM.parse(path)
85
+
86
+
87
+ _JM = _dnmodel_module()
88
+
89
+
90
+ def quat_mul(a, b):
91
+ aw, ax, ay, az = a
92
+ bw, bx, by, bz = b
93
+ return np.array([
94
+ aw * bw - ax * bx - ay * by - az * bz,
95
+ aw * bx + ax * bw + ay * bz - az * by,
96
+ aw * by - ax * bz + ay * bw + az * bx,
97
+ aw * bz + ax * by - ay * bx + az * bw,
98
+ ], dtype=np.float64)
99
+
100
+
101
+ def quat_axis_angle(axis, angle):
102
+ axis = np.asarray(axis, dtype=np.float64)
103
+ n = np.linalg.norm(axis)
104
+ assert n > 0
105
+ axis = axis / n
106
+ s = math.sin(0.5 * float(angle))
107
+ return np.array([math.cos(0.5 * float(angle)), axis[0] * s, axis[1] * s, axis[2] * s], dtype=np.float64)
108
+
109
+
110
+ def quat_rotate(q, v):
111
+ w, x, y, z = q
112
+ u = np.array([x, y, z], dtype=np.float64)
113
+ v = np.asarray(v, dtype=np.float64)
114
+ return v + 2.0 * w * np.cross(u, v) + 2.0 * np.cross(u, np.cross(u, v))
115
+
116
+
117
+ def normalize_quat(q):
118
+ q = np.asarray(q, dtype=np.float64)
119
+ return q / np.linalg.norm(q)
120
+
121
+
122
+ def quat_to_R(q):
123
+ """[w, x, y, z] quat -> 3x3 rotation matrix (f64; the render-side companion to quat_mul/quat_rotate).
124
+ Exporters use the SEPARATE tools/_mjcf_export_util.quat_to_R (same math, MJCF-export dialect)."""
125
+ w, x, y, z = (float(v) for v in q)
126
+ return np.array([[1 - 2 * (y * y + z * z), 2 * (x * y - z * w), 2 * (x * z + y * w)],
127
+ [2 * (x * y + z * w), 1 - 2 * (x * x + z * z), 2 * (y * z - x * w)],
128
+ [2 * (x * z - y * w), 2 * (y * z + x * w), 1 - 2 * (x * x + y * y)]], dtype=np.float64)
129
+
130
+
131
+ def fk_closure(jm, want):
132
+ """Ancestor closure of `want`, ascending. Pass to fk_poses(..., subset=) to skip bodies nobody reads.
133
+
134
+ Body order is topological (a parent always has a lower index -- fk_poses already relies on it to read
135
+ poses[parent] while filling in order), so ascending order of the closure is a valid evaluation order.
136
+ """
137
+ bodies = jm["bodies"]
138
+ need = set()
139
+ for b in want:
140
+ i = int(b)
141
+ while i >= 0:
142
+ need.add(i)
143
+ i = int(bodies[i]["parent"])
144
+ return sorted(need)
145
+
146
+
147
+ def fk_poses(jm, q, subset=None):
148
+ """World poses (n_body, 7) = [pos(3), quat(4)] per body.
149
+
150
+ `subset` = an fk_closure() list: evaluate ONLY those bodies and leave the rest NaN. Same math, just
151
+ skipping poses the caller never reads -- the full-body IK residual reads 8 bodies whose closure is 25 of
152
+ 156, and it runs ~200 FK per frame, so this is a 6x whole-retarget win. NaN (not zero) so an accidental
153
+ read of a skipped body propagates visibly instead of looking like a body at the origin.
154
+ """
155
+ bodies = jm["bodies"]
156
+ poses = (np.zeros((len(bodies), 7), dtype=np.float64) if subset is None
157
+ else np.full((len(bodies), 7), np.nan, dtype=np.float64))
158
+ # RENDER-ONLY kinematic couplings (physics ignores this top-level key, like `visual_geoms`): a body
159
+ # pinned to `fixed` for the dynamics but whose VISUAL mesh should track a coupling joint (the full-body
160
+ # patella -- pinned for stability, muscle handled by moving via-points, but the kneecap mesh must follow
161
+ # the knee to match the muscle). See docs/training/campaigns/fullbody/knee-simplification.md.
162
+ rc = jm.get("render_couplings", {})
163
+ v2q = {int(b["vadr"]): int(b["qadr"]) for b in bodies if b.get("vadr") is not None and b.get("qadr") is not None}
164
+ for i in (range(len(bodies)) if subset is None else subset):
165
+ body = bodies[i]
166
+ parent = int(body["parent"])
167
+ if parent >= 0:
168
+ pp = poses[parent, :3]
169
+ pq = poses[parent, 3:7]
170
+ else:
171
+ pp = np.zeros(3, dtype=np.float64)
172
+ pq = np.array([1.0, 0.0, 0.0, 0.0], dtype=np.float64)
173
+ rcpl = rc.get(str(i))
174
+ if rcpl is not None: # draw at the coupled pose: q_coupled =
175
+ base_p = pp + quat_rotate(pq, np.asarray(rcpl["pos"], dtype=np.float64)) # sum coef[k]*theta^k,
176
+ base_q = normalize_quat(quat_mul(pq, normalize_quat(rcpl["quat"]))) # theta = q[qadr(cdof)]
177
+ coef = np.asarray(rcpl["coef"], dtype=np.float64)
178
+ theta = float(q[v2q.get(int(rcpl["cdof"]), int(rcpl["cdof"]))])
179
+ qc = float((coef * theta ** np.arange(coef.shape[0])).sum())
180
+ axis = np.asarray(rcpl["axis"], dtype=np.float64)
181
+ if rcpl["joint"] in ("revolute", "hinge"):
182
+ poses[i, :3] = base_p
183
+ poses[i, 3:7] = normalize_quat(quat_mul(base_q, quat_axis_angle(axis, qc)))
184
+ elif rcpl["joint"] in ("slide", "prismatic"):
185
+ poses[i, :3] = base_p + quat_rotate(base_q, axis * qc)
186
+ poses[i, 3:7] = base_q
187
+ else:
188
+ raise AssertionError(f"render_coupling joint {rcpl['joint']}")
189
+ continue
190
+ cp = body.get("coupled")
191
+ if cp is not None: # PHYSICS coupled ("mimic") joint: q_dep =
192
+ local_p = np.asarray(body["pos"], dtype=np.float64) # sum coef[k]*q_master^k, driven scalar joint
193
+ local_q = normalize_quat(body["quat"])
194
+ base_p = pp + quat_rotate(pq, local_p)
195
+ base_q = normalize_quat(quat_mul(pq, local_q))
196
+ coef = np.asarray(cp["coef"], dtype=np.float64)
197
+ theta = float(q[int(cp["master_qadr"])])
198
+ qc = float((coef * theta ** np.arange(coef.shape[0])).sum())
199
+ axis = np.asarray(body["axis"], dtype=np.float64)
200
+ if body["joint"] in ("revolute", "hinge"):
201
+ poses[i, :3] = base_p
202
+ poses[i, 3:7] = normalize_quat(quat_mul(base_q, quat_axis_angle(axis, qc)))
203
+ elif body["joint"] in ("slide", "prismatic"):
204
+ poses[i, :3] = base_p + quat_rotate(base_q, axis * qc)
205
+ poses[i, 3:7] = base_q
206
+ else:
207
+ raise AssertionError(f"coupled joint {body['joint']}")
208
+ continue
209
+ local_p = np.asarray(body["pos"], dtype=np.float64)
210
+ local_q = normalize_quat(body["quat"])
211
+ base_p = pp + quat_rotate(pq, local_p)
212
+ base_q = normalize_quat(quat_mul(pq, local_q))
213
+ qa = int(body["qadr"])
214
+ if "joints" in body:
215
+ # compound joint: ordered scalar primitive stack T_J = T_0(q0)...T_{n-1},
216
+ # primitive 0 nearest the parent, body frame AFTER the last primitive.
217
+ # Accumulate the joint transform (R_j, p_j) in the parent-attach frame.
218
+ assert "joint" not in body, "a body has either 'joint' or 'joints'"
219
+ rj = np.array([1.0, 0.0, 0.0, 0.0], dtype=np.float64)
220
+ pj = np.zeros(3, dtype=np.float64)
221
+ off = 0
222
+ for prim in body["joints"]:
223
+ ptype = prim["type"]
224
+ axis = np.asarray(prim["axis"], dtype=np.float64)
225
+ if ptype in ("hinge", "revolute"):
226
+ rk = quat_axis_angle(axis, q[qa + off])
227
+ pk = np.zeros(3, dtype=np.float64)
228
+ elif ptype in ("slide", "prismatic"):
229
+ rk = np.array([1.0, 0.0, 0.0, 0.0], dtype=np.float64)
230
+ pk = axis * q[qa + off]
231
+ else:
232
+ raise AssertionError(f"unknown compound primitive {ptype}")
233
+ # T_J <- T_J . T_k : p_j += R_j p_k ; R_j = R_j R_k.
234
+ pj = pj + quat_rotate(rj, pk)
235
+ rj = quat_mul(rj, rk)
236
+ off += 1
237
+ out_p = base_p + quat_rotate(base_q, pj)
238
+ out_q = normalize_quat(quat_mul(base_q, rj))
239
+ poses[i, :3] = out_p
240
+ poses[i, 3:7] = out_q
241
+ continue
242
+ joint = body["joint"]
243
+ if joint == "fixed":
244
+ out_p, out_q = base_p, base_q
245
+ elif joint == "free":
246
+ # compose the body attach frame (base_p/base_q = parent o quat_tree/pos_tree) with the free
247
+ # joint's (pos, quat), matching the engine chain-FK. The old code used the raw free pos/quat
248
+ # and dropped quat_tree -> a model whose root quat_tree != identity (myoLeg26's +90deg-about-x
249
+ # y-up->z-up map) rendered LYING DOWN. base_q=identity models (ant) are unchanged.
250
+ out_p = base_p + quat_rotate(base_q, q[qa:qa + 3].astype(np.float64))
251
+ out_q = normalize_quat(quat_mul(base_q, q[qa + 3:qa + 7]))
252
+ elif joint == "ball":
253
+ out_p = base_p
254
+ out_q = normalize_quat(quat_mul(base_q, q[qa:qa + 4]))
255
+ elif joint in ("revolute", "hinge"):
256
+ out_p = base_p
257
+ out_q = normalize_quat(quat_mul(base_q, quat_axis_angle(body["axis"], q[qa])))
258
+ elif joint in ("slide", "prismatic"):
259
+ out_p = base_p + quat_rotate(base_q, np.asarray(body["axis"], dtype=np.float64) * q[qa])
260
+ out_q = base_q
261
+ else:
262
+ raise AssertionError(f"unknown joint {joint}")
263
+ poses[i, :3] = out_p
264
+ poses[i, 3:7] = out_q
265
+ return poses
266
+
267
+
268
+ def com_track(jm, pose):
269
+ """Whole-body centre of mass per frame -> (T, 1, 3), from the render pose (T, nbody, 7) + the dnmodel
270
+ body masses/com offsets. Pure kinematics (mass-weighted world body-COMs), for the viewer's COM-trail
271
+ overlay -- no engine/physics needed, works for any pose trajectory."""
272
+ pose = np.asarray(pose, np.float64)
273
+ bodies = jm["bodies"]
274
+ m = np.array([float(b.get("mass", 0.0)) for b in bodies])
275
+ lc = np.array([b.get("com", [0.0, 0.0, 0.0]) for b in bodies], float) # per-body LOCAL com offset
276
+ M = float(m.sum())
277
+ assert M > 0.0, "dnmodel has zero total mass; cannot compute COM"
278
+ T = pose.shape[0]
279
+ out = np.zeros((T, 1, 3))
280
+ for t in range(T):
281
+ wc = np.array([pose[t, b, :3] + quat_rotate(pose[t, b, 3:7], lc[b]) for b in range(len(bodies))])
282
+ out[t, 0] = (m[:, None] * wc).sum(axis=0) / M
283
+ return out.astype(np.float32)
284
+
285
+
286
+ SELFCOL_RENDER_GROUP = 7 # its own group so the collider can be toggled off in the viewer
287
+
288
+
289
+ def selfcol_shown():
290
+ """Whether renders SHOW the self-collision colliders by default. Design note, 2026-09-26: "turn the self collider
291
+ off in every render unless I explicitly ask for it" -- the translucent capsules overlapped the limbs oddly. They
292
+ are still written into the .dnrec and listed in its header's geom_groups_default (the file bytes do not depend on
293
+ this preference), and the offline renderer (renderer.make_scene: to_mp4 / snapshot / strobe) drops the group;
294
+ DN_RENDER_SELFCOL=1, or naming the group in --geom-groups, shows them."""
295
+ return os.environ.get("DN_RENDER_SELFCOL") == "1"
296
+
297
+
298
+ def _quat_from_z_to(v):
299
+ """Unit quaternion taking local +z onto the unit vector v (shortest arc)."""
300
+ c = float(v[2])
301
+ if c > 1 - 1e-12:
302
+ return [1.0, 0.0, 0.0, 0.0]
303
+ if c < -1 + 1e-12:
304
+ return [0.0, 1.0, 0.0, 0.0] # 180 deg about x
305
+ ax = np.cross([0.0, 0.0, 1.0], v)
306
+ sq = np.sqrt((1 + c) * 2)
307
+ q = np.array([sq * 0.5, ax[0] / sq, ax[1] / sq, ax[2] / sq])
308
+ return [float(x) for x in q / np.linalg.norm(q)]
309
+
310
+
311
+ def render_bodies_from_visual_geoms(jm):
312
+ """Build the write_dnrec `bodies` list (one {name, geoms} per engine body) from the .dnmodel's
313
+ top-level ``visual_geoms`` block — the SINGLE source of render geometry, carried WITH the model.
314
+
315
+ Fail-fast on purpose (dev-rules: no fallback): a model with no ``visual_geoms`` or zero geoms is a
316
+ hard error, NOT a cue to synthesize placeholder spheres. Synthesizing "dots" from mass/COM is exactly
317
+ the recurring bug this replaces — a physics model must not render as fake geometry. Add the real
318
+ capsules/spheres to the model (see tools/export_humanoid.py's visual_geoms emission) instead.
319
+ """
320
+ assert "visual_geoms" in jm, (
321
+ "dnmodel has no 'visual_geoms' block — the renderer needs real per-body geometry carried in the "
322
+ "model (see tools/export_humanoid.py). Refusing to synthesize placeholder spheres.")
323
+ vg = jm["visual_geoms"]
324
+ assert len(vg) == len(jm["bodies"]), (len(vg), len(jm["bodies"]))
325
+ size_len = {"capsule": 2, "sphere": 1, "box": 3} # type -> expected len(size)
326
+ bodies = []
327
+ for i, v in enumerate(vg):
328
+ geoms = [dict(g) for g in v.get("geoms", [])]
329
+ for g in v.get("geoms", []):
330
+ t = g.get("type")
331
+ if t == "mesh":
332
+ # STL bone mesh: an .stl file (abs or repo-relative) drawn under the body frame
333
+ # by TRS(pos, quat, scale). The renderer loads the raw mesh via meshes.load_stl.
334
+ assert isinstance(g.get("file"), str) and g["file"], f"body {i}: mesh geom needs a 'file' path"
335
+ assert len(g.get("scale", [])) == 3, f"body {i}: mesh geom needs scale[3]"
336
+ else:
337
+ assert t in size_len, f"body {i}: unsupported visual geom type {t!r} (capsule/sphere/box/mesh only)"
338
+ assert len(g.get("size", [])) == size_len[t], f"body {i}: {t} size must have {size_len[t]} element(s)"
339
+ assert len(g.get("pos", [])) == 3 and len(g.get("quat", [])) == 4 and len(g.get("rgba", [])) == 4, \
340
+ f"body {i}: each visual geom needs pos[3], quat[4], rgba[4]"
341
+ if "group" in g:
342
+ group = int(g["group"])
343
+ assert group >= 0 and float(g["group"]) == float(group), f"body {i}: geom group must be a non-negative int"
344
+ bodies.append({"name": v.get("name", f"B{i}"), "geoms": geoms})
345
+
346
+ # Optional contact-visual overlay. Physics still consumes only contact.{body,center,radius};
347
+ # render_group/render_rgba are renderer metadata so collision spheres can stay in a separate
348
+ # toggleable group while being visible in ordinary renders.
349
+ contact = jm.get("contact", {})
350
+ for gi, g in enumerate(contact.get("geoms", []) if isinstance(contact, dict) else []):
351
+ if "render_group" not in g:
352
+ continue
353
+ assert g.get("type") == "sphere", f"contact geom {gi}: renderable contact geoms must be sphere"
354
+ body = int(g["body"])
355
+ assert 0 <= body < len(bodies), f"contact geom {gi}: body index out of range"
356
+ group = int(g["render_group"])
357
+ assert group >= 0 and float(g["render_group"]) == float(group), (
358
+ f"contact geom {gi}: render_group must be a non-negative int")
359
+ rgba = g.get("render_rgba", [1.0, 0.58, 0.04, 0.78])
360
+ assert len(rgba) == 4, f"contact geom {gi}: render_rgba must be rgba[4]"
361
+ # render_radius is a display-only size (physics still uses the true contact radius). Real
362
+ # contact spheres are often ~1cm, which is nearly invisible and occluded by the limb geom; a
363
+ # slightly larger render_radius lets the collider be seen as a distinct marker.
364
+ render_radius = float(g.get("render_radius", g["radius"]))
365
+ assert render_radius > 0.0, f"contact geom {gi}: render_radius must be > 0"
366
+ bodies[body]["geoms"].append({
367
+ "type": "sphere",
368
+ "size": [render_radius],
369
+ "pos": [float(x) for x in g["center"]],
370
+ "quat": [1.0, 0.0, 0.0, 0.0],
371
+ "rgba": [float(x) for x in rgba],
372
+ "group": group,
373
+ "collider": "sphere",
374
+ })
375
+ # SELF-COLLISION overlay, same idea as the contact one above: collision-only shapes drawn into a
376
+ # separate group so they can be toggled. Unlike the contact spheres this needs no per-geom opt-in --
377
+ # a self_collision block exists only to constrain the body, and "how big is the collider" is a
378
+ # question you answer by looking at it. Set DN_RENDER_SELFCOL=0 to leave them out of the file; renders hide
379
+ # them by default either way (renderer.make_scene; see selfcol_shown).
380
+ #
381
+ # A shape is a segment plus a radius; the renderer's capsule is built along local +z and centred, so
382
+ # p0 -> p1 becomes a capsule at the midpoint rotated from +z onto (p1 - p0). p0 == p1 is a sphere,
383
+ # which is what a zero-length capsule is.
384
+ if os.environ.get("DN_RENDER_SELFCOL", "1") != "0":
385
+ seen = set()
386
+ for pair in jm.get("self_collision", {}).get("pairs", []):
387
+ for side in ("a", "b"):
388
+ sh = pair[side]
389
+ key = (sh["body"], tuple(sh["p0"]), tuple(sh["p1"]), sh["radius"])
390
+ if key in seen: # the same shape appears in several pairs
391
+ continue
392
+ seen.add(key)
393
+ b_i = int(sh["body"])
394
+ assert 0 <= b_i < len(bodies), f"self_collision: body index {b_i} out of range"
395
+ p0 = np.asarray(sh["p0"], float); p1 = np.asarray(sh["p1"], float)
396
+ seg = p1 - p0
397
+ L = float(np.linalg.norm(seg))
398
+ g = {"pos": [float(x) for x in (p0 + p1) * 0.5],
399
+ "rgba": [0.20, 0.85, 1.00, 0.12], "group": SELFCOL_RENDER_GROUP,
400
+ "collider": "self"}
401
+ if L < 1e-9:
402
+ g.update(type="sphere", size=[float(sh["radius"])], quat=[1.0, 0.0, 0.0, 0.0])
403
+ else:
404
+ g.update(type="capsule", size=[float(sh["radius"]), L * 0.5],
405
+ quat=_quat_from_z_to(seg / L))
406
+ bodies[b_i]["geoms"].append(g)
407
+
408
+ total = sum(len(b["geoms"]) for b in bodies)
409
+ assert total > 0, "visual_geoms is present but empty (0 geoms) — nothing to render"
410
+ return bodies
411
+
412
+
413
+ def default_geom_groups(bodies):
414
+ # every group present, the self-collider's included: this is WRITTEN into the .dnrec header, so it must not
415
+ # depend on a render preference (a re-eval would stop being byte-identical to the rollouts pinned in
416
+ # docs/repro/). The self-collider is hidden at RENDER time instead (renderer.make_scene, selfcol_shown).
417
+ groups = sorted({int(g.get("group", 0)) for b in bodies for g in b.get("geoms", [])})
418
+ return groups if groups else [0]
419
+
420
+
421
+ def motion_half_extent(pose, floor=2.5, margin=1.5):
422
+ """Ground-patch half-extent that ENCLOSES the motion's x/y reach, so a translating clip keeps a
423
+ floor under it (the writer's default patch is fixed at 2.0). `floor` = minimum half-extent,
424
+ `margin` = padding beyond the farthest body. Pass the result as `write_dnrec(ground_half_extent=)`."""
425
+ px, py = pose[:, :, 0], pose[:, :, 1]
426
+ reach = max(abs(float(px.max())), abs(float(px.min())), abs(float(py.max())), abs(float(py.min())))
427
+ return max(floor, reach + margin)
428
+
429
+
430
+ def write_dnrec(path, pose, qvel, mtu_poly, activation, contact, bodies, dt, scene="fullbody_contact",
431
+ qpos=None, lce_source=None, ground_half_extent=None,
432
+ caption=None, camera=None, root_index=None,
433
+ model=None, provenance=None, z=None, tau=None, act=None, reward=None, com=None, ground_rgba=None):
434
+ """Write a .dnrec physical trace. `lce_source` records the PROVENANCE of the l_ce slot in the
435
+ activation channel [A, radius_vol, l_mtu, l_ce]: "sim" = real simulated fiber
436
+ length (physical MTU state); "render_default_l_opt" = a render-only default derived from the
437
+ muscle's optimal fiber length (NOT physical -- training/analysis must not treat it as fiber state);
438
+ None = no muscles / no l_ce written. Consumers that need physical MTU state assert
439
+ header["lce_source"] == "sim". `ground_half_extent` overrides the default 2.0 ground patch (use
440
+ `motion_half_extent(pose)` to enclose a translating clip) -- no post-write header re-pack needed.
441
+
442
+ `caption` (optional list[str]) and `camera` (optional dict with yaw/pitch/dist[,z_lift]) stamp
443
+ header["caption"] / header["camera"] so a producer can declare its own on-screen caption and camera
444
+ framing instead of relying on the viewer's built-in per-scene tables (tools/viz/hud.SCENE_CAPTIONS,
445
+ tools/viz/camera.SCENE_CAM) -- those tables are generic fallbacks, used only when a clip omits these
446
+ fields. `root_index` (optional int, index into `bodies`) declares which body the viewer's live
447
+ readouts treat as "the" root/base (e.g. forward-speed); omitted -> the viewer defaults to body 0.
448
+ All three default to None (omitted from the header), so existing callers/clips are unaffected.
449
+
450
+ SELF-CONTAINED RECORD (v2, dnrec-format.md / issue #1): `model` embeds the FULL .dnmodel dict into
451
+ header["model"] so the clip replays AND renders standalone (no companion .dnmodel); `provenance` is a
452
+ free-form dict (producer/git_sha/...). The extra STATE channels are the record's full sim state:
453
+ `z` (stiction anchor, (frames, nz)), `tau` (applied generalized force, (frames, nv) -- the control
454
+ input a torque run needs for exact replay), `act` (raw policy action, (frames, na)), `reward`
455
+ ((frames,)). Each is written only when given. Presence of ANY v2 field (model/provenance/z/tau/act/
456
+ reward) stamps format version 2; otherwise version stays 1 (byte-compatible with pre-v2 clips).
457
+ All v2 params default to None, so existing callers/clips are unaffected."""
458
+ assert lce_source in (None, "sim", "render_default_l_opt"), lce_source
459
+ pose = np.asarray(pose, dtype="<f4")
460
+ if qpos is None:
461
+ qpos = np.zeros((pose.shape[0], 0), dtype="<f4")
462
+ qpos = np.asarray(qpos, dtype="<f4")
463
+ qvel = np.asarray(qvel, dtype="<f4")
464
+ mtu_poly = np.asarray(mtu_poly, dtype="<f4")
465
+ activation = np.asarray(activation, dtype="<f4")
466
+ contact = np.asarray(contact, dtype="<f4")
467
+ frames, nb, _ = pose.shape
468
+ assert nb == len(bodies)
469
+ assert qpos.shape[0] == frames
470
+ assert qvel.shape[0] == frames
471
+ assert mtu_poly.shape[0] == frames
472
+ assert activation.shape[0] == frames
473
+ assert contact.shape[0] == frames
474
+ stride = nb * 7
475
+ nq = qpos.shape[1]
476
+ nv = qvel.shape[1]
477
+ nm = mtu_poly.shape[1]
478
+ poly_stride = mtu_poly.shape[2]
479
+ channels = {
480
+ "pose": {"offset": 0, "stride_floats": 7, "count": nb},
481
+ "qpos": {"offset": stride, "stride_floats": 1, "count": nq},
482
+ }
483
+ blocks = [pose.reshape(frames, nb * 7), qpos.reshape(frames, nq)]
484
+ stride += nq
485
+ channels.update({
486
+ "qvel": {"offset": stride, "stride_floats": 1, "count": nv},
487
+ })
488
+ blocks.append(qvel.reshape(frames, nv))
489
+ stride += nv
490
+ if z is not None: # stiction anchor state (v2 replay); (frames, nz)
491
+ z = np.asarray(z, dtype="<f4"); assert z.shape[0] == frames, (z.shape, frames)
492
+ z = z.reshape(frames, -1); nz = z.shape[1]
493
+ channels["z"] = {"offset": stride, "stride_floats": 1, "count": nz}
494
+ blocks.append(z); stride += nz
495
+ channels["mtu_poly"] = {"offset": stride, "stride_floats": poly_stride, "count": nm}
496
+ blocks.append(mtu_poly.reshape(frames, nm * poly_stride))
497
+ stride += nm * poly_stride
498
+ # The activation channel carries its OWN count. It equals nm for every artifact built with the render
499
+ # geometry, but a LIGHT one (DN_DNREC_MTU=0, rl_env_render.light_muscle_channels) has no
500
+ # polylines and still has one activation row per muscle. The header already declares the two counts
501
+ # separately; only this line used to tie them together.
502
+ na = int(activation.shape[1])
503
+ assert nm in (0, na), f"mtu_poly has {nm} muscles but activation has {na}"
504
+ channels["activation"] = {"offset": stride, "stride_floats": 4, "count": na}
505
+ blocks.append(activation.reshape(frames, na * 4))
506
+ stride += na * 4
507
+ if contact.shape[1] > 0:
508
+ channels["contact"] = {"offset": stride, "stride_floats": 7, "count": contact.shape[1]}
509
+ blocks.append(contact.reshape(frames, contact.shape[1] * 7))
510
+ stride += contact.shape[1] * 7
511
+ if com is not None: # whole-body COM track (T,1,3) for the COM-trail overlay
512
+ com = np.asarray(com, dtype="<f4").reshape(frames, 3)
513
+ channels["com"] = {"offset": stride, "stride_floats": 3, "count": 1}
514
+ blocks.append(com); stride += 3
515
+ for _name, _arr in (("tau", tau), ("act", act), ("reward", reward)): # v2 record channels
516
+ if _arr is None:
517
+ continue
518
+ a = np.asarray(_arr, dtype="<f4"); assert a.shape[0] == frames, (_name, a.shape, frames)
519
+ a = a.reshape(frames, -1); c = a.shape[1]
520
+ channels[_name] = {"offset": stride, "stride_floats": 1, "count": c}
521
+ blocks.append(a); stride += c
522
+ header = {
523
+ "scene": scene,
524
+ "dt": float(dt),
525
+ "n_frames": int(frames),
526
+ "n_bodies": int(nb),
527
+ "bodies": bodies,
528
+ "geom_groups_default": default_geom_groups(bodies),
529
+ "ground": {"z": 0.0, "half_extent": 2.0 if ground_half_extent is None else float(ground_half_extent),
530
+ "rgba": [0.42, 0.43, 0.48, 1.0] if ground_rgba is None else [float(x) for x in ground_rgba]},
531
+ "frame": {"stride_floats": int(stride), "channels": channels},
532
+ }
533
+ if lce_source is not None:
534
+ header["lce_source"] = lce_source
535
+ if caption is not None:
536
+ assert isinstance(caption, (list, tuple)) and all(isinstance(x, str) for x in caption), caption
537
+ header["caption"] = list(caption)
538
+ if camera is not None:
539
+ assert isinstance(camera, dict) and {"yaw", "pitch", "dist"} <= set(camera), camera
540
+ header["camera"] = {k: float(v) for k, v in camera.items()}
541
+ if root_index is not None:
542
+ ri = int(root_index)
543
+ assert float(root_index) == float(ri) and 0 <= ri < len(bodies), (root_index, len(bodies))
544
+ header["root_index"] = ri
545
+ if model is not None: # embed the full .dnmodel -> self-contained (v2)
546
+ assert isinstance(model, dict) and "bodies" in model, "model must be the parsed .dnmodel dict"
547
+ header["model"] = model
548
+ if provenance is not None:
549
+ assert isinstance(provenance, dict), provenance
550
+ header["provenance"] = provenance
551
+ # Presence of ANY v2 field bumps the format version; else stay v1 (byte-IDENTICAL to old clips:
552
+ # v1 keeps no header "version" key, as before; the struct prefix carries the version for both).
553
+ version = 2 if any(x is not None for x in (model, provenance, z, tau, act, reward)) else 1
554
+ if version == 2:
555
+ header["version"] = 2
556
+ hb = json.dumps(header).encode("utf-8")
557
+ with open(path, "wb") as f:
558
+ f.write(MAGIC)
559
+ f.write(struct.pack("<II", version, len(hb)))
560
+ f.write(hb)
561
+ f.write(np.concatenate(blocks, axis=1).astype("<f4").tobytes())
562
+ return path
563
+
564
+
565
+ def load_dnrec(path):
566
+ """Read a .dnrec back into numpy (torch-free) -- the record-consumer side of the format (analysis,
567
+ replay). Returns dict(header, model, dt, n_frames, version, channels). `model` is the embedded
568
+ .dnmodel dict (v2) or None (v1 -> a .dnmodel must be supplied separately). `channels[name]` is
569
+ (frames, count) for scalar-stride channels (qpos/qvel/z/tau/act/reward) or (frames, count,
570
+ stride_floats) for structured ones (pose=7, activation=4, contact=7, mtu_poly). Handles both v1 and
571
+ v2 clips."""
572
+ with open(path, "rb") as f:
573
+ raw = f.read()
574
+ assert raw[:4] == MAGIC, (raw[:4],)
575
+ version, hlen = struct.unpack_from("<II", raw, 4)
576
+ assert version in (1, 2), f"unsupported .dnrec version {version}"
577
+ header = json.loads(raw[12:12 + hlen])
578
+ fr = header["frame"]; stride = int(fr["stride_floats"]); nfr = int(header["n_frames"])
579
+ flat = np.frombuffer(raw[12 + hlen:], dtype="<f4").reshape(nfr, stride)
580
+ channels = {}
581
+ for name, spec in fr["channels"].items():
582
+ off, sf, cnt = int(spec["offset"]), int(spec["stride_floats"]), int(spec["count"])
583
+ block = flat[:, off:off + cnt * sf]
584
+ channels[name] = block.reshape(nfr, cnt) if sf == 1 else block.reshape(nfr, cnt, sf)
585
+ return dict(header=header, model=header.get("model"), dt=float(header["dt"]),
586
+ n_frames=nfr, version=version, channels=channels)
587
+
588
+
589
+ def set_provenance(path, extra):
590
+ """Merge `extra` (a JSON-serializable dict) into a v2 `.dnrec` header's ``provenance`` block, in
591
+ place -- folds a record's non-state metadata (training curve / eval log / wall-time / n_env /
592
+ stiction params) INTO the single self-contained file so no companion `.npz` is needed
593
+ (dnrec-format.md P4). Rewrites the file: the JSON header length changes and shifts the frame offset,
594
+ so the float32 frame block is read then written back verbatim (byte-for-byte)."""
595
+ path = str(path)
596
+ assert is_record(path), path
597
+ assert isinstance(extra, dict), extra
598
+ with open(path, "rb") as f:
599
+ raw = f.read()
600
+ assert raw[:4] == MAGIC, (raw[:4],)
601
+ version, hlen = struct.unpack_from("<II", raw, 4)
602
+ assert version == 2, f"provenance requires a v2 record (with model/state); got version {version}"
603
+ header = json.loads(raw[12:12 + hlen])
604
+ frames = raw[12 + hlen:] # float32 block -- preserved verbatim
605
+ header.setdefault("provenance", {}).update(extra)
606
+ hb = json.dumps(header).encode("utf-8")
607
+ with open(path, "wb") as f:
608
+ f.write(MAGIC)
609
+ f.write(struct.pack("<II", version, len(hb)))
610
+ f.write(hb)
611
+ f.write(frames)
612
+ return path
613
+
614
+
615
+ def set_task(path, task):
616
+ """Stamp a steering record's TASK into its `.dnrec` header (header["task"]), in place, so the renderer draws the live map and
617
+ the task readout (hud.task_track). `task`: {"mode": "target" | "schedule" | "straight" | "random", "label": str, "targets":
618
+ [[x, y], ...] (metres in the start pose's frame, x ahead, y left), "radius": m, "speeds": [m/s per waypoint] (optional),
619
+ "schedule": [[t_s, deg_left], ...] or [[t_s, deg_left, v], ...] (a per-segment speed), "v_fixed": m/s, "footsteps": per
620
+ frame [p0x, p0y, p1x, p1y, heading, provisional, left] (WORLD, TASKWALK_FOOTSTEPS; optional, required for "random": the
621
+ plan is the only map a random command has)}. The frame block is preserved byte-for-byte (as set_provenance)."""
622
+ path = str(path)
623
+ assert is_record(path), path
624
+ assert isinstance(task, dict) and task.get("mode") in ("target", "schedule", "straight", "random"), task
625
+ if task["mode"] == "target":
626
+ assert task.get("targets") and all(len(t) == 2 for t in task["targets"]), task
627
+ if task["mode"] == "schedule":
628
+ assert task.get("schedule") and all(len(t) in (2, 3) for t in task["schedule"]), task
629
+ if task["mode"] == "random":
630
+ assert task.get("footsteps") and all(len(r) == 7 for r in task["footsteps"]), task
631
+ with open(path, "rb") as f:
632
+ raw = f.read()
633
+ assert raw[:4] == MAGIC, (raw[:4],)
634
+ version, hlen = struct.unpack_from("<II", raw, 4)
635
+ header = json.loads(raw[12:12 + hlen])
636
+ frames = raw[12 + hlen:]
637
+ header["task"] = task
638
+ hb = json.dumps(header).encode("utf-8")
639
+ with open(path, "wb") as f:
640
+ f.write(MAGIC)
641
+ f.write(struct.pack("<II", version, len(hb)))
642
+ f.write(hb)
643
+ f.write(frames)
644
+ return path
645
+
646
+
647
+ def load_record(path):
648
+ """Read a recorded rollout as a canonical numpy dict from EITHER a v2 `.dnrec` record OR a legacy
649
+ `.npz` -- the migration bridge (dnrec-format.md P2). A consumer swaps `np.load(p)` -> `load_record(p)`
650
+ and reads the same keys regardless of format, so producer/consumer migration is order-independent and
651
+ dropping the `.npz` later is transparent. Canonical keys (present when the record carries them):
652
+ `q` (=qpos), `qd` (=qvel), `z`, `lce`, `activation` (the A scalar), `action`, `reward`, `tau`, `dt`,
653
+ and `model` (the embedded .dnmodel, `.dnrec` v2 only). A `.npz` is returned key-for-key as written."""
654
+ path = str(path)
655
+ if not is_record(path):
656
+ with np.load(path) as z: # legacy .npz: pass through verbatim
657
+ return {k: z[k] for k in z.files}
658
+ d = load_dnrec(path)
659
+ ch = d["channels"]
660
+ out = {"dt": d["dt"]}
661
+ if d["model"] is not None:
662
+ out["model"] = d["model"]
663
+ if "qpos" in ch: out["q"] = ch["qpos"]
664
+ if "qvel" in ch: out["qd"] = ch["qvel"]
665
+ if "z" in ch: out["z"] = ch["z"]
666
+ if "activation" in ch: # activation channel = [A, radius_vol, l_mtu, l_ce]
667
+ out["activation"] = ch["activation"][:, :, 0] # the A scalar (what the .npz stored)
668
+ if d["header"].get("lce_source") == "sim": # l_ce is a real fiber state only if sim-provenance
669
+ out["lce"] = ch["activation"][:, :, 3]
670
+ if "tau" in ch: out["tau"] = ch["tau"]
671
+ if "act" in ch: out["action"] = ch["act"]
672
+ if "reward" in ch: out["reward"] = ch["reward"].reshape(d["n_frames"])
673
+ if "contact" in ch: # unpack the contact channel [witness3, force3, fn]
674
+ c = ch["contact"] # (nc, 7); RAW engine force -- the swing/stance
675
+ nf = d["n_frames"] # legibility floor is a RENDER-time skip, not stored
676
+ out["contact_witness"] = c[:, :, 0:3].reshape(nf, -1)
677
+ out["contact_force"] = c[:, :, 3:6].reshape(nf, -1)
678
+ prov = d["header"].get("provenance", {}) # layer-4 metadata (dnrec-format.md)
679
+ if prov:
680
+ out["provenance"] = prov
681
+ # Fold the training telemetry (curve/eval_log/n_env/steps_num/train_wall/reset_height/stick_*)
682
+ # to top-level so a metadata consumer reads the SAME keys whether the record is a `.npz` (keys
683
+ # are top-level) or a self-contained `.dnrec` (keys live under provenance.training) -- P4.
684
+ for k, v in prov.get("training", {}).items():
685
+ out[k] = np.asarray(v) if isinstance(v, list) else v
686
+ return out