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.
- diffneusim/__init__.py +1 -0
- diffneusim/_cache.py +42 -0
- diffneusim/_paths.py +5 -0
- diffneusim/bindings/rew14_ext.cu +115 -0
- diffneusim/bindings/soft14_capi.cpp +443 -0
- diffneusim/bindings/soft14_engine_ext.cu +596 -0
- diffneusim/bindings/soft_capi.cpp +782 -0
- diffneusim/bindings/soft_engine_ext.cu +495 -0
- diffneusim/core/cpu_engine/build.sh +40 -0
- diffneusim/core/cpu_engine/fiber/cuda_runtime.h +445 -0
- diffneusim/core/cpu_engine/x14_cpu.cpp +283 -0
- diffneusim/core/diff/dual.h +126 -0
- diffneusim/core/include/diffneusim/macros.h +35 -0
- diffneusim/core/kin/kinematic_tree.h +273 -0
- diffneusim/core/math/so3.h +182 -0
- diffneusim/core/soft/adj/out_adj.h +102 -0
- diffneusim/core/soft/adj/rnea_adj.h +425 -0
- diffneusim/core/soft/adj/rows_adj.h +439 -0
- diffneusim/core/soft/adj/rows_functor.h +89 -0
- diffneusim/core/soft/adj/rows_lanes.h +443 -0
- diffneusim/core/soft/adj/shell_adj.h +243 -0
- diffneusim/core/soft/adj/tree_adj.h +356 -0
- diffneusim/core/soft/collide.h +183 -0
- diffneusim/core/soft/gpu/adj14.cuh +233 -0
- diffneusim/core/soft/gpu/adj14_mus.cuh +98 -0
- diffneusim/core/soft/gpu/adj_shell.cuh +50 -0
- diffneusim/core/soft/gpu/adj_tab.cuh +49 -0
- diffneusim/core/soft/gpu/body14.cuh +47 -0
- diffneusim/core/soft/gpu/chol_rn.cuh +458 -0
- diffneusim/core/soft/gpu/chol_small.cuh +123 -0
- diffneusim/core/soft/gpu/chol_split.cuh +193 -0
- diffneusim/core/soft/gpu/engine_launch.cuh +263 -0
- diffneusim/core/soft/gpu/fk_rn.cuh +109 -0
- diffneusim/core/soft/gpu/generated/body_019e20820f86_mmfloor.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_62f77a4bb16b_mmfloor.cuh +52 -0
- diffneusim/core/soft/gpu/generated/body_77dbb7213f26_mmfloor_rampsb3l_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rampsb3l_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rhlsd05_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rhlsdef_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rhlsmjd_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_a1e8b196b2cd_mmfloor_rampsb3l_n6t12.cuh +52 -0
- diffneusim/core/soft/gpu/generated/body_a944653edd64_mmfloor.cuh +25 -0
- diffneusim/core/soft/gpu/generated/body_a944653edd64_mmfloor_rampsb3l_n6t12.cuh +25 -0
- diffneusim/core/soft/gpu/generated/g1_soft_5db44fd45286.cuh +74 -0
- diffneusim/core/soft/gpu/generated/split_62f77a4bb16b_mmfloor.cuh +18 -0
- diffneusim/core/soft/gpu/generated/split_a1e8b196b2cd_mmfloor_rampsb3l_n6t12.cuh +18 -0
- diffneusim/core/soft/gpu/generated/x14_soft_019e20820f86_mmfloor.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_62f77a4bb16b_mmfloor.cuh +129 -0
- diffneusim/core/soft/gpu/generated/x14_soft_77dbb7213f26_mmfloor_rampsb3l_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rampsb3l_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rhlsd05_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rhlsdef_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rhlsmjd_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_a1e8b196b2cd_mmfloor_rampsb3l_n6t12.cuh +129 -0
- diffneusim/core/soft/gpu/generated/x14_soft_a944653edd64_mmfloor.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_a944653edd64_mmfloor_rampsb3l_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/k_mus.cuh +1038 -0
- diffneusim/core/soft/gpu/k_mus_host.cuh +377 -0
- diffneusim/core/soft/gpu/k_pre.cuh +52 -0
- diffneusim/core/soft/gpu/kernel_p.cuh +490 -0
- diffneusim/core/soft/gpu/kp14.cuh +465 -0
- diffneusim/core/soft/gpu/l2v2.cuh +367 -0
- diffneusim/core/soft/gpu/l2x14.cuh +319 -0
- diffneusim/core/soft/gpu/l3.cuh +1483 -0
- diffneusim/core/soft/gpu/model_view.cuh +48 -0
- diffneusim/core/soft/gpu/mus_case_fits.h +15 -0
- diffneusim/core/soft/gpu/mus_classes.h +182 -0
- diffneusim/core/soft/gpu/mus_row_cf.h +44 -0
- diffneusim/core/soft/gpu/rew14.cuh +177 -0
- diffneusim/core/soft/gpu/rows_ctab.cuh +44 -0
- diffneusim/core/soft/gpu/tree_m.cuh +247 -0
- diffneusim/core/soft/gpu/x14_engine_kernels.cuh +260 -0
- diffneusim/core/soft/gpu/x14_rowcf.h +14 -0
- diffneusim/core/soft/hand.h +124 -0
- diffneusim/core/soft/impedance.h +115 -0
- diffneusim/core/soft/jvp.h +202 -0
- diffneusim/core/soft/kin.h +250 -0
- diffneusim/core/soft/muscle.h +1208 -0
- diffneusim/core/soft/newton.h +371 -0
- diffneusim/core/soft/rows.h +176 -0
- diffneusim/core/soft/step.h +188 -0
- diffneusim/core/soft/tape.h +313 -0
- diffneusim/core/soft/x14/collide14.h +69 -0
- diffneusim/core/soft/x14/jvp14.h +182 -0
- diffneusim/core/soft/x14/law14.h +453 -0
- diffneusim/core/soft/x14adj/collide14_adj.h +134 -0
- diffneusim/core/soft/x14adj/passive14_adj.h +162 -0
- diffneusim/core/soft/x14adj/reward14.h +484 -0
- diffneusim/core/soft/x14adj/rows14_adj.h +400 -0
- diffneusim/core/soft/x14adj/scan14.h +349 -0
- diffneusim/core/soft/x14adj/shell14_adj.h +122 -0
- diffneusim/core/soft/x14adj/sweep14.h +255 -0
- diffneusim/core/soft/x14adj/tree14_adj.h +500 -0
- diffneusim/core/soft/x14adj/x14adj_common.h +96 -0
- diffneusim/data/mirror/H1622v2k_geyer_hfdeq.npz +0 -0
- diffneusim/data/mirror/H1622v2k_hfd.npz +0 -0
- diffneusim/data/mirror/H1622v2k_millard_hfdeq.npz +0 -0
- diffneusim/data/mirror/fullbody_contact.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_p2str.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_p2str_rigid.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_calf2_pe.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_axfix.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_axfixlegs01.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_jd01.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_jd01legs.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_jd01lumbar.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_lumbfix.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_lumbfixlegs01.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1a.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n2.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_rom23.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_hinge.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1a.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n2.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_rom23.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_lspine_girdle_osimeq.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_lspine_girdle_millard.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_lspine_girdle_osimeq.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_compound_g14eq.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30_hip30.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30_hip30_luispe.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30_hip30_trunk0701.npz +0 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_axfix.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_axfixlegs01.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_jd01.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_jd01legs.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_jd01lumbar.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_lumbfix.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_lumbfixlegs01.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_n1.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_n1a.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_n2.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_rom23.json +91 -0
- diffneusim/data/reference/musclemimic/myofullbody_mimic_sites.json +261 -0
- diffneusim/data/reference/pose3/pose3_scone.json +305 -0
- diffneusim/data/reference/pose3/pose3_scone.txt +3 -0
- diffneusim/data/reference/pose3/pose3_scone_gait.npz +0 -0
- diffneusim/data/reference/pose3/pose3_scone_mirror.npz +0 -0
- diffneusim/data/reference/pose3/pose3_scone_stand.npz +0 -0
- diffneusim/data/reference/x016run/MD5SUMS +241 -0
- diffneusim/data/reference/x016run/x016run_states.txt +240 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r3.npz +0 -0
- diffneusim/data/state_prior/lumbar_poly_fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc.npz +0 -0
- diffneusim/engine/__init__.py +0 -0
- diffneusim/engine/build_tag.py +52 -0
- diffneusim/engine/case_tables.py +46 -0
- diffneusim/engine/d16_body.py +80 -0
- diffneusim/engine/engine14.py +367 -0
- diffneusim/engine/gen_split.py +159 -0
- diffneusim/engine/hand_format.py +69 -0
- diffneusim/engine/live14.py +149 -0
- diffneusim/engine/phase_b_tree.py +137 -0
- diffneusim/engine/soft14.py +130 -0
- diffneusim/engine/soft_capi.py +373 -0
- diffneusim/engine/soft_engine.py +165 -0
- diffneusim/engine/step14.py +132 -0
- diffneusim/engine/tape_format.py +89 -0
- diffneusim/engine/x14cpu.py +163 -0
- diffneusim/env/__init__.py +0 -0
- diffneusim/env/absent.py +20 -0
- diffneusim/env/cpu14.py +105 -0
- diffneusim/env/e0loop14.py +224 -0
- diffneusim/env/env14.py +568 -0
- diffneusim/env/kin_contact14.py +193 -0
- diffneusim/env/mimic_sites_x14.json +366 -0
- diffneusim/env/old_count.py +78 -0
- diffneusim/env/rew14.py +114 -0
- diffneusim/env/rew14_hook.py +105 -0
- diffneusim/g1/__init__.py +1 -0
- diffneusim/g1/arm_a2.py +165 -0
- diffneusim/g1/arm_a3.py +576 -0
- diffneusim/g1/read_a3.py +79 -0
- diffneusim/g1/rg1_read.py +89 -0
- diffneusim/model/__init__.py +66 -0
- diffneusim/model/case.py +17 -0
- diffneusim/model/dnmodel.py +79 -0
- diffneusim/model/fuse_fixed.py +281 -0
- diffneusim/model/monitor.py +834 -0
- diffneusim/models/BODIES.toml +48 -0
- diffneusim/models/MANIFEST.toml +979 -0
- diffneusim/models/cases/G290/case.bin +0 -0
- diffneusim/models/cases/G290/case.json +1 -0
- diffneusim/models/cases/G356-SRC/case.bin +0 -0
- diffneusim/models/cases/G356-SRC/case.json +1 -0
- diffneusim/models/cases/G416/case.bin +0 -0
- diffneusim/models/cases/G416/case.json +1 -0
- diffneusim/models/cases/M290C-SRC/case.bin +0 -0
- diffneusim/models/cases/M290C-SRC/case.json +1 -0
- diffneusim/models/cases/M290R-SRC/case.bin +0 -0
- diffneusim/models/cases/M290R-SRC/case.json +1 -0
- diffneusim/models/cases/M356C-SRC/case.bin +0 -0
- diffneusim/models/cases/M356C-SRC/case.json +1 -0
- diffneusim/models/cases/M356R-SRC/case.bin +0 -0
- diffneusim/models/cases/M356R-SRC/case.json +1 -0
- diffneusim/models/cases/M416C-SRC/case.bin +0 -0
- diffneusim/models/cases/M416C-SRC/case.json +1 -0
- diffneusim/models/derived/d16_expanded_62f77a4bb16b1e67_mmfloor.xml +673 -0
- diffneusim/models/derived/d16_expanded_a1e8b196b2cd7b3c_mmfloor.xml +673 -0
- diffneusim/models/derived/d16_soft_law_019e20820f8633b9_mmfloor.json +7844 -0
- diffneusim/models/derived/d16_soft_law_62f77a4bb16b1e67_mmfloor.json +16855 -0
- diffneusim/models/derived/d16_soft_law_77dbb7213f26e821_mmfloor_rampsb3l_n6t12.json +7883 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rampsb3l_n6t12.json +7883 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rhlsd05_n6t12.json +7868 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rhlsdef_n6t12.json +7868 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rhlsmjd_n6t12.json +7868 -0
- diffneusim/models/derived/d16_soft_law_a1e8b196b2cd7b3c_mmfloor_rampsb3l_n6t12.json +16894 -0
- diffneusim/models/derived/d16_soft_law_a944653edd642082_mmfloor.json +12655 -0
- diffneusim/models/derived/d16_soft_law_a944653edd642082_mmfloor_rampsb3l_n6t12.json +12700 -0
- diffneusim/models/derived/unitree_g1_soft_law.json +15580 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.dnmodel +28913 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid.dnmodel +29202 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_axfixlegs01.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.dnmodel +46970 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.dnmodel +38570 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid.dnmodel +38923 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1_qk.txt +1 -0
- diffneusim/models/fullbody_meshes/1mc.stl +0 -0
- diffneusim/models/fullbody_meshes/2distph.stl +0 -0
- diffneusim/models/fullbody_meshes/2mc.stl +0 -0
- diffneusim/models/fullbody_meshes/2midph.stl +0 -0
- diffneusim/models/fullbody_meshes/2proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/3distph.stl +0 -0
- diffneusim/models/fullbody_meshes/3mc.stl +0 -0
- diffneusim/models/fullbody_meshes/3midph.stl +0 -0
- diffneusim/models/fullbody_meshes/3proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/4distph.stl +0 -0
- diffneusim/models/fullbody_meshes/4mc.stl +0 -0
- diffneusim/models/fullbody_meshes/4midph.stl +0 -0
- diffneusim/models/fullbody_meshes/4proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/5distph.stl +0 -0
- diffneusim/models/fullbody_meshes/5mc.stl +0 -0
- diffneusim/models/fullbody_meshes/5midph.stl +0 -0
- diffneusim/models/fullbody_meshes/5proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/NOTICE +2 -0
- diffneusim/models/fullbody_meshes/capitate.stl +0 -0
- diffneusim/models/fullbody_meshes/clavicle.stl +0 -0
- diffneusim/models/fullbody_meshes/hamate.stl +0 -0
- diffneusim/models/fullbody_meshes/hat_cervical.stl +0 -0
- diffneusim/models/fullbody_meshes/hat_jaw.stl +0 -0
- diffneusim/models/fullbody_meshes/hat_skull.stl +0 -0
- diffneusim/models/fullbody_meshes/humerus.stl +0 -0
- diffneusim/models/fullbody_meshes/l_bofoot.stl +0 -0
- diffneusim/models/fullbody_meshes/l_femur.stl +0 -0
- diffneusim/models/fullbody_meshes/l_fibula.stl +0 -0
- diffneusim/models/fullbody_meshes/l_foot.stl +0 -0
- diffneusim/models/fullbody_meshes/l_patella.stl +0 -0
- diffneusim/models/fullbody_meshes/l_pelvis.stl +0 -0
- diffneusim/models/fullbody_meshes/l_talus.stl +0 -0
- diffneusim/models/fullbody_meshes/l_tibia.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar1.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar2.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar3.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar4.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar5.stl +0 -0
- diffneusim/models/fullbody_meshes/lunate.stl +0 -0
- diffneusim/models/fullbody_meshes/pisiform.stl +0 -0
- diffneusim/models/fullbody_meshes/r_bofoot.stl +0 -0
- diffneusim/models/fullbody_meshes/r_femur.stl +0 -0
- diffneusim/models/fullbody_meshes/r_fibula.stl +0 -0
- diffneusim/models/fullbody_meshes/r_foot.stl +0 -0
- diffneusim/models/fullbody_meshes/r_patella.stl +0 -0
- diffneusim/models/fullbody_meshes/r_pelvis.stl +0 -0
- diffneusim/models/fullbody_meshes/r_talus.stl +0 -0
- diffneusim/models/fullbody_meshes/r_tibia.stl +0 -0
- diffneusim/models/fullbody_meshes/radius.stl +0 -0
- diffneusim/models/fullbody_meshes/sacrum.stl +0 -0
- diffneusim/models/fullbody_meshes/scaphoid.stl +0 -0
- diffneusim/models/fullbody_meshes/scapula.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic10_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic11_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic12_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic1_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic2_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic3_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic4_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic5_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic6_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic7_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic8_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic9_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thorax.stl +0 -0
- diffneusim/models/fullbody_meshes/thumbdist.stl +0 -0
- diffneusim/models/fullbody_meshes/thumbprox.stl +0 -0
- diffneusim/models/fullbody_meshes/trapezium.stl +0 -0
- diffneusim/models/fullbody_meshes/trapezoid.stl +0 -0
- diffneusim/models/fullbody_meshes/triquetrum.stl +0 -0
- diffneusim/models/fullbody_meshes/ulna.stl +0 -0
- diffneusim/models/source/myo_fullbody/UPSTREAM.md +91 -0
- diffneusim/models/source/myoleg/UPSTREAM.md +52 -0
- diffneusim/models/source/unitree_g1/LICENSE.mjlab +202 -0
- diffneusim/models/source/unitree_g1/UPSTREAM.md +38 -0
- diffneusim/models/source/unitree_g1/assets/head_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_ankle_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_ankle_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_elbow_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_hip_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_hip_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_hip_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_knee_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_rubber_hand.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_shoulder_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_shoulder_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_shoulder_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_wrist_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_wrist_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_wrist_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/logo_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/pelvis.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/pelvis_contour_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_ankle_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_ankle_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_elbow_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_hip_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_hip_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_hip_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_knee_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_rubber_hand.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_shoulder_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_shoulder_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_shoulder_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_wrist_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_wrist_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_wrist_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/torso_link_rev_1_0.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/waist_roll_link_rev_1_0.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/waist_yaw_link_rev_1_0.STL +0 -0
- diffneusim/models/source/unitree_g1/dump_mjlab_reference.py +30 -0
- diffneusim/models/source/unitree_g1/g1.xml +308 -0
- diffneusim/models/source/unitree_g1/g1_constants.py +298 -0
- diffneusim/models/source/unitree_g1/mjlab_compiled_reference.json +857 -0
- diffneusim/models/unitree_g1.dnmodel +4393 -0
- diffneusim/models/unitree_g1_selfcol.dnmodel +20824 -0
- diffneusim/rl/__init__.py +2 -0
- diffneusim/rl/dynsyn_layer.py +146 -0
- diffneusim/rl/footstep_plan.py +337 -0
- diffneusim/rl/g1_bm_env.py +572 -0
- diffneusim/rl/g1_bm_eval.py +168 -0
- diffneusim/rl/g1_bm_fused.py +275 -0
- diffneusim/rl/g1_bm_ppo.py +622 -0
- diffneusim/rl/g1_bm_sapo.py +551 -0
- diffneusim/rl/g1_ppo.py +395 -0
- diffneusim/rl/g1_sapo_soft.py +240 -0
- diffneusim/rl/g1_soft_env.py +452 -0
- diffneusim/rl/g1_soft_grad.py +145 -0
- diffneusim/rl/geyer_curves_torch.py +108 -0
- diffneusim/rl/gpu_fullbody_vec_env.py +1241 -0
- diffneusim/rl/imitation.py +2027 -0
- diffneusim/rl/imitation_reward_v2.py +248 -0
- diffneusim/rl/imitation_reward_v3.py +349 -0
- diffneusim/rl/latent_task.py +175 -0
- diffneusim/rl/llc_reward.py +316 -0
- diffneusim/rl/millard_curves_torch.py +154 -0
- diffneusim/rl/mirror_symmetry.py +212 -0
- diffneusim/rl/model_path.py +35 -0
- diffneusim/rl/mvae_recon.py +123 -0
- diffneusim/rl/nets_shac.py +599 -0
- diffneusim/rl/reset_pool.py +154 -0
- diffneusim/rl/sapo_capture.py +873 -0
- diffneusim/rl/sapo_vec.py +1051 -0
- diffneusim/rl/shac_vec.py +346 -0
- diffneusim/rl/state_prior.py +151 -0
- diffneusim/rl/step_library.py +105 -0
- diffneusim/rl/task_walk_env.py +1793 -0
- diffneusim/rl/task_walk_reward.py +3300 -0
- diffneusim/run.py +23 -0
- diffneusim/run_env.py +46 -0
- diffneusim/tasks/__init__.py +147 -0
- diffneusim/tasks/legacy_names.py +63 -0
- diffneusim/tasks/paths.py +79 -0
- diffneusim/tasks/settings.py +202 -0
- diffneusim/third_party/instantmimic_947430ee/LICENSE +202 -0
- diffneusim/third_party/instantmimic_947430ee/NOTICE +19 -0
- diffneusim/third_party/instantmimic_947430ee/README.md +31 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/envs/unitree_g1/tasks/beyondmimic_tracking/benchmark_protocol.py +106 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/envs/unitree_g1/tasks/beyondmimic_tracking/metrics.py +214 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/envs/unitree_g1/tasks/beyondmimic_tracking/reference.py +513 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/motion/quaternion.py +193 -0
- diffneusim/train/__init__.py +0 -0
- diffneusim/train/eval_ckpt.py +239 -0
- diffneusim/train/eval_mimic.py +133 -0
- diffneusim/train/gait_report.py +203 -0
- diffneusim/train/gcot_chain.py +51 -0
- diffneusim/train/levers.py +135 -0
- diffneusim/train/masked_reset.py +314 -0
- diffneusim/train/rl_algorithm_suite.py +917 -0
- diffneusim/train/train14.py +240 -0
- diffneusim/train/train_tw14.py +674 -0
- diffneusim/viz/__init__.py +5 -0
- diffneusim/viz/__main__.py +41 -0
- diffneusim/viz/camera.py +115 -0
- diffneusim/viz/dnrec.py +118 -0
- diffneusim/viz/dnrec_io.py +686 -0
- diffneusim/viz/hud.py +565 -0
- diffneusim/viz/meshes.py +458 -0
- diffneusim/viz/play.py +237 -0
- diffneusim/viz/record.py +74 -0
- diffneusim/viz/render.py +1402 -0
- diffneusim/viz/renderer.py +268 -0
- diffneusim/viz/rl_env_render.py +635 -0
- diffneusim/viz/snapshot.py +54 -0
- diffneusim/viz/strobe.py +124 -0
- diffneusim/viz/to_mp4.py +58 -0
- diffneusim/viz/ui.py +481 -0
- diffneusim/viz/viewer.py +2086 -0
- diffneusim-1.0.0.dist-info/METADATA +226 -0
- diffneusim-1.0.0.dist-info/RECORD +682 -0
- diffneusim-1.0.0.dist-info/WHEEL +5 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSE +201 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/BSD-3-Clause-NC-ARMS-hand-wrist-4.3.txt +20 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/BSD-3-Clause-NC-MoBL-ARMS.txt +25 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/CC-BY-3.0-OpenSim-geometry.txt +25 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Christophy2012-lumbarspine.txt +10 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Lai2017-model-high-flex.txt +10 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Lee2015-hand_muscle.txt +11 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Rajagopal2016-full_body.txt +11 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Uhlrich2022-fbmodpassivecal.txt +10 -0
- diffneusim-1.0.0.dist-info/licenses/NOTICE +274 -0
- diffneusim-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1241 @@
|
|
|
1
|
+
"""Batched GPU full-body (myoFullBody, nq=115/nv=114/nm=416) vector env for DiffRL-style SHAC.
|
|
2
|
+
|
|
3
|
+
Mirrors GpuMyoLegVecEnv but for the 3D full-body model: the base is a FREE joint
|
|
4
|
+
(qpos[0:3]=x,y,z, qpos[3:7]=quaternion w,x,y,z) instead of myoLeg's planar (tx,ty,tilt). So
|
|
5
|
+
forward progress = qvel[0] (world x linear velocity), height = qpos[2], upright = the world-z
|
|
6
|
+
component of the torso up-axis from the root quaternion.
|
|
7
|
+
|
|
8
|
+
Requires the armature-regularized fullbody.dnmodel (else the explicit ABA diverges, see
|
|
9
|
+
fullbody-armature-stability-fix) PLUS feet contacts (the base dnmodel ships ncontact=0, so this
|
|
10
|
+
env writes a contact overlay at init using the FK-validated foot spheres). Physics runs through
|
|
11
|
+
the production f_ext GPU muscle step (mtu_step_gpu), validated finite fwd+bwd.
|
|
12
|
+
|
|
13
|
+
FIRST CUT: simple qk-drop reset (no elaborate settle yet) + DiffRL-style reward (forward + upright
|
|
14
|
+
+ alive - effort). TODO: stance settle, reward shaping, eval pose. Validate trainability (finite
|
|
15
|
+
SHAC + reward trend), not a finished walk.
|
|
16
|
+
|
|
17
|
+
DeepMimic imitation (Peng et al. 2018) is opt-in via DN_IMITATION=1 (default OFF -> the reward
|
|
18
|
+
above is byte-for-byte unchanged). When on, the env composes a shared Morphology + stateless
|
|
19
|
+
ImitationTask (diffneusim.rl.imitation), owning the mutable phase/_prev_phase/_h_prev/_prev_x/
|
|
20
|
+
eval_mode state + the RNG; the same pattern as GpuMyoLeg26VecEnv but for the plain z-up full body.
|
|
21
|
+
"""
|
|
22
|
+
import os
|
|
23
|
+
import pathlib
|
|
24
|
+
|
|
25
|
+
import torch
|
|
26
|
+
|
|
27
|
+
from diffneusim.env.absent import Absent
|
|
28
|
+
from diffneusim.model import model_dims, read_model
|
|
29
|
+
from diffneusim.model.monitor import _quat_mul, _quat_rotate, _quat_rotate_batched
|
|
30
|
+
from diffneusim.rl.imitation import Morphology, ImitationTask
|
|
31
|
+
from diffneusim.rl.task_walk_env import TaskWalkEnvMixin, TaskWalkSpec
|
|
32
|
+
|
|
33
|
+
from diffneusim.rl.model_path import resolve_model
|
|
34
|
+
|
|
35
|
+
from diffneusim._paths import ROOT as ROOT # (3a) the repo root
|
|
36
|
+
from diffneusim.viz.dnrec_io import muscle_l_opts
|
|
37
|
+
|
|
38
|
+
_bridge = Absent("gpu_bridge") # the earlier engine's contact force (diffneusim/env/absent.py)
|
|
39
|
+
MODEL = resolve_model(os.environ.get("FULLBODY_DNMODEL", "fullbody_contact_spinecoupled_lspine_girdle_osimeq.dnmodel")) # canonical coupled full-hand artifact (lumbar spine + shoulder girdles as their sources couple them, source-equivalent muscles; 84.3 kg); FULLBODY_DNMODEL overrides (e.g. the armless lane)
|
|
40
|
+
|
|
41
|
+
# Free-base world-frame q layout (plain z-up; body 1 = free base identity, body 2 = pelvis fixed offset):
|
|
42
|
+
# q[0]=world x (forward), q[1]=world y (lateral), q[2]=world z (height); q[3:7]=free-joint quat (w,x,y,z).
|
|
43
|
+
# Unlike myoLeg26 (pelvis quat_tree = +90deg-about-x, y-up->z-up), the fullbody root is plain world z-up.
|
|
44
|
+
ROOT_FWD, ROOT_LAT, ROOT_HEIGHT = 0, 1, 2
|
|
45
|
+
|
|
46
|
+
# (Legacy RSI-init guards DN_RSI_VEL_SCALE / _PHASE_EXCLUDE removed -- superseded by the engine
|
|
47
|
+
# LDL^T pivot guard in core/dyn/ldlt.h, which is the real contact-fold-NaN fix; see issue #18.)
|
|
48
|
+
|
|
49
|
+
# FK-validated foot contact spheres (calcn/toes, bodies 137/138/151/152) -- see
|
|
50
|
+
# tools/fullbody_contact_render.py FOOT_CONTACT_SPHERES (corrected centers).
|
|
51
|
+
FOOT_CONTACT_SPHERES = (
|
|
52
|
+
{"type": "sphere", "body": 137, "center": [0.010, 0.0, 0.000], "radius": 0.020},
|
|
53
|
+
{"type": "sphere", "body": 137, "center": [0.175, 0.0, -0.030], "radius": 0.020},
|
|
54
|
+
{"type": "sphere", "body": 137, "center": [0.140, 0.0, 0.030], "radius": 0.020},
|
|
55
|
+
{"type": "sphere", "body": 138, "center": [0.055460, 0.0, -0.031080], "radius": 0.0175},
|
|
56
|
+
{"type": "sphere", "body": 138, "center": [0.016200, 0.0, 0.036920], "radius": 0.0175},
|
|
57
|
+
{"type": "sphere", "body": 151, "center": [0.010, 0.0, 0.000], "radius": 0.020},
|
|
58
|
+
{"type": "sphere", "body": 151, "center": [0.175, 0.0, 0.030], "radius": 0.020},
|
|
59
|
+
{"type": "sphere", "body": 151, "center": [0.140, 0.0, -0.030], "radius": 0.020},
|
|
60
|
+
{"type": "sphere", "body": 152, "center": [0.055460, 0.0, 0.031080], "radius": 0.0175},
|
|
61
|
+
{"type": "sphere", "body": 152, "center": [0.016200, 0.0, -0.036920], "radius": 0.0175},
|
|
62
|
+
)
|
|
63
|
+
CONTACT_PARAMS = [1e5, 2e-3, 1000.0, 0.8, 1e-2, 1.0] # [k, beta, d, mu, v_s, eps_n] (myoLeg-proven)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _renderable_contact_geom(geom):
|
|
67
|
+
out = dict(geom)
|
|
68
|
+
right = int(out["body"]) in (137, 138)
|
|
69
|
+
out["render_group"] = 1
|
|
70
|
+
out["render_rgba"] = [1.0, 0.25, 0.12, 0.78] if right else [0.10, 0.55, 1.0, 0.78]
|
|
71
|
+
return out
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def yaw_free_obs_quat(q_root):
|
|
75
|
+
"""The root orientation with the heading divided out (DnModelMonitor.yaw_free_quat), in the w >= 0 HEMISPHERE: (4, n).
|
|
76
|
+
|
|
77
|
+
yaw_free_quat takes the yaw from atan2, which wraps at +-180 deg, while the simulator's root quaternion is continuous; past
|
|
78
|
+
180 deg of accumulated turning conj(yaw(q)) (x) q therefore comes out as MINUS the tilt quaternion. Same rotation, opposite
|
|
79
|
+
sign: the policy saw w ~ +1 for every heading it was trained near and got w ~ -1 once a body had turned half a circle. Every
|
|
80
|
+
steering fall through S1e came as the world heading passed ~180-210 deg (alternating turns, which stay within +-90, survived
|
|
81
|
+
20 s; docs-dev/deeploco/20261020_2000_s1_heading RESULT 8). The tilt of a walking body is far from 180 deg, so w is far from 0
|
|
82
|
+
and the flip is never ambiguous. The mirror's root map (w, -x, y, -z) keeps w, so it still commutes exactly."""
|
|
83
|
+
from diffneusim.model.monitor import DnModelMonitor as _M
|
|
84
|
+
yf = _M.yaw_free_quat(q_root)
|
|
85
|
+
return yf * torch.where(yf[0:1] < 0, -torch.ones_like(yf[0:1]), torch.ones_like(yf[0:1]))
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class _FibresPending(Absent):
|
|
89
|
+
"""The env's fibre handle until env14 installs its own: a construction reset that keeps the seed fibres (env._fibres_pending), since
|
|
90
|
+
the earlier engine's fibre solve is not part of DiffNeuSim; env14.install_equil14 equilibrates them. Anything else is Absent."""
|
|
91
|
+
|
|
92
|
+
def __init__(self, env):
|
|
93
|
+
super().__init__("mtu_gpu")
|
|
94
|
+
self._env = env
|
|
95
|
+
|
|
96
|
+
def equilibrate_fibers(self, q0, lce0, a0, dt, model_path=None, qd=None, iters=None):
|
|
97
|
+
self._env._fibres_pending = True
|
|
98
|
+
return lce0
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class GpuFullBodyVecEnv(TaskWalkEnvMixin):
|
|
102
|
+
name = "fullbody_gpu_vec"
|
|
103
|
+
|
|
104
|
+
def __init__(self, num_envs=64, device="cuda", episode_length=300, stochastic_init=True,
|
|
105
|
+
seed=0, vx_w=1.0, up_w=0.2, alive_w=0.5, ctrl_cost=0.001,
|
|
106
|
+
substeps=20, control_hz=30.0, drop=0.072, a_max=1.0, work_dir=None):
|
|
107
|
+
# a_max: activation ceiling for the [-1,1]->[0,A_MAX] excitation map. Default 1.0 = NO cap
|
|
108
|
+
# (myoLeg parity). The old a_max=0.3 cap was a band-aid: at dt=1/600 high activation NaN'd the
|
|
109
|
+
# rollout, but the ROOT CAUSE was 10 arm joints that missed the armature floor (near-massless
|
|
110
|
+
# 0.0001 -> a strong arm muscle makes the explicit position-coupling stiffness k/I huge, so the
|
|
111
|
+
# semi-implicit step diverges; myoLeg is leg-only so it never had these). Fixed in the model by
|
|
112
|
+
# tools/fix_fullbody_armature.py (arm armature -> 0.01), verified dt=1/600 AMAX=1.0-stable, so
|
|
113
|
+
# the cap is gone with no throughput loss (no dt drop).
|
|
114
|
+
self.A_MAX = a_max
|
|
115
|
+
# Full-body physics (f32 dynamics, ABA backend, imex_stick contact) is DECLARED in the contact
|
|
116
|
+
# -overlay .dnmodel (built below from the armature-baked full-body base, which carries precision
|
|
117
|
+
# /dynamics_backend/fiber_precision/contact_mode) -- NOT env vars. sim.step/activate carry the
|
|
118
|
+
# overlay path, so its ext is built + cached keyed by it (per-model, no global state).
|
|
119
|
+
# (3a) the compiled old engine is not shipped: the construction reset keeps its seed fibres, marked pending, and env14's
|
|
120
|
+
# install_equil14 equilibrates every world on Engine14 at the same (q, a) from the same seed (no RNG draw). The paper's runs
|
|
121
|
+
# discarded the old engine's construction result the same way (env14 redid it; Millard cases).
|
|
122
|
+
self._myoleg_gpu = _FibresPending(self)
|
|
123
|
+
|
|
124
|
+
del work_dir # retained for API compat; the contact model is now a committed static artifact
|
|
125
|
+
# Full-body contact model = the committed static artifact models/fullbody_contact.dnmodel (the
|
|
126
|
+
# armature-baked base + the foot-contact overlay). It declares f32 / ABA / imex_stick, so it
|
|
127
|
+
# loads ENV-FREE through the public engine -- no runtime overlay build, no global-state mutation.
|
|
128
|
+
# sim.step/activate carry this path, so its ext is built + cached keyed by it (per-model).
|
|
129
|
+
assert MODEL.exists(), f"missing {MODEL}"
|
|
130
|
+
self.model = str(MODEL)
|
|
131
|
+
self.sim = Absent("sim", path=self.model) # env14 installs the engine (diffneusim/env/absent.py)
|
|
132
|
+
self._activation = self.sim.activate
|
|
133
|
+
self.device = torch.device(device)
|
|
134
|
+
self.num_envs = num_envs
|
|
135
|
+
_d = model_dims(read_model(self.model))
|
|
136
|
+
self.nq, self.nv, self.nm, self.ncon = _d[0], _d[1], _d[2], _d[4]
|
|
137
|
+
# nq=115: Walker-knee secondaries pinned to a 1-DOF hinge (keyframe-seated patella keeps the quad
|
|
138
|
+
# moment arm). See docs/training/campaigns/fullbody/knee-simplification.md + tools/pin_fullbody_knee.py.
|
|
139
|
+
# default nq=115 (Walker-knee pinned); a FULLBODY_DNMODEL override (e.g. spine-pinned de-risk variant)
|
|
140
|
+
# relaxes to the structural invariant: 416 muscles + free-base (nq-nv==1). Keeps the gross-error guard.
|
|
141
|
+
# nq-nv counts the quaternion coords: +1 free base, +1 per native Ball hip (armless_ball). Guard nm
|
|
142
|
+
# (gross-error) + this structural count. 416 full-hand / 356 fused-hand / 290 armless (welded arms).
|
|
143
|
+
_nball = sum(1 for b in read_model(self.model)["bodies"] if b.get("joint") == "ball")
|
|
144
|
+
assert self.nm in (416, 356, 290) and self.nq - self.nv == 1 + _nball, (self.nq, self.nv, self.nm, _nball)
|
|
145
|
+
assert self.ncon == len(FOOT_CONTACT_SPHERES), (self.ncon,)
|
|
146
|
+
# coupled ("mimic") spine variant: dep coords removed (nq=100 vs base 115). Detect via a body carrying
|
|
147
|
+
# a "coupled" section (the mimic-joint marker) -- NOT the top-level "muscle_coupling" key, which is the
|
|
148
|
+
# generic moving-via ("gen_tau_moving_via") config present in EVERY full-body muscle model. Used below so
|
|
149
|
+
# the nq-dependent artifacts (keyframe QK, imitation reference) auto-match the loaded model's layout.
|
|
150
|
+
self._is_coupled = any("coupled" in b for b in read_model(self.model)["bodies"])
|
|
151
|
+
|
|
152
|
+
self.SUBSTEPS = substeps
|
|
153
|
+
self.control_hz = control_hz
|
|
154
|
+
self.dt = 1.0 / (control_hz * substeps)
|
|
155
|
+
self.episode_length = episode_length
|
|
156
|
+
self.stochastic_init = stochastic_init
|
|
157
|
+
self.num_actions = self.nm
|
|
158
|
+
# --- DynSyn (Dynamical Synergies, arXiv:2407.11472), DEFAULT OFF (byte-identical when off) ------
|
|
159
|
+
# Same opt-in synergy reparameterization as the myoleg26 env: policy emits k<nm per-group actions,
|
|
160
|
+
# a fixed differentiable grouping map broadcasts them to the nm per-muscle excitations. Grouping
|
|
161
|
+
# from DN_DYNSYN_BINS, which must name bins built for THIS model (no default: bins are per model).
|
|
162
|
+
self.DYNSYN = bool(int(os.environ.get("DN_DYNSYN", "0")))
|
|
163
|
+
self.dynsyn = None
|
|
164
|
+
if self.DYNSYN:
|
|
165
|
+
from diffneusim.rl.dynsyn_layer import DynSynExpander, load_bins
|
|
166
|
+
bins_path = None
|
|
167
|
+
assert bins_path, "DN_DYNSYN=1 needs DN_DYNSYN_BINS: the bins that were bundled were built for retired models"
|
|
168
|
+
_w = False
|
|
169
|
+
_amp = 0.0
|
|
170
|
+
self.dynsyn = DynSynExpander(load_bins(bins_path), self.nm, self.device, weight=_w, amp=_amp)
|
|
171
|
+
self.num_actions = self.dynsyn.num_actions
|
|
172
|
+
self.num_obs = (self.nq - 2) + self.nv + self.nm # drop absolute x,y (translation-invariant)
|
|
173
|
+
# Opt-in muscle-state + contact proprioception (default OFF => obs bit-identical). MuscleMimic feeds
|
|
174
|
+
# activation/velocity/force/contact; we add the no-rebuild subset: activation a, fiber velocity
|
|
175
|
+
# l_ce_dot (control-step finite-diff), and per-contact force (contact_force readout, detached sensor).
|
|
176
|
+
# MTU length + force (same kernel) are the deferred rebuild-needing channels.
|
|
177
|
+
self.OBS_AUG = False
|
|
178
|
+
# heading-free observation; MUST match the imitation reward (imitation.py IM_YAW_FREE reads the
|
|
179
|
+
# same var) or the policy is scored in a frame it cannot see.
|
|
180
|
+
self.YAW_FREE = False
|
|
181
|
+
self.VX_W, self.UP_W, self.ALIVE_W, self.CTRL_COST = vx_w, up_w, alive_w, ctrl_cost
|
|
182
|
+
# Root-height fall guard (qk z≈0.93 after drop). A knob because the LaFAN1 run1 take crouches its
|
|
183
|
+
# reference root to 0.612 m, 12 mm above this guard, so a run imitation may need it lowered. Default
|
|
184
|
+
# unchanged (float("0.6") == 0.6).
|
|
185
|
+
self.TERM_Z = 0.6
|
|
186
|
+
self.HIGH_Z = 1.4
|
|
187
|
+
self.UPRIGHT_MIN = float(os.environ.get("FULLBODY_UPRIGHT_MIN", "0.5")) # cos-like upright term below this = toppled
|
|
188
|
+
# E0_TERM=mm (the review, 11-04): MuscleMimic's full-body MDP, whose training config (fullbody/conf_fullbody.yaml:
|
|
189
|
+
# MeanRelativeSiteDeviationWithRootTerminalStateHandler) ends an episode on its deviations only (1 m / 1 m / 1 rad, our
|
|
190
|
+
# DN_MM_ET), with no pelvis-height and no upright check: so the bad_height (TERM_Z / HIGH_Z) and toppled
|
|
191
|
+
# (UPRIGHT_MIN) terminations are off, and crawl / sit / lying / inverted references can be followed. Unset = as before
|
|
192
|
+
# (the defaults above are the old constants, float("1.4") == 1.4, float("0.5") == 0.5).
|
|
193
|
+
self.E0_TERM = os.environ.get("E0_TERM", "")
|
|
194
|
+
assert self.E0_TERM in ("", "mm"), f"E0_TERM={self.E0_TERM!r}: unset or 'mm'"
|
|
195
|
+
self.QD_MAX = 60.0
|
|
196
|
+
self.A0 = 0.05
|
|
197
|
+
|
|
198
|
+
# rest/drop keyframe: explicit FULLBODY_QK override, else the model's own <stem>_qk.txt (every published
|
|
199
|
+
# coupled model ships one, tools/build_fullbody.py), else the models/fullbody_qk*.txt whose value-count ==
|
|
200
|
+
# the loaded model's nq (the uncoupled bases: 115) -- so a FULLBODY_DNMODEL override no longer needs a
|
|
201
|
+
# matching FULLBODY_QK. Fail loudly if none matches.
|
|
202
|
+
_qk_env = os.environ.get("FULLBODY_QK")
|
|
203
|
+
_qk_own = pathlib.Path(self.model).with_name(pathlib.Path(self.model).stem + "_qk.txt")
|
|
204
|
+
if _qk_env:
|
|
205
|
+
qk_path = ROOT / "models" / _qk_env
|
|
206
|
+
elif _qk_own.exists():
|
|
207
|
+
qk_path = _qk_own
|
|
208
|
+
else:
|
|
209
|
+
_cands = [p for p in sorted((ROOT / "models").glob("fullbody_qk*.txt"))
|
|
210
|
+
if len(p.read_text().split()) == self.nq]
|
|
211
|
+
assert _cands, f"no models/fullbody_qk*.txt with {self.nq} values for {self.model}"
|
|
212
|
+
qk_path = _cands[0]
|
|
213
|
+
q0 = torch.tensor([float(x) for x in qk_path.read_text().split()], dtype=torch.float32, device=self.device)
|
|
214
|
+
assert q0.shape[0] == self.nq, (q0.shape, self.nq, str(qk_path))
|
|
215
|
+
q0 = q0.clone(); q0[2] -= drop # drop feet onto the ground
|
|
216
|
+
self._q_init = q0
|
|
217
|
+
self.l_opt = self._load_lopt()
|
|
218
|
+
self._build_joint_limits() # RSI-pose feasibility clamp (see reset())
|
|
219
|
+
|
|
220
|
+
self.rng = torch.Generator(device=self.device); self.rng.manual_seed(seed)
|
|
221
|
+
self.q = torch.zeros(self.nq, num_envs, dtype=torch.float32, device=self.device)
|
|
222
|
+
self.qd = torch.zeros(self.nv, num_envs, dtype=torch.float32, device=self.device)
|
|
223
|
+
self.lce = torch.zeros(self.nm, num_envs, dtype=torch.float32, device=self.device)
|
|
224
|
+
self._lce_prev = self.lce.detach().clone() # OBS_AUG: baseline for l_ce_dot finite-diff
|
|
225
|
+
self.a = torch.full((self.nm, num_envs), self.A0, dtype=torch.float32, device=self.device)
|
|
226
|
+
self.z = torch.zeros(3 * self.ncon, num_envs, dtype=torch.float32, device=self.device)
|
|
227
|
+
self.musclepd = None
|
|
228
|
+
# Policy-warmstart the activation state on the FIRST post-reset step: set a = the commanded excitation
|
|
229
|
+
# u (skip the activation-dynamics ramp for that one frame) so the muscle starts where the policy drives
|
|
230
|
+
# it instead of ramping up from A0 (removes the measured 0.05->~0.2 start transient). The reference is
|
|
231
|
+
# kinematic-only (no activation), so u is the best pose-adaptive init AND it co-adapts with the policy
|
|
232
|
+
# (unlike a fixed A0 or a GRF-less inverse-dynamics estimate). Opt-in, default off (byte-identical).
|
|
233
|
+
self.act_warmstart = False
|
|
234
|
+
self._just_reset = torch.zeros(num_envs, dtype=torch.bool, device=self.device)
|
|
235
|
+
self.actions = torch.zeros(num_envs, self.num_actions, dtype=torch.float32, device=self.device)
|
|
236
|
+
self.progress = torch.zeros(num_envs, dtype=torch.long, device=self.device)
|
|
237
|
+
# PREREG_S290 Amendment 16 (11-23; the 50 Hz decision): TASKWALK_DECISION_EVERY = k > 1 decides on every k-th control step
|
|
238
|
+
# of each world's episode (its clock = progress, so the first step after ANY reset decides) and holds the PHYSICAL applied action
|
|
239
|
+
# (after the mirror and DynSyn: a flip at a foot strike between two decisions must not swap the held muscles) on the k - 1 steps
|
|
240
|
+
# between. Unset or 1 = off: the attribute is 1, _dr_held never exists, and no line of the hold runs.
|
|
241
|
+
self.decision_every = 1
|
|
242
|
+
assert self.decision_every >= 1, f"TASKWALK_DECISION_EVERY={self.decision_every}: a positive integer (1 = off)"
|
|
243
|
+
if self.decision_every > 1:
|
|
244
|
+
self._dr_held = torch.zeros(num_envs, self.num_actions, dtype=torch.float32, device=self.device)
|
|
245
|
+
self._dr_diag = "" # gate diagnostics only: "", detach_held, no_entmask
|
|
246
|
+
|
|
247
|
+
# --- DeepMimic-style imitation (Peng et al. 2018), DEFAULT OFF (bit-parity when off) ----------
|
|
248
|
+
# Composition shared with the myoLeg envs: a Morphology (model facts as DATA) + a stateless
|
|
249
|
+
# ImitationTask (imitation.py). The ENV owns all mutable imitation state (phase/_prev_phase/
|
|
250
|
+
# _h_prev/_prev_x/eval_mode) and the shared RNG; the task is pure. Full-body frame is plain world
|
|
251
|
+
# z-up: root = the free base (body 1), root translation q[0:3]=(x,y,z). End-effectors = the two
|
|
252
|
+
# calcn bodies [137, 151] (VERIFIED against FOOT_CONTACT_SPHERES: spheres attach to 137/138=right,
|
|
253
|
+
# 151/152=left; calcn is the safe non-toe end-effector). Morphology is built from the base dnmodel
|
|
254
|
+
# (identical bodies to the contact overlay); the fullbody dnmodel has NO leading comment -> plain json.
|
|
255
|
+
self.eval_mode = False # eval sets True -> skip the imitation desync ET (measures SUSTAINED behavior)
|
|
256
|
+
# an EVAL's external generalized force (nv, n_env), added to the joint torques at every substep of the next control step
|
|
257
|
+
# (tools/steer/dl_push.py: DeepLoco's push test, J^T F at the torso); None in training, and nothing reads it then
|
|
258
|
+
self.ext_tau = None
|
|
259
|
+
self._emit_cfnorm = False # per-env-cut contact-force signal: compute only when the cut is on (else non-PEC runs pay no contact_force call)
|
|
260
|
+
self._train_steps = 0 # monotonic step() counter (imitation desync-anneal, see imitation_task.desync_mask)
|
|
261
|
+
self.imitation = bool(int(os.environ.get("DN_IMITATION", "0")))
|
|
262
|
+
self.imitation_task = None
|
|
263
|
+
# Reference-free task walking (arXiv:2603.04166): a task reward + a synergy action prior instead of
|
|
264
|
+
# clip tracking. Mutually exclusive with DN_IMITATION -- asserted rather than silently preferred,
|
|
265
|
+
# because a run that quietly optimized a blend of the two would be evidence about neither.
|
|
266
|
+
self.taskwalk = None
|
|
267
|
+
self._taskwalk_on = bool(int(os.environ.get("DN_TASKWALK", "0")))
|
|
268
|
+
# TASK-WALK INITIAL STATE. A muscle model cannot stand from a static keyframe with the muscles off:
|
|
269
|
+
# measured, the contact impulse throws it airborne within two control steps and every episode ends
|
|
270
|
+
# in ~6 steps with the feet 50 cm up. The authors hit the same wall and solved it the same way --
|
|
271
|
+
# H2190.scone sets `state_init_file = InitStateGait10.zml`, a MID-GAIT pose WITH velocities
|
|
272
|
+
# (pelvis_tx = 1.0 m/s). So we draw (q0, qd0) from our own walk corpus. This is a state SAMPLER
|
|
273
|
+
# only: no tracking term, no phase observation, no desync termination -- the reward stays purely
|
|
274
|
+
# the task reward, so the run is still reference-free in the sense that matters.
|
|
275
|
+
self._tw_init_ref = os.environ.get("TASKWALK_INIT_REF", "")
|
|
276
|
+
assert not (self._taskwalk_on and self.imitation), (
|
|
277
|
+
"DN_TASKWALK and DN_IMITATION are different experiments (task reward vs clip tracking); "
|
|
278
|
+
"enable exactly one")
|
|
279
|
+
self.phase = None; self._prev_phase = None; self._h_prev = None
|
|
280
|
+
self._prev_x = torch.zeros(num_envs, dtype=torch.float32, device=self.device)
|
|
281
|
+
# The monitor is the FK the reward runs on -- needed by BOTH task families (imitation's
|
|
282
|
+
# feet/COM terms and taskwalk's head/COM terms), so it is built for either.
|
|
283
|
+
self._monitor = None
|
|
284
|
+
if self.imitation or self._taskwalk_on:
|
|
285
|
+
from diffneusim.model.monitor import DnModelMonitor
|
|
286
|
+
self._monitor = DnModelMonitor(self.model, self.device) # contact model; body_poses = FK for feet/com
|
|
287
|
+
if self.imitation or (self._taskwalk_on and self._tw_init_ref):
|
|
288
|
+
# Morphology must be built from the ACTUALLY-loaded model (respects FULLBODY_DNMODEL) so its qadr/vadr
|
|
289
|
+
# maps match the model's dof layout -- a spine-coupled variant is nq=100 (dep coords removed), the
|
|
290
|
+
# base is nq=115. Bodies are identical (coupled deps remain as 0-dof bodies), so feet/hand/root body
|
|
291
|
+
# indices below are unchanged; only the coord layout differs. (Was BASE_MODEL nq=115 -> wrong for coupled.)
|
|
292
|
+
jm = read_model(self.model)
|
|
293
|
+
# End-effectors for imitation tracking (reward e_ee + the max-EE desync ET): DeepMimic tracks
|
|
294
|
+
# feet AND hands. Feet = calcn [137, 151]; hands = the arm-chain distal leaves [47(R), 96(L)]
|
|
295
|
+
# (found by tracing the arm-joint subtrees to their tip; mass ~0.02). 4-EE default (DN_FULLBODY_HANDS=1);
|
|
296
|
+
# set =0 for the feet-only 2-EE baseline (A/B). Adding hands makes the max-EE ET catch a stalled
|
|
297
|
+
# arm swing and the e_ee reward track arm motion.
|
|
298
|
+
_hands = []
|
|
299
|
+
self.morphology = Morphology.build(
|
|
300
|
+
jm, nq=self.nq, nv=self.nv, root_fwd=ROOT_FWD, root_height=ROOT_HEIGHT, root_lat=ROOT_LAT,
|
|
301
|
+
root_body=1, feet=[137, 151] + _hands, device=self.device)
|
|
302
|
+
# Canonical ref = 35_01_LOOP_fullbody_ref.npz (subject-35 CMU walk, made LOOPABLE) -- USER-selected
|
|
303
|
+
# default, SHARED with the myoleg26 default (35_01_loop_myoleg26_ref.npz) so both models imitate the
|
|
304
|
+
# same motion. TRAINING INVARIANT: this MUST be a _loop_ ref (tools/reference/make_loopable_ref.py;
|
|
305
|
+
# docs/training/concepts/loopable-refs.md) -- the imitation phase-wrap (imitation.py:advance_phase) loops the
|
|
306
|
+
# clip, and a raw CMU retarget does NOT close (35_01 raw seam cost 6.2 -> loop 0.097; joint seam
|
|
307
|
+
# 0.105 -> 0.009 rad) so a non-loop ref makes the walk die at the first seam. If you point DN_REF
|
|
308
|
+
# at a NEW motion, run make_loopable_ref.py FIRST (fullbody axes: --fwd-axis 0 --lat-axis 1).
|
|
309
|
+
# RSI-safe after the armature-floor + RSI-clamp fixes. Fallbacks: DN_REF=data/reference/cmu/
|
|
310
|
+
# 07_01_loop_fullbody_ref.npz (1.53 m/cycle @1.40 m/s) or another <clip>_loop_fullbody_ref.npz.
|
|
311
|
+
# ONE artifact per clip: the nq=115 retarget. adapt_reference() column-selects it onto whatever
|
|
312
|
+
# this model is (coupled nq100 / fused nq60 / armless_ball nq26) BY BODY at load, and reproduces
|
|
313
|
+
# the old per-model files EXACTLY (verified max|dq| = max|dqd| = 0 against the committed nq100 and
|
|
314
|
+
# nq60 refs). The derived files are gone: keeping them meant hand-carrying every retarget fix
|
|
315
|
+
# through a 3-hop chain, which drifted twice in one day (the MTP fix missed fusedhand; the
|
|
316
|
+
# foot-target fix missed coupled, so full-body trained on a pre-fix reference).
|
|
317
|
+
_ref_default = "35_01_loop_fullbody_ref.npz"
|
|
318
|
+
ref_path = (self._tw_init_ref if (self._taskwalk_on and self._tw_init_ref)
|
|
319
|
+
else os.environ.get("DN_REF", str(ROOT / "data/reference/cmu" / _ref_default)))
|
|
320
|
+
# model_jm lets the task column-select a richer parent ref (e.g. coupled nq=100) onto THIS
|
|
321
|
+
# model by body (armless nq=24 uses the coupled clip directly -- no per-model ref file needed).
|
|
322
|
+
# EXCEPTION to the loop invariant above: a WHOLE clip that declares `loop=False` in its npz (the
|
|
323
|
+
# LaFAN1 takes) is not wrapped; it is truncated at its last frame (step(), `clip_end`).
|
|
324
|
+
self.imitation_task = ImitationTask(self.morphology, ref_path, self._monitor, self.device, model_jm=jm)
|
|
325
|
+
# the whole-clip RSI range and clip-end test count CONTROL steps; must precede the first reset()
|
|
326
|
+
self.imitation_task.set_control_dt(self.SUBSTEPS * self.dt)
|
|
327
|
+
# DiffMimic demonstration-replay (Ren et al. 2023, arXiv:2304.03274 Eq.3.5): when the rollout
|
|
328
|
+
# drifts past snap_eps from the reference, SNAP q,qd back to the reference (detached) and CONTINUE
|
|
329
|
+
# -- instead of the imitation desync EARLY-TERMINATION. This keeps the pathwise gradient flowing
|
|
330
|
+
# over long horizons (error-triggered adaptive truncation) and is what lets DiffMimic escape the
|
|
331
|
+
# "collapse/use-arms-to-support" local min (== our forward-lean-then-topple). The snap threshold
|
|
332
|
+
# is a WHOLE-BODY joint-space pose-L2 (per-joint normalized), DECOUPLED from the fall-ET (physical
|
|
333
|
+
# bad-height/topple/divergence STILL ends the episode) AND from the max-EE desync-ET (which DR
|
|
334
|
+
# replaces). Default OFF => the desync-ET path (byte-identical). Training-only (eval never snaps).
|
|
335
|
+
self.dr_snap = False
|
|
336
|
+
self.snap_eps = 0.25 # per-joint mean-sq pose drift to snap
|
|
337
|
+
self.phase = torch.zeros(num_envs, dtype=torch.float32, device=self.device)
|
|
338
|
+
# TASKWALK_TRACK_POSE=1 (the DeepLoco-lite tracking arm): under taskwalk the RSI phase is KEPT and advanced, and the
|
|
339
|
+
# reward gets the local pose error against ref(phase) (task_walk_reward.track_pose_error). The phase runs at the
|
|
340
|
+
# clip's own rate times the HUMAN cadence ratio at the command, cadence*(v) / cadence*(v_clip), from the Fukuchi
|
|
341
|
+
# 2018 population's linear trend (TASKWALK_TRACK_CADENCE_FIT "a,b": cadence* = a + b v, 231 trials, 0.36-2.06 m/s).
|
|
342
|
+
self._tw_track = self._taskwalk_on and False
|
|
343
|
+
if self._tw_track:
|
|
344
|
+
_ab = [float(x) for x in ['0.2715', '0.2522']]
|
|
345
|
+
assert len(_ab) == 2 and _ab[0] > 0.0 and _ab[1] >= 0.0, _ab
|
|
346
|
+
self._tw_track_cad = tuple(_ab)
|
|
347
|
+
assert self.imitation_task.n_clips == 1, "the tracking arm takes ONE clip (TASKWALK_INIT_REF)"
|
|
348
|
+
self._tw_track_vclip = float(self.imitation_task.clip_vfwd[0])
|
|
349
|
+
m = self.morphology
|
|
350
|
+
self._tw_track_scalar = m.pose_scalar_idx[m.pose_scalar_idx != ROOT_HEIGHT]
|
|
351
|
+
self._tw_track_quats = [(s_, L) for (s_, L) in m.quat_blocks if m.root_quat is None or s_ != m.root_quat[0]]
|
|
352
|
+
self.imitation_task.clip_id = torch.zeros(num_envs, dtype=torch.long, device=self.device)
|
|
353
|
+
# TASKWALK_TRACK_PHASE=heel (2026-10-22): the reference phase is ANCHORED to the body's own gait instead of a free
|
|
354
|
+
# clock. MEASURED (tools/steer/track_components.py): under the free clock the reference phase at the body's right heel
|
|
355
|
+
# strikes is near-uniform (resultant R 0.15-0.18), the policy walks out of step with the clip, the knee error is
|
|
356
|
+
# ~20 deg rms even straight and the reward pays ~3 of 10. Heel mode: at each right heel strike (vertical GRF onset
|
|
357
|
+
# > 0.2 BW) the phase jumps to the CLIP's right heel strike (Zeni 2008: the heel's maximum forward offset from the
|
|
358
|
+
# pelvis) and advances over the body's last measured stride period, clamped to [0.7, 1.4] x the expected one.
|
|
359
|
+
self._tw_track_phase = "clock"
|
|
360
|
+
assert self._tw_track_phase in ("clock", "heel", "steps"), self._tw_track_phase
|
|
361
|
+
# TASKWALK_TRACK_PHASE=steps (2026-10-23, DeepLoco's per-step reference): the tracked pose comes from a LIBRARY of
|
|
362
|
+
# single steps (TASKWALK_STEP_LIBRARY, tools/steer/build_step_library.py), the entry nearest to the body's state
|
|
363
|
+
# chosen at every new footstep-plan step and played over its nominal step time (diffneusim/rl/
|
|
364
|
+
# step_library.py); TASKWALK_INIT_REF stays the reset clip only.
|
|
365
|
+
self._tw_steplib = None
|
|
366
|
+
if self._tw_track_phase == "steps":
|
|
367
|
+
from diffneusim.rl.step_library import StepLibrary
|
|
368
|
+
_lib = ""
|
|
369
|
+
assert _lib, "TASKWALK_TRACK_PHASE=steps needs TASKWALK_STEP_LIBRARY (a build_step_library.py library.json)"
|
|
370
|
+
assert False, "the step library is chosen per footstep-plan step"
|
|
371
|
+
self._tw_steplib = StepLibrary.load(_lib, self.morphology, self._monitor, self.device, jm)
|
|
372
|
+
# TASKWALK_STEP_EE=1: DeepLoco's end-effector term, the feet relative to the root against the chosen step's
|
|
373
|
+
# (step_library.py); 0 = the joints only (fslib1 .. fslibw50)
|
|
374
|
+
_ee = "0"
|
|
375
|
+
self._tw_step_ee = _ee == "1"
|
|
376
|
+
# TASKWALK_STEP_EE_H=1 (2026-10-24): its vertical part, each foot's height above the lower against the step's
|
|
377
|
+
# (step_library.py); 0 = horizontal only (fslibee .. llctorso)
|
|
378
|
+
_eh = "0"
|
|
379
|
+
self._tw_step_ee_h = _eh == "1"
|
|
380
|
+
assert self._tw_step_ee or not self._tw_step_ee_h, "TASKWALK_STEP_EE_H is the vertical part of TASKWALK_STEP_EE"
|
|
381
|
+
if self._tw_step_ee:
|
|
382
|
+
self._tw_steplib.build_ee(self._monitor, (137, 151))
|
|
383
|
+
self._tw_steplib.task.clip_id = torch.zeros(num_envs, dtype=torch.long, device=self.device)
|
|
384
|
+
self._tw_sl_T = torch.ones(num_envs, device=self.device) # each env's play time of its step (s)
|
|
385
|
+
print(f"[taskwalk] STEP LIBRARY tracking: {_lib}, {self._tw_steplib.n} steps (+ mirrored), clip dt "
|
|
386
|
+
f"{self._tw_steplib.task.ref_dt:.4f} s", flush=True)
|
|
387
|
+
if self._tw_track_phase == "heel":
|
|
388
|
+
names = [b.get("name", "") for b in jm["bodies"]]
|
|
389
|
+
i_pel, i_cr = names.index("pelvis"), names.index("calcn_r")
|
|
390
|
+
with torch.no_grad():
|
|
391
|
+
pos_r, _, _ = self._monitor.body_poses_subset(self.imitation_task.ref_q.t().contiguous(), [i_pel, i_cr], False)
|
|
392
|
+
fwd = (pos_r[i_cr][0] - pos_r[i_pel][0]).cpu().numpy()
|
|
393
|
+
self._tw_trk_phi_rhs = float(int(fwd.argmax()) / len(fwd))
|
|
394
|
+
self._tw_trk_t = torch.zeros(num_envs, device=self.device)
|
|
395
|
+
self._tw_trk_T = torch.full((num_envs,), self.imitation_task.ref_secs, device=self.device)
|
|
396
|
+
self._tw_trk_prev_ld = torch.ones(num_envs, dtype=torch.bool, device=self.device)
|
|
397
|
+
self._tw_trk_grf = None
|
|
398
|
+
print(f"[taskwalk] tracking phase ANCHORED to the right heel strike: clip RHS phase {self._tw_trk_phi_rhs:.3f}", flush=True)
|
|
399
|
+
print(f"[taskwalk] pose TRACKING on: clip {ref_path}, v_clip {self._tw_track_vclip:.3f} m/s, cycle "
|
|
400
|
+
f"{self.imitation_task.ref_secs:.3f} s, {len(self._tw_track_scalar)} scalar dofs + {len(self._tw_track_quats)} ball joints, "
|
|
401
|
+
f"cadence fit {self._tw_track_cad}", flush=True)
|
|
402
|
+
if self.imitation_task.PHASE_OBS:
|
|
403
|
+
self.num_obs += 2
|
|
404
|
+
if self.imitation_task.COND_OBS: # (v_fwd, cadence) of the clip this env is tracking
|
|
405
|
+
self.num_obs += 2
|
|
406
|
+
if self.imitation_task.IM_MIMIC: # MuscleMimic's concise lookahead goal
|
|
407
|
+
self.num_obs += self.imitation_task.mimic_goal_dim()
|
|
408
|
+
# MuscleVAE's COLLECTION PROTOCOL (muscle_env.py; repro_table rows C4, C7), opt-in, unset = every path unchanged:
|
|
409
|
+
# DN_ET_MODE=mvae_head their termination in place of the desync ET and the root-height / topple gates: the head's
|
|
410
|
+
# height error against the reference's > 0.5 m counts up, otherwise down (floor 0), and the episode fails at 20
|
|
411
|
+
# counts once 26 steps have passed (cal_done, l. 193-218; env_err_threshod / env_err_length / env_min_length). The
|
|
412
|
+
# non-finite and |qd| gates stay (their non-finite and |obs| > 50 guards); training only, as the desync ET.
|
|
413
|
+
# DN_REF_SWITCH_STEPS=N every N control steps, and at a whole clip's end, the TARGET jumps to a newly drawn
|
|
414
|
+
# (clip, phase) while the body keeps going (after_step, l. 332-354, play_random_mode with env_random_count 96);
|
|
415
|
+
# a clip's end then no longer ends the episode. The draw is the RSI draw (uniform; their value-balanced p is C3).
|
|
416
|
+
# Training only, as the head ET: an eval readout tracks one clip.
|
|
417
|
+
self.ET_MODE = ""
|
|
418
|
+
assert self.ET_MODE in ("", "mvae_head"), self.ET_MODE
|
|
419
|
+
self.REF_SWITCH = 0
|
|
420
|
+
# E0_M4C=1 (M4c, tools/e0speed/LEVERS_PLAN.md): step()'s post-physics block (_post_physics) and the post-reset obs run
|
|
421
|
+
# torch.compile'd, so its ~390 eager launches per control step fuse. Off runs the same method uncompiled: the same
|
|
422
|
+
# operations in the same order. The reset (done.nonzero, a host sync) stays outside the compiled region.
|
|
423
|
+
self.M4C = False
|
|
424
|
+
if self.ET_MODE:
|
|
425
|
+
assert self.imitation, ( # the task phase tracks no clip
|
|
426
|
+
"DN_ET_MODE / DN_REF_SWITCH_STEPS are the imitation collection protocol")
|
|
427
|
+
if self.ET_MODE == "mvae_head":
|
|
428
|
+
self.HEAD_ET_TH = 0.5
|
|
429
|
+
self.HEAD_ET_CNT = 20
|
|
430
|
+
self.HEAD_ET_MIN = 26
|
|
431
|
+
self._head_cnt = torch.zeros(num_envs, dtype=torch.long, device=self.device)
|
|
432
|
+
# LATENT SKILL MODEL (DN_LATENT=1, default off: nothing below runs and obs / reward / extra are unchanged).
|
|
433
|
+
# The ControlVAE / MuscleVAE posterior q(z | s, s~') reads the NEXT reference frame s~', i.e. the target the
|
|
434
|
+
# reward scores after the coming control step. It is a SEPARATE block (latent_ref_obs, NOT part of the policy
|
|
435
|
+
# observation): the decoder sees only s and z, so the reference reaches the action only through the latent.
|
|
436
|
+
# See _latent_ref_features for the layout.
|
|
437
|
+
self.LATENT = False
|
|
438
|
+
self.num_ref_obs = 0
|
|
439
|
+
if self.LATENT:
|
|
440
|
+
assert self.imitation, "DN_LATENT encodes the next REFERENCE frame; it needs DN_IMITATION=1"
|
|
441
|
+
self.num_ref_obs = (self.nq - 7) + (self.nv - 6) + 1 + 6 + 3 + 3
|
|
442
|
+
self.latent_task = None
|
|
443
|
+
self.num_task_obs = 0
|
|
444
|
+
if self._taskwalk_on:
|
|
445
|
+
# Model facts for the shared task-walk wiring (task_walk_env.TaskWalkEnvMixin). The head body
|
|
446
|
+
# and the joint indices come from the reward's own per-nq dof map.
|
|
447
|
+
_fb = sorted({int(g["body"]) for g in FOOT_CONTACT_SPHERES})
|
|
448
|
+
self._tw_setup(TaskWalkSpec(
|
|
449
|
+
feet=(137, 151), # calcn_r / calcn_l, the authors' ground reference
|
|
450
|
+
contact_bodies=tuple(_fb),
|
|
451
|
+
right_bodies=(137, 138),
|
|
452
|
+
foot_bodies=(137, 138, 151, 152), # every contact sphere is on a foot; TASKWALK_FALL_FOOT_GEOM only
|
|
453
|
+
knee_muscles=("recfem", "vasint", "vaslat", "vasmed", "bflh", "bfsh", "semimem",
|
|
454
|
+
"semiten", "grac", "sart", "gaslat", "gasmed")))
|
|
455
|
+
# A commanded heading with the absolute heading in the observation would let the policy key on the compass
|
|
456
|
+
# direction the training happened to face; the steering task is posed in the body's own yaw frame.
|
|
457
|
+
assert not self._tw_heading_on, "TASKWALK_HEADING=1 needs DN_YAW_FREE=1"
|
|
458
|
+
# AFTER _tw_setup (it reads _tw_spec.right_bodies) and BEFORE reset() (which calls _obs()).
|
|
459
|
+
self._init_mirror(num_envs, self.device)
|
|
460
|
+
assert not (self.LATENT and self.mirror is not None), (
|
|
461
|
+
"DN_LATENT with DN_MIRROR_SYM: the mirror latch would canonicalise the observation but not the "
|
|
462
|
+
"reference block the posterior reads")
|
|
463
|
+
assert not (self.latent_task is not None and self.mirror is not None), (
|
|
464
|
+
"DN_LATENT_TASK with DN_MIRROR_SYM: the mirror latch would canonicalise the observation but not the "
|
|
465
|
+
"command block")
|
|
466
|
+
# TASKWALK_CYCLE_PHASE_BINS: the one-hot bins are the observation's last K slots; the algorithm gates every other input by
|
|
467
|
+
# them and leaves them unnormalized (nets_shac.PhaseGate, RunningMeanStd.fixed). None = no gate.
|
|
468
|
+
self.phase_gate_bins = None
|
|
469
|
+
if getattr(self, "_tw_fs", None) is not None and self._tw_cyc_bins:
|
|
470
|
+
assert self.mirror is None, "the phase bins must be the observation's last slots"
|
|
471
|
+
self.phase_gate_bins = list(range(self.num_obs - self._tw_cyc_bins, self.num_obs))
|
|
472
|
+
# The declared width MUST equal what _obs() returns: the algo sizes obs_rms and the actor/critic input
|
|
473
|
+
# from num_obs, and a mismatch surfaces far away as a running-mean shape error
|
|
474
|
+
# ("size of tensor a (949) must match tensor b (947)") rather than here. Assert it at construction.
|
|
475
|
+
self.reset()
|
|
476
|
+
if self.taskwalk is not None:
|
|
477
|
+
self._tw_q_stand = self._q_init # the standing keyframe: the head-upright reference
|
|
478
|
+
self._tw_calibrate()
|
|
479
|
+
_n = int(self._obs().shape[1])
|
|
480
|
+
assert _n == self.num_obs, (
|
|
481
|
+
f"declared num_obs={self.num_obs} but _obs() returns {_n}; every optional observation block must "
|
|
482
|
+
f"add its width above")
|
|
483
|
+
|
|
484
|
+
def _load_lopt(self):
|
|
485
|
+
# ACTUAL loaded model (respects FULLBODY_DNMODEL), NOT the hardcoded nq115/nm416 BASE_MODEL: the
|
|
486
|
+
# fused-hand locomotion model has nm=356 (26 intrinsic hand muscles dropped), so l_opt must match
|
|
487
|
+
# self.nm or the lce init [nm,n_env] mismatches at reset(). (Mirrors _build_joint_limits.)
|
|
488
|
+
jm = read_model(self.model)
|
|
489
|
+
return torch.tensor(muscle_l_opts(jm),
|
|
490
|
+
dtype=torch.float32, device=self.device)
|
|
491
|
+
|
|
492
|
+
def _build_joint_limits(self):
|
|
493
|
+
"""Parse the limited-joint ranges (qadr, lo, hi) exactly like diffneusim.model.monitor so reset()
|
|
494
|
+
can project the init pose into the feasible set. Needed because RSI adds Gaussian reset noise
|
|
495
|
+
(imitation.rsi: q0 += 0.02*randn) and the full-body model has extremely tight lumbar/spine limits
|
|
496
|
+
(as small as +-0.03 rad); the noise pushes those DOFs past their limits, and the stiff IMEX limit
|
|
497
|
+
force whips the joint and occasionally NaNs the f32 rollout. See reset()."""
|
|
498
|
+
# read the ACTUAL loaded model (respects FULLBODY_DNMODEL) -- NOT the hardcoded nq=115 base -- so the
|
|
499
|
+
# limited-joint qadr match the model's dof layout (a spine-coupled variant is nq=100, base is 115).
|
|
500
|
+
jm = read_model(self.model)
|
|
501
|
+
qadr, lo, hi = [], [], []
|
|
502
|
+
for body in jm["bodies"]:
|
|
503
|
+
if "coupled" in body: # driven ("mimic") joint: position set by the master, not clamped
|
|
504
|
+
continue
|
|
505
|
+
qa = int(body["qadr"])
|
|
506
|
+
if "joints" in body:
|
|
507
|
+
for k, prim in enumerate(body["joints"]):
|
|
508
|
+
if prim.get("limited", False):
|
|
509
|
+
r = prim["range"]; qadr.append(qa + k); lo.append(float(r[0])); hi.append(float(r[1]))
|
|
510
|
+
continue
|
|
511
|
+
if body.get("joint") in ("hinge", "revolute", "slide", "prismatic") and body.get("limited", False):
|
|
512
|
+
r = body["range"]; qadr.append(qa); lo.append(float(r[0])); hi.append(float(r[1]))
|
|
513
|
+
assert qadr, "no limited joints parsed from the full-body model"
|
|
514
|
+
self._lim_qadr = torch.tensor(qadr, dtype=torch.long, device=self.device)
|
|
515
|
+
self._lim_lo = torch.tensor(lo, dtype=torch.float32, device=self.device)[:, None]
|
|
516
|
+
self._lim_hi = torch.tensor(hi, dtype=torch.float32, device=self.device)[:, None]
|
|
517
|
+
|
|
518
|
+
def _start_state(self, n):
|
|
519
|
+
q = self._q_init.view(-1, 1).repeat(1, n).contiguous()
|
|
520
|
+
qd = torch.zeros(self.nv, n, dtype=torch.float32, device=self.device)
|
|
521
|
+
lce = self.l_opt.view(-1, 1).repeat(1, n).contiguous()
|
|
522
|
+
if self.stochastic_init:
|
|
523
|
+
q[7:] += 0.01 * torch.randn(self.nq - 7, n, generator=self.rng, device=self.device) # gentle hinge noise (not the free base)
|
|
524
|
+
qd += 0.005 * torch.randn(self.nv, n, generator=self.rng, device=self.device)
|
|
525
|
+
a = torch.full((self.nm, n), self.A0, dtype=torch.float32, device=self.device)
|
|
526
|
+
return q, qd, lce, a
|
|
527
|
+
|
|
528
|
+
def _tw_trk_ratio(self):
|
|
529
|
+
"""(n,) the human cadence ratio at each env's command, cadence*(v) / cadence*(v_clip) (the Fukuchi trend, TASKWALK_TRACK_CADENCE_FIT)."""
|
|
530
|
+
a_, b_ = self._tw_track_cad
|
|
531
|
+
v = torch.as_tensor(self.taskwalk.v_tgt, device=self.device, dtype=self.phase.dtype).expand_as(self.phase)
|
|
532
|
+
return (a_ + b_ * v) / (a_ + b_ * self._tw_track_vclip)
|
|
533
|
+
|
|
534
|
+
def reset(self, env_ids=None):
|
|
535
|
+
self._reset_envs(env_ids)
|
|
536
|
+
return self._obs()
|
|
537
|
+
|
|
538
|
+
def _reset_envs(self, env_ids=None):
|
|
539
|
+
"""reset() without its observation. step() resets its done envs and then builds its own observation, so the one
|
|
540
|
+
reset() returns was computed there and dropped every control step; _obs() reads the state and writes nothing."""
|
|
541
|
+
if env_ids is None:
|
|
542
|
+
env_ids = torch.arange(self.num_envs, device=self.device)
|
|
543
|
+
n = len(env_ids)
|
|
544
|
+
if n > 0:
|
|
545
|
+
q0, qd0, lce0, a0 = self._start_state(n)
|
|
546
|
+
if self.taskwalk is not None:
|
|
547
|
+
self._tw_draw(env_ids) # rng: command speed, THEN the rsi below
|
|
548
|
+
if self.imitation_task is not None:
|
|
549
|
+
# mid-gait (q, qd) from the walk corpus -- state only, unless the tracking arm keeps the phase
|
|
550
|
+
q0, qd0, _phi, _cid = self.imitation_task.rsi(n, self.rng, self.stochastic_init)
|
|
551
|
+
if getattr(self, "_tw_track", False):
|
|
552
|
+
self.phase = self.phase.clone(); self.phase[env_ids] = _phi
|
|
553
|
+
if self._tw_track_phase == "heel": # the clock restarts where the RSI frame sits in the cycle
|
|
554
|
+
T0 = self.imitation_task.ref_secs / self._tw_trk_ratio()[env_ids]
|
|
555
|
+
self._tw_trk_T = self._tw_trk_T.clone(); self._tw_trk_T[env_ids] = T0
|
|
556
|
+
self._tw_trk_t = self._tw_trk_t.clone(); self._tw_trk_t[env_ids] = ((_phi - self._tw_trk_phi_rhs) % 1.0) * T0
|
|
557
|
+
pl = self._tw_trk_prev_ld.clone(); pl[env_ids] = True; self._tw_trk_prev_ld = pl
|
|
558
|
+
if getattr(self, "_tw_fs", None) is not None and self._tw_reset_lib:
|
|
559
|
+
q0, qd0 = self._tw_reset_from_steplib(env_ids) # TASKWALK_RESET_STEPLIB: DeepLoco's SAMPLE_INIT_STATES
|
|
560
|
+
q0 = self._tw_ground_pose(q0, env_ids) # AFTER the slope draw: grounds onto the new plane
|
|
561
|
+
if self.imitation: # reference-state-init: start ON the ref clip
|
|
562
|
+
q0, qd0, phi, cid = self.imitation_task.rsi(n, self.rng, self.stochastic_init) # shared env rng, AFTER _start_state (stream order preserved)
|
|
563
|
+
self.phase = self.phase.clone(); self.phase[env_ids] = phi
|
|
564
|
+
t = self.imitation_task # per-env clip, scattered like the phase
|
|
565
|
+
if t.clip_id.numel() != self.num_envs:
|
|
566
|
+
t.clip_id = torch.zeros(self.num_envs, dtype=torch.long, device=self.device)
|
|
567
|
+
t.clip_id = t.clip_id.clone(); t.clip_id[env_ids] = cid
|
|
568
|
+
# lce0 stays = l_opt (from _start_state); the imitation-RSI NaN was reference-side, fixed by
|
|
569
|
+
# retargeting to the over-stretch-free segmented ref, NOT a muscle-init hook (removed, #17)
|
|
570
|
+
# Project the init pose into the feasible joint set. RSI adds Gaussian reset noise
|
|
571
|
+
# (imitation.rsi: q0 += 0.02*randn); the full-body model has tight lumbar/spine limits
|
|
572
|
+
# (+-0.03 rad), so the noise pushes those DOFs past their limits (measured: 256/256 envs
|
|
573
|
+
# violate, pen up to 0.073), and the stiff IMEX limit force whips the joint (dof10 0->45 rad/s
|
|
574
|
+
# in one substep) -> occasional f32 NaN. The raw ref clip is already in-limit; only the reset
|
|
575
|
+
# noise violates, so clamping the noised pose to [lo,hi] removes the RSI limit-force transient.
|
|
576
|
+
q0[self._lim_qadr] = torch.clamp(q0[self._lim_qadr], self._lim_lo, self._lim_hi)
|
|
577
|
+
# Fibers: solve for isometric equilibrium at the FINAL pose (after RSI and the limit clamp),
|
|
578
|
+
# not l_opt. l_ce is a state that enters the step's residual through v_ce, so an off-equilibrium
|
|
579
|
+
# seed injects a spurious fiber velocity -- 146 mm off here, i.e. ~40x v_max at dt=1/500.
|
|
580
|
+
# (A muscle-init hook was removed as #17 when the RSI NaN turned out to be reference-side; this
|
|
581
|
+
# is back for a different, measured reason. DN_FIBER_INIT_ITERS=0 restores l_opt.)
|
|
582
|
+
# A CPU-constructed GpuVecEnv is a reward/obs-math shell, not a simulator: diffneusim.load
|
|
583
|
+
# defaults to the CUDA backend, so it cannot step and there is no muscle state to make
|
|
584
|
+
# consistent. Equilibrate only where the simulation actually runs.
|
|
585
|
+
if str(self.device).startswith("cuda") or getattr(self, "sim_on_cpu", False): # env14's CPU backend steps on the CPU (the Mac dry-run)
|
|
586
|
+
# DN_FIBER_INIT_VC=1: equilibrate one substep back along qd0, so the first substep carries the start's
|
|
587
|
+
# fiber velocity instead of 0 (mtu_gpu.equilibrate_fibers). Unset, the call is unchanged.
|
|
588
|
+
lce0 = self._myoleg_gpu.equilibrate_fibers(q0, lce0, a0, self.dt, self.model,
|
|
589
|
+
qd=None)
|
|
590
|
+
self.q = self.q.clone(); self.qd = self.qd.clone(); self.lce = self.lce.clone()
|
|
591
|
+
self.a = self.a.clone(); self.z = self.z.clone(); self.actions = self.actions.clone()
|
|
592
|
+
self.q[:, env_ids] = q0
|
|
593
|
+
self.qd[:, env_ids] = qd0
|
|
594
|
+
self.lce[:, env_ids] = lce0
|
|
595
|
+
if self.musclepd is not None: # a reset fibre starts at rest: zero rate on its first substep
|
|
596
|
+
self._pd_lce_prev = self._pd_lce_prev.clone()
|
|
597
|
+
self._pd_lce_prev[:, env_ids] = lce0
|
|
598
|
+
self.a[:, env_ids] = a0
|
|
599
|
+
# index_fill_, not `x[env_ids] = 0.0`: an indexed write of a Python scalar is index_put_ with a CPU 0-dim
|
|
600
|
+
# value, copied to the device with a stream sync, and its IndexPutBackward makes the same copy in BPTT; z
|
|
601
|
+
# and actions carry gradient, so every step's backward drained the GPU queue there (nsys, perf-log 10-28)
|
|
602
|
+
self.z.index_fill_(1, env_ids, 0.0)
|
|
603
|
+
self.actions.index_fill_(0, env_ids, 0.0)
|
|
604
|
+
self.progress.index_fill_(0, env_ids, 0)
|
|
605
|
+
self._just_reset.index_fill_(0, env_ids, True) # policy-warmstart the activation on this env's next step
|
|
606
|
+
if getattr(self, "ET_MODE", "") == "mvae_head":
|
|
607
|
+
self._head_cnt = self._head_cnt.clone(); self._head_cnt[env_ids] = 0
|
|
608
|
+
if self.mirror is not None:
|
|
609
|
+
self.mirror.reset(env_ids) # their wrapper sets phase = 0.0 in reset()
|
|
610
|
+
if self.imitation:
|
|
611
|
+
self._prev_x = self._prev_x.clone(); self._prev_x[env_ids] = self.q[ROOT_FWD, env_ids].detach()
|
|
612
|
+
if self.latent_task is not None:
|
|
613
|
+
self.latent_task.reset(env_ids, self.q) # new commands (env rng, after the RSI draws), the pose in place
|
|
614
|
+
if self.taskwalk is not None and self.TW_LANE_HALF_W > 0.0:
|
|
615
|
+
# the lane's centre is where this episode started (myoLeg26 env, the same code)
|
|
616
|
+
self._tw_lane0 = self._tw_lane0.clone()
|
|
617
|
+
self._tw_lane0[env_ids] = self.q[ROOT_LAT, env_ids].detach()
|
|
618
|
+
if self.taskwalk is not None:
|
|
619
|
+
self._tw_heading_reset(env_ids) # TASKWALK_HEADING: the command starts as the reset pose's own heading
|
|
620
|
+
|
|
621
|
+
def clear_grad(self):
|
|
622
|
+
with torch.no_grad():
|
|
623
|
+
self.q = self.q.detach().clone(); self.qd = self.qd.detach().clone()
|
|
624
|
+
self.lce = self.lce.detach().clone(); self.a = self.a.detach().clone()
|
|
625
|
+
self.z = self.z.detach().clone(); self.actions = self.actions.detach().clone()
|
|
626
|
+
if self.decision_every > 1: # Amendment 16: the held action is cut with the window like the state
|
|
627
|
+
self._dr_held = self._dr_held.detach().clone()
|
|
628
|
+
self._lce_prev = self.lce.detach().clone() # OBS_AUG: zero l_ce_dot at trajectory start
|
|
629
|
+
if getattr(self, "musclepd", None) is not None: # the PD rate's previous fibre length: cut with the window
|
|
630
|
+
self._pd_lce_prev = self._pd_lce_prev.detach().clone()
|
|
631
|
+
|
|
632
|
+
def initialize_trajectory(self):
|
|
633
|
+
self.clear_grad()
|
|
634
|
+
if getattr(self, "_asat_gate", None) is not None: # TASKWALK_ACTIVE_SAT_GATE: the weight's once-per-window step (task_walk_env)
|
|
635
|
+
self._asat_gate_update()
|
|
636
|
+
if getattr(self, "_tw_log_vtgt_every", 0) > 0: # TASKWALK_LOG_VTGT_EVERY: the drawn commands, once per N windows (task_walk_env)
|
|
637
|
+
self._tw_log_vtgt()
|
|
638
|
+
if getattr(self, "_tw_sterm_frac", 0.0) > 0.0: # M4: the speed-shortfall terminations so far, once per N windows (task_walk_env)
|
|
639
|
+
self._tw_sterm_log()
|
|
640
|
+
if getattr(self, "_tw_tlog", None) is not None: # TASKWALK_LOG_TERMINALS: the terminal census, once per N windows (task_walk_env)
|
|
641
|
+
self._tw_term_log()
|
|
642
|
+
if self.taskwalk is not None:
|
|
643
|
+
self.taskwalk.detach_history() # TASKWALK_COM_RATE_COUPLED holds last step's COM attached
|
|
644
|
+
# TASKWALK_LCE_DOT_COUPLED holds last step's `lce` attached (task_walk_env.py); the previous window's graph
|
|
645
|
+
# is gone, so drop it here. Ported from GpuMyoLeg26VecEnv.initialize_trajectory (reachable on the full
|
|
646
|
+
# body since bca8fe36 let the metabolic / knee-load terms build their MTU table).
|
|
647
|
+
if getattr(self, "_tw_lce_prev_graph", None) is not None:
|
|
648
|
+
self._tw_lce_prev_graph = None
|
|
649
|
+
if getattr(self, "_tw_fs", None) is not None:
|
|
650
|
+
# TASKWALK_FOOTSTEPS caches the task state at the reward call, in the graph of the window just cut
|
|
651
|
+
self._tw_fs_obs = self._tw_fs_obs.detach()
|
|
652
|
+
return self._obs()
|
|
653
|
+
|
|
654
|
+
def _tw_foot_fz(self):
|
|
655
|
+
"""(right, left) (n,): each leg's summed vertical contact force (N), the signal of the mirror latch (> MIRROR_F_ON) and of
|
|
656
|
+
the footstep plan's strikes (> TASKWALK_FOOTSTEP_STRIKE_N)."""
|
|
657
|
+
with torch.no_grad():
|
|
658
|
+
_, cf = self.sim.contact_force(self.q.detach(), self.qd.detach(), self.z.detach())
|
|
659
|
+
fz = cf.reshape(self.ncon, 3, -1)[:, 2, :]
|
|
660
|
+
return fz[self._mir_r].sum(0), fz[self._mir_l].sum(0)
|
|
661
|
+
|
|
662
|
+
def _mirror_down(self):
|
|
663
|
+
"""(right, left) (n,) bool: the mirror latch's per-foot contact, each leg's summed vertical contact force above MIRROR_F_ON (the
|
|
664
|
+
footstep plan reads _tw_foot_fz itself). env14's E0_ENV14_KINLATCH replaces it with the D16 law's own contact set (kin_contact14)."""
|
|
665
|
+
fz_r, fz_l = self._tw_foot_fz()
|
|
666
|
+
return fz_r > self.MIRROR_F_ON, fz_l > self.MIRROR_F_ON
|
|
667
|
+
|
|
668
|
+
def _init_mirror(self, num_envs, device):
|
|
669
|
+
"""Canonical-frame L/R symmetry (Park et al. `use_symmetry`), DEFAULT OFF.
|
|
670
|
+
|
|
671
|
+
Ported from GpuMyoLeg26VecEnv, which had it while this env did not -- so DN_MIRROR_SYM was
|
|
672
|
+
SILENTLY IGNORED here, and the full-body policies walk with the trunk yawed to one side. It is on in
|
|
673
|
+
every one of the reference implementation's five configs: a premise, not an ablation.
|
|
674
|
+
|
|
675
|
+
Two things differ from myoleg26's copy. The obs layout drops q[0:2] (absolute x AND y), so the
|
|
676
|
+
mirror's q-block skips two leading entries instead of one. And the action is LATENT: every full-body
|
|
677
|
+
run that walks emits into the 32-dim SVD basis, which the mirror handles rather than forbids (see
|
|
678
|
+
MirrorSymmetry._latent_mirror -- P V = V T with T an exact signed permutation on a --symmetrize'd
|
|
679
|
+
basis, so the reduction and the symmetry prior compose).
|
|
680
|
+
"""
|
|
681
|
+
self.mirror = None
|
|
682
|
+
if not bool(int(os.environ.get("DN_MIRROR_SYM", "0"))):
|
|
683
|
+
if getattr(self, "_tw_fs", None) is not None:
|
|
684
|
+
self._init_foot_split(device) # an unmirrored footstep policy (the clock's) still reads each foot's contact
|
|
685
|
+
return
|
|
686
|
+
# The mirror is a heel-strike latch on obs and action, not a phase shift, but under imitation the reward
|
|
687
|
+
# still tracks the UNMIRRORED clip. That is consistent only when the mirrored reference equals the
|
|
688
|
+
# reference half a cycle away -- a property of a symmetric gait loop, not of a whole take that turns,
|
|
689
|
+
# stops and jumps. (A taskwalk run that uses the clip only as an RSI state sampler is unaffected.)
|
|
690
|
+
assert not (self.imitation and self.imitation_task.any_nonloop), (
|
|
691
|
+
"DN_MIRROR_SYM with imitation of a whole clip (loop=False): the canonical-frame mirror relies on "
|
|
692
|
+
"the reference being left/right symmetric under a half-cycle shift")
|
|
693
|
+
from diffneusim.rl.dynsyn_layer import LinearBasisExpander
|
|
694
|
+
from diffneusim.rl.mirror_symmetry import MirrorSymmetry
|
|
695
|
+
# A LINEAR action basis (DN_SVD_BASIS) still mirrors: --symmetrize makes span(V) invariant under
|
|
696
|
+
# the muscle permutation, so the mirror acts on the LATENT action as a signed permutation
|
|
697
|
+
# (MirrorSymmetry._latent_mirror, which verifies it). A DynSyn BIN grouping has no such matrix.
|
|
698
|
+
basis = None
|
|
699
|
+
if self.DYNSYN:
|
|
700
|
+
assert isinstance(self.dynsyn, LinearBasisExpander), (
|
|
701
|
+
"DN_MIRROR_SYM mirrors PER-MUSCLE actions; a DynSyn bin grouping gives the policy a "
|
|
702
|
+
"latent action with no mirror map. Use DN_SVD_BASIS (a linear basis does have one) or "
|
|
703
|
+
"turn the grouping off")
|
|
704
|
+
basis = self.dynsyn.V
|
|
705
|
+
blocks = ["q", "qd", "lce"] + (["scalar"] if self.taskwalk is not None else []) \
|
|
706
|
+
+ (["heading"] if getattr(self, "_tw_heading_on", False) else []) \
|
|
707
|
+
+ (["footstep"] if getattr(self, "_tw_fs", None) is not None else []) \
|
|
708
|
+
+ (["scalar"] if getattr(self, "_tw_phase_obs", False) else []) # the step phase: mirror-invariant
|
|
709
|
+
self.mirror = MirrorSymmetry(str(self.model), num_envs, device, tuple(blocks), n_drop_q=2,
|
|
710
|
+
act_basis=basis)
|
|
711
|
+
assert self.mirror.n_obs == self.num_obs, (self.mirror.n_obs, self.num_obs)
|
|
712
|
+
self._init_foot_split(device)
|
|
713
|
+
|
|
714
|
+
def _init_foot_split(self, device):
|
|
715
|
+
"""The contact spheres of each foot (_mir_r / _mir_l) and the latch's level (MIRROR_F_ON): the mirror latch's and the
|
|
716
|
+
footstep plan's strike signal, and TASKWALK_CONTACT_OBS's flags."""
|
|
717
|
+
from diffneusim.model.monitor import DnModelMonitor
|
|
718
|
+
if not hasattr(self, "_monitor"):
|
|
719
|
+
self._monitor = DnModelMonitor(str(self.model), device=device)
|
|
720
|
+
spec = self._tw_spec if hasattr(self, "_tw_spec") else None
|
|
721
|
+
rb = set(spec.right_bodies) if spec is not None and spec.right_bodies else None
|
|
722
|
+
assert rb, "the mirror latch needs the taskwalk spec's right_bodies to split the contact spheres"
|
|
723
|
+
# LEFT = the declared contact bodies minus the right ones, NOT "everything that is not right": a
|
|
724
|
+
# non-foot contact sphere (torso, hand) would otherwise be counted as a left-foot strike.
|
|
725
|
+
lb = set(spec.contact_bodies) - rb
|
|
726
|
+
cb = [int(b) for b in self._monitor.contact_body]
|
|
727
|
+
assert set(cb) <= (rb | lb), (
|
|
728
|
+
f"contact spheres on bodies {sorted(set(cb) - (rb | lb))} are in neither foot; the strike latch "
|
|
729
|
+
f"cannot classify them")
|
|
730
|
+
self._mir_r = torch.tensor([i for i, b in enumerate(cb) if b in rb], dtype=torch.long, device=device)
|
|
731
|
+
self._mir_l = torch.tensor([i for i, b in enumerate(cb) if b in lb], dtype=torch.long, device=device)
|
|
732
|
+
assert len(self._mir_r) and len(self._mir_l), (len(self._mir_r), len(self._mir_l))
|
|
733
|
+
self.MIRROR_F_ON = 1.0 # theirs: > 1 N
|
|
734
|
+
|
|
735
|
+
def _obs(self):
|
|
736
|
+
# q[2:] already drops the absolute x,y (translation-invariant). q[3:7] is the root QUATERNION and
|
|
737
|
+
# carries the absolute HEADING, so without DN_YAW_FREE the policy is told which compass direction
|
|
738
|
+
# it faces -- which biases it to the training clips' direction and blocks ever asking for another one.
|
|
739
|
+
# Dividing the heading out leaves roll and pitch, which is what balance actually needs. The reward
|
|
740
|
+
# must agree: the same env var switches the imitation task's task-space terms into the heading frame.
|
|
741
|
+
qobs = self.q[2:]
|
|
742
|
+
if getattr(self, "_tw_obs_h_ground", False): # TASKWALK_OBS_H_ABOVE_GROUND: the height above the plane (through 0) under the root
|
|
743
|
+
n_ = self._tw_normals.to(self.q.dtype)
|
|
744
|
+
qobs = torch.cat([self.q[2:3] + (n_[0:1] * self.q[0:1] + n_[1:2] * self.q[1:2]) / n_[2:3], qobs[1:]], dim=0)
|
|
745
|
+
obs = torch.cat([qobs.t(), self.qd.t(), self.lce.t()], dim=1)
|
|
746
|
+
if self.imitation and self.imitation_task is not None: # opt-in (sin,cos) phase clock, else obs unchanged (bit-parity)
|
|
747
|
+
extra = self.imitation_task.phase_obs(self.phase)
|
|
748
|
+
if extra is not None:
|
|
749
|
+
obs = torch.cat([obs, extra], dim=1)
|
|
750
|
+
cond = self.imitation_task.cond_obs(obs.shape[0]) # (v_fwd, cadence) of this env's clip
|
|
751
|
+
if cond is not None:
|
|
752
|
+
obs = torch.cat([obs, cond], dim=1)
|
|
753
|
+
if self.imitation_task.IM_MIMIC: # reference-only, so no gradient path: MuscleMimic's goal
|
|
754
|
+
obs = torch.cat([obs, self.imitation_task.mimic_goal_obs(self.phase)], dim=1)
|
|
755
|
+
if self.taskwalk is not None:
|
|
756
|
+
# the COMMANDED speed. The paper's policy is speed-conditioned (its curriculum sweeps
|
|
757
|
+
# 0.7-1.5 m/s), so the target has to be observable or the task is partially unobservable.
|
|
758
|
+
obs = torch.cat([obs, self.taskwalk.v_tgt[:, None]], dim=1)
|
|
759
|
+
if self._tw_heading_on: # TASKWALK_HEADING: (sin, cos) of the heading error
|
|
760
|
+
obs = torch.cat([obs, self._tw_heading_obs()], dim=1)
|
|
761
|
+
if getattr(self, "_tw_fs", None) is not None: # TASKWALK_FOOTSTEPS: the two footstep targets (heading frame)
|
|
762
|
+
obs = torch.cat([obs, self._tw_fs_obs_out().to(obs.dtype)], dim=1) # by role, or per foot (OBS_SIDES)
|
|
763
|
+
if getattr(self, "_tw_phase_obs", False): # TASKWALK_STEP_PHASE_OBS: the step clip's phase
|
|
764
|
+
assert getattr(self, "_tw_steplib", None) is not None, "the step phase is the step library clip's"
|
|
765
|
+
obs = torch.cat([obs, (self._tw_fs.t / self._tw_sl_T).clamp(0.0, 1.0)[:, None].to(obs.dtype)], dim=1)
|
|
766
|
+
if self._tw_contact_obs: # TASKWALK_CONTACT_OBS: the feet's contact flags
|
|
767
|
+
obs = torch.cat([obs, self._tw_contact_flags().to(obs.dtype)], dim=1)
|
|
768
|
+
if getattr(self, "_tw_fs", None) is not None and self._tw_cyc_bins:
|
|
769
|
+
# TASKWALK_CYCLE_PHASE_BINS: the clock's cycle phase and its one-hot bins, LAST (phase_gate_bins names the bins' slots)
|
|
770
|
+
obs = torch.cat([obs, self._tw_cycle_phase_obs().to(obs.dtype)], dim=1)
|
|
771
|
+
if self.mirror is not None:
|
|
772
|
+
obs = self.mirror.obs(obs) # LAST: the policy sees the canonical frame, nothing else does
|
|
773
|
+
return obs
|
|
774
|
+
|
|
775
|
+
def latent_ref_obs(self):
|
|
776
|
+
"""The posterior's next-reference block for the CURRENT state and phase, (n, num_ref_obs). Call it right after
|
|
777
|
+
reset() / initialize_trajectory() / step(), beside the observation they return (after an autoreset it already
|
|
778
|
+
describes the new episode). DN_LATENT only."""
|
|
779
|
+
assert self.LATENT, "latent_ref_obs needs DN_LATENT=1"
|
|
780
|
+
return self._latent_ref_features(self.q, self.phase)
|
|
781
|
+
|
|
782
|
+
def latent_task_obs(self):
|
|
783
|
+
"""The task policy's command block for the CURRENT state and command, (n, 3): [v*, cos, sin] of the commanded
|
|
784
|
+
heading relative to the root's (latent_task.HeadingSpeedTask.obs), in the graph through the root. Call it right
|
|
785
|
+
after reset() / initialize_trajectory() / step(), beside the observation they return (after an autoreset it
|
|
786
|
+
already holds the new episode's command). DN_LATENT_TASK only."""
|
|
787
|
+
assert self.latent_task is not None, "latent_task_obs needs DN_LATENT_TASK=1"
|
|
788
|
+
return self.latent_task.obs(self.q)
|
|
789
|
+
|
|
790
|
+
def latent_task_stats(self):
|
|
791
|
+
"""Means of the task's heading error (deg), speed error (m/s) and L_g over the env steps since the last call (one
|
|
792
|
+
host read: the trainer calls it once per epoch). DN_LATENT_TASK only."""
|
|
793
|
+
assert self.latent_task is not None, "latent_task_stats needs DN_LATENT_TASK=1"
|
|
794
|
+
return self.latent_task.pop_stats()
|
|
795
|
+
|
|
796
|
+
def _latent_ref_features(self, q, phase):
|
|
797
|
+
"""The reference frame the reward scores after the NEXT control step (phase advanced one step, as step() does
|
|
798
|
+
before its reward), expressed so it is invariant to world position and heading:
|
|
799
|
+
|
|
800
|
+
ref joint coordinates q~[7:] (nq - 7) frame-free already
|
|
801
|
+
ref joint velocities qd~[6:] (nv - 6)
|
|
802
|
+
ref root height minus the current one 1
|
|
803
|
+
ref root orientation in the current root frame 6 conj(q_root) (x) q~_root, the first two
|
|
804
|
+
columns of its rotation matrix (the 6D form)
|
|
805
|
+
ref root linear and angular velocity in the 3 + 3 qd~[3:6], qd~[0:3] are body-frame ([w_body;
|
|
806
|
+
current root frame v_body]), so R(q_rel) maps them over
|
|
807
|
+
|
|
808
|
+
DEVIATION, stated: ControlVAE's target is the reference state in ITS OWN root frame (state2ob of the reference).
|
|
809
|
+
Here the root block is relative to the CURRENT root, so the posterior also sees the heading and tilt error that
|
|
810
|
+
this env's tracking reward prices (the pose term compares the root quaternion itself). The root's horizontal
|
|
811
|
+
offset is left out on purpose: no reward term reads the absolute root xy (Morphology.build excludes it), so it
|
|
812
|
+
would only be an unbounded drift input. In the graph through `q` (the reference itself is a constant)."""
|
|
813
|
+
t = self.imitation_task
|
|
814
|
+
nxt, _ = t.advance_phase(phase, self.SUBSTEPS * self.dt)
|
|
815
|
+
q_ref, qd_ref = t.ref_at(nxt) # (nq, n), (nv, n)
|
|
816
|
+
qc = q[3:7]
|
|
817
|
+
q_rel = _quat_mul(torch.stack((qc[0], -qc[1], -qc[2], -qc[3]), 0), q_ref[3:7])
|
|
818
|
+
w, x, y, z = q_rel[0], q_rel[1], q_rel[2], q_rel[3]
|
|
819
|
+
rot6 = torch.stack((1 - 2 * (y * y + z * z), 2 * (x * y + w * z), 2 * (x * z - w * y), # R[:, 0]
|
|
820
|
+
2 * (x * y - w * z), 1 - 2 * (x * x + z * z), 2 * (y * z + w * x)), 0) # R[:, 1]
|
|
821
|
+
return torch.cat([q_ref[7:], qd_ref[6:], q_ref[2:3] - q[2:3], rot6,
|
|
822
|
+
_quat_rotate(q_rel, qd_ref[3:6]), _quat_rotate(q_rel, qd_ref[0:3])], 0).t()
|
|
823
|
+
def slope_slots(self):
|
|
824
|
+
"""The state blocks the observation carries as RAW coordinates, for the critic-slope term (SAPO_CRITIC_SLOPE_W): a list of
|
|
825
|
+
(state attr, first row, obs slot, length) in the pre-mirror layout of _obs. q[2:] comes first with the root quaternion
|
|
826
|
+
q[3:7] (or its yaw-free form, also 4 values) in slots 1-4, so the joint angles q[7:] sit at slot 5, then qd, then lce. The
|
|
827
|
+
task observations after them depend on the state only through the root. Checked against _obs on the envs the mirror has
|
|
828
|
+
not flipped, and the mirror's signed permutation must map the slot set onto itself."""
|
|
829
|
+
nq, nv, nm = self.q.shape[0], self.qd.shape[0], self.lce.shape[0]
|
|
830
|
+
slots = [("q", 7, 5, nq - 7), ("qd", 0, nq - 2, nv), ("lce", 0, nq - 2 + nv, nm)]
|
|
831
|
+
with torch.no_grad():
|
|
832
|
+
o = self._obs()
|
|
833
|
+
keep = torch.ones(self.num_envs, dtype=torch.bool, device=o.device) if self.mirror is None else ~self.mirror.flipped
|
|
834
|
+
assert bool(keep.any()), "every env is mirrored: the layout check needs one that is not"
|
|
835
|
+
for attr, r0, s0, n in slots:
|
|
836
|
+
x = getattr(self, attr)[r0:r0 + n].t()
|
|
837
|
+
assert torch.equal(o[keep, s0:s0 + n], x[keep].to(o.dtype)), f"slope slot {attr} is not at obs[{s0}:{s0 + n}]"
|
|
838
|
+
if self.mirror is not None:
|
|
839
|
+
idx = torch.cat([torch.arange(s0, s0 + n) for _, _, s0, n in slots]).to(self.mirror.obs_idx.device)
|
|
840
|
+
assert set(self.mirror.obs_idx[idx].tolist()) == set(idx.tolist()), "the mirror maps a raw slot outside the slot set"
|
|
841
|
+
assert bool((self.mirror.obs_sgn.abs() == 1).all()), "the mirror is not a signed permutation"
|
|
842
|
+
return slots
|
|
843
|
+
|
|
844
|
+
def slope_obs_flip(self):
|
|
845
|
+
"""The mirror's per-env flip for the observation just built (None without the mirror)."""
|
|
846
|
+
return None if self.mirror is None else self.mirror.flipped.clone()
|
|
847
|
+
|
|
848
|
+
def slope_to_obs(self, g, flipped):
|
|
849
|
+
"""A gradient in the pre-mirror obs layout (n_env, n_obs) -> the layout the critic sees. The mirror is a signed permutation
|
|
850
|
+
P (o = P f), orthogonal, so a slope target t_f on f becomes P t_f on o, the same map as the observation's."""
|
|
851
|
+
if self.mirror is None:
|
|
852
|
+
return g
|
|
853
|
+
m = g[:, self.mirror.obs_idx] * self.mirror.obs_sgn
|
|
854
|
+
return torch.where(flipped[:, None], m, g)
|
|
855
|
+
|
|
856
|
+
def _upright(self):
|
|
857
|
+
# world-z component of the torso up-axis from root quaternion (w,x,y,z) = R[2,2] = 1-2(x^2+y^2)
|
|
858
|
+
qx, qy = self.q[4], self.q[5]
|
|
859
|
+
return 1.0 - 2.0 * (qx * qx + qy * qy)
|
|
860
|
+
|
|
861
|
+
def _forward_vx(self):
|
|
862
|
+
# Anatomical FORWARD (anterior) velocity, body-frame -> heading-invariant. Since issue #29 baked
|
|
863
|
+
# the +x-forward convention into the model (the pelvis offset now maps local-x = anterior to
|
|
864
|
+
# +world-x), the anterior direction in the free-joint (body-1) frame is constant [1,0,0], so the
|
|
865
|
+
# forward speed is v_body . [1,0,0] = qd[3]. (Before #29 the model faced -y and this was -qd[4].)
|
|
866
|
+
return self.qd[3]
|
|
867
|
+
|
|
868
|
+
def pop_pd_stats(self):
|
|
869
|
+
"""musclepd: the share of muscle-substeps since the last call with f_pd = 0 (the servo slack), A clipped at 0 or at 1 --
|
|
870
|
+
the substeps through which the PD layer passes no gradient to the policy -- then reset the counters."""
|
|
871
|
+
n = max(self._pd_stats_n, 1)
|
|
872
|
+
out = {k: v / n for k, v in self._pd_stats_sum.items()}
|
|
873
|
+
self._pd_stats_sum, self._pd_stats_n = {k: 0.0 for k in self._pd_stats_sum}, 0
|
|
874
|
+
return out
|
|
875
|
+
|
|
876
|
+
def _act_to_excitation(self, actions):
|
|
877
|
+
assert actions.shape == (self.num_envs, self.nm), actions.shape # per-muscle (post-DynSyn expand)
|
|
878
|
+
# map [-1,1] -> [0, A_MAX]; cap keeps SHAC inside the numerically-stable activation regime
|
|
879
|
+
return (0.5 * self.A_MAX * (actions.t().contiguous() + 1.0)).clamp_(0.0, self.A_MAX).contiguous()
|
|
880
|
+
|
|
881
|
+
def _im_ankle_moment_reference(self):
|
|
882
|
+
"""THE REFERENCE (test only, 2026-10-09): the first, per-sphere loop with its own FK pass; training uses
|
|
883
|
+
ImitationTask.ankle_moment, which must equal this to float roundoff (checked by a separate ankle-moment check).
|
|
884
|
+
Per-foot ankle moment the ground reaction demands, IN the graph, N.m/kg, + = plantarflexion, (2, n) [right, left]:
|
|
885
|
+
sum over the foot's contact spheres of (x_i - x_a) F_z,i - (z_i - z_a) F_x,i, with the force the engine applies at the
|
|
886
|
+
sphere's ground point (centre - radius along the ground normal) and x_a, z_a the talus origin (the ankle centre).
|
|
887
|
+
DN_IM_WANK's simulated side (imitation.py)."""
|
|
888
|
+
from diffneusim.model.monitor import _quat_rotate
|
|
889
|
+
mon = self._monitor
|
|
890
|
+
if getattr(self, "_im_ank_spec", None) is None:
|
|
891
|
+
names = [b["name"] for b in mon.jm["bodies"]]
|
|
892
|
+
cb = [names[int(b)] for b in mon.contact_body]
|
|
893
|
+
assert all(n.startswith(("calcn_", "toes_")) for n in cb), ("foot-only contact set expected", cb)
|
|
894
|
+
assert len(cb) == self.ncon, (len(cb), self.ncon)
|
|
895
|
+
self._im_ank_spec = [([i for i, n in enumerate(cb) if n.endswith(s)], names.index(f"talus{s}")) for s in ("_r", "_l")]
|
|
896
|
+
self._im_ank_mass = float(sum(float(b.get("mass", 0.0)) for b in mon.jm["bodies"]))
|
|
897
|
+
cf = _bridge.contact_force_gpu(self.q, self.qd, self.z, self.sim.path).reshape(self.ncon, 3, -1)
|
|
898
|
+
bodies = sorted({int(mon.contact_body[i]) for gi, _ in self._im_ank_spec for i in gi} | {t for _, t in self._im_ank_spec})
|
|
899
|
+
pos, quat, _ = mon.body_poses_subset(self.q, bodies, False)
|
|
900
|
+
nrm = mon.ground_normal
|
|
901
|
+
out = []
|
|
902
|
+
for gi, ta in self._im_ank_spec:
|
|
903
|
+
pa = pos[ta]
|
|
904
|
+
m = torch.zeros_like(pa[0])
|
|
905
|
+
for i in gi:
|
|
906
|
+
b = int(mon.contact_body[i])
|
|
907
|
+
c = mon.contact_center[i].to(dtype=self.q.dtype, device=self.q.device)[:, None].expand(3, self.q.shape[1])
|
|
908
|
+
p = pos[b] + _quat_rotate(quat[b], c)
|
|
909
|
+
px = p[0] - float(nrm[0]) * mon.contact_radius[i]
|
|
910
|
+
pz = p[2] - float(nrm[2]) * mon.contact_radius[i]
|
|
911
|
+
m = m + (px - pa[0]) * cf[i, 2] - (pz - pa[2]) * cf[i, 0]
|
|
912
|
+
out.append(m / self._im_ank_mass)
|
|
913
|
+
return torch.stack(out)
|
|
914
|
+
|
|
915
|
+
def _reward(self, a_mean, x_prev, q_prev=None):
|
|
916
|
+
if self.latent_task is not None:
|
|
917
|
+
# The latent model's task phase (DN_LATENT_TASK): ALIVE - L_g, MuscleVAE's heading task, against the
|
|
918
|
+
# command this step's action was chosen under. Checked BEFORE the imitation branch, which it replaces: the
|
|
919
|
+
# clips only seed the episodes.
|
|
920
|
+
return self.latent_task.reward(self.q, self.qd)
|
|
921
|
+
if self.taskwalk is not None:
|
|
922
|
+
# Reference-free task walking (arXiv:2603.04166 eq. 3). Checked BEFORE the imitation branch so
|
|
923
|
+
# the two are mutually exclusive by construction: mixing a tracking reward with this one would
|
|
924
|
+
# make any result uninterpretable as evidence about either.
|
|
925
|
+
return self._tw_reward(a_mean, self.SUBSTEPS * self.dt)
|
|
926
|
+
if self.imitation:
|
|
927
|
+
# DeepMimic tracking (pose/vel/feet/com), differentiable in q,qd. upright = the env's own
|
|
928
|
+
# R[2,2] torso-up term (only used if IM_UPRIGHT_W>0; the tracking reward is frame-agnostic).
|
|
929
|
+
grf_z = None
|
|
930
|
+
cf_all = None
|
|
931
|
+
if self.imitation_task.IM_WGRF > 0.0 or self.imitation_task.IM_WANK > 0.0:
|
|
932
|
+
cf_all = _bridge.contact_force_gpu(self.q, self.qd, self.z, self.sim.path).reshape(self.ncon, 3, -1)
|
|
933
|
+
if self.imitation_task.IM_WGRF > 0.0:
|
|
934
|
+
# per-foot VERTICAL ground reaction in body weights, IN the graph (the term's pathwise gradient), from the
|
|
935
|
+
# engine's own contact force at the post-step state; the foot of each contact sphere from its body's name
|
|
936
|
+
if getattr(self, "_im_grf_idx", None) is None:
|
|
937
|
+
names = [b["name"] for b in self._monitor.jm["bodies"]]
|
|
938
|
+
cb = [names[int(b)] for b in self._monitor.contact_body]
|
|
939
|
+
assert all(n.startswith(("calcn_", "toes_")) for n in cb), ("foot-only contact set expected", cb)
|
|
940
|
+
self._im_grf_idx = [torch.tensor([i for i, n in enumerate(cb) if n.endswith(s)], dtype=torch.long,
|
|
941
|
+
device=self.device) for s in ("_r", "_l")]
|
|
942
|
+
self._im_bw = 9.81 * float(sum(float(b.get("mass", 0.0)) for b in self._monitor.jm["bodies"]))
|
|
943
|
+
grf_z = torch.stack([cf_all[i, 2, :].sum(0) for i in self._im_grf_idx]) / self._im_bw
|
|
944
|
+
return self.imitation_task.reward(self.q, self.qd, a_mean, self.phase, self._prev_phase,
|
|
945
|
+
self._h_prev, x_prev, self._upright(), self.SUBSTEPS * self.dt,
|
|
946
|
+
train_steps=self._train_steps, foot_grf_z=grf_z, # effort-price anneal
|
|
947
|
+
foot_contact_f=cf_all if self.imitation_task.IM_WANK > 0.0 else None,
|
|
948
|
+
q_prev=q_prev)
|
|
949
|
+
progress = self._forward_vx() # world-frame forward (x) velocity (the lever)
|
|
950
|
+
upright = self._upright()
|
|
951
|
+
alive = torch.ones_like(progress)
|
|
952
|
+
effort = (a_mean ** 2).t().sum(dim=1)
|
|
953
|
+
return self.VX_W * progress + self.UP_W * upright + self.ALIVE_W * alive - self.CTRL_COST * effort
|
|
954
|
+
|
|
955
|
+
def step(self, actions):
|
|
956
|
+
"""One control step: (obs, rew, done, extra), obs after the resets. Three parts, in this order (CAPTURE_PLAN.md P2 (iii);
|
|
957
|
+
the same operations as the single method they were split from): _step_a, the action through the physics and
|
|
958
|
+
_post_physics up to `done` (no host read in the configuration); _step_reset, the reference switch and the resets (the step's one host read,
|
|
959
|
+
done.nonzero()); _step_obs, the post-reset observation."""
|
|
960
|
+
rew, done, extra, switching, switch_at, timeout = self._step_a(actions)
|
|
961
|
+
self._step_reset(done, extra, switching, switch_at, timeout)
|
|
962
|
+
return self._step_obs(), rew, done, extra
|
|
963
|
+
|
|
964
|
+
def _step_a(self, actions):
|
|
965
|
+
"""step()'s first part: the action through the physics, the phase advance and _post_physics, up to `done`. No host read in
|
|
966
|
+
the configuration (the opt-in DN_IM_ACT_WARMSTART reads one). Returns _post_physics' (rew, done, extra, switching, switch_at, timeout)."""
|
|
967
|
+
if getattr(self, "_exc_k", None) is not None: # TASKWALK_EXC_NOISE_SD > 0 (task_walk_env.set_exc_noise): the action + N(0, sd^2),
|
|
968
|
+
actions = self._tw_exc_noise(actions) # clamped to [-1, 1], before anything reads it (xeval_cpu --action-noise's order)
|
|
969
|
+
self.actions = actions
|
|
970
|
+
self._lce_prev = self.lce.detach() # OBS_AUG: pre-step fiber length -> l_ce_dot in _obs
|
|
971
|
+
x_prev0 = self.q[ROOT_FWD] # pre-step forward pos (world x; imitation task term)
|
|
972
|
+
q_prev0 = self.q # pre-step state, in the graph (DN_IM_RECON's velocities)
|
|
973
|
+
if self.imitation:
|
|
974
|
+
self._h_prev = self.q[ROOT_HEIGHT].clone() # pre-step root height (imitation anti-sink term)
|
|
975
|
+
# The policy speaks in the canonical frame; put its action back on the physical muscles. The mirror
|
|
976
|
+
# is an involution, so the same call serves both directions.
|
|
977
|
+
act_full = self.mirror.action(actions) if self.mirror is not None else actions
|
|
978
|
+
# DynSyn: expand k-dim per-group action -> nm per-muscle excitation (off => unchanged, byte-identical)
|
|
979
|
+
act_full = self.dynsyn.expand(act_full) if self.DYNSYN else act_full
|
|
980
|
+
if self.decision_every > 1:
|
|
981
|
+
# Amendment 16: a held step applies the previous step's applied action, the same tensor values (its noise included); the
|
|
982
|
+
# held tensor stays in the graph, so the held step's reward reaches the decision's action through BPTT. A device mask, no
|
|
983
|
+
# host read: capture-safe (the window carries _dr_held as extra state).
|
|
984
|
+
assert self._dr_held.shape == act_full.shape, (tuple(self._dr_held.shape), tuple(act_full.shape)) # static shapes, no sync
|
|
985
|
+
hold = (self.progress % self.decision_every) != 0
|
|
986
|
+
act_full = torch.where(hold[:, None], self._dr_held, act_full)
|
|
987
|
+
# TASKWALK_DECISION_DIAG=detach_held: a GATE DIAGNOSTIC only (11-23 17:0x, G2 (ii)'s first-replay backward difference):
|
|
988
|
+
# the held tensor carries no gradient into the next step (train_tw14 refuses it outside D16_TW_DIAG=decision_gate)
|
|
989
|
+
self._dr_held = act_full
|
|
990
|
+
u = self._act_to_excitation(act_full)
|
|
991
|
+
if self.taskwalk is not None:
|
|
992
|
+
# The reward's `excitation` argument. Never assigned before 2026-09-26, so every reader got
|
|
993
|
+
# the zeros `_tw_setup` allocates: the metabolic model ran with u = 0 and the action-rate term
|
|
994
|
+
# was identically 0 in every cell that set either weight.
|
|
995
|
+
self._tw_last_u = u
|
|
996
|
+
tau = torch.zeros(self.nv, self.num_envs, dtype=torch.float32, device=self.device)
|
|
997
|
+
if self.ext_tau is not None:
|
|
998
|
+
assert self.ext_tau.shape == tau.shape and not self.ext_tau.requires_grad, (tuple(self.ext_tau.shape), tuple(tau.shape))
|
|
999
|
+
tau = self.ext_tau.to(tau.dtype).contiguous()
|
|
1000
|
+
if getattr(self, "_tw_xtau", None) is not None: # TASKWALK_EXPLORE_TAU (task_walk_env): training-only joint-torque kicks
|
|
1001
|
+
xt = self._tw_explore_tau()
|
|
1002
|
+
if xt is not None:
|
|
1003
|
+
tau = (tau + xt.to(tau.dtype)).contiguous()
|
|
1004
|
+
srv = self._tw_explore_servo_begin() if getattr(self, "_tw_xsrv", None) is not None else None # TASKWALK_EXPLORE_SERVO
|
|
1005
|
+
a = self.a
|
|
1006
|
+
a_sum = torch.zeros_like(a)
|
|
1007
|
+
if self.musclepd is not None:
|
|
1008
|
+
a_pd = act_full.t().contiguous() # (nm, n): the policy's per-muscle action, the PD target's a
|
|
1009
|
+
lce_sub_prev = self._pd_lce_prev
|
|
1010
|
+
for _ in range(self.SUBSTEPS):
|
|
1011
|
+
if self.musclepd is not None: # MuscleVAE's PD servo -> A at this substep's fibre state
|
|
1012
|
+
a, st = self.musclepd.activation(a_pd, self.lce, lce_sub_prev, self.dt)
|
|
1013
|
+
for k, v in st.items():
|
|
1014
|
+
self._pd_stats_sum[k] += v
|
|
1015
|
+
self._pd_stats_n += 1
|
|
1016
|
+
lce_sub_prev = self.lce
|
|
1017
|
+
else:
|
|
1018
|
+
a = self._activation(u, a, self.dt) # excitation -> activation (== mtu_activation_gpu)
|
|
1019
|
+
a_sum = a_sum + a
|
|
1020
|
+
tau_s = tau if srv is None else (tau + self._tw_explore_servo_tau(srv).to(tau.dtype)).contiguous()
|
|
1021
|
+
self.q, self.qd, self.lce, self.z = self.sim.step( # f_ext production step (== mtu_step_gpu)
|
|
1022
|
+
self.q, self.qd, tau=tau_s, lce=self.lce, A=a, z=self.z, dt=self.dt)
|
|
1023
|
+
if self.musclepd is not None:
|
|
1024
|
+
# Kept IN THE GRAPH across control steps (detached with the window in clear_grad / detach_envs): the next step's first
|
|
1025
|
+
# substep reads it in its rate, and through f_v that rate sets A. Detached (as until 10-28), the analytic gradient carried
|
|
1026
|
+
# the rate's l_ce side and not its l_ce_prev side, a biased gradient (docs/logs/bug-grad-audits.md 2026-09-28's rule).
|
|
1027
|
+
self._pd_lce_prev = lce_sub_prev
|
|
1028
|
+
self.a = a
|
|
1029
|
+
self.progress = self.progress + 1
|
|
1030
|
+
self._train_steps += 1 # monotonic step() counter (imitation desync-anneal)
|
|
1031
|
+
if getattr(self, "_tw_track", False) and self._tw_track_phase == "clock":
|
|
1032
|
+
# the tracking arm: the clip's rate x the human cadence ratio at each env's command
|
|
1033
|
+
self.phase = (self.phase + self._tw_trk_ratio() * (self.SUBSTEPS * self.dt) / self.imitation_task.ref_secs) % 1.0
|
|
1034
|
+
elif getattr(self, "_tw_track", False) and self._tw_track_phase == "heel":
|
|
1035
|
+
# heel-anchored: the previous step's right-foot vertical GRF (the reward's own reading) marks the strikes
|
|
1036
|
+
with torch.no_grad():
|
|
1037
|
+
dtc = self.SUBSTEPS * self.dt
|
|
1038
|
+
T_ref = self.imitation_task.ref_secs / self._tw_trk_ratio()
|
|
1039
|
+
if self._tw_trk_grf is not None:
|
|
1040
|
+
ld = self._tw_trk_grf[0] > 0.2
|
|
1041
|
+
strike = ld & ~self._tw_trk_prev_ld & (self._tw_trk_t > 0.35 * T_ref)
|
|
1042
|
+
T_new = torch.minimum(torch.maximum(self._tw_trk_t, 0.7 * T_ref), 1.4 * T_ref)
|
|
1043
|
+
self._tw_trk_T = torch.where(strike, T_new, self._tw_trk_T)
|
|
1044
|
+
self._tw_trk_t = torch.where(strike, torch.zeros_like(self._tw_trk_t), self._tw_trk_t)
|
|
1045
|
+
self._tw_trk_prev_ld = ld
|
|
1046
|
+
self._tw_trk_t = self._tw_trk_t + dtc
|
|
1047
|
+
self.phase = (self._tw_trk_phi_rhs + (self._tw_trk_t / self._tw_trk_T).clamp(max=0.999)) % 1.0
|
|
1048
|
+
wrapped = None
|
|
1049
|
+
if self.imitation:
|
|
1050
|
+
# Advance phase in lockstep BEFORE the reward so the tracking reward scores the POST-step
|
|
1051
|
+
# state q_{t+1} against ref(phi_{t+1}). The env owns phase/_prev_phase (the task is stateless).
|
|
1052
|
+
# Outside _post_physics (M4c): the phase carries across steps, so it stays eager and exact.
|
|
1053
|
+
prev_phase = self.phase
|
|
1054
|
+
self.phase, wrapped = self.imitation_task.advance_phase(self.phase, self.SUBSTEPS * self.dt)
|
|
1055
|
+
self._prev_phase = prev_phase
|
|
1056
|
+
post = self._post_physics
|
|
1057
|
+
return post(a_sum, x_prev0, q_prev0, wrapped)
|
|
1058
|
+
|
|
1059
|
+
def _step_reset(self, done, extra, switching, switch_at, timeout):
|
|
1060
|
+
"""step()'s second part: the reference switch (REF_SWITCH) and the resets of the done envs. done.nonzero() is the step's
|
|
1061
|
+
one host read; the reset's shapes depend on it."""
|
|
1062
|
+
# autoreset=False (fixed-horizon rollouts / CUDA-graph capture) SKIPS the done.nonzero()+reset:
|
|
1063
|
+
# .nonzero() is a host sync (dynamic-size output) that blocks graph capture, and a fixed-horizon
|
|
1064
|
+
# rollout with termination disabled never actually resets. Training keeps autoreset=True (default).
|
|
1065
|
+
if switching:
|
|
1066
|
+
# their after_step: at step_cnt % N == 0 (step_cnt = the steps before this one) or at the clip's end, a new target
|
|
1067
|
+
sw = ~done & (switch_at | (((self.progress - 1) % self.REF_SWITCH == 0) & (self.progress > 1)))
|
|
1068
|
+
ids = sw.nonzero(as_tuple=False).squeeze(-1)
|
|
1069
|
+
if len(ids) > 0:
|
|
1070
|
+
t = self.imitation_task
|
|
1071
|
+
_, _, phi, cid = t.rsi(len(ids), self.rng, False)
|
|
1072
|
+
self.phase = self.phase.clone(); self.phase[ids] = phi
|
|
1073
|
+
t.clip_id = t.clip_id.clone(); t.clip_id[ids] = cid
|
|
1074
|
+
extra["ref_switch"] = sw
|
|
1075
|
+
if getattr(self, "autoreset", True):
|
|
1076
|
+
env_ids = done.nonzero(as_tuple=False).squeeze(-1)
|
|
1077
|
+
if len(env_ids) > 0:
|
|
1078
|
+
if self.taskwalk is not None:
|
|
1079
|
+
# Difficulty feedback BEFORE the reset, which overwrites _tw_env_slope for these envs.
|
|
1080
|
+
# "Fell" is every termination that is not the horizon: a timeout means the episode was
|
|
1081
|
+
# SURVIVED on that slope, and scoring it as a failure would make the curriculum chase
|
|
1082
|
+
# the terrain the policy already handles.
|
|
1083
|
+
self._tw_slope_feedback(env_ids, (~timeout[env_ids]))
|
|
1084
|
+
self._reset_envs(env_ids)
|
|
1085
|
+
|
|
1086
|
+
def _step_obs(self):
|
|
1087
|
+
"""step()'s third part: the observation of the post-reset state"""
|
|
1088
|
+
return self._obs()
|
|
1089
|
+
|
|
1090
|
+
def _post_physics(self, a_sum, x_prev0, q_prev0, wrapped):
|
|
1091
|
+
"""step()'s block between the phase advance and the reset (M4c): the reward, the obs, the finite masks, the
|
|
1092
|
+
termination masks, the desync test and the extra dict. Moved here verbatim; E0_M4C=1 compiles it. `wrapped` is
|
|
1093
|
+
the phase advance's seam flag (None when the env does not imitate)."""
|
|
1094
|
+
|
|
1095
|
+
if getattr(self, "_tw_latch_from_reward", False):
|
|
1096
|
+
# TW1 K2 (off by default; train_tw14 --tw1-k2): the reward's FK of this step's q, the same call _tw_reward makes, hoisted
|
|
1097
|
+
# before the mirror latch so the latch reads its foot poses (detached) instead of running its own eager FK (~900 launches
|
|
1098
|
+
# per step). The reward reuses it, so its value is the same call's; the latch's distances carry the compiled FK's roundoff.
|
|
1099
|
+
self._tw_fk_pre = self._monitor.body_poses_subset(self.q, self._tw_bodies, True)
|
|
1100
|
+
if self.mirror is not None:
|
|
1101
|
+
# phase_detect reads each leg's vertical contact force with a 1 N threshold. Same signal, same
|
|
1102
|
+
# threshold -- and BEFORE _obs(), so the observation the policy gets is already in the frame
|
|
1103
|
+
# this step's strike selected.
|
|
1104
|
+
with torch.no_grad():
|
|
1105
|
+
if getattr(self, "_tw_fs", None) is None:
|
|
1106
|
+
self.mirror.update(*self._mirror_down())
|
|
1107
|
+
else:
|
|
1108
|
+
fz_r, fz_l = self._tw_foot_fz()
|
|
1109
|
+
self.mirror.update(fz_r > self.MIRROR_F_ON, fz_l > self.MIRROR_F_ON)
|
|
1110
|
+
if getattr(self, "_tw_fs", None) is not None: # the footstep plan's strike signal, at its own threshold
|
|
1111
|
+
self._tw_foot_on = (fz_r > self._tw_fs_strike_n, fz_l > self._tw_fs_strike_n)
|
|
1112
|
+
self._tw_foot_off = (fz_r < self._tw_fs_arm_n, fz_l < self._tw_fs_arm_n) # the armed strike's unloading
|
|
1113
|
+
elif getattr(self, "_tw_fs", None) is not None: # unmirrored (the clock's): the same signal without the latch
|
|
1114
|
+
with torch.no_grad():
|
|
1115
|
+
fz_r, fz_l = self._tw_foot_fz()
|
|
1116
|
+
self._tw_foot_on = (fz_r > self._tw_fs_strike_n, fz_l > self._tw_fs_strike_n)
|
|
1117
|
+
self._tw_foot_off = (fz_r < self._tw_fs_arm_n, fz_l < self._tw_fs_arm_n)
|
|
1118
|
+
rew = self._reward(a_sum / self.SUBSTEPS, x_prev0, q_prev0)
|
|
1119
|
+
if self.latent_task is not None:
|
|
1120
|
+
self.latent_task.advance() # the command for the NEXT step, after this step's reward
|
|
1121
|
+
obs = self._obs()
|
|
1122
|
+
finite = (torch.isfinite(self.q).all(dim=0) & torch.isfinite(self.qd).all(dim=0)
|
|
1123
|
+
& torch.isfinite(self.lce).all(dim=0) & torch.isfinite(self.a).all(dim=0)
|
|
1124
|
+
& torch.isfinite(self.z).all(dim=0))
|
|
1125
|
+
# NaN-POISONING GUARD: a rare per-substep physics divergence can leave a handful of envs'
|
|
1126
|
+
# q/qd/lce non-finite for exactly this one terminal step (they are flagged `done` below via
|
|
1127
|
+
# ~finite and reset immediately after, so this transient garbage is never seen again). Left
|
|
1128
|
+
# unmasked, that NaN/Inf reward/obs enters the batch RunningMeanStd.update() (nets_shac.py,
|
|
1129
|
+
# a plain arr.mean(dim=0)) and PERMANENTLY corrupts the running mean/var for every other
|
|
1130
|
+
# (healthy) env from that point on, and/or NaNs the aggregate return/loss for the whole
|
|
1131
|
+
# rollout -- observed as a sudden, irreversible ret=nan/vloss=nan (see
|
|
1132
|
+
# fullbody-imitation-sink-lurch-localmin). Zero the reward/obs ONLY for the non-finite rows;
|
|
1133
|
+
# this doesn't hide the divergence (finite/done still flags + resets it every time, and
|
|
1134
|
+
# extra["term_nonfinite"] below still counts it), it only stops one terminal garbage value
|
|
1135
|
+
# from statistically poisoning the other N-1 envs in the batch.
|
|
1136
|
+
# sync-free: run the mask UNCONDITIONALLY (no-op / bit-identical when all-finite) so there is NO
|
|
1137
|
+
# per-step bool(finite.all()) host-sync -- lets the CPU run ahead of the GPU and is a prerequisite
|
|
1138
|
+
# for CUDA-graph capture of the step. (The rare non-finite row is still masked + flagged/reset below.)
|
|
1139
|
+
rew = torch.where(finite, rew, torch.zeros_like(rew))
|
|
1140
|
+
obs = torch.where(finite.unsqueeze(1), obs, torch.zeros_like(obs))
|
|
1141
|
+
if self.LATENT:
|
|
1142
|
+
# the posterior block of the state `obs` describes (before any reset), for the critic's V(s') bootstrap at
|
|
1143
|
+
# a truncation; non-finite rows zeroed exactly as the observation's
|
|
1144
|
+
lref = self._latent_ref_features(self.q, self.phase)
|
|
1145
|
+
lref = torch.where(finite.unsqueeze(1), lref, torch.zeros_like(lref))
|
|
1146
|
+
if self.latent_task is not None:
|
|
1147
|
+
# the command block of the state `obs` describes (before any reset, after this step's command advance), for
|
|
1148
|
+
# the critic's V(s', g') at a truncation; non-finite rows zeroed exactly as the observation's
|
|
1149
|
+
tobs = self.latent_task.obs(self.q)
|
|
1150
|
+
tobs = torch.where(finite.unsqueeze(1), tobs, torch.zeros_like(tobs))
|
|
1151
|
+
bad_height = (self.q[2] < self.TERM_Z) | (self.q[2] > self.HIGH_Z)
|
|
1152
|
+
if self.taskwalk is not None:
|
|
1153
|
+
# COM height ABOVE THE LOWER FOOT, the authors' test. The absolute-height gate cannot be
|
|
1154
|
+
# used under the slope curriculum: an env on a +5 degree ramp legitimately climbs.
|
|
1155
|
+
bad_height = getattr(self, "_tw_fell", torch.zeros_like(bad_height))
|
|
1156
|
+
toppled = self._upright() < self.UPRIGHT_MIN
|
|
1157
|
+
if self.E0_TERM == "mm": # MuscleMimic's deviation-only termination (above): no height, no upright
|
|
1158
|
+
bad_height, toppled = torch.zeros_like(bad_height), torch.zeros_like(toppled)
|
|
1159
|
+
diverged = self.qd.abs().max(dim=0).values > self.QD_MAX
|
|
1160
|
+
timeout = self.progress >= self.episode_length
|
|
1161
|
+
# LANE TERMINATION (Bolt's env_lanes._get_terminated; TASKWALK_LANE_HALF_W, on the root). Only the myoLeg26
|
|
1162
|
+
# env applied it until 2026-09-28: this env read the knob and never used it, so the two full-body Bolt cells
|
|
1163
|
+
# ran with the lane off while their env files said 0.6. Off (0) is bit-identical.
|
|
1164
|
+
out_of_lane = torch.zeros_like(timeout)
|
|
1165
|
+
if self.taskwalk is not None and self.TW_LANE_HALF_W > 0.0:
|
|
1166
|
+
out_of_lane = (self.q[ROOT_LAT] - self._tw_lane0).abs() > self.TW_LANE_HALF_W
|
|
1167
|
+
stepfail = torch.zeros_like(timeout)
|
|
1168
|
+
if getattr(self, "_tw_fs", None) is not None:
|
|
1169
|
+
stepfail = self._tw_fs_fail # DeepLoco's step fail: the foot landed > TASKWALK_STEP_FAIL_DIST from its target
|
|
1170
|
+
# WHOLE-CLIP END (imitation of a loop=False clip): the reference has no frame past this step's, so the
|
|
1171
|
+
# episode ends here as a TRUNCATION. It joins `timeout` in episode_end below, which is exactly the flag
|
|
1172
|
+
# the trainers bootstrap V(s') on (sapo_vec: boot = done & episode_end), so it is valued like a time
|
|
1173
|
+
# limit and never like a fall. Applies in eval too: there is no target to track past the clip.
|
|
1174
|
+
clip_end = torch.zeros_like(timeout)
|
|
1175
|
+
if self.imitation and self.imitation_task.any_nonloop and self.latent_task is None: # the task tracks no clip
|
|
1176
|
+
clip_end = self.imitation_task.clip_end(self.phase, self.SUBSTEPS * self.dt)
|
|
1177
|
+
if self.ET_MODE == "mvae_head":
|
|
1178
|
+
head_term = torch.zeros_like(timeout)
|
|
1179
|
+
if not self.eval_mode:
|
|
1180
|
+
with torch.no_grad():
|
|
1181
|
+
err = self.imitation_task.head_height_error(self.q.detach(), self.phase)
|
|
1182
|
+
self._head_cnt = torch.where(err > self.HEAD_ET_TH, self._head_cnt + 1, (self._head_cnt - 1).clamp_min(0))
|
|
1183
|
+
head_term = (self.progress > self.HEAD_ET_MIN) & (self._head_cnt >= self.HEAD_ET_CNT)
|
|
1184
|
+
switching = False # training only: a readout tracks one clip
|
|
1185
|
+
if self.ET_MODE == "mvae_head" and not self.eval_mode: # a readout keeps the plain gates its survival count is read by
|
|
1186
|
+
done = (~finite) | diverged | timeout | head_term | clip_end | stepfail
|
|
1187
|
+
else:
|
|
1188
|
+
done = (~finite) | bad_height | toppled | diverged | timeout | out_of_lane | clip_end | stepfail
|
|
1189
|
+
desync = torch.zeros_like(done)
|
|
1190
|
+
snapped = torch.zeros_like(done)
|
|
1191
|
+
# imitation desync ET is TRAINING-only (eval measures SUSTAINED behavior), and off in the latent task phase,
|
|
1192
|
+
# which tracks no reference
|
|
1193
|
+
if self.imitation and not self.eval_mode and self.latent_task is None and not self.ET_MODE:
|
|
1194
|
+
desync = self.imitation_task.desync_mask(self.q, self.phase, self.q[ROOT_HEIGHT], self._train_steps) # sustained behavior via the fall gate
|
|
1195
|
+
desync = desync & ~wrapped # env applies ~wrapped (skip the non-loopable clip seam)
|
|
1196
|
+
done = done | desync
|
|
1197
|
+
|
|
1198
|
+
# DIAGNOSTIC (freeloader-basin instrumentation, see fullbody-imitation-sink-lurch-localmin):
|
|
1199
|
+
# per-reason termination masks + the progress value AT termination (before reset() zeroes it),
|
|
1200
|
+
# so a caller can build a termination-reason histogram and completed-episode-length distribution
|
|
1201
|
+
# without touching the reward/training math. Zero cost when unused (extra dict entries only).
|
|
1202
|
+
extra = {"obs_before_reset": obs, "episode_end": timeout | clip_end,
|
|
1203
|
+
"progress_at_done": self.progress.clone(), "term_nonfinite": ~finite,
|
|
1204
|
+
"term_bad_height": bad_height, "term_lane": out_of_lane, "term_toppled": toppled, "term_diverged": diverged,
|
|
1205
|
+
"term_timeout": timeout, "term_clip_end": clip_end, "term_desync": desync, "term_snapped": snapped, "term_stepfail": stepfail,
|
|
1206
|
+
"cfnorm": (self.sim.contact_force(self.q.detach(), self.qd.detach(), self.z.detach())[1].norm(dim=0)
|
|
1207
|
+
if self._emit_cfnorm else torch.zeros(self.q.shape[1], device=self.device))} # per-env GROUND-CONTACT-FORCE magnitude (AHAC per-env-cut signal); z alone is the tangential-stiction accumulator (0 when stiction off), so use the real contact_force GRF
|
|
1208
|
+
if self.LATENT:
|
|
1209
|
+
extra["latent_ref_before_reset"] = lref
|
|
1210
|
+
if self.latent_task is not None:
|
|
1211
|
+
extra["latent_task_obs_before_reset"] = tobs
|
|
1212
|
+
if getattr(self, "_tw_tlog", None) is not None: # TASKWALK_LOG_TERMINALS (task_walk_env): the in-graph terminal census, detached
|
|
1213
|
+
self._tw_term_accumulate(done, bad_height, toppled, diverged, timeout, rew)
|
|
1214
|
+
return rew, done, extra, switching, None, timeout
|
|
1215
|
+
|
|
1216
|
+
def detach_envs(self, mask):
|
|
1217
|
+
"""Per-env BPTT truncation (AHAC per-env cut): detach the differentiable state (q/qd/lce/z/a) for
|
|
1218
|
+
the `mask` envs WITHOUT resetting them -- the physical trajectory continues but the pathwise
|
|
1219
|
+
gradient stops here for those envs. The state (not the obs) is the BPTT carrier (q_{t+1}=f(q_t)).
|
|
1220
|
+
|
|
1221
|
+
NO `if mask.any()` early-out: reading a device tensor on the host is a full sync, once per step of
|
|
1222
|
+
every rollout, on an engine whose step is launch-bound. torch.where is already a no-op for an
|
|
1223
|
+
all-False mask, so the guard bought nothing and cost a pipeline stall -- and at the pec_C values we
|
|
1224
|
+
actually run (cut ~2-20%) the mask is almost never all-False, so it never short-circuited either."""
|
|
1225
|
+
m = mask[None, :] # (1,n) broadcast over the leading state dim
|
|
1226
|
+
self.q = torch.where(m, self.q.detach(), self.q).contiguous()
|
|
1227
|
+
self.qd = torch.where(m, self.qd.detach(), self.qd).contiguous()
|
|
1228
|
+
self.lce = torch.where(m, self.lce.detach(), self.lce).contiguous()
|
|
1229
|
+
self.z = torch.where(m, self.z.detach(), self.z).contiguous()
|
|
1230
|
+
self.a = torch.where(m, self.a.detach(), self.a).contiguous()
|
|
1231
|
+
if self.decision_every > 1: # Amendment 16: and the held action (a cut world's next held step)
|
|
1232
|
+
self._dr_held = torch.where(mask[:, None], self._dr_held.detach(), self._dr_held).contiguous()
|
|
1233
|
+
if self.taskwalk is not None:
|
|
1234
|
+
self.taskwalk.detach_history(mask) # the same cut for the reward's attached COM sample
|
|
1235
|
+
if getattr(self, "musclepd", None) is not None: # and for the PD rate's attached previous fibre length
|
|
1236
|
+
self._pd_lce_prev = torch.where(m, self._pd_lce_prev.detach(), self._pd_lce_prev).contiguous()
|
|
1237
|
+
# and for TASKWALK_LCE_DOT_COUPLED's attached `lce` (ported from GpuMyoLeg26VecEnv.detach_envs)
|
|
1238
|
+
if getattr(self, "_tw_lce_prev_graph", None) is not None:
|
|
1239
|
+
self._tw_lce_prev_graph = torch.where(mask[None, :], self._tw_lce_prev_graph.detach(),
|
|
1240
|
+
self._tw_lce_prev_graph).contiguous()
|
|
1241
|
+
self._tw_lce_fresh = self._tw_lce_fresh | mask
|