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,635 @@
1
+ """Render a saved RL eval rollout (.npz q-traj) to a `.dnrec`, generically for the
2
+ ant / cartpole / myoLeg22 envs -- mirrors tools/humanoid_render.py but for the other envs.
3
+
4
+ Physics is NOT re-solved: the .npz `q` (T, nq) is the engine's own eval trajectory; this only
5
+ runs forward-kinematics (viz.dnrec_io.fk_poses, torch-free, handles free/ball/hinge/slide/compound)
6
+ to per-body world poses, attaches the env's VISUAL geoms, and packs a `.dnrec`. `tools/viz/to_mp4.py`
7
+ draws it (use `--follow` for a tracking camera).
8
+
9
+ STANDARDIZATION (so muscle/contact overlays are NEVER silently dropped again):
10
+ * MUSCLES are read straight from the dnmodel's `"muscles"` list (each has origin/insertion {body,pos}).
11
+ If the model has muscles, we ALWAYS build the mtu_poly + activation channels from the eval npz's
12
+ `activation` -- there is no separate "remember to add muscles" step to forget. A hard assert fires
13
+ if a muscle model is rendered without muscle overlays.
14
+ * CONTACT forces are read straight from the eval npz (`contact_force` + `contact_witness`, if present)
15
+ and ALWAYS drawn as force arrows.
16
+ The model file marks WHAT to render (its `"muscles"` list); the renderer just honours it.
17
+
18
+ Geom source: every model-backed env (ant / myoleg22 / myoleg26) reads its VISUAL geoms straight from
19
+ its own .dnmodel's `visual_geoms` block, via the single model-agnostic build_from_dnmodel builder below
20
+ (no per-env sidecar files, no per-env builder function). cartpole has no .dnmodel (analytic 2-body:
21
+ nq=2 = [cart_x, pole_angle]) and keeps its own builder.
22
+
23
+ Run:
24
+ python tools/rl_env_render.py myoleg22 docs-dev/.../eval_npz/myoleg22_shac_eval.npz out.dnrec
25
+ then:
26
+ cd tools/viz && uv run --with "moderngl,imageio[ffmpeg],numpy,Pillow" --no-project \
27
+ python to_mp4.py <out.dnrec> <out.mp4> --follow --fps <round(1/dt)>
28
+ """
29
+ import argparse
30
+ import math
31
+ import os
32
+ import pathlib
33
+
34
+ import numpy as np
35
+
36
+ from diffneusim._paths import ROOT as ROOT # (3a) the repo root
37
+ # (3a) was: sys.path.insert(0, str(ROOT / "tools"))
38
+ # (3a) was: sys.path.insert(0, str(ROOT / "tools" / "viz")) # robust when imported (not just run as a script)
39
+ from diffneusim.viz.dnrec_io import ( # noqa: E402
40
+ fk_poses, load_dnmodel, motion_half_extent, normalize_quat, quat_axis_angle, quat_rotate,
41
+ render_bodies_from_visual_geoms, write_dnrec)
42
+ # (3a) was: sys.path.insert(0, str(ROOT / "python"))
43
+ from diffneusim.rl.model_path import MYOLEG26_DEFAULT as _MYOLEG26_DEFAULT # noqa: E402 decisions/0033
44
+ from diffneusim.viz.dnrec_io import muscle_f_maxes, muscle_l_opt # noqa: E402
45
+
46
+ # Muscle specific tension (peak isometric stress). Sets PCSA = Fmax/sigma_max and hence the derived belly
47
+ # VOLUME V = l_opt * PCSA when a muscle has no authored dnmodel "volume". This is the one knob that scales
48
+ # overall rendered muscle thickness; it is a visualization constant, not a sim value. 0.6 MPa fills the
49
+ # FULL-BODY (416 muscles) so the bellies read as packed muscle -- the round-balloon look that used to
50
+ # force thin muscles is gone now that the belly cross-section is FLATTENED (render.py muscle_aspect), so
51
+ # fatter muscles pack rather than bulge. Raise sigma for leaner muscles, lower it for bulkier.
52
+ MUSCLE_SIGMA_MAX = 6.0e5 # N/m^2
53
+
54
+
55
+ def _via_local(pt, qt, v2q=None, single_dof=None):
56
+ """One path via-point's body-local position. FIXED site = {body, off}. MOVING site =
57
+ {body, cdof, coef[K][3]} = polynomial in the coupling joint angle theta = q[qadr(cdof)]. cdof is a
58
+ VELOCITY index (vadr); with a Free base + Ball hips qadr != vadr, so we remap vadr->qadr (matches the
59
+ engine). A multi-DOF (Ball/Free) coupling joint has NO scalar angle -> bake to the neutral offset
60
+ coef[0] rather than read a quaternion component (matches the engine loader)."""
61
+ if "off" in pt:
62
+ return np.asarray(pt["off"], np.float64)
63
+ cdof = int(pt["cdof"])
64
+ coef = np.asarray(pt["coef"], np.float64) # (K, 3)
65
+ if single_dof is not None and not single_dof.get(cdof, False):
66
+ return coef[0] # Ball/Free-coupled -> baked fixed
67
+ qi = v2q.get(cdof, cdof) if v2q is not None else cdof # vadr -> qadr
68
+ theta = float(qt[qi])
69
+ powers = theta ** np.arange(coef.shape[0])
70
+ return (coef * powers[:, None]).sum(0)
71
+
72
+
73
+ def _via_local_rows(pt, q, v2q, single_dof):
74
+ """`_via_local` for every frame at once: (3,) for a fixed or a baked site, (T, 3) for a moving one. The same numpy operations
75
+ in the same order, each over T rows (theta ** arange(K), coef * powers, the sum over K), so every value is the per-frame one."""
76
+ if "off" in pt:
77
+ return np.asarray(pt["off"], np.float64)
78
+ cdof = int(pt["cdof"])
79
+ coef = np.asarray(pt["coef"], np.float64) # (K, 3)
80
+ if single_dof is not None and not single_dof.get(cdof, False):
81
+ return coef[0]
82
+ qi = v2q.get(cdof, cdof) if v2q is not None else cdof
83
+ theta = q[:, qi] # (T,) float64, the per-frame float(qt[qi])
84
+ powers = theta[:, None] ** np.arange(coef.shape[0]) # (T, K)
85
+ return (coef[None, :, :] * powers[:, :, None]).sum(1)
86
+
87
+
88
+ def _rowdot(x):
89
+ """x . x of every row of x (T, n) through matmul's vector @ vector case, which calls the same BLAS dot (DOUBLE_dot) as the 1-D
90
+ x.dot(x) inside np.linalg.norm, so sqrt(_rowdot(x)) is np.linalg.norm row by row, bitwise, on any BLAS. (A hand-written
91
+ ((x0 x0 + x1 x1) + x2 x2) + x3 x3 is not: on Accelerate it differs at n = 4 in 15 % of rows.) Contiguous rows, or matmul
92
+ takes its no-BLAS loop."""
93
+ x = np.ascontiguousarray(x, np.float64)
94
+ return np.matmul(x[:, None, :], x[:, :, None])[:, 0, 0]
95
+
96
+
97
+ def _qrot_rows(q, v):
98
+ """dnrec_io.quat_rotate over rows: q (4,) or (T, 4) = [w, x, y, z], v (3,) or (T, 3). Operation for operation:
99
+ v + (2 w) cross(u, v) + 2 cross(u, cross(u, v)), u in float64, 2 w in q's dtype (exact)."""
100
+ w = q[..., 0]
101
+ u = np.asarray(q[..., 1:4], np.float64)
102
+ u, v = np.broadcast_arrays(u, np.asarray(v, np.float64))
103
+ return v + (2.0 * w)[..., None] * np.cross(u, v) + 2.0 * np.cross(u, np.cross(u, v))
104
+
105
+
106
+ def _qmul_rows(a, b):
107
+ """dnrec_io.quat_mul over rows: a, b (4,) or (T, 4); its four expressions, term for term."""
108
+ aw, ax, ay, az = (a[..., k] for k in range(4))
109
+ bw, bx, by, bz = (b[..., k] for k in range(4))
110
+ return np.stack(np.broadcast_arrays(aw * bw - ax * bx - ay * by - az * bz,
111
+ aw * bx + ax * bw + ay * bz - az * by,
112
+ aw * by - ax * bz + ay * bw + az * bx,
113
+ aw * bz + ax * by - ay * bx + az * bw), axis=-1).astype(np.float64)
114
+
115
+
116
+ def _qnormalize_rows(q):
117
+ """dnrec_io.normalize_quat over rows: q / np.linalg.norm(q), the norm through _rowdot."""
118
+ q = np.asarray(q, np.float64)
119
+ if q.ndim == 1:
120
+ return q / np.linalg.norm(q)
121
+ return q / np.sqrt(_rowdot(q))[:, None]
122
+
123
+
124
+ def _qaxis_angle_rows(axis, angle):
125
+ """dnrec_io.quat_axis_angle over rows of `angle` (T,): the axis normalised as there, sin / cos through math (as there; numpy's
126
+ SIMD sin / cos is not libm's on every host)."""
127
+ axis = np.asarray(axis, dtype=np.float64)
128
+ n = np.linalg.norm(axis)
129
+ assert n > 0
130
+ axis = axis / n
131
+ half = (0.5 * np.asarray(angle, np.float64)).tolist()
132
+ s = np.array([math.sin(h) for h in half], np.float64)
133
+ c = np.array([math.cos(h) for h in half], np.float64)
134
+ return np.stack([c, axis[0] * s, axis[1] * s, axis[2] * s], axis=-1)
135
+
136
+
137
+ def fk_poses_rows(jm, Q):
138
+ """dnrec_io.fk_poses (subset None) for every frame of Q (T, nq) at once: (T, n_body, 7) float64, each body's operations done over
139
+ T rows in fk_poses' order (render couplings, physics-coupled joints, fixed / free / ball / hinge / slide). Compound joints are not
140
+ ported: they assert. DN_DNREC_VEC=1 only; tools/launch/mtu_vec_gate.py checks it against the per-frame stack."""
141
+ Q = np.asarray(Q, np.float64)
142
+ T = Q.shape[0]
143
+ bodies = jm["bodies"]
144
+ poses = np.zeros((T, len(bodies), 7), dtype=np.float64)
145
+ rc = jm.get("render_couplings", {})
146
+ 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}
147
+
148
+ def coupled_angle(coef, theta): # float((coef * theta ** arange(K)).sum()) per row
149
+ return (coef[None, :] * theta[:, None] ** np.arange(coef.shape[0])).sum(1)
150
+
151
+ for i, body in enumerate(bodies):
152
+ parent = int(body["parent"])
153
+ if parent >= 0:
154
+ pp, pq = poses[:, parent, :3], poses[:, parent, 3:7]
155
+ else:
156
+ pp, pq = np.zeros(3, dtype=np.float64), np.array([1.0, 0.0, 0.0, 0.0], dtype=np.float64)
157
+ rcpl = rc.get(str(i))
158
+ cp = body.get("coupled")
159
+ if rcpl is not None or cp is not None:
160
+ src = rcpl if rcpl is not None else body
161
+ local_p = np.asarray(src["pos"], dtype=np.float64)
162
+ base_p = pp + _qrot_rows(pq, local_p)
163
+ base_q = _qnormalize_rows(_qmul_rows(pq, normalize_quat(src["quat"])))
164
+ if rcpl is not None:
165
+ coef = np.asarray(rcpl["coef"], dtype=np.float64)
166
+ qc = coupled_angle(coef, Q[:, v2q.get(int(rcpl["cdof"]), int(rcpl["cdof"]))])
167
+ axis, kind = np.asarray(rcpl["axis"], dtype=np.float64), rcpl["joint"]
168
+ else:
169
+ coef = np.asarray(cp["coef"], dtype=np.float64)
170
+ qc = coupled_angle(coef, Q[:, int(cp["master_qadr"])])
171
+ axis, kind = np.asarray(body["axis"], dtype=np.float64), body["joint"]
172
+ if kind in ("revolute", "hinge"):
173
+ poses[:, i, :3] = base_p
174
+ poses[:, i, 3:7] = _qnormalize_rows(_qmul_rows(base_q, _qaxis_angle_rows(axis, qc)))
175
+ elif kind in ("slide", "prismatic"):
176
+ poses[:, i, :3] = base_p + _qrot_rows(base_q, axis[None, :] * qc[:, None])
177
+ poses[:, i, 3:7] = base_q
178
+ else:
179
+ raise AssertionError(f"coupled joint {kind}")
180
+ continue
181
+ assert "joints" not in body, f"body {i}: compound joints are not ported to fk_poses_rows (use DN_DNREC_VEC=0)"
182
+ local_p = np.asarray(body["pos"], dtype=np.float64)
183
+ base_p = pp + _qrot_rows(pq, local_p)
184
+ base_q = _qnormalize_rows(_qmul_rows(pq, normalize_quat(body["quat"])))
185
+ qa = int(body["qadr"])
186
+ joint = body["joint"]
187
+ if joint == "fixed":
188
+ out_p, out_q = base_p, base_q
189
+ elif joint == "free":
190
+ out_p = base_p + _qrot_rows(base_q, Q[:, qa:qa + 3])
191
+ out_q = _qnormalize_rows(_qmul_rows(base_q, Q[:, qa + 3:qa + 7]))
192
+ elif joint == "ball":
193
+ out_p = base_p
194
+ out_q = _qnormalize_rows(_qmul_rows(base_q, Q[:, qa:qa + 4]))
195
+ elif joint in ("revolute", "hinge"):
196
+ out_p = base_p
197
+ out_q = _qnormalize_rows(_qmul_rows(base_q, _qaxis_angle_rows(body["axis"], Q[:, qa])))
198
+ elif joint in ("slide", "prismatic"):
199
+ out_p = base_p + _qrot_rows(base_q, np.asarray(body["axis"], dtype=np.float64)[None, :] * Q[:, qa][:, None])
200
+ out_q = base_q
201
+ else:
202
+ raise AssertionError(f"unknown joint {joint}")
203
+ poses[:, i, :3] = out_p
204
+ poses[:, i, 3:7] = out_q
205
+ return poses
206
+
207
+
208
+ def _fill_muscle_rows(mtu, activation, paths, pose, q, v2q, single_dof, act, rad_vol, lce, l_opt):
209
+ """muscle_channels' per-frame loop, one muscle via-point at a time over all T frames (DN_DNREC_VEC=1; the default 0 keeps
210
+ the per-frame loop). Fills `mtu` and `activation` in place with the values the loop writes:
211
+ - the world point = pose[:, b, :3] + quat_rotate(pose quat, local), as the loop;
212
+ - l_mtu = 0 + |d_0| + |d_1| + ... in segment order (Python's sum), |d| through _rowdot (np.linalg.norm's BLAS dot);
213
+ - l_ce = the simulated one, or min(l_opt, 0.9 l_mtu); then clamped to [1e-4, l_mtu]."""
214
+ T = pose.shape[0]
215
+ for mi, path in enumerate(paths):
216
+ mtu[:, mi, 0] = len(path)
217
+ pts = []
218
+ for s, pt in enumerate(path):
219
+ b = int(pt["body"])
220
+ world = pose[:, b, :3] + _qrot_rows(pose[:, b, 3:7], _via_local_rows(pt, q, v2q, single_dof))
221
+ pts.append(world)
222
+ mtu[:, mi, 1 + s * 3: 4 + s * 3] = world
223
+ l_mtu = np.zeros(T, np.float64)
224
+ for i in range(len(pts) - 1):
225
+ l_mtu = l_mtu + np.sqrt(_rowdot(pts[i + 1] - pts[i]))
226
+ assert (l_mtu > 1e-6).all(), f"muscle {mi}: zero drawn MTU path length at frames {np.where(~(l_mtu > 1e-6))[0][:5]}"
227
+ l_ce = lce[:, mi] if lce is not None else np.minimum(l_opt[mi], 0.9 * l_mtu)
228
+ l_ce = np.minimum(np.maximum(l_ce, 1e-4), l_mtu)
229
+ activation[:, mi, 0] = act[:, mi]
230
+ activation[:, mi, 1] = rad_vol[mi]
231
+ activation[:, mi, 2] = l_mtu
232
+ activation[:, mi, 3] = l_ce
233
+
234
+
235
+ def dnrec_vec():
236
+ """DN_DNREC_VEC: '1' builds a record's pose (fk_poses_rows) and muscle channels (_fill_muscle_rows) over all frames at once;
237
+ '0' (the default) keeps the per-frame loops. The gate (bitwise, per host): tools/launch/mtu_vec_gate.py."""
238
+ v = os.environ.get("DN_DNREC_VEC", "0")
239
+ assert v in ("0", "1"), f"DN_DNREC_VEC={v!r} must be exactly '0' or '1'"
240
+ return v == "1"
241
+
242
+
243
+ def light_muscle_channels(jm, data, T):
244
+ """The activation channel WITHOUT the render geometry: `[A, 0, 0, l_ce]` and an EMPTY `mtu_poly`.
245
+
246
+ WHY. `muscle_channels` costs 44.5 s per 1000-frame start on the full body (290 muscles x 25 via-points
247
+ x T), which is 83% of a `.dnrec`'s build time and ~67% of a sweep's non-step time (perf-log 2026-10-01)
248
+ -- and it is built for all 8 starts of every checkpoint while ONE start of ONE checkpoint is ever
249
+ rendered. No analysis tool reads `mtu_poly`: `fb_vs_ref`, `pushoff_friction`, `brake_per_foot` and
250
+ `leg_activation` take qpos / qvel / z / pose and `activation[..., 0]`.
251
+
252
+ WHAT IS LOST, stated. Slots 1 and 2 of the activation channel -- `rad_vol` (the renderer's isovolumetric
253
+ belly coefficient, a per-muscle CONSTANT recoverable from the model) and `l_mtu` (the drawn via-point
254
+ arc length, which needs exactly the geometry this skips). `l_mtu` has one consumer,
255
+ `tools/gait/energy_audit.py`, which is a manual analysis and not in any sweep; it must be run against a
256
+ FULL artifact. Slot 0 (`A`) and slot 3 (`l_ce`) come straight from the eval payload and are bit-identical
257
+ to the full path.
258
+
259
+ Gated by `DN_DNREC_MTU=0`; the default is 1 and every existing artifact is unchanged."""
260
+ muscles = (jm or {}).get("muscles", [])
261
+ M = len(muscles)
262
+ act = np.zeros((T, M, 4), np.float32)
263
+ if M:
264
+ assert "activation" in data, f"a light .dnrec still needs the activation channel (has {list(data)})"
265
+ act[..., 0] = np.asarray(data["activation"], np.float32)[:T]
266
+ if data.get("lce") is not None:
267
+ act[..., 3] = np.asarray(data["lce"], np.float32)[:T]
268
+ lce_source = "sim" if data.get("lce") is not None else "render_default_l_opt"
269
+ return np.zeros((T, 0, 7), np.float32), act, lce_source
270
+
271
+
272
+ def muscle_channels(jm, data, pose, *, kinematic_reference=False, reference_activation=0.3):
273
+ """AUTO from the dnmodel `"muscles"`: draw each muscle as its FULL via-point polyline (the model's
274
+ `path`: origin -> moving/fixed via-points -> insertion), NOT a straight origin->insertion line
275
+ (which cuts through the limb). Moving via-points follow the coupling joint angle (see _via_local).
276
+ Returns (mtu_poly[t,m]=[npts, p0(3), p1(3), ...], activation[t,m]=[A,rad_vol,l_mtu,l_ce]).
277
+ `rad_vol` = V/pi (m^3), the isovolumetric belly coefficient: the renderer draws belly_r=sqrt(rad_vol/
278
+ l_ce) so the belly bulges as the fiber shortens (V from an authored dnmodel "volume" or l_opt*Fmax/sigma).
279
+ l_mtu is the actual drawn via-point arc length. l_ce is the muscle-belly (fiber) length that the
280
+ `mtu` render mode uses to split the path into proximal tendon + belly + distal tendon. If the eval
281
+ capture has a real simulated `lce`, use it. Otherwise (a kinematic reference has no fiber sim) fall
282
+ back to the muscle's OPTIMAL FIBER LENGTH gainprm[1] (capped to 0.9*l_mtu). This matters: the old
283
+ fallback set l_ce = l_mtu, which zeroed the tendons and drew every muscle as ONE uniform tube -- and
284
+ at low activation that tube reads as a tendon. Using gainprm[1] gives a real belly/tendon split
285
+ (thick fiber belly, thin series tendons), matching python/examples/myoleg26_structure_preview.py."""
286
+ T = pose.shape[0]
287
+ muscles = (jm or {}).get("muscles", [])
288
+ if not muscles:
289
+ return np.zeros((T, 0, 7), np.float32), np.zeros((T, 0, 4), np.float32), None
290
+ q = np.asarray(data["q"], np.float64) # (T, nq) for moving via-point theta
291
+ M = len(muscles)
292
+ if "activation" in data:
293
+ act = np.asarray(data["activation"], np.float64) # (T, M)
294
+ else:
295
+ assert kinematic_reference, (
296
+ "muscle model render input has no activation channel. Pass kinematic_reference=True only "
297
+ "for non-dynamic reference clips that need visual muscle routing.")
298
+ assert 0.0 <= reference_activation <= 1.0, reference_activation
299
+ act = np.full((T, M), float(reference_activation), dtype=np.float64)
300
+ assert act.shape[0] == T and act.shape[1] == M, \
301
+ f"activation shape {act.shape} != (T={T}, M={M} muscles)"
302
+ lce = None
303
+ if "lce" in data:
304
+ lce = np.asarray(data["lce"], np.float64)
305
+ assert lce.shape == (T, M), f"lce shape {lce.shape} != (T={T}, M={M} muscles)"
306
+ # moving-via theta = q[qadr(cdof)]; single-DOF joints only (Ball/Free -> baked fixed). Matches engine.
307
+ v2q, single_dof = {}, {}
308
+ for b in jm.get("bodies", []):
309
+ va, qa, jt = b.get("vadr"), b.get("qadr"), b.get("joint")
310
+ if va is not None and qa is not None:
311
+ v2q[va] = qa
312
+ single_dof[va] = jt in ("revolute", "hinge", "slide", "prismatic")
313
+
314
+ def path_of(m):
315
+ p = m.get("path")
316
+ if p:
317
+ return p
318
+ # RENDER-ONLY geometry that a polynomial-path model may still carry. Its length is NOT the
319
+ # polynomial's length -- for a muscle whose stated route was stripped of its wrapping the two
320
+ # disagree by centimetres -- so it draws the muscle and must never feed a measurement.
321
+ rp = m.get("render_path")
322
+ if rp:
323
+ return rp
324
+ if "origin" not in m:
325
+ # A `path_poly` muscle carries LENGTH as a polynomial in the coordinates it crosses and
326
+ # no spatial route at all -- enough for the dynamics, but there is nothing to draw. It is
327
+ # dropped from the render rather than faked, so a missing muscle in the picture means
328
+ # "this model states no geometry for it", not "the renderer lost it".
329
+ return None
330
+ return [{"body": m["origin"]["body"], "off": m["origin"]["pos"]},
331
+ {"body": m["insertion"]["body"], "off": m["insertion"]["pos"]}]
332
+ drawable = [(m, path_of(m)) for m in muscles]
333
+ skipped = [m["name"] for m, pa in drawable if pa is None]
334
+ if skipped:
335
+ print(f"[render] {len(skipped)} muscle(s) have a polynomial path and no geometry to draw "
336
+ f"(e.g. {', '.join(skipped[:3])}); drawing the remaining {len(drawable) - len(skipped)}")
337
+ muscles = [m for m, pa in drawable if pa is not None]
338
+ paths = [pa for _, pa in drawable if pa is not None]
339
+ if not paths:
340
+ # Every muscle states its length as a polynomial, so the model has no muscle geometry at all.
341
+ # Same empty-channel shape the no-muscle model returns above -- bones still draw.
342
+ return np.zeros((T, 0, 7), np.float32), np.zeros((T, 0, 4), np.float32), None
343
+ l_opt = [muscle_l_opt(m) for m in muscles] # optimal fibre length (either .dnmodel spelling)
344
+ # VOLUMETRIC belly radius (isovolumetric muscle): the belly cross-section A obeys A*l_ce = V, so the
345
+ # drawn belly radius is sqrt(V/(pi*l_ce)) -- the belly BULGES as the fiber shortens and thins as it
346
+ # lengthens, at constant volume V. V is a per-muscle constant: an authored dnmodel "volume" (m^3) when
347
+ # present, else physiology V = l_opt * PCSA with PCSA = Fmax/sigma_max (peak force gainprm[0]). We pack
348
+ # V/pi ("rad_vol", m^3) into the width slot; the renderer rebuilds belly & tendon radii from rad_vol +
349
+ # the per-frame l_ce/l_mtu (slots 2,3). This replaces the old sqrt(Fmax) render radius: thickness is
350
+ # now PHYSICAL (fiber-length coupled) while activation drives colour (+ a small active bulge) downstream.
351
+ _g0 = np.array(muscle_f_maxes({"muscles": muscles}), np.float64) # peak force Fmax (either spelling)
352
+ _vol = np.array([float(m["volume"]) if m.get("volume") is not None
353
+ else lo * max(f0, 0.0) / MUSCLE_SIGMA_MAX
354
+ for m, lo, f0 in zip(muscles, l_opt, _g0)], np.float64)
355
+ rad_vol = np.maximum(_vol, 1e-12) / np.pi # V/pi (m^3); slot-1 volumetric coefficient
356
+ # Provenance of the l_ce slot (dnrec-contract / write_dnrec): real simulated fiber length, or a
357
+ # render-only default from optimal fiber length. Consumers assert "sim" for physical MTU state.
358
+ lce_source = "sim" if lce is not None else "render_default_l_opt"
359
+ maxpts = max(len(p) for p in paths)
360
+ mtu = np.zeros((T, M, 1 + 3 * maxpts), np.float32)
361
+ activation = np.zeros((T, M, 4), np.float32)
362
+ if dnrec_vec():
363
+ _fill_muscle_rows(mtu, activation, paths, pose, q, v2q, single_dof, act, rad_vol, lce, l_opt)
364
+ return mtu, activation, lce_source
365
+ for t in range(T):
366
+ for mi, path in enumerate(paths):
367
+ mtu[t, mi, 0] = len(path)
368
+ pts = []
369
+ for s, pt in enumerate(path):
370
+ b = int(pt["body"])
371
+ world = pose[t, b, :3] + quat_rotate(pose[t, b, 3:7], _via_local(pt, q[t], v2q, single_dof))
372
+ pts.append(world)
373
+ mtu[t, mi, 1 + s * 3: 4 + s * 3] = world
374
+ l_mtu = sum(float(np.linalg.norm(pts[i + 1] - pts[i])) for i in range(len(pts) - 1))
375
+ # No simulated fiber length on a kinematic reference -> use the optimal fiber length
376
+ # (gainprm[1]) capped below l_mtu so `mtu` mode renders a real belly/tendon split.
377
+ l_ce = float(lce[t, mi]) if lce is not None else min(l_opt[mi], 0.9 * l_mtu)
378
+ assert l_mtu > 1e-6, f"muscle {mi}: zero drawn MTU path length"
379
+ # Real simulated l_ce can go slightly <0 or >l_mtu at extreme muscle states (e.g. a policy
380
+ # that topples drives a fiber out of range); CLAMP for rendering rather than crash -- the
381
+ # render is a visualization, not a correctness gate. (A kinematic reference's l_ce = l_opt
382
+ # is always in-range, so this clamp is a no-op there.)
383
+ l_ce = float(min(max(l_ce, 1e-4), l_mtu))
384
+ activation[t, mi] = (float(act[t, mi]), float(rad_vol[mi]), l_mtu, l_ce)
385
+ return mtu, activation, lce_source
386
+
387
+
388
+ def contact_visual_bottom_z(pose, bodies):
389
+ """Minimum world z of renderable contact spheres per frame."""
390
+ pose = np.asarray(pose, np.float64)
391
+ collider_sites = []
392
+ for bi, body in enumerate(bodies):
393
+ for geom in body.get("geoms", []):
394
+ if geom.get("collider") != "sphere":
395
+ continue
396
+ assert geom["type"] == "sphere", (bi, geom)
397
+ assert len(geom["size"]) == 1, geom
398
+ collider_sites.append((bi, np.asarray(geom["pos"], np.float64), float(geom["size"][0])))
399
+ assert collider_sites, "ground-contact render requested, but the .dnrec bodies contain no collider spheres"
400
+ out = np.empty(pose.shape[0], dtype=np.float64)
401
+ for t in range(pose.shape[0]):
402
+ zmin = np.inf
403
+ for bi, local, radius in collider_sites:
404
+ center = pose[t, bi, :3] + quat_rotate(pose[t, bi, 3:7], local)
405
+ zmin = min(zmin, float(center[2] - radius))
406
+ assert np.isfinite(zmin), zmin
407
+ out[t] = zmin
408
+ return out
409
+
410
+
411
+ def ground_pose_on_contact_spheres(pose, bodies, clearance=0.002):
412
+ """Shift every body in z so one contact sphere reaches ground+clearance each frame.
413
+
414
+ This is for kinematic reference playback only. It does not alter joint angles, body-relative
415
+ geometry, or MTU routing; it just removes the global floor-offset error before writing `.dnrec`.
416
+ """
417
+ pose = np.asarray(pose, dtype=np.float64).copy()
418
+ assert clearance >= 0.0, clearance
419
+ bottom = contact_visual_bottom_z(pose, bodies)
420
+ shift = float(clearance) - bottom
421
+ pose[:, :, 2] += shift[:, None]
422
+ grounded = contact_visual_bottom_z(pose, bodies)
423
+ assert np.allclose(grounded, clearance, atol=5e-7), (grounded.min(), grounded.max(), clearance)
424
+ return pose.astype(np.float32), shift.astype(np.float32)
425
+
426
+
427
+ # NOTE: the stance/swing legibility floor -- suppress a contact arrow where the foot is not really on
428
+ # the ground (a swing/airborne foot carries a ~0.5 N penalty residual + a shear fx, stance is 100s-1000s
429
+ # N) -- is applied at RENDER time now (viz/render.py CONTACT_NORMAL_MIN_N), NOT baked into the stored
430
+ # channel. The record keeps the RAW engine force so .dnrec contact_force round-trips bit-exact.
431
+
432
+
433
+ def contact_channels(data, T):
434
+ """AUTO from the eval npz: contact_force + contact_witness are (T, 3*nc). Store the RAW engine
435
+ contact per point: contact[t,ci] = [witness(3), force(3), 0]. The stance/swing legibility floor
436
+ (skip the arrow when the normal-z force < CONTACT_NORMAL_MIN_N) is a RENDER-time decision
437
+ (viz/render._draw_contact_arrow), NOT baked in here -- so the record keeps the full force and the
438
+ .dnrec contact_force round-trips bit-exact (dnrec-format.md)."""
439
+ if "contact_force" not in data or "contact_witness" not in data:
440
+ return np.zeros((T, 0), np.float32)
441
+ cf = np.asarray(data["contact_force"], np.float64)
442
+ cw = np.asarray(data["contact_witness"], np.float64)
443
+ nc = cf.shape[1] // 3
444
+ if nc == 0 or cf.shape[0] != T:
445
+ return np.zeros((T, 0), np.float32)
446
+ contact = np.zeros((T, nc, 7), np.float32)
447
+ contact[:, :, 0:3] = cw[:, : nc * 3].reshape(T, nc, 3)
448
+ contact[:, :, 3:6] = cf[:, : nc * 3].reshape(T, nc, 3)
449
+ return contact
450
+
451
+
452
+ def build_from_dnmodel(dnmodel_path, scene, q):
453
+ """Model-agnostic builder for ANY .dnmodel-backed env: load the model, pull its VISUAL geoms
454
+ (model-owned, see render_bodies_from_visual_geoms), and run forward-kinematics (fk_poses handles
455
+ free/ball/hinge/slide/compound joints) over the q-trajectory `q` (T, nq). Whether the model carries
456
+ muscles, compound joints, etc. is read straight from `jm` downstream (muscle_channels) -- this
457
+ builder never branches on env identity, only on the dnmodel path + scene label it's given."""
458
+ jm = load_dnmodel(dnmodel_path)
459
+ bodies = render_bodies_from_visual_geoms(jm) # model-owned visual geometry
460
+ q = np.asarray(q, np.float64)
461
+ pose = (fk_poses_rows(jm, q) if dnrec_vec() else np.stack([fk_poses(jm, q[t]) for t in range(len(q))])).astype(np.float32)
462
+ return pose, bodies, scene, jm, q.astype(np.float32)
463
+
464
+
465
+ def build_cartpole(q):
466
+ """Analytic 2-body: nq=2 = [cart_x (slide, world x), pole_angle (hinge about y)].
467
+ Matches CartpoleVecEnv._obs (theta from q[1]) and rl_algorithm_suite.cartpole_dnrec geometry.
468
+ Not .dnmodel-backed (no model file on disk), so it keeps its own analytic builder."""
469
+ q = np.asarray(q, np.float64)
470
+ assert q.shape[1] == 2, f"cartpole qpos must be (T, 2); got {q.shape}"
471
+ z0 = 0.6
472
+ cart_q = np.array([1.0, 0.0, 0.0, 0.0])
473
+ poses = np.zeros((len(q), 2, 7), dtype=np.float32)
474
+ for t, (x, th) in enumerate(q):
475
+ pole_q = quat_axis_angle([0.0, 1.0, 0.0], th)
476
+ poses[t, 0] = [x, 0.0, z0, *cart_q] # cart
477
+ poses[t, 1] = [x, 0.0, z0, *pole_q] # pole (rotates about the cart pivot)
478
+ bodies = [
479
+ {"name": "cart", "geoms": [{"type": "box", "size": [0.12, 0.09, 0.05],
480
+ "pos": [0, 0, 0], "quat": [1, 0, 0, 0],
481
+ "rgba": [0.25, 0.55, 0.95, 1.0]}]},
482
+ {"name": "pole", "geoms": [{"type": "capsule", "size": [0.035, 0.30],
483
+ "pos": [0, 0, 0.32], "quat": [1, 0, 0, 0],
484
+ "rgba": [0.95, 0.60, 0.20, 1.0]}]},
485
+ ]
486
+ return poses, bodies, "cartpole_rl", None, q.astype(np.float32)
487
+
488
+
489
+ # .dnmodel path + scene label per model-backed env. build_from_dnmodel is the single loader for ALL of
490
+ # these (dispatch is purely this path+scene pair) -- a new model-backed env is just a new entry here,
491
+ # never a new builder function. cartpole has no .dnmodel and keeps the analytic builder above.
492
+ DNMODEL_ENVS = {
493
+ "ant": (ROOT / "models" / "ant.dnmodel", "ant_rl"),
494
+ # the Unitree G1 (mjlab's G1, tools/export_g1.py): rigid, its visual meshes in the dnmodel
495
+ "unitree_g1": (ROOT / "models" / "unitree_g1.dnmodel", "unitree_g1_track"),
496
+ "myoleg22": (ROOT / "models" / "myoleg22_2d_g14eq.dnmodel", "myoleg22_rl"),
497
+ # myoleg26: the dnmodel is selected by MYOLEG26_DNMODEL, exactly as "fullbody" honours FULLBODY_DNMODEL
498
+ # and for the same reason -- the render must match the model that was TRAINED. Hardcoded, it built
499
+ # myoleg26_3d (nq=21, Ball hips) for an H1622v2k rollout (nq=15) and fk_poses then read a Ball quat
500
+ # off the end of q: "not enough values to unpack (expected 4, got 1)". That surfaced as the sweep
501
+ # reporting "no dnrec at v=..." for every speed, because the eval's stderr is filtered by a
502
+ # `grep -e steps=` in the sweep script.
503
+ "myoleg26": (ROOT / "models" / _MYOLEG26_DEFAULT,
504
+ "myoleg26_rl"),
505
+ "humanoid": (ROOT / "models" / "humanoid_compound.dnmodel", "humanoid_rl"),
506
+ # full-body: the dnmodel is selected by FULLBODY_DNMODEL (same env the trainer/eval use), so the render
507
+ # matches whatever model was trained (default = the hand-fused locomotion model).
508
+ "fullbody": (ROOT / "models" / os.environ.get("FULLBODY_DNMODEL",
509
+ "fullbody_contact_spinecoupled_fusedhand_lspine_girdle_osimeq.dnmodel"), "fullbody_rl"),
510
+ }
511
+
512
+
513
+ def _build_for_env(env_name, q):
514
+ """Dispatch env_name -> (pose, bodies, scene, jm, qpos) from a q-trajectory (T, nq): the path+scene
515
+ table above for any model-backed env, or the analytic cartpole builder -- no per-model branching in
516
+ the build logic itself (that lives in build_from_dnmodel, identical for every entry in DNMODEL_ENVS)."""
517
+ if env_name == "cartpole":
518
+ return build_cartpole(q)
519
+ dnmodel_path, scene = DNMODEL_ENVS[env_name]
520
+ return build_from_dnmodel(dnmodel_path, scene, q)
521
+
522
+
523
+ SUPPORTED = set(DNMODEL_ENVS) | {"cartpole"} # envs this builder can turn into a self-contained .dnrec
524
+
525
+
526
+ # The reference ghost's look (the design brief, 2026-11-01): a red-tinted, semi-transparent copy of the body overlaid on the policy
527
+ # in the same scene, not a separate panel, so the eye compares each limb in place. One value for every producer.
528
+ GHOST_RGBA = (0.92, 0.22, 0.20, 0.35)
529
+
530
+
531
+ def render_npz_to_dnrec(env_name, source, out_dnrec, *, kinematic_reference=False,
532
+ ground_contact=False, scene_name=None, ghost_ref_q=None, caption=None, ground_rgba=None,
533
+ dnmodel_path=None):
534
+ """Build ONE self-contained v2 `.dnrec` (poses + qvel + muscle + contact + embedded MODEL + full
535
+ state) from an eval rollout. `source` is either an eval-rollout `.npz` PATH or an in-memory DICT of
536
+ the same arrays (q, qd, z, lce, activation, ...), so a record path can produce the `.dnrec` DIRECTLY
537
+ with no intermediate `.npz` (dnrec-format.md P2 / GitHub #1).
538
+
539
+ `ghost_ref_q` (T,nq): optional phase-synced REFERENCE qpos trajectory. When given (dnmodel envs only),
540
+ a translucent second body-set posed at the reference is appended so the render shows the policy
541
+ (opaque) tracking the clip (ghost). Muscle/contact channels index the FIRST (policy) bodies, so they
542
+ are unaffected by the appended ghost bodies. The ghost is drawn in GHOST_RGBA (red, alpha 0.35). `caption`
543
+ (optional list[str]) is stamped on the clip's HUD (write_dnrec). `dnmodel_path` builds from that body file instead of
544
+ env_name's table entry (diffneusim.viz.write_record: states from any simulator); env_name then only labels the provenance."""
545
+ if isinstance(source, (str, pathlib.Path)):
546
+ with np.load(source) as _z:
547
+ data = {k: _z[k] for k in _z.files}
548
+ else:
549
+ data = dict(source)
550
+ dt = float(data["dt"]) if "dt" in data else 1.0 / 60.0
551
+ if dnmodel_path is None:
552
+ pose, bodies, scene, jm, qpos = _build_for_env(env_name, data["q"])
553
+ else:
554
+ pose, bodies, scene, jm, qpos = build_from_dnmodel(dnmodel_path, scene_name or "fullbody_rl", data["q"])
555
+ T, nb, _ = pose.shape
556
+ if ground_contact:
557
+ assert kinematic_reference, "ground_contact is only valid for kinematic reference playback"
558
+ pose, ground_shift = ground_pose_on_contact_spheres(pose, bodies)
559
+ else:
560
+ ground_shift = np.zeros(T, dtype=np.float32)
561
+ qd = data["qd"].astype(np.float32) if "qd" in data else np.zeros((T, 0), dtype=np.float32)
562
+ qvel = qd if qd.shape[0] == T else np.zeros((T, 0), dtype=np.float32)
563
+ if ground_contact:
564
+ # legacy Ball-hip reference layout (myoleg26's Free+Ball qpos); myoleg26_ball_q_to_qd asserts
565
+ # its own nq==21 shape contract, so this stays correctly gated without a name/dim check here.
566
+ qpos = qpos.copy()
567
+ qpos[:, 1] += ground_shift
568
+ from reference.retarget_myoleg26 import myoleg26_ball_q_to_qd
569
+ qvel = myoleg26_ball_q_to_qd(qpos, dt)
570
+ # DN_DNREC_MTU=0 skips the render geometry (see light_muscle_channels). Default 1 = unchanged.
571
+ _mtu_flag = os.environ.get("DN_DNREC_MTU", "1")
572
+ assert _mtu_flag in ("0", "1"), f"DN_DNREC_MTU={_mtu_flag!r} must be exactly '0' or '1'"
573
+ if _mtu_flag == "1":
574
+ mtu_poly, activation, lce_source = muscle_channels(jm, data, pose, kinematic_reference=kinematic_reference)
575
+ else:
576
+ assert not kinematic_reference, "a kinematic reference clip is render-only; it needs the full channel"
577
+ mtu_poly, activation, lce_source = light_muscle_channels(jm, data, T)
578
+ contact = contact_channels(data, T) # auto from npz, masked to real contact
579
+ n_model_muscles = len((jm or {}).get("muscles", []))
580
+ if n_model_muscles > 0 and _mtu_flag == "1": # anti-"muscle got dropped" guard
581
+ assert mtu_poly.shape[1] == n_model_muscles, (
582
+ f"{scene}: model declares {n_model_muscles} muscles but built {mtu_poly.shape[1]} polylines "
583
+ f"-- muscle overlay would be dropped. eval npz needs 'activation' (has {list(data)}).")
584
+ px, py = pose[:, :, 0], pose[:, :, 1]
585
+ ground_half = motion_half_extent(pose, floor=3.0, margin=2.0)
586
+ # v2 self-contained record (dnrec-format.md P2): embed the model (so the clip replays + renders
587
+ # standalone) + carry the extra sim-state channels the npz held. jm is None for cartpole (analytic,
588
+ # no .dnmodel) -> stays v1. All optional -> a rollout without these keys writes exactly as before.
589
+ _opt = lambda k: (data[k].astype(np.float32) if k in data else None) # noqa: E731
590
+ prov = {"producer": f"rl_env_render:{env_name}", "scene": scene_name or scene}
591
+ # REFERENCE GHOST overlay: append a translucent second body-set posed at the phase-synced reference
592
+ # qpos, so the render shows the policy (opaque) vs the clip it is tracking (ghost). Policy bodies stay
593
+ # first (indices 0..nb-1) so muscle via-point / contact indexing is unchanged.
594
+ if ghost_ref_q is not None and jm is not None:
595
+ import copy as _copy
596
+ assert len(ghost_ref_q) == T, (len(ghost_ref_q), T)
597
+ ref_pose = (fk_poses_rows(jm, np.asarray(ghost_ref_q, dtype=np.float64)) if dnrec_vec() else
598
+ np.stack([fk_poses(jm, np.asarray(ghost_ref_q[t], dtype=np.float64)) for t in range(T)])).astype(np.float32)
599
+ ghost_bodies = _copy.deepcopy(bodies)
600
+ for gb in ghost_bodies:
601
+ gb["name"] = "ghost_" + str(gb.get("name", ""))
602
+ for g in gb.get("geoms", []):
603
+ g["rgba"] = list(GHOST_RGBA) # red, translucent -> renderer ghosts it
604
+ pose = np.concatenate([pose, ref_pose], axis=1) # (T, 2*nb, 7)
605
+ bodies = bodies + ghost_bodies
606
+ write_dnrec(out_dnrec, pose, qvel, mtu_poly, activation, contact, bodies, dt,
607
+ scene=scene_name or scene, qpos=qpos, lce_source=lce_source, ground_half_extent=ground_half,
608
+ model=jm, provenance=prov, z=_opt("z"), tau=_opt("tau"), act=_opt("action"), reward=_opt("reward"),
609
+ caption=caption, ground_rgba=ground_rgba)
610
+ return dict(scene=scene, frames=T, bodies=nb, muscles=int(mtu_poly.shape[1]),
611
+ contacts=int(contact.shape[1] if contact.ndim > 1 else 0), dt=dt,
612
+ fps=int(round(1 / dt)), x_range=float(px.max() - px.min()), ground_half=float(ground_half),
613
+ ground_shift_max=float(np.max(np.abs(ground_shift))), lce_source=lce_source)
614
+
615
+
616
+ def main():
617
+ ap = argparse.ArgumentParser()
618
+ ap.add_argument("env", choices=sorted(SUPPORTED))
619
+ ap.add_argument("npz")
620
+ ap.add_argument("out_dnrec")
621
+ ap.add_argument("--kinematic-reference", action="store_true",
622
+ help="render a non-dynamic reference clip with baseline visual muscle activation")
623
+ ap.add_argument("--ground-contact", action="store_true",
624
+ help="for kinematic references, z-shift each frame so contact spheres sit on the ground")
625
+ ap.add_argument("--scene", default=None, help="override the .dnrec scene label")
626
+ args = ap.parse_args()
627
+ info = render_npz_to_dnrec(args.env, args.npz, args.out_dnrec,
628
+ kinematic_reference=args.kinematic_reference,
629
+ ground_contact=args.ground_contact,
630
+ scene_name=args.scene)
631
+ print(f"wrote {args.out_dnrec} {info}", flush=True)
632
+
633
+
634
+ if __name__ == "__main__":
635
+ main()